Dept of | by Philip Likens

Archive for July, 2010

Cloning Arrays in Flash AS3

Thursday, July 29th, 2010

So I thought I might share something I learned today about Arrays in Flash AS3. In most languages I’ve used, it’s fairly simple to clone an array. For instance:

In Javascript:

  1. var x = new Array(‘Bob’,'Tom’,'Joe’);
  2. var y = x;
  3. y[1] = “Stan”;
  4. // x contains Bob, Tom, Joe
  5. // y contains Bob, Stan, Joe

In PHP:

  1. $x = array(‘Bob’,'Tom’,'Joe’);
  2. $y = $x;
  3. $y[1] = “Stan”;
  4. // $x contains Bob, Tom, Joe
  5. // $y contains Bob, Stan, Joe

However in Flash you would get:

  1. var x:Array = new Array(‘Bob’,'Tom’,'Joe’);
  2. var y:Array = x;
  3. y[1] = “Stan”;
  4. // x contains Bob, Stan, Joe
  5. // y contains Bob, Stan, Joe

What? Why? Because Flash automatically creates a reference when you assign arrays to each other, it does not clone the arrays like the other languages. You can do something like that in PHP with the &= assignment operator, but it’s not the default. Why would Flash not do the same as PHP? How does it make any sense that when I assign one thing a value that the two values should then be tied together automatically?

There is a solution. The Flash help system actually talks about this problem here. So the new code would look like:

  1. var x:Array = new Array(‘Bob’,'Tom’,'Joe’);
  2. var y:Array = x.concat();
  3. y[1] = “Stan”;
  4. // x contains Bob, Tom, Joe
  5. // y contains Bob, Stan, Joe

Basically, whenever you use the concat method it automatically returns a new array (rather than a reference), which solves the problem. But, if you have a multidimensional array, this method does not work. Concat does not touch the arrays within the arrays – it only converts the initial values in the base array. Fortunately Flash’s help system recommends the following code (which works):

  1. import flash.utils.ByteArray;
  2. function clone(source:Object):*
  3. {
  4. var myBA:ByteArray = new ByteArray();
  5. myBA.writeObject(source);
  6. myBA.position = 0;
  7. return(myBA.readObject());
  8. }
  9. var x:Array = new Array(‘Bob’,'Tom’,'Joe’);
  10. var y:Array = clone(x);
  11. y[1] = “Stan”;
  12. // x contains Bob, Tom, Joe
  13. // y contains Bob, Stan, Joe

So I’m glad to have a solution, but it seems awfully weird to have to go to so much trouble…

Barbell Strategy

Thursday, July 29th, 2010

On the side (of web design and development, teaching, etc) I like to read and think about investing.  The Intelligent Investor is my favorite book on investing, written by the brilliant man Benjamin Graham.  The reason it is my favorite book is that it makes practical sense to me.  It seems wise.  It rails against speculation.  It is about as conservative and grounded an investing strategy as you can get.

As I read through Taleb’s The Black Swan, I recognized an idea that is complementary.  It is all about limiting your risk to the unknown – which is really what Graham was getting at.  Here’s Taleb’s approach:

I am trying here to generalize to real life the notion of the “barbell” strategy I used as a trader, which is as follows.  If you know that you are vulnerable to prediction errors, and if you accept that most “risk measures” are flawed, because of the Black Swan, then your strategy is to be as hyper conservative and hyper aggressive as you can instead of being mildly aggressive or conservative.  Instead of putting your money in “medium risk” investments (how do you know it is medium risk?  By listening to tenure-seeking “experts”?), you need to put a portion, say 85-90 percent, in extremely safe instruments, like Treasury bills – as safe a class of instruments as you can manage to find on this planet.  The remaining 10 to 15 percent you put in extremely speculative bets, as leveraged as possible (like options), preferably venture capital-syle portfolios.  That way you do not depend on errors of risk management; no Black Swan can hurt you at all beyond your “floor,” the nest egg that you have in maximally investments.  Or, equivalently, you can have a speculative portfolio and insure it (if possible) against losses of more than, say, 15 percent.  You are “clipping” your incomputable risk, the one that is harmful to you.  Instead of having medium risk, you have high risk on one side and no risk on the other.  The average will be medium risk, but constitutes a positive exposure to the Black Swan.  More technically, this can be called a “convex” combination.

The Black Swan, pages 205-206

