Kai Staats: writing

On the Right Side of the Brain

GP Sketches by Kai Staats GP Sketches by Kai Staats GP Sketches by Kai Staats GP Sketches by Kai Staats GP Sketches by Kai Staats

GP Sketches by Kai Staats

When I arrived to Sutherland, with eight days and nights stretched out before me with just one principal task on my agenda, I was certain the Grow method (one of two branch mutations) was in my grasp. Yes, it evaded me for that week and another after I returned to Muizenberg. In fact, it became the single most challenging part of building Karoo GP (as noted in the email to my professor and fellow researchers May 26).

Despite the myriad sketches I produced, I was unable to see the path to fruition. I must have pursued a half dozen avenues, writing hundreds of lines of code that in the end, all failed.

I began to notice a pattern in my behaviour. I would repeatedly envision a solution. From that vantage point, I could see the challenge, the path, and the conclusion. I sketched the means, to assure it was real, and then dove into the code.

Several hours, even a day or two later, I hit a wall. Not just a small barrier, nor new challenge, but an insurmountable, unavoidable wall. With each wall, I was again reminded there was no work-around, no short-cut. The only solution invoked many stages and a great deal of coding.

GP Sketches by Kai Staats

How could I not have seen this? Why had this only now become no-go when just minute before, it was still possible?

I drew more sketches, more flow-diagrams, and arrived to more solutions. I even came back to an already failed solution. Having forgotten why it failed, I felt sure I must have missed something and dove back in only to be met with the same, obvious wall.

I felt stupid. Frustrated beyond belief. What’s more, my clarity of vision was diminishing rapidly. I could no longer see a half dozen steps down the coding path, but only two or three. My reduced exercise, pulling late nights with the astronomers, and change in diet all contributed.

I recall a high school art class in which we followed a book called “Drawing on the Right Side of the Brain by Betty Edwards” by Betty Edwards. One chapter advised us to hold a pencil or pen in our favoured hand, brainstorm and produce thumbnail sketches until our ideas ran dry. We felt we had surely exhausted all the possibilities for that concept.

Then we grasped the pen with the other hand, even if awkward to the majority of us who are not ambidextrous. More ideas came! Ideas from a completely different foundation.

I knew enough about my internal processes, having spent much of my undergraduate program in Industrial Design in problem solving, to recognise that I would benefit from working on something else, something that came to me more easily. I improved the interface, cleaned up the Python methods, and developed small, useful tools such as a method for tree population renumbering, another for renumbering columns in an axis-1 Numpy array, each of which represented a node in a GP tree; and ultimately, a method for tracking the differences between original and skewed node positions as a branch was inserted into a tree.

GP sketches by Kai Staats When I returned to Muizenberg and my office with a blackboard, I drew my diagrams much larger, using my entire upper body to bring form to my visions. I was able to see the solutions more clearly than when at Sutherland.

Yet, repeatedly, when I turned to sit at my computer, the blackboard to my back, the clarity vanished quickly. I’d start typing and … hit a roadblock, or completely forget what was to happen next.

I thought I was losing my mind. I could see two, sometimes three steps at a time, but four or more and I failed miserably. Endless loops of indigestible code, a headache, backache, and neck filled with anxiety.

I returned to the blackboard, erased everything, and started over. I took the sketches deeper, down to the pseudo-code level such that I was writing loose versions of Python directly on the board.

Those tiny tools I had developed in Sutherland became invaluable, for in each was a means by which I could relieve my mind of that function, trusting the power of a tested black box. The more tools I developed, the more I could focus on flow instead of the detailed interaction of ever level of code.

Success came to me when I broke a complex problem into the smallest pieces possible, connected those pieces with each other, and then validated the flow of data across the system. From this came the “debug” mode, not integral to Karoo GP as a means by which the user can monitor the mutations in real-time.

It’s fascinating to watch, even to me.

By |2017-11-24T23:54:57-04:00May 30th, 2015|Ramblings of a Researcher|Comments Off on On the Right Side of the Brain

GP update 2015 05/26

