Wednesday, December 22, 2010

Open AL, Adobe Director - No sound in projector [FIX]

One of the most annoying thing about Adobe Director is its lack of support. Open AL Xtra enables director to use OpenAL runtimes for 3D sound manipulation. Unfortunately, in a projector/exe, it doesn't play any sound. This issue was pointed out at multiple forums (here and here), without any fix so far. After struggling for nearly 4-5 hrs, I finally figured it out. The solution couldn't be any simpler. Just include these two xtras in the projector.

- Mix Services
- Sound Import Export

I got he hint from playFile() documentation for Director. It mentions the use of "Correct Mix Xtra" to play sound properly.

Tuesday, December 7, 2010

Recenberg 1/5th success rule applied to life..

For those who are not familiar, Rechenberg's 1/5 rule refers to adaptive mutation in evolutionary strategies (ES). It says that the ratio of successful mutations to all mutation should be 1/5. Deriving from this idea, if you get too successful (i.e., more than 1 out of 5 tries) then you're converging too fast to a local optima (aka safe options) and will result in stagnation later on. So, don't run after too many successes. Ideally, at-least according to Rechenberg, one should try 1 safe thing for every 4 risky things in life to optimally balance stagnation vs. growth.

Thursday, November 18, 2010

Flaw with patent law?

Math functions cannot be patented. Imagine sin, cos being patented, that'd be crazy right. Ironically computer programs can be patented. It has long been proved that computer programs are equivalent to mathematical functions. Does anyone realize its the same as patenting math functions?

Wednesday, November 17, 2010

Kleiber's Law

Last week, I happened to read about Kleiber's law while browsing through literature on natural evolution. Its implications are really fascinating. It establishes a relationship between mass and metabolism as:
Metabolism is ultimately linked to the number of heartbeats (heart pumps oxygenated blood, which is responsible for metabolism). Therefore, #heartbeats is proportional to the mass. Also, smaller creatures have high metabolism (heat generated per unit volume) and therefore have faster heart rate.

Curiously, the number of heartbeats per lifetime tends to be constant. Thus, bigger animals live longer as their heart beats slower. Flies on the other hand have shorter lifespan because of high metabolism (smaller mass).

Come to think of it, if we have fixed number of heartbeats, wouldn't running/exercising make us die faster? We are spending more heartbeats per second and it makes perfect sense. Then why is it that people who exercise live longer? The answer is simple...I'll let you think about it.

Friday, October 8, 2010

The paradox...

Newton made calculus to simplify mathematics...a true paradox!

Friday, September 24, 2010

Adding class attributes at runtime :O

The use is kind of hard to describe. In some situations, it makes more sense to add attributes to an instance at runtime. One example would be to perform optimizations at runtime (Maybe I'll describe a solid example at a latter time).

The trick is to use a HashMap to store property name and value pair. For ease of use, I defined a class 'Bufferable' with this capability. Any class extending 'Bufferable' should inherit dynamic attribute feature.

/**
* A Utility class to support addition of new properties to a java bean
* at the runtime. Extend your class with this to make it bufferable. It is
* useful if you want to associate certain properties with an object and
* maintain the OOP nature of your code.
*
*

This class extends AbstractSerializableBean
* for serialization and property change support.
*
* @author Ragha
* @see AbstractSerializableBean
* @version 1.0
*/
public class Bufferable extends AbstractSerializableBean
{
private static final long serialVersionUID = 506835437375346326L;

/**
* This map is used to store property name and object as key-value pairs.
*/
private HashMap buffer = new HashMap();

/**
* This method is used as a getter for the associated property in the
* buffer.
*
*

You must typically create the property using
* {@link #createPropertyInBuffer(java.lang.String) createPropertyInBuffer(...)} method
* before using this method.
*
* @param property The property to be used
* @return The value of the property.
* @throws java.lang.IllegalArgumentException If there is no such property.
*/
public Object getValueFromBuffer(String property)
throws IllegalArgumentException
{
if(buffer.containsKey(property))
return buffer.get(property);
else
{
throw new IllegalArgumentException("Property: '"+property+"' " +
"does not exist...");
}
}

/**
* This method can be used as a setter for the associated property.
* in the buffer.
*
*

You must typically create the property using
* {@link #createPropertyInBuffer(java.lang.String) createPropertyInBuffer(...)} method
* before using this method.
*
* @param property The property value to be set
* @param Value The value to be set
* @throws java.lang.IllegalArgumentException If there is no such property
*/
public void putValueInBuffer(String property, Object Value)
throws IllegalArgumentException
{
if(buffer.containsKey(property))
buffer.put(property, Value);
else
{
throw new IllegalArgumentException("Property: '"+property+"' " +
"does not exist...");
}
}

/**
* Creates a new property in the buffer. Once the property is created,
* it can be get or set using the
* {@link #putValueInBuffer(java.lang.String, java.lang.Object) putValueInBuffer(...)} and
* {@link #getValueFromBuffer(java.lang.String) getValueFromBuffer(...)} methods
*
*

It is recommended that you use Classname-property name as property
* string to avoid conflicts with other existing property names...
*
* @param property The property name to be associated with the buffer.
* @throws java.lang.IllegalArgumentException If the property name already exists.
*/
public void createPropertyInBuffer(String property)
throws IllegalArgumentException
{
if(buffer.containsKey(property))
{
throw new IllegalArgumentException("Property: '"+property+"' " +
"already exists...");
}
else
{
buffer.put(property, new Object());
}
}

/**
* This method can be used to check if a given property already exists.
* @param property The property to be checked.
* @return true, if the property exists.
*/
public boolean isPropertyInBuffer(String property)
{
return buffer.containsKey(property);
}

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Bufferable other = (Bufferable) obj;
if (this.buffer != other.buffer && (this.buffer == null || !this.buffer.equals(other.buffer))) {
return false;
}
return true;
}

@Override
public int hashCode() {
int hash = 3;
hash = 79 * hash + (this.buffer != null ? this.buffer.hashCode() : 0);
return hash;
}
}

