Rendering Trees with Meteor.js + Handlebars

Handlebars is currently the only template engine integrated with Meteor. Notably absent from Handlebar’s feature set is the ability to pass context between blocks. Furthermore, the scope of a parent block is absolutely inaccessible from the child’s context (no super, no this.parent).

One can get around any restriction imposed by Handlebar’s markup by writing a custom block helper. The theory behind block helpers is to keep logic separate from the design markup. Every block in Handlebars (if, each, with, list…) calls a block helper behind the scenes. The block helper is a function which takes the block’s HTML content as an argument, as well as any arguments listed in the block’s declaration, and uses these arguments to return a string which is rendered in place of the block. It’s sort of like a macro.

In the case of a tree, using a block helper is absolutely the way to go.

DSP Experiments

I spent the final days of the summer exploring the Fourier transform with Nicolas Avrutin by writing an image <-> audio converter in Python/Numpy. This was more an exercise in learning Numpy, but the result is pretty cool:

This is the spectrograph of an 18 second audio file generated by our script. The ghostly vertical lines are due to interpolation issues, translating an image sampled at a certain rate into an image with far fewer pixels columns than necessary. Color represents intensity of the sound.

We implemented a full color version by using a three channel WAV file (usually used for surround sound or secondary language purposes). We had to write a custom spectrograph generator, as SOX will not combine the channels into a color image. Here’s SOX’s spectrograph:

And our own spectrograph:

Work has been halted on this project while Nick and I deal with school, but this could be used to embed a faint image into music.

ORM Models for restful APIs

I wrote a nifty class which wraps URLLib behind an interface for RESTful web services. The result is a set of one-liners that can be used to import data from compatible APIs.

The goal of this project is to easily import and process data from disparate APIs without needing to read thousands of pages of poorly written documentation. Just import the models you need and hit the ground running.

Think of it as Yahoo Pipes, but local and in Python instead of a graphical programming language.

Single Rule L-System Fractal Generator in Python for Autocad

My first assignment at Cooper Union was to make something in AutoCad, a program used by engineers worldwide to draft architectural plans and machine parts. I decided to write a script in Python that generates the lines of an L-System fractal (as described in The Computational Beauty of Nature by Flake) I used the SDXF library for Python to write the AutoCad DXF file format. You can check out my source code here -> autol.py

Processing Chaos

After reading the wonderful Chaos (James Gleik), I was inspired to pick up a copy of The Computational Beauty of Nature (Gary Flake) and explore chaotic computation for myself! My tool of choice was Processing, a simplified yet powerful programming language built on Java.

I began this endeavor by exploring the Mandelbrot set with Zlata over the MIT Spark weekend. In the wee hours of Sunday morning, the first grainy images of the Mandelbrot set came into view. Uplifted by this success, we toiled tirelessly to create a full color, zoomable, and downright awesome fractal generator.

One of the best renderings from our Mandelbrot generator.

View Demo

Adding color was one of the toughest challenges we encountered. The standard RGB color notation is great for most purposes, but it really does fall short for generating the spectrum. In order to more easily generate a smooth color spectrum, we switched the project to HSL color and were able to simply scale the “H” (hue) property with each point’s iteration count.

Another interesting problem which still exists as a “bug” in the demo applet above is the lower limit imposed by the floating point datatype. As you zoom in farther and farther, the coordinates shrink down to absurdly small and precise values. Eventually, the measly floating point becomes imprecise, and the display seems pixelated. An easy fix would be switching all datatypes to doubles or bignums, but that would just take too much effort. It works!

Next I tackled the Lorenz Attractor. One of many such “strange attractors” that visualize the changes in a dynamic system by plotting the system’s state in “system space.” In the case of the Lorenz Attractor, fluid convection is represented in 3-space by the following set of equations:
From hypertextbook.com:
dx/dt = σ(y − x)
dy/dt = ρx − y − xz
dz/dt = xy − βz

As stated above, “x” is the convective flow, “y” is the horizontal temperature distribution, and “z” is the vertical temperature distribution of the system. Curiously, the orbit of point (x,y,z) over time will not “settle down” or form a repetitious cycle given certain critical values for σ, ρ, and β. Instead, the orbit forms a magnificent, infinitely complex object known as a strange attractor.

The Lorenz Attractor

View Demo

Bresenham’s Line Algorithm

Bresenham’s line algorithm is the best known way to render a continuous and straight line through a raster display. I started out allowing floating point operations, but quickly decided to implement the algorithm using only integers. I didn’t like the online explanations and tutorials of the algo, so I decided to write something that I conceptually understood. View my code here.

My algorithm works by increasing an “error” variable by y0 – y1 every iteration. Should the error ever rise above x0-x1, the error is decreased by x0 – x1 and the drawn Y value is increased by 1.

Intel Submission: Observing Integrated Information in Evolving Neural Networks

I have completed a research paper on the how integrated information behaves during artificial evolution of neural networks in Polyworld. Mad props to Virgil Griffith (with his integrated information calculator) and Larry Yeager (author of the aforementioned Polyworld) for their incredible insight and willingness to help out a mere high school student.

Download the full paper as PDF (400k)

Abstract:

Evolution has proven to be a wildly successful autonomous process for creating intelligent systems in the natural world and in simulation. Since the early 1960s, re- searchers have used artificial evolution to find ingenious and novel solutions to complex problems such as series prediction and flight control. Recently, artificial evolution has been applied to neural networks with the aim of evolving more robust artificial intel- ligence. Several metrics have been proposed to chart the emergence of intelligence in these evolved networks. This work analyzes the behavior of a new metric, integrated information (φ). Observed data is analyzed, interpreted, and compared to more con- ventional properties of the artificial neural network. The data analysis shows that φ increases over evolutionary time and is therefore promising as a heuristic measure.

Experimental Data:

Results from Integrated Information experiments. The data set includes anatomical neural network sampled from 5,202 Polyworldians, at death, from three genetically independent simulations. Each data point represents a 200 time step bin size. *First sample for which p < 0.01