(email to my fellow researchers)

A week has come and gone. And with it, some 60 hours coding, if not more. I have accomplished a great deal, further fine-tuning the code, building tool-sets, and building a stronger method-based platform for GP. I can now build a Tree from the command line in 5 lines of code, evaluate for fitness, mutate, and save with a few more.

While I witnessed my GP converge on a solution a few nights ago for the first time, using only reproduction (copy) and simple point mutation, I have not yet completed crossover nor the grow method for branch mutation.

These have proved to be incredibly, mentally challenging. I have never struggled with something at this level (I want to say “in my life,” but I may not be thinking clearly :)

I freely admit the issue is not one of Python, but an incredibly complex array book keeping effort that borders on my having to create my own pointer system.

I spent 3 days exploring work-arounds, tricks, and short-cuts, but in the end, am back to the realisation there is just one way–the hard way.

The good news is that I have slowly eroded the challenge by building a suite of tools, each of which performs a single task. Cool.

I will get there, one step at a time.

Today was lost to the realisation (and subsequent rewrite) that my core Tournament code was (inadvertently) taking advantage of Python’s ability to perform basic comparisons (>, <, =) on strings which contains numbers, as compared to converting those to integers first. It works, but the results are not consistent. Fixed! I am far more confident, even though another day behind my slated sched.

What’s more, Python’s numpy random generator is clearly NOT random by any stretch of the imagination. 100 Trees evolved over 10 generations in non-interactive mode generates far, far more positive results than when I enter interactive mode (code pauses / continues with RETURN). This causes me to believe the random generator is using keyboard input as a random seed, which drastically (and negatively) affects the results.

I will, at another time, replace Numpy with a call to a proper, external random number generator. I see this current effort as computer science more than applied mathematics. However, what I am learning about the underlying structure of code is likely quite valuable.

Been coding till 2 or 3 am every night, photographing when the sky is clear ’till 5 or 6 am. Sleep till 10:30, go for a run, and back to the grind :)

kai

By |2017-11-24T23:55:09-04:00May 26th, 2015|Ramblings of a Researcher|Comments Off on GP update 2015 05/26

It’s a-l-i-v-e!

GP comes to live! by Kai Staats

At roughly 1:45 am, my code came to life for the very first time. My genetic program found a solution not through a one-time, randomly generated polynomial expression, but through an evolutionary process which arrived to the desired solution.

I pushed back from the end of the SALT control room desk, threw my hands into the air, and at a respectable volume, “It’s alive!”

Given an equation with 2 terminals (variables) and 1 function (operand):

goal: a^b = c
data: 4,2,16
operands: +,-,*,/

Zero solutions found in the first 3 generations, but by the 5th, it produced 7 correct solutions out of 10 trees. This is with a very basic “either you get it or you don’t kernel”. No parsimony (reduction to the simplest solution). No crossover. Just simple point mutation. I also tried up to 100 trees in fewer generations or fewer trees in 100 generations. Each converges at a different rate.

I am very, very excited … and totally exhausted.

By |2017-11-25T00:00:48-04:00May 22nd, 2015|Ramblings of a Researcher|Comments Off on It’s a-l-i-v-e!

Salsa & SALT

SALT, Sutherland, South Africa by Kai Staats

I was again mugged last week, just three train stops down from Muizenberg. My fellow researcher was knocked to the ground and repeatedly hit upside his head. I tried to defend, but one of the four guys displayed a gun tucked into the front of his trousers when I charged them. I backed off while one of them forced his hands into my friend’s pockets. Oddly, they did not discover his cell phone nor wallet. Following much yelling and insisting we had nothing for them to take other than the car battery we were carrying, they took the battery and ran.

We were lucky, we learned, as a man has been shot in that same spot a few weeks prior. Not the best part of town to walk through, it seems.

I was very much on edge for the following days. When I found a man who had been harassing another of the homeless population pressed up against a wall, the folds of his jacket in the clutches of my hands, I knew I had to get away for a while.