Everything should look pretty obvious except for why i am extending my class with AbstractSerializableBean. Well, this is done in order to make the class Serializable. The code for AbstractSerializableBean should make things clearer.

/**
* This subclass enhances {@code AbstractBean} by implementing the
* {@code Serializable} interface. {@code AbstractSerializableBean} correctly
* serializes all {@code Serializable} listeners that it contains. Implementors
* that need to extends {@code AbstractBean} or one of its subclasses and
* require serialization should use this class if possible. If it is not
* possible to extend this class, the implementation can guide implementors on
* how to properly serialize the listeners.
*
* @see AbstractBean
* @author Ragha
*/
public class AbstractSerializableBean extends AbstractBean implements Serializable
{
private static final long serialVersionUID = -3459406004204097480L;

protected AbstractSerializableBean()
{
super();
}

private void writeObject(ObjectOutputStream s) throws IOException {
s.defaultWriteObject();

for (PropertyChangeListener l : getPropertyChangeListeners()) {
if (l instanceof Serializable) {
s.writeObject(l);
}
}
s.writeObject(null);
}

private void readObject(ObjectInputStream s) throws ClassNotFoundException,
IOException {
s.defaultReadObject();

Object listenerOrNull;
while (null != (listenerOrNull = s.readObject())) {
if (listenerOrNull instanceof PropertyChangeListener) {
addPropertyChangeListener((PropertyChangeListener) listenerOrNull);
}
}
}
}
That's it...pretty straight forward isn't it..

Predicting hand position on the keyboard by observing random text \m/

Today, I was just typing some nonsense keys on my keyboard and happened to observe something interesting. Below is a uniform random sample of what I typed:

gh
jgh
jg
hjg
hjg
hjg
hjg
hjg
hkg
hjg
hg
jg
hjg
hjg
hg
hjg
hg
hjg
h
gh
gh
ghj
ghj
ghj
g
hjg
khg
hg
hg
hg
hjg
hjg
hjg
hjg
h
ghj

Notice how 'h' repeats a lot of times. It so happens that my middle finger was on 'h'. So, is frequency somehow linked to the length of finger? Turns out I was right. See table below. I used the keys G, H, J, K. My index finger was on G, middle on H, ring finger on J and little finger on K.

Character (Ordered by frequency)
Actual Finger on char
Finger (Ordered by length)
H
Middle
Middle
J
Ring
Ring
G
Index
Index
K
Little
Little

You can try this on your own. Place your fingers on the keyboard (horizontally, any other orientation complicates the situation as relative length changes).

Probability theory says that the chance of occurrence of G, H, J or K is 1/4. But I think that in this case, probability is somehow weighted, in a sense that it is proportional to the length of the finger.

So, what's the use of all this?
  1. I wasted your time...haha!
  2. You can predict the hand position based on random text...duh!
  3. Its cool!
  4. See 1
