Sunday, January 15, 2017

Aesthetics in design improve the appeal of the product. Indeed, top designers look to improve products based on some of the following virtues:
1) mastery of complex systems and self-assembly
2) passion for versatility
3) redesign in a positive and constructive way
4) knack for making information clear and engaging
5) metaphysical appreciation of bodily functions
6) infusing objects with elegance and intelligence
But how much do we really enhance a tool to make it appealing enough for daily use ? We don’t think twice about using our toothbrush while sophisticated tooth brushes like the sonic toothbrush has also become mainstream. Furthermore, from forks, fidbits to cars, gadgets have been increasingly measuring every activity we do and becoming intelligent in making efficiencies in our habits. With the internet of things, IoT, a jargon used often to refer to connectivity to the internet for appliances and gadgets, these same measurement and data find their way from small devices to cloud based services and eventually to our smartphones giving us a rich experience of knowing even more about what we do and how to do it better.
But when does a HAPIfork that can monitor how quickly we are eating and signal us to slow down become enough that we reach for the drawer and get the old fashioned fork out? In fact, user experience talks to the art of demanding just the right amount of attention from the user and being polite and enticing to the user to get their tasks done as easily as possible.
With the social engineering applications such as Facebook, Twitter etc and their ecosystems allowing the devices and applications to share information and tap into the peer pressure for punishing and rewarding certain behaviors taking the devices from becoming smart and connected to the next level of reaching out to your friends. The application BinCam was about making your recycling behavior visible to your circle to reward responsible behavior.
This is a new trend of re-inventing social engineering as product engineering and even arguably advertising. From smart glasses to smart forks, “Smart” in Silicon Valley for example is the shorthand for transforming the convention with a disdain for the poor souls who haven’t upgraded.
But what really is a balance between the an old fork and a smart connected fork? There in seems to be the feng shui of design which can tip between good “smart” and bad “smart”. While most people can immediately relate to the two ends of spectrum between what is helpful and appreciable and the other overwhelming or resulting in premature balding, there is a far more troublesome and complicated story when all the perspectives fall into the picture. From designer, advertiser, business etc all the way to the enduser, each one has a different meaning to what is good and what is bad. There doesn’t seem to be a panacea that can be strived for in the end product but yes a common ground would almost always be welcome. There may still be concerns such as privacy and verbose information but they can be alleviated with technology and standards borrowed from realms involving the bigger world such as computers and clouds.
Among all these concerns, perhaps the closest one that I find unequivocally alluring in almost all domains is the notion of quality assurance. A product, simple or sophisticated, can be a joy to use so long as it can earn the trust of its user. The reliability and accuracy comes from quality control. Hand in hand with this working formula is the notion of minimalist design.  Minimalistic design embraces the idea that less is more. The adage goes that the most important thing for an application is not what it does, but what users think it should do. Creating not just a clear map between purpose and function but also a clever map that strikes a chord with the user, then seems to be the right approach from a product design perspective that can withstand the forces exerted by the different players around the product from business to consumer.
There’s a lot more debate and some hugely popular with TED talkers but I just present a short list in the reference together with my understanding above.
Reference:
1) http://www.intelligencesquaredus.org/debates/smart-technology-making-us-dumb
2) http://gizmodo.com/5918045/why-smart-people-are-actually-dumb
3) http://www.newyorker.com/tech/frontal-cortex/why-smart-people-are-stupid
4) https://www.fastcodesign.com/3027943/innovation-by-design/berg-wants-to-be-the-platform-to-make-any-dumb-appliance-smart
5) https://www.mirumagency.com/blog/when-dumb-design-smart-tech-companies-find-minimalism-leads-success-0

6) Are smart gadgets making us dumb ? http://www.wsj.com/articles/SB10001424127887324503204578318462215991802


#codingexercise
List<int> AddTwoLists(List<int> a, List<int> b)
{
Var num1= a.ToDouble();
Var num2 = b.ToDouble();
Var sum = (a + b);
Return sum.ToList();
}
List<int> AddTwoListsDetailed(List<int> a, List<int> b)
{
Int k = a.Count + b.Count - 1;
Var ret = new List<int>(k){0};
Int I = a.Count - 1;
Int j = b.count - 1;
Int carryover = 0;

While ( I >= 0 && j >= 0)
{
Var sum = a[i] +b[j] + ret[k] + carryover;
ret[k] = sum%10;
Carryover = sum/10;
i--;
j--;
k--;
}
While( I >= 0)
{
Var sum = a[i] + ret[k] + carryover;
ret[k] = sum%10;
carryover = sum/10;
i--;
k--;
}
While( j >= 0)
{
Var sum = b[j]+ ret[k] + carryover;
ret[k] = sum%10;
carryover = sum/10;
j--;
k--;
}
While(carryover)
{
Ret[k] = carryover%10;
Carryover /= 10;
k--;
}
Return ret;
}
It can be shown that the sum of two numbers cannot have more digits than both of them combined which is why we allocate and initailze a list of zeros to store the sum.

