Friday, July 31, 2015

The road to reinvention Book Summary continued from a few posts earlier
One of the reasons that Polaroid tumbled down to bankruptcy was that its leaders were resisting change especially after a historic success against rival Kodak. Instead of opening up new possibilities of innovation, the company seemed to narrow its tunnel vision. Each suggestion was stonewalled with the objection “We can’t do that. We can’t cannibalize our core business!” 
In their version of the world, survival is the only goal; forget about growing and thriving. Regardless of our industries and no matter how powerful our organizations may be, we can’t prevent disruption. Instead of sprinting towards cannibalization, it left the opportunity on the table to be seized by a newcomer Instagram that ironically was popular to make digital photos resemble like old polaroids. 
A good litmus test to ensure you H.O.S.E the competition by delivering a new product or service is  
  1. High Value : Unless it solves a real problem in a meaningful way, forget about it. 
  1. Original: Keep your offering uniquely so it always stands out 
  1. Significant:  Go big by breaking the mold of the past and launching something that truly matters. 
  1. Emotionally Charged: If your product evokes passion, customers will line up to buy. 
Contrast the example above with that of Quicken loans which at the peak of its success wanted to make a successful reinvention for a far bigger impact. And it did. Quicken loans grew the business from an  already record high 30 billion in loans to 70 billion in loans by applying to technology to serve customers better and no product innovation. 
Operational Innovation, coined by Michael Hammer, is the concept of overhauling the way a company does business in an effort to create a significant competitive advantage. In essence, it rewrites the rules of the game. To kick off operational change, do the following: 1) make the case for a change 2)set an audacious goal, 3) do a friction audit, 4) bypass who for what and 5) borrow ideas from other industries. 
Create vivid experiences says the author of this book. And he gives the example of running a karate studio by connecting the customers sense to with the details of the whole company. He calls it the Five Senses test. One thing he notes from how the customers feel, hear, see, taste or smell in your business is to keep it consistent because even if you do 99 % of things perfectly. It’s the 1 percent mismatch that people will most remember. 
Nick Morgan is a master storyteller who has written memorable and inspiring speeches for elected officials. There are five kinds of stories that can help you drive your audience to act. These are: 
Quests:  These begin with ordinary people in an ordinary situation and takes them to a goal which may not be logical but it is believable and that’s why its powerful 
A strange land: The heroes suddenly find themselves in a new landscape, one with an unknown terrain, language or rules. A master then helps us to not only survive but thrive. 
Love Stories : Two people fall in love, fall out and find love again. This is the right story for people to get along better. 
Rags to riches stories: These help us believe that ordinary people still have a chance to succeed in a society that seems stacked against us 
Revenge stories: These stories reassert the order that society all too often fails to provide 
By applying these basic patterns, you can use storytelling effectively. 
Stories are only good only when they are delivered. 
  1. Keep it simple : Make your communications dead simple for anyone who reads it. 
  1. Make it clear : Expunge vagueness, ambiguity and imprecision 
  1. Speak to your audience, not yourself: Expunge vagueness, ambiguity and imprecision 
  1. Keep it brief : “be bold, be brief, be gone” 
  1. Make it memorable : People will remember stories and feelings far more than details and figures. 
  1. Activate with action: Start with the end goal in mind, and make sure your communications all lead to the desired outcome. 
#codingexercise
Double 
GetProductNthEveryFifthPower (Double [] A, Double  p)

{

If ( A== null) return 0;

Return A.GetProductNthEveryFifthPower(p);

}




1 / 1

This is a continuation of the interview question and answers on binary trees:

1) Question: Given a binary tree, create its mirror image:

Solution:

Void Mirror (Node root)

{

 if root == null return;

 var temp = root.left;

 root.left = root.right;

 root.right = temp;

 Mirror (root.left);

 Mirror(root.right);

}

2) Determine if a binary tree is symmetrical?

Bool isSymmetrical(Node root)