Is it of any use?
I guess not, that explains the label 'lame observations'. But who cares?

Thursday, August 12, 2010

P vs NP solved?

Vinay Deolalikar, an Indian scientist @ HP Labs claims to have proved P != NP. This is a significant breakthrough and is of great importance to Computer Scientists. A detailed problem description can be found at http://www.claymath.org/millennium/P_vs_NP/pvsnp.pdf


Note: This is not the final version and is currently undergoing intense peer review.

If his claim holds true, two clay math problems will have been solved! This is exciting!

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 !!!"

Monday, June 7, 2010

Report generation in adobe director..

Report generation is perhaps the most plagued problem with director. There are a lot of xtras out there, but are commercial. Most of them are around $100-350, and all are limited in one way or another. After weeks of exploration, few of which included:
  1. Using adobe reader
  2. Interfacing it via. java program (this one almost worked)
  3. Wasted time with lots of useless xtras
I decided to make my own scheme, one which works in most situations. The idea is as follows:
  1. Create a HTML template of your report. For instance, if you wanted customer information report. You create a HTML template, fill in all the blanks with $1, $2, ... $n.
  2. From director, while generating the report, you first read in the template (preferably from root folder\templates\).
  3. Replace $1, $2, with appropriate values.
  4. Generate HTML file and open it with default browser.
I created a utility class for the above tasks. You'll be needing FileIO xtra and FileXtra4 (both of which are available for free)

-------------------------------------------------------------
--------------Report generation Utility class----------------
-------------------------------------------------------------

--Finds and replaces the first occurrence of 'aLookForString' with 'aReplaceString'
--in 'aString' and returns the new string
on findAndReplace me, aString, aLookForString, aReplaceString

n = aLookForString.length -1
is_ok = false

repeat while is_ok = false

place = offset(aLookForString, aString)

if (place = 0) then
is_ok = true
exit repeat
else
put aReplaceString into char place to (place+n) of aString
exit repeat
end if

end repeat

return aString
end

--Saves the text in given filename
on saveText me, text, filename

-- create the FileIO instance
fileObj = new(xtra "FileIO")

-- delete existing file, if any
openFile (fileObj,filename,2)
delete(fileObj)

-- create and open the file
createFile(fileObj,filename)
openFile(fileObj,filename,2)

-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return FALSE
end if

-- write the file
writeString(fileObj,text)

-- close the file
closeFile(fileObj)

return TRUE

end

--Reads the text from a given filename
on readFromFile me, filename

-- create the FileIO instance
fileObj = new(xtra "FileIO")

-- open the file
openFile(fileObj,filename,1)

-- check to see if file opened ok
if status(fileObj) <> 0 then
err = error(fileObj,status(fileObj))
alert "Error:"&&err
return ""
end if

-- read the file
text = readFile(fileObj)

-- close the file
closeFile(fileObj)

--return the text
return text

end


Sample usage is illustrated below:

oUtilClass = new(script "UtilClass")

--Read html from the template
html = oUtilClass.readFromFile(the moviepath & "\\Templates\\summary report.htm")

--Fill in data..
global strSelectedDate
html = oUtilClass.findAndReplace(html, "$1", someVar)
html = oUtilClass.findAndReplace(html, "$2", anotherVar)

filename = the moviepath & "print.html"
oUtilClass.saveText(html, filename)

--Invoke through a browser..
fileXtra4Obj = xtra("FileXtra4").new()
fileXtra4Obj.fx_FileRunApp(the moviepath & "run.bat")



In run.bat, you just have to call print.html by writing "print.html", Duh!
Therefore, run.bat opens print.html with the default browser, which can then be printed, previewed by the courtesy of browser. Whats more, you also get to fiddle with niche layout settings at runtime. In other operating systems like linux, you just have to replace run.bat with a shell script.

Some Minor Tidbits

What if you wanted to generate a table at runtime? Here's what I'd do:

Generate HTML template from dreamweaver or MS word with one row of data in the table..
For example...
<html>
Some blah blah..

Name: $1 </br>
Age : $2 </br>

<table>
<tr>
<td> Subject </td>
<td> Marks </td>
</tr>

<tr>
<td> Some subject </td>
<td> 85 </td>
</tr>
</table>

</html>

Now, create a file template1_rows.txt containing the row data..<html>
<tr>
<td> $1 </td>
<td> $2 </td>
</tr>
Here's the big idea. Whenever you build a table, read in the row data template, fill it and append it to the main html. Here's an example. Highlighted code achieves dynamic table generation behavior.
 --Read html from the template
