Wednesday, November 26, 2008

The Magic Number SEVEN - Teasing our Memory

"And finally, what about the magical number seven? What about the seven wonders of the world, the seven seas, the seven deadly sins, the seven daughters of Atlas in the Pleiades, the seven ages of man, the seven levels of hell, the seven primary colors, the seven notes of the musical scale, and the seven days of the week? What about the seven-point rating scale, the seven categories for absolute judgment, the seven objects in the span of attention, and the seven digits in the span of immediate memory? For the present I propose to withhold judgment. Perhaps there is something deep and profound behind all these sevens, something just calling out for us to discover it. But I suspect that it is only a pernicious, Pythagorean coincidence. "

- Miller, G. A. (1956). The magical number seven, plus or minus two: Some limits on our capacity for processing information.

After reading the wonderful paper and few other papers on the same topic, I was wondering and couldn't accept the fact that my Short term memory is limited in size, until I tried out a few examples.

Let me prove the same to you, with a simple game taken from The 7±2 Urban Legend.

Slowly and steadily read the digits in a single row, out loud. At the end of each row close your eyes and try to repeat the sequence of digits back, in the same order. If you make a mistake go onto the next row. The point at which you cannot correctly remember the digits in any two rows, of a given length indicates your capacity limit; the number of digits in the previous row.


Why couldn't you complete the game?

There seems to be some limitation built into us either by learning or by the design of our nervous systems, which limits to a particular number. Confusions will appear near the point that we are calling his "channel capacity". Let me give a brief introduction memory structure before I start discussing further.

Memory system:

A common model of human memory divides it into two units; a short term memory and a long term memory. The short term memory is a limited capacity store for holding temporary information. The long term memory is usually treated as an infinite capacity store capable of holding information throughout a persons life.

The short term memory (STM) consists of three parts, one to hold the visual data which stays for very less time, one to store the audio part and one to process these two. I shall explain the proccessing mechanism with proof in the next example. Now the question is which part of STM goes into Permanent Memory? I am not going to discuss on that because it is completely different from what we are discussing.

Visual part -> Processing Part <- Audio part

But, I can answer another interesting question. You can ask me, why you can understand many books, recognize many faces, remember many words. But this does not constraint me on a number as small as 7±2.

Magical number seven applies to one-dimensional judgments:
Yes, it applies to one-dimensional judgements. When the activity is changed.

Testing the one dimensional judgement:

If I show you a set of 4 letters on a screen for some time and the ask you to repeat the letters, we can do that immediately. Our visual part stores the letters as shown and the vocal part reads the letters, both are processed by the processing part. If I ask the same letters after 1 hour, we forget. This proves that it is going into the STM. Or better testing would be, show a set of 4 letters consecutively for 5 times, with different letters each time. Remembering them immediately will be easy. But after 10 minutes, we forget. We forget it because it is there in the STM.

Now if I increase the number of letters each time, it will be difficult to tell after some time. This is when we reach the "channel capacity".

The coincidence between the input and understanding is covariance.

It may look like this:
At 4 alphabets:

At 7 Alphabets:

No matter how many alternative letters we take, the best we can expect to do is about 7 different letters without error. Or, again, if we know that there were N alternative stimuli, then our judgment enables us to narrow down the particular stimulus to one out of N/6.

There were many tests that were made. Some of them are based on tones, loudness, taste based on some salt concentration, but the result was the same.

For more than multi-dimensional tests:

When the 3-D space is taken, its totally different. Then there are different things coming into picture. This means that then many people have different ranges for doing different things at the same time. So the results differ. For e.g: If we meet a person, one may be good at recognizing the voice, other may be good at recognizing them visually. The test on this showed varied results. But numerically it was bigger than the one-dimensional one.

This happens because we have different ways of storing information. For e.g: If someone speaks in other languages that we don't understand, we start representing them in English and our STM gives its own representation. So, its easier to hold the information in 3-D space. This is the primary reason why we can recognize a sentence, even if our 1-D recognition is very less than what we assume.

Since the memory span is a fixed number of chunks, we can increase the number of bits of information that it contains simply by building larger and larger chunks, each chunk containing more information than before.For e.g: We hear and then form words and then organize them into large chunks. This is something like representation 9800048486 as 98-000-48-48-6.

Paradox of Choice ( from speeches by Prof. Barry Schwartz ):

When we are exposed to a list of choices, we actually believe that we are having more freedom and hence more satisfied. But experimental results have proved that satisfaction decreases when the choices cross the numeric value (7±2 in most cases). Let me prove this from one of the experiments take from "Paradox of choice - Barry Schwartz". There are quite many but let me put down one.

Jam Example:

Experiment was conducted in Supermarket, as most of the decision making experiments are conducted in Super markets. For marketing the imported Jams, there were 26 choices of jams being placed as samples to be tasted. The offer was, if they buy the jam immediately after tasting, there was 1$ discount. This increased the crowd and some of them bought the Jam after tasting.

The same experiment was conducted after a few days, where only 6 samples were placed and the offer was the same. The crowd was less compared to 26 choices and some of them bought the Jam.