The South African Astronomical Observatory site at Sutherland is my retreat of choice.

Feels so good to be away from trains, sirens, car alarms, people shouting, and the constant awareness of potential crime. Planning a long hike across two or three ridges to a distant set of peaks I have wanted to visit since my first visit here two years ago.

Tonight I am working from the control room of SALT, one of the world’s largest telescopes. Listening to salsa, chatting with astronomers, and working on my Genetic Programming suite.

Every few hours I step out onto the wind-strewn plateau to enjoy the dark, southern sky.

By |2017-11-25T00:03:45-04:00May 20th, 2015|Ramblings of a Researcher|Comments Off on Salsa & SALT

GP update 2015 05/11

(email to my fellow researchers)

Been coding 4-8 hrs every day for two weeks (since the GPU workshop). I feel I am making a snails-pace of progress, but at the same time learning a lot, step-by-step, piece-by-piece.

In the past 72 hrs I have migrated all functions into a Class (library), the foundation of proper Object Oriented Programming. Thuso stopped by yesterday and got me over a hurdle. Robert gave me some pointers as well. Mostly motivation. All coding remains at the tips of own fingers.

My code is clean, modular, and scalable. All functions are now ‘gp.[method]’ enabled. Once I get the internal message passing working properly, building a GP will be as simple as passing a few variables from one method to the next. In essence, I am creating a GP platform.

This may seem a bit overboard, but it sets the foundation for much simpler movement into the next steps: mutation, cross-over, and reproduction. I have merged what were two scripts into a single base which enables both Classify and Symbolic regression functionality, auto-selecting the associated dataset from the files/ directory.

The Tournament selection is done and tested. It randomly picks n Trees from the total population, selects the one with the highest fitness, and stores that in a list. Once for reproduction and mutation. Twice for cross-over.

Mutation is drafted. Need to call the methods in the right order.

Back to work …

kai

By |2017-11-25T00:03:38-04:00May 11th, 2015|Ramblings of a Researcher|Comments Off on GP update 2015 05/11

Goodbye Galen

Two nights ago, my uncle Galen passed away after a return of cancer. I have said all that needs to be said in a forum more appropriate than this, but he was a second father for me at times; I will miss him dearly.

What I loved most was his direct approach to life. He never held back what he thought. Direct. Even blunt. In our final conversation, just hours before he passed, there was again story telling and laughter.

I am going to miss that. Thank you.

By |2015-09-23T10:46:21-04:00April 26th, 2015|The Written|Comments Off on Goodbye Galen

GP update 2015 04/14

(email to fellow researchers)

The GP Evaluation section of my code is complete.

I don’t want to admit to how simple this was, but after a few sleepless nights I woke this morning with a solution to synchronise the variables created by the SymPy eval function with the columns in the original data.csv

My code now draws the variables from the first row of data.csv (instead of a sep file) and auto-walks through every row for each tree, comparing the output of the randomly generated polynomial against the desired solution.

For my very simple test, I built a .csv whose solution for every row is the sum of all the numbers, as follows:

   a,b,c,s
   1,2,3,6
   4,5,6,15
   7,8,9,24

And by random luck, my third run of a single tree came up with the solution. However, it has not happened again, since :)

I can, as of now, draw from *any* .csv file, including the SKA data set. While it would not produce a valuable answer, it feels good to be real-world capable.

Now I am adding a flag for each tree that succeeds. Next, I will add support for Boolean operators and then build the Tournament.

Exciting!

kai

By |2017-11-25T00:03:22-04:00April 14th, 2015|Ramblings of a Researcher|Comments Off on GP update 2015 04/14

Learning recursion

Yesterday presented a real mental struggle.

I entered my office at AIMS with good friend Adriaan who had spent the night at my flat. I walked him through my work in Genetic Programming, sharing the challenges and success to date. The next step was to flatten the GP tree into a live polynomial in order to push real-world data through and learn how each tree performs.

I had devised a bottom-up approach, analysing the GP tree structure using the 2D array which holds each node and all of its associated values. A series of nested for-next loops would build the formula, starting at the bottom and working to the top. A bit mechanical, but something I knew how to do.