html = oUtilClass.readFromFile(the moviepath & "\\Templates\\template1.htm")

--Fill in data..
global strSelectedDate
html = oUtilClass.findAndReplace(html, "$1", name)
html = oUtilClass.findAndReplace(html, "$2", age)

tableRows = ""
--Read in the row template..
rowTemplate = oUtilClass.readFromFile(the moviepath & "\\Templates\\template1_rows.htm")

--Generate table rows..
repeat with row=1 to numRows
tableRow = rowTemplate
tableRow = oUtilClass.findAndReplace(tableRow , "$1", subject)

--Append data to tableRows..
tableRows = tableRows & rowTemplate
end repeat

--Fill in table data..
html = oUtilClass.findAndReplace(html, "$3", tableRows)

filename = the moviepath & "print.html"
oUtilClass.saveText(html, filename)

fileXtra4Obj = xtra("FileXtra4").new()
fileXtra4Obj.fx_FileRunApp(the moviepath & "run.bat")
I know, it looks complicated. But atleast this is transparent and you exactly know whats going on. Moreover, this approach gives you unlimited formatting options, works and is free. Once you get a hand of it, it'll seem pretty simple.

Controlling print behavior

If you don't want your table to break across pages, you can use . Beware, this only works with opera browser. So be sure to ship your software with opera. Even better, use opera portable (requires no installation), make appropriate changes to run.bat to invoke html with the shipped browser.

Comments and suggestions are welcome. If anyone has simpler and free approach, please let me know by posting comments.

Tuesday, June 1, 2010

Segmentation fault with c++ vector

Ever been in a situation where you got a seg. fault when you tried to push_back a pointer into the vector? What's more, you have a useless log file with no clues whatsoever. I had the same issue when i was working on an assignment with deadline in 2 hours. After whacking my head for 1-2 hours, I finally found a way to resolve the issue.

I was working on "simple ecosystem" project. The code where new fishes are created and added to the ecosystem seg. faulted. Take a look, I cut down unnecessary things to keep this example simple.
for (vector::iterator it = vecPossiblePositions.begin(); it!=vecPossiblePositions.end(); ++it)
{
//create a new fish..
Fish *f = new Fish();
f->setPosition(it->getX(), it->getY());

//This method does a push_back
//operation on some vector
ecosystem->addEcosystemObject(f);
}
If i comment out ecosystem->addEcosystemObject(f) line, then it runs without seg. fault. Apparently, the line Fish *f = new Fish() was causing the problem. So here's what i did.
Fish *f = NULL;
for (vector::iterator it = vecPossiblePositions.begin(); it!=vecPossiblePositions.end(); ++it)
{
//create a new fish..
f = new Fish();
f->setPosition(it->getX(), it->getY());

//This method does a push_back
//operation on some vector
ecosystem->addEcosystemObject(f);
}
and that fixed the problem! I have no idea why it worked. So, today's lesson of the day is "Keep the damn ptr declarations outside loops"

Enter teeki chawal

Got bored of same old food? Try this recipe..I found out about it from a friend of mine and made a few modifications of my own.

Here's what you need:
  1. Cooked rice
  2. Oil (obviously)
  3. Mirchi powder, jeera, salt, chopped onions, semi boiled and cut potato (one will do)
  4. Crushed tomatoes, c, carrots, beans, green peas, corn
Here's how you proceed:
  1. Heat a pan with lots of oil..
  2. Put jeera (one handful, needs to be more)
  3. Put onions and fry em' all at med flame
  4. Once onions are semi fried, put capsicum, potatoes and cook for like 7 mins
  5. Put remaining veggies and cook for another 7 mins.
  6. Add mirchi powder, and any other spices you fancy (Dhaniya powder, Hing, Garam masala will also do)
  7. Let it cook for another 5 mins..(At any point, if you notice that the veggies are burning, add a little bit of crushed tomato puree)
  8. Add 40% of the crushed tomatoes from the can.
  9. Cook for 10 mins.
  10. Now, taste the mixture, it should be slightly spicier, if not, add more spices. Also, at this point you should notice oil separating from the mixture
  11. Add cooked rice (cold one preferably), and stir for 3-5 mins..
That's it..enjoy your meal :)

Thursday, May 27, 2010

Measuring the Observer Expectancy Effect