In addition to it’s application to investing, this idea can be applied to life.  And, indeed, Taleb details what that might look like at a later point in the book.  But the idea is to be conservative in your job, in your pursuits, etc with all but 10-15 percent of your life.  In that other 10-15 percent you take risks that have maximum upside.  As in, look for opportunities that “scale” (as a business person might say).  You look for things that allow you to input some amount (time, money, etc) but can return gains that are non-proportional.  I can put this idea in the negative better than the positive: if you plan on making widgets, your earnings will always be proportional with the number of widgets you make.  Sure, you may be able to raise the price, but you will always have to work harder to make more widgets and make more money.  If, instead, I could write a book, there’s a chance that book will sell millions of copies (*cough* Harry Potter *cough*) and give me a disproportionate return.  As in, I write one book which takes me x hours (say 200 hours).  The more books I sell, the more I make for those 200 hours – I do not (necessarily) need to work more hours to make more money.  David Heinemeier Hansson from 37 Signals talks about this same idea.

Anyway, it’s a very interesting idea to me and I wonder how this might apply to both my career and my investments.

Speculation and Self-Confidence

Wednesday, July 28th, 2010

On pages 58-59 of The Black Swan, Nassim Nicholas Taleb talks about an experiment by P.C. Wason.  Wason gave his subjects a number sequence – 2, 4, 6 – and asked them to try to guess the rule that generates the sequence.  In order to guess the test subjects produced other three-number sequences.  They were ten told “yes” or “no” depending on whether or not their sequences fit the rule.  The correct answer was “numbers in ascending order” but very few people got it right.  In order to see the rule, people would have had to provide number in descending order, or out of order – but very few people tried those sequences.  Generally, the subject would come up with a hypothesis of what they thought the rule might be and try to confirm it through their guesses.  Taleb goes on…

But there are exceptions.  Among them figure chess grand masters, who, it has been shown, actually do focus on where a speculative move might be weak; rookies, by comparison, look for confirmatory instances instead of falsifying ones. But don’t play chess to practice skepticism.  Scientists believe that it is the search for their own weaknesses that makes them good chess players, not the practice of chess that turns them into skeptics.  Similarly, the speculator George Soros, when making a financial be, keeps looking for instance that would prove his initial theory wrong.  This, perhaps, is true self-confidence: the ability to look at the world without the need to find signs that stroke one’s ego.

What’s interesting about all of this is my own perspective.  I find myself wanting to ignore the negative.  I want to dodge the weak points in my speculations.  Rather, I want to bolster my own confidence, my own ego by proving that my way is right.  When, in reality, I would go further faster if I failed faster by shooting down my own ideas.  Oh to be that self-confident.

On Paper Prototyping

Thursday, July 22nd, 2010

I am currently enrolled in ITGM 723, Human-Centered Interactive Design.  Generally, I don’t love “clinical” user testing. I don’t like bringing someone into a room, giving them a task, observing them doing the task, recording the results and creating the analysis. I would rather talk to a few people, talk through the process, what they might like in a product, what’s important to them, etc. However, I know from research a person’s spoken desires and functional desires are two different things. In other words, people have a hard time articulating what they want, but they can usually identify it (in the negative or positive sense) when they see it.

Paper prototyping is a traditional, clinical way of reviewing user needs and refining user experiences. I’ve not used paper prototyping (as a testing mechanism) before. As I read about it, and as I put together my first paper prototype I felt the whole idea was very stupid. To put that much effort into a “functional” prototype that did not move the development needle seemed ludicrous. Even still, I picked a task and created a functional paper prototype.

I went ahead and read other chapters of the book Paper Prototyping by Carolyn Snyder besides the one assigned. Specifically I went through the section on “Deciding Whether to Use Paper.” I begrudgingly agreed and understood what the author was getting at and why she might be a proponent of paper prototyping. I read through the research that shows that low and high fidelity prototypes generally reveal the same problems. And I feel like I understand a little better now.

However, it still bothers me that paper prototyping doesn’t really contribute much to the actual development process. Digital interactive wire frames are more involved to put together, but I think there’s some merit to the fact that I can actually expand on that development and it’s not “wasted time.” Especially in the recent years with the advent of XHTML and CSS – moving information around on the screen is not difficult and layouts can be changed very easily – that’s the point of those technologies. And I understand the author of the book is advocating “rough” paper prototypes and rapid development of those materials, but it still seems like a waste to me.

So all in all, I see how paper prototypes can fit in. I understand the merits, and I see some of the drawbacks. Will I use paper prototyping in my professional career? Probably not much if I do at all. Was it a good exercise to go through? Absolutely. Is it a good tool to have access to? Sure, it’s always good to have another tool available.