Saturday, January 14, 2017

We continue discussing the paper by Papadimitriou  - Algorithms, Games and Internet. We started with Nash equilibrium and then we discussed Internet Equilibria. We viewed the latter in terms of multi commodity flow network where the maximum total flow in a subgraph is in the core of a coalition game. we saw the definition of core to hint at optimal set. Next we looked at markets.  Markets are known for price equilibrium. and then we discussed mechanism design problems.

Next we discussed privacy and clustering.  Then we reviewed web-graph. 
The web graph is considered as a directed graph with the documents as nodes and the hyperlinks as edges but it is notoriously different from a classical graph.The deviations from classical graph have prompted many other efforts to model the web graph. One such approach is the heavy tailed distribution which is interesting because it seems to have parallels in other domains.  The population of xth largest city of any country is cx^(-1) with c depending on country. 
 The xth largest indegree or outdegree in a web graph is about c.x^(-alpha) where c and alpha are positive instead of the Gaussian predicted by the law of large numbers.

#codingexercise
/* Multiply contents of two linked lists */
double multiplyTwoLists (Node first, Node second)
{
    double num1 = 0;
    double num2 = 0;
    while (first != null || second != null)
    {
        if(first != null){
            num1 = num1*10 + first.data;
            first = first.next;
        }
        if(second != null)
        {
            num2 = num2*10 + second.data;
            second = second.next;
        }
    }
    return num1*num2;
}

double multiplyTwoLists(List<int> first, List<int>second)
{
var ret = new List<int>(first.count+second.count){0};
int iteration = 0;
for (int i = second.count()-1; i >=0; i--)
{
int multiplier = second[i];
int carryover = 0;
int j  = ret.Count  - 1 - iteration;
for (int k = first.count()-1;k >=0; k--)
{
var product = first[k]*second[i];
product += ret[j];
product += carryover;
var value = product %10;
ret[j] =value;
carryover = product / 10;
j--;
}
If ( I ==0)
{
While(carryover)
{
Ret[j]= carryover%10;

Carryover /= 10;
J--;
}
}
iteration++;
}

return ret.ToNumber();
}
List<int> multiplyTwoLists(List<int> first, List<int> second)
{
Double num1 = first.ToDouble();
Double num2 = second.ToDouble();
Double result = num1 x num2;
Return result.ToList();
}

Friday, January 13, 2017

We continue discussing the paper by Papadimitriou  - Algorithms, Games and Internet. We started with Nash equilibrium and then we discussed Internet Equilibria. We viewed the latter in terms of multi commodity flow network where the maximum total flow in a subgraph is in the core of a coalition game. we saw the definition of core to hint at optimal set. Next we looked at markets.  Markets are known for price equilibrium. and then we discussed mechanism design problems.

Next we discussed privacy and clustering.  Today we review web-graph. The web graph is considered as a directed graph with the documents as nodes and the hyperlinks as edges. However it violates the principles of classical graph models. For example its indegrees and outdegrees of the nodes are distributed by a polynomial tailed distribution. The xth largest indegree or outdegree is about c.x^(-alpha) where c and alpha are positive instead of the Gaussian predicted by the law of large numbers. Its giant strongly connected components cover only 40% of the nodes instead of all or none. Also, there are scores of K3,3 subgraphs instead of none. A K3,3 graph is a complete bipartite graph of six vertices usually illustrated with two subsets of three nodes and  edges joining every vertex in one subset with another. The deviations from classical graph have prompted many other efforts to model the web graph. However no model comes close to satisfactorily explaination One model called the heavy tailed distributions is interesting because it seems to have parallels in other domains.  The population of xth largest city of any country is cx^(-1) with c depending on country. The market share of xth largest manufacturer in any sector is c.x^(-alpha) A document's indegree is determined by how interesting the document is and intuitively analogous to market share while outdegree depends on the entity's attention which is not very different from income. The heavy tailed distributions are also observed beyond the world wide web such as the degrees of routers and autonomous systems.


