Saturday, July 24, 2010

Are some people more intelligent than others? - A Mathematical Perspective

People consider some to be more intelligent than others. For example, most of us would agree if I consider newton or Einstein to be more intelligent than you. But is this really true? First off, what is intelligence? At birth everyone is (more or less) at the same level. Then why is it that some people are good at studies, while some just aren't?

In my opinion, intelligence is all about making rational decisions given the information/knowledge you possess. People are different because the definition of being rational is different for each of us. For some of us, the act of crossing the road carefully might be rational. For others, most rational thing is to cross the road as quickly as possible. These beliefs are based on prior experiences. Someone who has witnessed a road cross accident might prefer to cross it carefully. Those who got fired because of being late might consider a hush hush approach towards crossing.

Bottom line: People are different because of different experiences they possess. This can actually be explained mathematically by a principle most of us are familiar with. Its called 'Bayes Rule'. Bayes rule seeks to find a hypothesis h with high probability given an observation D. Imagine this: You go to your kitchen, find a chair that was used to reach a cookie jar which is now empty. This is observed data D. Probability of this happening is P(D). Now, you can have a set of hypothesis h belonging to set H (representing all possible hypothesis). For instance h1 can be "My daughter must have stolen the cookie". h2 = "A thief stole a cookie as he was hungry". We don't know which of these are true, all may be equally likely. However if we did observe our house to be messed up (typical indicator of stealing), it increases chances of h2 to be true. This rule may be summarized mathematically as:


Our definition of rationality is based on how our knowledge is updated by this rule. By our experiences, we form various P(D)'s and P(H)'s that direct our thinking.

Back to the original question: "Are some people smarter than others by birth?". According to bayes rule "NO". It is our experiences that lets us update probability distributions of likelihood of events/hypothesis. These probabilities guide our actions. If someone makes an intelligent choice despite this, then he/she just got lucky.

Einstein and Newton are intelligent because of their experiences. Some take their experiences for granted. For instance, most of us would just pick up and eat the apple if it fell on our head. Instead, newton reasoned as to why it happened. Is this an indicator of superior intellect? He decided to do a different action (reasoning instead of eating) which is a manifestation of past experience. He must have observed/experienced that its rewarding when you reason every small aspect.

Why do some people learn faster than others? Is it because of genetics? If so, it is again a propagation of ancestral experiences. It might be the case that they worked hard in their childhood (more experience), thereby improving their intellect. Hence, they don't have to work as hard as you to pick things up.

So, in conclusion: "All people are born with the same intellect. It is their experiences that define them. To some extent you decide your experiences, so you control how intelligent you want to be."

Tuesday, July 20, 2010

Validation framework for adobe director

Validation can be a real pain in the ass. After all no developer likes doing labor tasks. With Java, there are many excellent validation frameworks. To know about my take on validation with java see this article. Adobe director however doesn't have anything like it. So i decided to go ahead and make a simple framework in lingo.

Lets start with usage point of view. We need the name of text field, type of validator (regex, length etc..) and the error message when validation fails. Lets represent this as a list L = {"text field name", "Validator name", "error msg"}. To keep it simple, I only consider validation on text fields (I could have extended it, but it'd make the code look ugly, I wanted to keep it simple. Also, 99% of validation is on text fields)

Its obvious that a field can have multiple validators. Also, it'd be nice to validate everything in one call. So we can have input as List {L1, L2, ...Ln), where Li aforementioned list format.

But validators can have parameters. For example length validator can have 'length' parameter. So L should be List("text field name", List ("validator name", param1, param2, ...), "error message"). From the usage point of view we could have something like:
oValidator = new(script "ValidationUtil")
isValid = oValidator.validate([ \
["txtField1", ["NonEmptyValidator"],"Please enter textField1"], \
["txtSSN", ["LengthValidator", 4],"Please enter 4 digit ssn"], \
["txtSSN", ["NumberValidator"],"Please enter a numeric value"]
)
Predefined validators (functions) can be called by their string name using call(...) method.
Since we have all the necessary things are worked out, heres a complete listing of ValidationUtils class. You are free to use and modify this class as per your requirements. Just let me know if your are using it. At least i'll know it was useful to someone.
-----------------------------------------------------
-- This class manages all the validation stuff --
-- @author : Raghavendra Kotikalapudi --
-- @email : ragha.unique2000@gmail.com --
-----------------------------------------------------

--Currently works only for text fields..
--Checks for validation on the given validator..
on isValidOnValidator me, memberName, lstValidatorAndParams

val = sprite(memberName).text
--Extract validator name..
validator = lstValidatorAndParams[1]
otherParams = lstValidatorAndParams
--Remove validator name...it now has params only.
otherParams.deleteAt(1)
--Achieves dynamic function calling..
return call(symbol(validator), me, val, otherParams)

end

--This is the main function to be called.
on validate me, lstMembersAndValidators

ret = true
repeat with lst in lstMembersAndValidators

if isValidOnValidator(me, lst[1], lst[2]) = false then
alert(lst[3])
ret = false
exit repeat
end if

end repeat

return ret

end


--Validates non emptiness..
on NonEmptyValidator me, str, lstOptionalParams

if voidP(str) then
return false
else if length(str) = 0 then
return false
else
return true
end if

end

--Validates of length of str in in the range (low, hi) inclusive
--lstOptParams has low, high pair
on LengthRangeValidator me, str, lstOptionalParams

len = length(str)
if len >= lstOptionalParams[1] and len <= lstOptionalParams[2] then return true else return false end if end --Validates for non existence of special symbols.. --i.e, str can contain a-z, A-Z or 0-9 on NoSpecialSymbolsValidator me, str, lstOptionalParams foundCount = PRegEx_Search([str], "~+|`+|!+|@+|#+|\$+|%+|\^+|&+|\*+|\(+|\)+|\{+|\}+|\[+|\]+|\++|\\+|\|+|:+|;+|/+|\<+|\>+|\?+|,+")

--If special char is found, validate to false
if foundCount > 0 then
return false
else
return true
end if

end

--Validates if the given str is a valid name or not, i.e., it should not contain
--special symbols or 0-9
on NameValidator me, str, lstOptionalParams

val = NoSpecialSymbolsValidator(me, str, lstOptionalParams)
if val = false then
return false
else
foundCount = PRegEx_Search([str], "[0-9]+")
--If number if found..
if foundCount > 0 then
return false
else
return true
end if
end if

end
New Validators can be added as an when needed. PRegEX_search(...) comes from PRegEx Xtra. Fortunately, it is free to download. This framework handles error notifications by showing alert messages whenever validation fails. Neat isn't it.

If you have any suggestions or improvements, please let me know through comments. Hope you find this useful!

Friday, July 2, 2010

Women and Their Craze for Possessions

A woman parked her brand-new Lexus in front of her office ready to show it off to her colleagues. As she got out, a truck passed too close and completely tore off the door on the driver's side. The woman immediately grabbed her cell phone, dialed 911, and within minutes a policeman pulled up. Before the officer had a chance to ask any questions, the woman started screaming hysterically.

Her Lexus, which she had just picked up the day before, was now completely ruined and would never be the same, no matter what the body shop did to it. When the woman finally wound down from her ranting and raving, the officer shook his head in disgust and disbelief. "I can't believe how materialistic you women are," he said. "You are so focused on your possessions that you don't notice anything else."

"How can you say such a thing?" asked the woman.

The cop replied, "Don't you know that your right arm is missing from the elbow down? It must have been torn off when the truck hit you."

"OH MY GOD!" screamed the woman. "Where's my new bracelet !!!"