The 4027 Error

Wednesday, July 21st, 2010
The 4027 Error

The 4027 Error

I had the funniest error message on a computer at the school this morning.  After I rebooted it was fine, but it made me smile.  It’s now floating around to all the techs.  The screen capture is to the left, but the error read as follows:

You can’t use this version of the application EPSON Scan with this version of Mac OS X.
You have Mac OS X 10.6.4. The application requires Mac OS X 214753.53.9 or later.”

Mac OS X 214,753?  Is it year 4027 yet?  I thought it was 2010! And where’s my rocket pack?

After-The-Fact Attribution of Skill

Monday, July 19th, 2010

“…What we call ‘talent’ generally comes from success, rather than the opposite.  A great deal of empiricism has been done on the subject, most notably by Art De Vany, an insightful and original thinker who single mindedly studied wild uncertainty in the movies.  He showed that, sadly, much of what we ascribe to skills is an after-the-fact attribution.  The movie makes the actor, he claims – and a large dose of nonlinear luck makes the movie.”

from Nassim Nicholas Taleb’s The Black Swan, pages 30-31

I’ve been reading the book The Black Swan.  It’s a very interesting book, but the above quotation really caught my eye.  I do think that “success” is largely based on circumstance and that people generally step into the role they’re given.  If much is expected, much will be returned.

From what I understand, something like this happens in the armed forces.  I have heard people say that you have no idea what you can do physically until you’re pushed to your limits.  Evidently the armed forces have a way of pushing people up to their limit, but not (usually) beyond.

Of course, what the book is talking is as much about fame and social standing as it is actual skill.  But I like the idea.  If I am put in a place, with the right motivations (I don’t like to fail, I have some reward, etc), I will generally succeed.  And looking back, people will say “see, Philip was the right person for that job, no one else could have done it.”  When in reality, my ability to do the task probably hinged on my being assigned the task and my own motivations rather than my actual skill level.  There are many people with adequate skill – just not many with the same opportunity.

However, once given that opportunity, and that success, I think some of the skill then becomes legitimate.  For instance, only a handful of players in the NBA have played in the Finals.  By circumstance, they have an advantage over everyone else.  But that experience has made them better as well.

This is all very interesting.  Ultimately my faith plays in at some point, but I won’t get into the details now.  Generally though, it is best to look to acquire the skills of your peers and above, but also to hunt for opportunities.  The two together seems to breed success.

CodeLab Summer 2010

Wednesday, July 14th, 2010

As always I will be hosting CodeLab this semester at the Art Institute of Dallas.  It’ll be in room 307 from 10 to Noon.  I’ll take questions or problems dealing with programming primarily, but any other web or business related questions are welcome.  Hint: The students who struggle with programming tend to learn more and  do better in the classes if they participate in CodeLab. I hope to see you there.

CodeLab Summer 2010

Jeff Hawkins on Problem-Solving

Wednesday, July 14th, 2010

Jeff Hawkins is many things – an Entrepreneur (Palm, RNI, Neumenta), brilliant product designer (Palm Pilot) and a neuroscientist.  Here’s what he has to say about problem solving.  I think this applies to everything from general creativity to programming.  The following excerpt is taken from On Intelligence by Jeff Hawkins, pages 189-192.

Can you train yourself to be more creative?

Yes, most definitely.  I have found there are ways to foster finding useful analogies when working on problems.  First, you need to assume up front that there is an answer to what you are trying to solve.  People give up to easily.  You need confidence that a solution is waiting to be discovered and you must persist in thinking about the problem for an extended period of time.

Second, you need to let your mind wander.  You need to give your brain the time and space to discover the solution.  Finding a solution to a problem is literally finding a pattern in the world, or a stored pattern in your cortex that is analogous to the problem you are working on.  If you are stuck on a problem, the memory-prediction model suggests that you should find different ways to look at it to increase the likelihood of seeing an analogy with a past experience.  If you just sit there and stare at it over and over, you won’t get very far.  Try taking the parts of your problem and rearranging them in different ways – literally and figuratively.  When I play Scrabble, I constantly shuffle the order of the tiles.  It isn’t that I hope the letters will by chance spell a new word, but that different letter combinations will remind me of words or parts of words that might be part of a solution.  If you are looking at a drawing of something that just doesn’t make sense, try drawing it upside down, changing colors, or changing perspectives.  For example, when I was thinking about how different patterns in V1 could lead to invariant representations in IT, I was stuck.  So I flipped the problem around and asked how a constant pattern in IT could lead to different predictions in V1.  Inverting the problem was immediately helpful, ultimately leading to my belief that V1 should not be viewed as a single cortical region.