{

 Node clone = MakeCopy(root);

 Mirror(clone);

 isSymmetrical(root, clone);

}

IsSymmetrical (Node root, Node mirror)

{

 if (root == NULL && mirror == NULL) return true;

 if (root == NULL || mirror == NULL) return false;

 if (root.data != mirror.data) return false;

 return IsSymmetrical(root.left, mirror.right) && IsSymmetrical(root.right, mirror.left);

}

Thursday, July 30, 2015

Simplex Algorithm (discussion continued from previous writeup)
We saw that the Simplex can be started at the origin and we know what to do if we are at the origin. But if our current vertex u is elsewhere. The trick is to transform u into the origin.And we shift the entire co-ordinate system from x1, x2, .. xn to  the local view from u and denoted by y1, y2 … yn to the n hyperplanes that define and enclose u. Specifically, if one of these enclosing inequalities is a.xi <= b, then the distance from a point x to the particular “wall” is yi = bi – ai.x

The n equations  of this type, one per wall, defines the yi’s as linear functions of xi’s and this relationship can be inverted to express the xi’s as a linear function of the yis. Thus we can represent the entire LP in terms of they y’s.

By shifting the co-ordinate system we don’t change anything from the earlier optimal value but the objective function does change. The transformations include:
1)   the inequalities y >= 0, which are simply the transformed versions of the inequalities defining u
2)   u itself is now the origin
3)   The cost function becomes max cu + transformed-cost-vector. y


The simplex algorithm is now fully defined. It moves from vertex to neighbouring vertex stopping when the objective function is locally optimal. At this point, the coordiantes of the local cost vector are all zero or negative. A vertex with this property must also be globally optimal.
The Simplex algorithm: 
This algorithm solves a linear program -  set of linear equations. It takes a set of linear inequalities and a linear objective function and finds optimal feasible point by the following strategy. 
  1. Find a vertex v in the feasible region 
  1. While there’s a neighbor v’ of v with better objective value: set v = v’  
A linear equation involving the n dimensions defines a hyperplane when plotted in an n-dimensional space and the corresponding linear inequality defines a half-space, all  points that are precisely hyperplane or lie on one particular side of it. The feasible region of a linear program specified by a set of inequalities is the intersection of the corresponding half-spaces, a convex polyhedron.  
But what do the concepts of vertex and neighbor mean in this general context. Each vertex is the unique point at which some set of hyperplanes meet. 
Each vertex is specified by a set of n inequalities. 
Two vertices are neighbours if they have n-1 defining inequalities in common. 
On each iteration of the algorithm, the simplex has two tasks 
  1. Check whether the current vertex is optimal 
  1. Determine where to move next 
As we will see, both tasks are easy if the vertex happens to be at the origin. And if the vertex is elsewhere, we will transform the co-ordinate system to move it to the origin.  
When the origin is feasible, it is certainly a vertex, since it is the unique point at which the n inequalities are tight.  
The origin is optimal if and only if all ci <= 0 where ci is the contraint we try to maximize in each dimension 
If all ci <= 0, then considering  the constraints x >= 0, we can’t hope for a better objective value. Conversely if the origin is not optimal, we can improve one of the constraints. 
Thus for task 2 we can move by increasing some xi for which ci > 0. We can keep on increasing it until we hit another constraint. At that point we again have n tight inequalities and hence we arrive at a new vertex. 
For example, given the objective function max 2x1+5x2 
  1. 2x1-x2 <= 4 
  1. X1 + x2 <= 9 
  1. -x1 + x2 <= 3 
  1. X1 >= 0 
  1. X2 > = 0 
Simplex can start at the origin with inequalities 4) and 5). As x2 is gradually increased, the first constraint is met with equation 3 and therefore it stops at x2 = 3 and the new vertex is given by 3) and 4)  We converge towards the solution in the next step. 

#codingexercise
Double
GetProductNthEveryFourthPower (Double [] A, Double  p)
{
If ( A== null) return 0;
Return A.GetProductNthEveryFourthPower(p);
}