Adriaan suggested a top-down recursive method. I understood the concept of recursion, but had never programmed one properly. He drew an example on the black board and I was lost. He drew another, and I remained lost. I need physical examples for my brain to grasp a concept, and recursion is fairly ambiguous by nature. I grew frustrated. And Adriaan had to leave for Town.

I worked on two other updates to my code. Now my operands and coefficients reside in external .csv files which are imported at run-time.

Arun arrived an hour later and suggested I write a basic recursion script to calculate factorials. Of course. That made sense. And it worked!

I then returned to my script and in about two hours more had it working. The challenge was fine-tuning the code to present 3 different levels of recursion depending on the ‘arity’ (number of child nodes) for each parent node. In the end, the number of lines of code was similar to my original approach, but recursion is more elegant … and I learned something new.

Thank you Adriaan and Arun!

Now, my GP code generates randomly generated mathematical polynomials which will soon be tested in a tournament to determine which ones will move into four types of mutation and reproduction to build the subsequent generation.

Progress!

By |2017-11-25T00:03:13-04:00April 7th, 2015|Ramblings of a Researcher|Comments Off on Learning recursion

When Nature Calls

Adriaan, Holy and I went to Natures Valley with the intent to camp for three nights, kayak, hike, and relax. The kayaking was wonderful, as we engaged in a guided tour of the shallow estuary, its tributaries, and hatcheries. We enjoyd a mid afternoon nap on the first day there followed by a fabulous dinner cooked over two camp stoves and an open fire.

But on the second evening, it began to rain.

That night, I woke to the realisation that the floor of my tent was holding back a substantial amount of water. I looked outside the door to find my shoes floating. By the time I sat up, put on my shorts, and threw the few loose items into my backpack, the water had risen over the waterproof portion of the tent and soaked my sleeping bag.

I yelled, “Adriaan! I think it is time to go!” He yelled back, “Yeah, I agree. Already packing!”

I raced from my tent to the back of his bukkie (truck). Holy was already in the camper shell, having escaped the drips on her face in their large, shared tent two hours prior. The water was up to the wheel wells but the started the engine. Adriaan drove off to make certain he could get the vehicle out.

The entire camp ground came to life. Car engines sputtered and choked. Horns and sirens sounded as electrical systems shorted. People drove and walked to the higher ground just outside the entrance. We were lucky, as our campsite was but 50 meters from the gate. I can’t imagine the effort those further into the camping ground and further downhill must have mustered to escape.

I pulled each corner of my tent from the ground, throwing it over my shoulder. I walked, barefoot, to the top of the road and found Adriaan, Holy, and the bukkie. We went back to get more of our things from their tent and the picnic table. By this time, we waded through water nearly to our waist.

We helped the neighbours escape as they had three children, the youngest of which could not have been a year old. Their car was on higher ground, the water to the undercarriage. They did not seem to recognize what they had to drive through to get out. We walked with their car to make certain they made it, their tent and some belongings left behind.

The water went down nearly as quickly as it had risen. We removed Adriaan’s tent and by 2 am were on the road again, soaked, chilled, and overwhelmed by all that had happened.

Adriaan drove all night. I slept in back, wrapped in a damp sleeping bag, Holy in front with the heater on high. The day went well, with a visit to the southern tip of Africa and then a national park just outside of Hermanus. There we dried our gear and enjoyed a four hours hike.

The next week, I was discussing the adventure with one of the astronomers at SAAO. He was there also, but arrived the next morning. When he and his family arrived, it appeared to be a war zone, downed trees piled across the bridge and riddled across the campground. Gear, tables, chairs, and toys scattered everywhere, soaked, snapped, or destroyed.

The sad truth, Petri explained, is that this happens every couple of years, yet there is not a single sign warning patrons of the possibility of flash flood.

By |2017-04-10T11:17:34-04:00April 7th, 2015|2015, Out of Africa|Comments Off on When Nature Calls
Go to Top