If you get stuck on a problem, go away for a little while.  Do something else.  Then start again, rephrasing the problem anew.  If you do this enough times something will click sooner or later.  It may take days or weeks, but eventually it will happen.  The goal is to find an analogous situation somewhere in your past or present experience.  To succeed you must ponder the problem often but also do other things so the cortex will have the opportunity to find an analogous memory.

Here is another example of how rearranging a problem led to a novel solution.  In 1994, my colleagues and I were trying to figure out how to enter text on handheld computers.  Everyone was focused on handwriting recognition software.  They said, “Look, you write things on pieces of paper, you should be able to write the same way on a computer screen.” Unfortunately, this turns out to be really hard.  It’s another one of those things that computers aren’t very good at, even though brains find it quite simple.  The reason is that the brain uses memory and current context to predict what is written.  Words and letters that are unrecognizable on their own are easily recognized in cortex. Pattern matching with computers is not sufficient to the task.  I had designed several computers that used traditional handwriting recognition but it was never good enough.

I struggled with how to make the recognition software work better for several years and was stuck.  One day I stepped back and decided to look at the problem from a different perspective.  I looked for analogous problems.  I said to myself, “How do we enter text into desktop computers? We type on a keyboard.  How do we know how to type on a keyboard?  Well, actually, it’s not easy.  It’s a recent invention and it takes a long time to learn.  Touch-typing on a typewriter-style keyboard is hard and not intuitive, it isn’t at all like writing – yet millions of people learn how.  Why?  Because it works.”  My thinking continued by analogy, “Maybe I can come up with a text input system that is not necessarily intuitive, that you have to learn, but people will use it because it works.”

Literally, that’s the process I went through.  I used the act of typing on a keyboard as an analogy to figure out how to enter text with a stylus on a display.  I recognized that people were willing to learn a difficult task (typing) because it was a reliable and fast way to enter text into a machine.  Therefore if we could create a new method of entering text with a stylus that was fast and reliable, people would use it even though it required learning.  So I designed an alphabet that would reliably translate what you wrote into computer text; we called it Graffiti.  With traditional handwriting recognition systems, when the computer misinterprets your writing you don’t know why.  But the Graffiti system always produces the correct letter unless you make a mistake in writing.  Our brains hate unpredictability, which is why people hate traditional handwriting recognition systems.

Many people thought Graffiti was a sensationally stupid idea.  IT went against everything they believed about how computers were supposed to work.  The mantra in those days was that computers should adapt to the user, not the other way around.  But I was confident that people would accept this new way of entering text by analogy to the keyboard.  Graffiti turned out to be a good solution and was widely adopted.  To this day I still hear people claim that computers should adapt to users.  This isn’t always true.  Our brains prefer systems that are consistent and predictable, and we like learning new skills.

Vacation: Shepherd of the Ozarks

Tuesday, July 6th, 2010

My wife and I just got back from a very restful trip out to the Shepherd of the Ozarks Camp in Arkansas.  It was really wonderful.  I scheduled next to nothing, made some new friends and caught up on sleep.  I finished two books while I was there – The Design of Everyday Things, which I’m reading for a class this semester, and On Intelligence, which I read just for fun.  I felt as though The Design of Everyday Things would be best rewritten as a brochure about design – there were some really great points, but the book did not need to be 272 pages.

On Intelligence, however, was wonderful.  The book is by Jeff Hawkins and Sandra Blakeslee.  Jeff Hawkins started Palm, among other things, and is a neuroscientist along with his many other technology ventures.  He talks about a general idea of brain function, specifically dealing with the neo-cortex, but casts the whole thing in a technological light.  His discoveries have serious implications for intelligence in computer systems.  He outlines a new system, better than neural networks and has a company called Nuementa which is trying to implement that system.  I won’t be using his work this semester in grad school, but I am using neural networks to do some basic pattern recognition.  I wish I had more time to research his technology.  If you want to know more about Jeff Hawkins, you might check out his talk at Stanford.

I also met a wonder retired professor that has become a friend and I look forward to talking more.  He’s been very helpful so far in providing some much needed guidance to a career path that seems a little ambiguous at times.  All in all, it was a really wonderful trip.