#codingexercise
Yesterday we showed that the optimum way of clustering into k segments of a demand curve is O(n^2)
Today we show that this can be done with dynamic programming. If the price is x, the ith customer will buy a quantity y = (bi-ai)x. The k segments are determined by increasing values of ai/bi.
int GetOptimumRevenueDP(int a, int b, int u, int i, int k, List<Customer>customers)
{
if (n == 1){assert(a <= u && u <= b);
            return minimum (Revenue (u,b) + Revenue(a,u));
}
return minimum(Revenue(u,b) + GetOptimumRevenue(a,b,u,n-1,k,customers);
}


Courtesy: https://www.rand.org/content/dam/rand/pubs/research_memoranda/2008/RM2978.pdf

Palindrome partitioning
find the minimum number of partitions for partitioning a string into palindromes.
int GetMinPartitions(String str, int i, int j)
{
if (i ==j ) return 0;
if (IsPalindrome(str.GetRangeBetween(i,j))/ return 0;
int min = int_max;
for (int k = i; k <=j-1; k++)
{
int val = GetMinPartitions(str, i, k) + 1 + GetMinPartitions(str, k+1, j);
if (val < min)
   min = val;
}
return min;
}
all non palindromes have an upper limit for the partitions as the number of characters in the string

Thursday, January 12, 2017

We continue discussing the paper by Papadimitriou  - Algorithms, Games and Internet. We started with Nash equilibrium and then we discussed Internet Equilibria. We viewed the latter in terms of multi commodity flow network where the maximum total flow in a subgraph is in the core of a coalition game. we saw the definition of core to hint at optimal set. Next we looked at markets.  Markets are known for price equilibrium. and then we discussed mechanism design problems.

Today we discuss privacy, clustering and the web-graph. Privacy is important enough that in Computer Science we have standards to safeguard it. Privacy is endangered when the decisions about the use of personal information are made by the entities other than the person involved. These anomalies are called extranalities and are often considered the root cause of trouble. Personal information is said to be intellectual property that bears negative royalty. Coalition game theory can be used as a modeling tool in this case as well. The outcomes are the fair royalty due to the individual and this model has interesting algorithmic problems.

Clustering is yet another important domain of use for game theory. Although its widely practiced, it does not have the strict foundation as other areas because they are far too many criteria for the goodness of a clustering. There are many ways to come up with clusters and little guidance to choose between them. Economic  The author states that economic considerations are crucial for understanding the issues here as well.  Clustering strives to improve decision making by allowing different segments of space to be treated differently which is a domain of novel optimization problems called segmentation problems.

To take an example of such a study of clustering, the author cites how a monopolist would want to cluster its customers into k segments of a demand curve, with a different price to each segment, in order to maximize revenue. The clustering that maximizes revenue subdivides the customers into segments of consecutive values  of ai/bi. where a and b are customer boundaries and i ranges from 1 to k. The optimum can be computed in O(n^2) by dynamic programming. 

int GetOptimumRevenueFrom(n, a, b, customers)
{
int ratio = a/b
double val = 0;
var clusters = new List<double>()
for (int i = 0; i < n; i++)
{
val += ratio/n;
clusters.Add(val);

}
return GetOptimumRevenue(clusters, n, a, b);
}
double GetOptimumRevenue(clusters,n, a,b, customers)
{
for (int i = 0; i < customers.count; i++;)
      classify(customers[i], clusters);
double revenue = 0;
for (int k =0; k < n; k++)
 {
      revenue += customers.select(x => x.label == clusters[k]).count()*PriceQuantity(clusters[k]);
  }
return revenue;
}
clustering is iterative and we can employ any similarity measure

Wednesday, January 11, 2017

Today we continue discussing graphical user interface for DRAC access :
As a recap, DRAC stands for DELL Remote Access Controller. It is an out-of-band management platform on certain DELL servers There are salient features : First, it is an out of band management mechanism and the default server resource and operating system does not matter. Second, it comes as an expansion card on the server or an integration to the main board and as such is dedicated to the server.
The virtual console feature of the DRAC enables you to access the local console remotely in either graphic or text mode. We discussed the benefits of text mode, but we now investigate graphic mode.
The graphical user interface to the virtual console is available from DRAC either as a java plugin or an ActiveX plugin but both cannot be opened simultaneously. A maximum of four simultaneous Virtual Console Sessions are supported for the same managed server console.  The first has full access and all others are granted sharing. A Virtual Console Session should not be launched from a Web browser on the managed system. iDRAC Virtual Console is available for linux too but must be switched to text mode.
For Java plugin, we have to enable Java content in the browser and add the drac ip address to the exceptions list. The plugin is downloaded as a JNLP file and its source is not open.
We can specify the plugin operations on a mac where we 1) filter finder items based on jnlp extension 2) we specify to automatically open the DRAC console and 3) we run the shell script as 
sed -e "s/\(.*\)/\"\1\"/" | xargs /usr/bin/javaws
The JNLP file may have hardcoded settings to connect to the DRAC which can be overridden. Different versions of DRAC may have different JNLP files.
The virtual console seems to run only with the following file dependencies:
1) avctKVM.jar
2) an old jre such as 1.7.0_80 from the Server JRE package downloaded and extracted to a local jre folder
3) lib/avctKVMIO.so for Linux and .dll for Windows
4) lib/avmWinLib.so for Linux and .dll for Windows
And the command required to run may then be 
./jre/bin/java -cp avctKVM.jar -Djava.library.path=./lib com.avocent.idrac.kvm.Main ip=$drachost kmport=5900 vport=5900 user=$dracuser passwd=$dracpwd apcp=1 version=2 vmprivilege=true "helpurl=https://$drachost:443/help/contents.html"