The result (not obvious) was that out of Jams sold from 6 samples, only 1/10 was sold with 26 choices.

There are many reasons why the increasing the choice reduced the sale. Some are:

  • Regret of wrong choice: Most of the people are much worried about the wrong choice and since this feeling increases, they normally quit to take the choice.
  • Opportunity cost: We make a choice, then we start thinking about the features that we are missing in others. This reduces our satisfaction and hence we quit.
  • Increased Expectation: When the choices are more, expectations are more. And we start looking for the perfect ones.
  • Self Blame: When the choice is less and we make a choice and if something is wrong, we blame the producers. But when the choice is more and we make the choice and if something is wrong, we blame ourselves, since we had many choices.

One solution for making decisions may be categorizing or reducing the chunks. If the 26 Jams are categorized into 6 categories, the choice becomes less and all the above factors come down. Or the second one is to make an agent select the choices or taking the opinion poll. Like we google for the best imported jam and then we find the agent making choice for us based on the opinion of others who have used. Here we are not making the choice, but we are depending on the agent to make the choice. So, the above mentioned factors won't appear.

"We might argue that in the course of evolution those organisms were most successful that were responsive to the widest range of stimulus energies in their environment. In order to survive in a constantly fluctuating world, it was better to have a little information about a lot of things than to have a lot of information about a small segment of the environment. If a compromise was necessary, the one we seem to have made is clearly the more adaptive."

- George Miller

Monday, November 24, 2008

OOP - Basics of Object Orientation

OOP's, Its always too late to discuss about OOP. Its not mandatory that for any good design we follow OO. Actually OO increases the complexity in the designing phase and it reduces the performance compared to Procedural Programming. Having said that why do we follow OO. Its all for one word:
A good design is very simple like the nature. Its without any instuctions. Take Tree for example, we need not need any instructions, we see the nature and learn. We learn how to eat fruit or how to climb without any instuctions. So, in the process of representing the nature we started using OOP.

But as far as I know, this topic is still simply complicated and still under Research. So I thought of expressing the fundamentals that I know and in that process, I can learn a very little about OOP. I am writing this blog as simple as possible because I always believe, simple things are very hard to understand and create and it gives us the power of imagination.

The first question is, "What is an Object?".
Object has 3 things:

  • Identity
  • State
  • Behaviour

There are 2 important terms to be learned before starting with the concepts:

  • Invariable: The one that is known, that can be reused, abstract, which won't change
  • Variable: Which changes

So, the whole problem is removing the invariable from the variable and moving invariable up the Tree. This produces Shallow tree and which is more prefered than a Deep Tree.

For example:

  • CreateWindow
  • EditWindow
  • SaveWindow
  • CloseWindow

Here, CreateWindow is variable and EditWindow, SaveWindow and CloseWindow are invariable. Because CreateWindow can be called many times, but the EditWindow, SaveWindow and CloseWindow can be called on a particular instance of Window.

For OOP there 4 mandatory concepts:

  • Abstraction and Encapsulation
  • Implementing Encapsulation using Inheritance or Composability.


Abstraction is taking the Invariable part out of the Variable. A natural example may be Fruit. Apple exists and once eaten cannot be reused. But Fruit is something that cannot be eaten and that exists only in some form.


Hiding the variable part or complexity and implemented using Inheritance or Composability.


Composability is very dynamic. Its Composing/Delegating/Ordering. Like someone asks you for time. You see a watch/clock/mobile and then tell time. Here you are encapsulating the implementation, i.e, you are not inbuilt with time functionality. But, you are delegating it to a watch/clock/mobile and telling time. Since there is delegation, its costlier. Most of the times, Composability comes along with Inheritance.


Inheritance is static. It is Derivation. Let us take the same watch. You see the watch and look into the time. But for a watch mechanic, the encapsulation is different, he looks into the internal parts of the watch. He sees the implementation.

Implementing Encapsulation using Inheritance/Composability may seem confusing. So, let us take another example, say a Data Structure implementation.


LIFO should be implemented and for that we need two methods push and pop.

Providing push and pop hiding the implementation.

Implementing stack using Inheritance:
Extend LinkedList and then provide push and pop and implement them using LinkedList methods.

Implementing stack using Composability:
Provide push and pop and then call/use some other methods for implementing the same.

Composability is more global. Hence the reusability is more. Let us take an example:

Sale: log()

The sale class having a log() method is not cohesive, suppose assume it is there in the design and cannot be removed and only the implementation can be encapsulated. A better way is to call and external API for the log() implementation.

AbstractLog:log() <- SalesLog:log()

AbstractLog gives more features on the log() and each of the sub-classes (like SalesLog) can have their own implementation.

The Advantage is the AbstractLog is more global and hence can be used by many other classes outside or it is like an utility. But the abstraction comes via Inheritance. So sometimes Composability comes along with Inheritance.

A good programming need not follow OOP. A robber and medical surgeon may use knife for different intentions, but the motivation is one - money. In the same way, The Intentions may be different for using OO, but the Motivation should be "REUSE".