Tuesday, July 28, 2015

We will resume our book review from previous post shortly but first lets look into
Zero Sum games as described in Dasgupta et al 2006.
We represent various conflict situation in life by matrix games. The schoolyard game rock-paper-scissors is specified by the payoff matrix as illustrated here. There are two players called  Row and Column and they each pick a move from {r, p, s}. They then lookup the matrix entry corresponding to their moves, and Column pays row this amount.
For eg:
                G  =                                                                        Column
r
p
s
r
0
-1
1
p
1
0
-1
s
-1
1
0

                                                                Row
Let the two play the game repeatedly. If Row always make the same move, Column will quickly catch on because it will play the countermove, winning every time. So Row should mix things up. It can model by allowing row to have a mixed strategy, in which on each turn she plays r with probability x1, p with x2 and s with x3. This strategy is represented by a vector x and similarly Column’s strategy is represented by a vector y.

On any given round, there is an xi, yj chance that Row and Column will play ith and jth moves. The expected average payoff is Sigma(I,j) Gij.Prob(xi,yj) which is equal to

Sum-over-I-and-j (Gij.xi.yj)
Since its Rows gain and Columns loss, Row wants to maximize and Column wants to minimize it.
If Row plays the completely random strategy where xi is each 1/3 and if column plays r, then the expected payoff is the weighted average 1/3*0+1/3*(1)+1/3(-1) = 0 Thus by playing the completely random strategy, row forces an expected payoff of zero, no matter what column does. This means that the column cannot get a negative payoff. Symmetrically, column can play the same and force Row to have a zero payoff.
Thinking about this differently, lets review the following two cases:
First, row announces her strategy, and then Column pick his.
First, column announces his strategy, and then Row chooses hers.
Now we would expect the player going next to fully exploit the known strategy of the first to get the desired payoff. But this is amazingly not the case. If both play optimally, then it doesn’t hurt a player to announce his or her strategy in advance. This remarkable property is a consequence of – and in fact equivalent to – linear programming duality.

(The duality theorem is mentioned this way: If a linear program has a bounded optimum, then so does its dual, and the two optimum values coincide   

To visualize duality, we imagine a string connecting the nodes that is stretched taut. In other words, the dual problem is to stretch s and t as far apart as possible, subject to the constraint that the endpoint of any edge {u,v} are separated by a distance of at most Wuv) 

Imagine a presidential election scenario, in which there are two candidates for office, and the moves they make correspond to campaign issues on which they can focus (the initials stand for economy, society, morality, and tax cut). 

The payoff entries are millions of votes lost by Column. 

G                m             t 

        e         3             -1 

        s         -2             1 

If Row announces that she will play the mixed strategy of x = (½, ½ ), what should the column do ? Since m incurs loss of ½ and t incurs loss of 0, Column should have a pure strategy of (0,1) 

This can be generalized to Pick (x1, x2) that maximizes min (3x1-2x2, -x1 + x2) which is the payoff from Column's best response to x. 

This choice of xi's gives Row the best possible guarantee about her expected payoff. And we 

will now see that it can be found by an LP! The main trick is to notice that for fixed x1 and x2 

the following are equivalent: 

z = min(3x1 - 2x2, -x1 + x2) 

max z 

z  <= 3x1 -2x2 

z   <= -x1 + x2 

and row needs to choose x1 and x2 to maximize this z 

max z 

-3x1 + 2x2 + z < = 0 

x1 -x2 + z <= 0 

3 / 3

x1 + x2 = 1 

x1,x2 >= 0 


Symmetrically we can compose the linear equations in terms of y 

and the critical observation is that these two LPs are dual to each other. 

#codingexercise

Double

GetProductNthEveryThirdPower (Double [] A,Double  p)


{


If ( A== null) return 0;


Return A.GetProductNthEveryThirdPower(p);


}