#codingexercise
Perform Trie insert and search

void Insert(TrieNode root, string key)
{
var current = root;
for (int level = 0; level < key.Length; level++)
{
   int index = CharToIndex(key[level]);
   if (current.children[index] == null)  // TrieNode has children[alphabet_size]
   {
         current.children[index] = InitializeNode();
   }
   current = current.children[index];
}
current.IsLeaf = true;
}


void search(TrieNode root, string key)
{
var current = root;
for (int level = 0; level < key.Length; level++)
{
      int index = CharToIndex(key[level]);
      if (current.children[index] == null)
          return false;
      current = current.children[index];
}
return (current != null && current.IsLeaf);
}

void PrintBoundariesOfABinaryTree(node root)
{
int max = 0;
PrintLeftView(root, 0, ref max);
PrintLeaves(root);
max = 0;
PrintRightView(root, 0, ref max);
// care must be taken to not print the leaves redundantly

}
// The above could be modified to pass in a list for the nodes.

Tuesday, January 10, 2017

Text or graphical user interface for DRAC access :
DRAC stands for DELL Remote Access Controller. It is an out-of-band management platform on certain DELL servers typically those that host Windows but by no means are restricted to just Windows.  There are two important things to note about DRAC
1) It is out-of-band.  The operating system on the server be it Windows or Linux does NOT matter.  It uses separate resources from the main server resources  for managing the server
2) It is dedicated to the server and provides access only to that server and not to any other server. Consequently the notion of serial port aggregator across multiple VMs  as from VMWare do not hold here.  This is specific to each hardware resource. The DRAC is available as an Expansion card or as an integrated controller on the motherboard in which case it's called iDRAC.

Furthermore, the access to this out-of-band server management platform is enabled over IP usually with the help of an SSH access. The RACADM command as well as the console session commands can both be issued at the same level over this vt100 text based terminal console  RACADM stands for Remote Access Controller Admin command that gives a set of commands for remote or local management of the managed system. The console session commands are for interaction with the managed system to its prompts. This remote management is done over the IP layer with the help of SSH access. 

The vt100 console typically provides the many Control Escape sequences some of which include:
Query Device code = Requests a Report Device Code response from the device.
Report Device code = Generated by the device in response to Query Device Code request.
Query Cursor position = Requests a Report Cursor Position response from the device.
Report Cursor position = Generated by the device in response to a Query Cursor Position request; reports current cursor position.
Reset Device = Reset all terminal settings to default.
Cursor Home  = Sets the cursor position where subsequent text will begin.
Cursor Up = Moves the cursor up by COUNT rows; the default count is 1.
Cursor Down = Moves the cursor down by COUNT rows; the default count is 1.
Cursor Forward  = Moves the cursor forward by COUNT columns; the default count is 1.
Cursor Backward  = Moves the cursor backward by COUNT columns; the default count is 1.
Scroll Screen = Enable scrolling for entire display.
Scroll Down = Scroll display down one line.
Scroll Up = Scroll display up one line.
Set Display Attributes Sets multiple display attribute settings. The following lists standard attributes:
Sets multiple display attribute settings. The following lists standard attributes:
0 Reset all attributes
:
Foreground Colours
30 Black
:
37 White

Background Colours
40 Black
:

47 White


The upshot is that the DRAC access over SSH enables console interaction in text mode using serial and telnet commands as done locally on the server. This enables quick and easy server management for the most routine management operations on the server and lends itself to easy automation given the ssh connectivity and text based interaction. More on configuring and using this access is provided in the DRAC manual here : http://www.dell.com/support/article/us/en/19/SLN285488 
The DRAC 5 console redirection feature enables us to access the local console remotely in either graphic or text mode. When we open a console redirection session, the Dell Virtual KVM Viewer Application starts and the remote system's desktop appears in the viewer. Using the Virtual KVM Viewer Application, we can control the system's mouse and keyboard functions from a local or remote management station. This is initiated with the "connect" command.