If you are performing an experiment in which you tell the participant what you are expecting, then this biases the result due to placebo effect. This is the observer expectancy effect. How can you measure this? Intuitively, the solution seems simple. Do the experiment twice, in the first, tell the participant about the expected outcomes and in the second don't tell him anything about the experiment. Then, you measure the difference in outcomes to calculate the variance introduced due to observer expectancy effect. But, is that accurate?

Lets consider a simple example. Suppose you are to create stress relief program. How would you measure if stress is relived or not? If you tell your subjects that they were participating in stress relief program, placebo effect will come into account and you cannot truly determine if the reduction in stress is actually due to the program you created. If you don't tell anyone about anything, including researchers and participants, you can get rid of the observer expectancy effect. This is the Double Blind trial strategy.

Coming back to the original question, if you do the experiment twice, one with the expectancy effect and another using double blind strategy and consider the difference in performance, do we then have the measure of observer expectancy?

The answer is NO because in both the experiments the state of the participant is different. To be accurate, you'll have to conduct both the experiments in which the researchers, participants and in fact the entire universe is in the same state, i.e., do both the experiments simultaneously, which obviously doesn't work out.

How else can we go about this problem? First we start by formalizing the problem, making it concise. For simplicity, let us consider a single participant. In a given experiment, let the state of the participant be Sp (could involve factors such as personality etc..) and the state of everything else be Se (state of the environment, ideally the entire universe, but a local region would suffice). Therefore, the state of an experiment can be defined by the Tuple (Sp, Se).

Now, perform N experiments with blind trial strategy, each represented by different tuples (S1p, S1e) ... (Snp, Sne) You can now build a regression model to determine the the outcome of the experiment as a function of Se and Sp, after collecting data from sufficiently large number of experiments.

Now we can apply the strategy discussed before. We perform experiment with double blind trial with parameters (S1e, S1p). The second experiment (with expectancy effect) with parameters (S2e, S2p). We can now extrapolate the outcomes of first experiment if parameters S2e and S2p were used instead of S1e and S1p. Since, both the experiments are now virtually conducted simultaneously, we can now determine the observer expectancy effect by computing the difference in outcome.

More accurate the regression model, better is the accuracy of the observer expectancy. With few obvious modifications, one can also build a model to estimate observer expectancy as a function of experiment, Se and Sp.

On a second thought, who gives a damn? If the stress relief program works, be it due to expectancy, that's all we really care about.

Sunday, April 25, 2010

How to solve puzzles

Interested in solving single player puzzles such as "Sudoku", "Rubik's Cube", "Missionaries and Cannibals", "Traveling Salesman Problem"? Try out my newest project, JSimpleAI. For a detailed description, check my blog post on How to solve puzzles

How to solve puzzles

I recently came across this puzzle called as frog leap. Its an interesting puzzle, so, I sat down trying to solve it. I quickly lost my patience, and being a computer science student, decided to write an AI to solve it. It just took me 20 minutes to write an AI that solves this puzzle! boy am i glad not to have wasted my time thinking about the puzzle.

I decided to go ahead an start a project that allows you to solve single player puzzles such as "Sudoku", "Rubik's cube", "Missionaries and Cannibals problem", the notorious euclidean traveling salesman problem etc.. Its called JSimpleAI and is open sourced @ java.net. I currently implemented TSP and Frog Leap solvers as demos. I'll be more than happy if any of you are interested in implementing suduko, rubiks cube etc..For the algorithmically oriented, you can implement SMA* algorithm. Think about the number of people that can benefit from this!

I am very proud of the project logo that i chose:

It shows the search landscape and the local optima's. Cool isn't it!

In case you're wondering about the solution for frog leap, there are two of them. Here is a screenshot from JSimpleAI. It took 0 secs to solve it! Why dont you go ahead and try writing a code to solve missionaries and cannibals problem? It'll be fun

Monday, April 12, 2010

Monday, January 11, 2010

The irony..

A Japanese fisher man loves to fish. He sells just enough fish to pay for his bills; and enjoys a happy family life since his fishing does not take up all his time. A business man comes along, shakes his head and suggests that the fisher man buys a boat, hires men and fishes in deeper waters. That way, he advises, the fisherman can catch more fish... See More, make more money, and in turn buy more boats and hire even more men!

The fisher man asks, "for what reason would I do such a thing?" The businessman smiles and says that once he has established a thriving business, he has then the option to sell it so that he can live a more leisurely life; perhaps spend more time with his family and hobbies. The fisherman smiles and says – "I already have that now…why would I waste time walking in circles only to come back to where I am now?"