In addition to the ssh access, the browser based access is tightly coupled and provided by the manufacturer. It can be hosted as is in an iFrame on any client side application but requires the use of a java applet that demands additional security privileges from any browser. However, this is not as cost-effective to automate as the text based mode for the same routine management operations. Currently, there are very few KVM libraries that can be used directly as a client side technology for working with any remote based system including the DELL Remote Access Controller because most of it is proprietary. However, it is not impossible to reverse engineer the interactions between the Java applet and the remote access controller. That is why this is a more expensive route.
Moreover, the benefit of using ssh command is that we can now use ssh relay to access it from anywhere. we do this with the following command:
ssh -f user@drac_ipv4_address -L localport:jumpserver:remoteport -N

This way we only access the intermediary server for all DRAC ip address.

Additionally, we overcome firewall limitations in the cloud which makes it all the more desirable for ubiquitous but secure access.

#codingexercise
Print Right View of  Binary Tree

void RightView(Node root, int level, ref int max)
{
if (root == null) return;

if (max < level)
{
Console.Write("{0}", root.data);
max = level;
}
RightView(root.right, level + 1, ref max);
RightView(root.left, level + 1, ref max);
}

Print Left View of  Binary Tree

void LeftView(Node root, int level, ref int max)
{
if (root == null) return;

if (max < level)
{
Console.Write("{0}", root.data);
max = level;
}
LeftView(root.left, level + 1, ref max);
LeftView(root.right, level + 1, ref max);
}
these methods could also be used in conjunction with a method that prints leaves of the tree for finding the nodes on the boundary of the tree

Monday, January 9, 2017

We continue discussing the paper by Papadimitriou  - Algorithms, Games and Internet. We started with Nash equilibrium and then we discussed Internet Equilibria. We viewed the latter in terms of multi commodity flow network where the maximum total flow in a subgraph is in the core of a coalition game. we saw the definition of core to hint at optimal set. Next we looked at markets.  Markets are known for price equilibrium. and then we discussed mechanism design problems.

A mechanism is said to implement a social choice function if there is an equilibrium of the game induced by the mechanism that yields the same outcomes as the social choice function for each possible profile of types.  A social welfare mechanism implements a social choice function.  A direct revelation mechanism is a mechanism in which the strategies are truthful as per the type and all the functions are utility functions and the outcome  is directly the social choice function.  Enumerating all the social choice functions that are implementable is not easy. The revelation principle also tells us that  we can further restrict our attention to direct revelation mechanisms in which truth telling is an optimal strategy for each agent. A social choice function is truthfully implementable if the direct revelation mechanism has an equilibrium if the strategies are the types and the truth telling by each agent constitutes an equilibrium. As an example, a first price sealed bid auction is a truthful implementation of the social choice function

We can apply game theories to networking as well. In particular, we can view it as a coalition game with the total flow as the outcome. When we add an IP header over the original IP header payload and secure the communications between networks with IP tunneling, we are establishing a coalition and a different network.
           tunnel = IP (header) + IP (payload)
That is why we can overlay this game over any networking even if its for the cloud as mentioned here : https://1drv.ms/w/s!Ashlm-Nw-wnWqXUqaKP1HX09wuwo 


#codingexercise

Print the bottom view of a binary tree
void PrintBottomView(Node root)
{
if (root == null) return;
int hd = 0;
var d =  new SortedDictionary<int, int>();
var q = new Queue<Node>();
root.hd = 0;
q.enqueue(root);
while (q.empty() == false)
{
var first = q.front();
q.dequeue();
hd = first.hd;
d[hd] = root.data;
if (first.left != null)
{
first.left.hd = hd - 1;
q.enqueue(first.left);
}
if (first.right != null)
{
first.right.hd = hd + 1;
q.enqueue(first.right);
}
}
foreach (var kvp in d)
  Console.Write("{0} ", kvp.value);
}

Find the number of rectangles contained in a matrix of size m x n.
int GetCountRectangles(int m, int n)
{
int count = 0;
for( int i = 0; i < m; i++)
   for( int j = 0; j < n; j++)
{
     count += getWithTopLeft(i,j, 0, 0, m-1, n-1);
}
return count;
}
rectangles that start with top left as i,j span columns incrementally or span rows incrementally or both.
for( int i = 0; i < m; i++)

   for( int j = 0; j < n; j++)
{
var bottomright = new Tuple<int, int>(i,j);
}