Friday, January 25, 2008

Life is like JavaScript, not like Java

Today most object-oriented programming languages, such as Java, are based around the class concept. The class describes the properties shared by all instances (objects) of that class; and individual objects are created as instances of a particular class. Class-based object-oriented programming originated with Simula and Smalltalk. An alternative is prototype-based object-oriented programming. This is used in JavaScript, and originated with Self. In prototype-based object-oriented programming there are no classes, only instances. New instances are created by copying the properties of an existing instance (the prototype) and adding new properties.

The difference between class-based and prototype-based programming is a useful metaphor for understanding the complexities of the biological concept of Species. Life consists of instances copied from one another (like JavaScript). Species are a class hierarchy (like Java) we try to impose on the instances after the fact -- we forget species is a man-made construct. Nature just does whatever it does, and we try to simplify it by mapping to categories and rules. Certainly species is a useful concept for living in the world. You don't want to take a child to the zoo and say "see the animal instance?" "see the plant instance?" (or just "see the instance?" !). You want to say "see the giraffe?". However, the usefulness of species (or folk categories) does not mean they always obey our expectations.

The difference between class-based and prototype-based programming is also related to the philosophical Problem of Universals. Do classes exist in the real world, or only instances? The most famous theory of real-world classes is Plato's Theory of Forms. In Platonic Idealism pure archetypes for different objects (such as chairs, or giraffes), and ideas (such as justice, or triangles), actually exist in some other space or dimension our minds can contact. This theory was modified, but not completely rejected, by Aristotle's Theory of Universals. Aristotle thought universals were constructed from the common properties of the instances, rather than existing as pure Forms somewhere else. From these Greeks we inherited the idea of dividing the world up into invariant categories, and performing logical operations on them. That works to a point, and makes science possible. But the simplified model is not the real world -- "the map is not the territory".

The psychology of folk-biology, along with folk-psychology, folk-physics, etc. arose naturally through our evolutionary heritage and individual maturation and learning via interaction with the natural world. Even beliefs in the soul, etc. are understandable in this context. A great book on all this is Philosophy in the Flesh : The Embodied Mind and Its Challenge to Western Thought, by George Lakoff and Mark Johnson. Yes, it is a 624 page slog. In part II some of the examples can be skimmed. But if you make it through it will completely change your understanding of what metaphor is and how we think. You will realize that 99% of philosophy is out of date. That we often just trade one set of absolutes for another, without understanding the real biological reasons why we are wired to search for and believe in absolutes in the first place.

Sunday, January 20, 2008

Did the First Giraffe Have a Navel?

Intelligent Design is turning into a hot topic. Given all the efforts being made by IDers to get attention, it is surprisingly hard to find details on how their alternative to Evolution is supposed to work.

A common criticism among IDers is about the lack of fossils of "intermediate forms" between species that evolved from one another. The ID answer is that there was no intermediate form; instead the new species was created whole. An example of an allegedly missing intermediate form is a short-necked ancestor of the giraffe.

What I'm not finding any details about is exactly how, according to IDers, the first giraffe appeared. Did 2 adults (one male, one female) miraculously poof into existence a million years ago? Or was the first pair of baby giraffes born to and raised by deer? The first seems more likely if the intelligent designer was a deity, the second if it was space aliens[1].

Any links to explanations would be appreciated. Does anybody know if The Design of Life (3rd edition of the ID high school biology textbook Of Pandas and People) has an answer?

[1] "It could be space aliens," said William Dembski, a mathematician and philosopher at Baylor University in Texas and author of No Free Lunch [and later The Design of Life], a new book on intelligent design. "There are many possibilities." San Francisco Chronicle, Sunday, March 17, 2002

Sunday, December 2, 2007

OpenMP

Intel C++ supports OpenMP, a standardized API for shared-memory multiprocessing in C++. By adding a simple #pragma loops can be split up to automatically run in parallel on multiple cores. I added a simple change to the per-screen-line rendering loop of my generic ray tracer:

int screenX;
#ifdef USE_OMP
#pragma omp parallel for firstprivate(portPoint)
#endif
for (screenX = 0;
screenX < SCREEN_WIDTH;
screenX++) {

With this change each pixel is rendered by a separate thread, with a maximum of 4 (the number of cores) running simultaneously. This use of threads is an alternative to the explicit pthread threading tested previously, where a separate thread was used per line of the screen. In this case OpenMP is simpler than explicit threading, though it yields slightly lower performance.

GCC 4.2 also supports OpenMP, but its performance is much worse than Intel.

Monday, October 15, 2007

Genezzo Drive Performance

My Clustered Genezzo code is relatively slow because it doesn't use a write-ahead log. Its access pattern involves repeated writes and syncs alternating between blocks at opposite ends of the data file. Potentially it could run much faster on a solid-state drive. I tested the performance of inserting 1000 integers into a table, with a commit after each insert. I avoided SQL to eliminate Perl Parse::RecDescent overhead. I tested a internal SATA drive, a Coraid ATA-over-Ethernet SAN drive on 100Mbit ethernet, and a SanDisk USB 2.0 ("keychain") flash drive. The system monitor showed the internal SATA drive test was CPU-limited, while the ATA-over-Ethernet SAN drive test was network-limited. I also tested base Genezzo without Genezzo::Contrib::Clustered enabled. Base Genezzo also lacks a write-ahead log, but performs fewer syncs per commit and fewer widely-spaced writes. All tests were done on 500M databases, except for Genezzo::Contrib::Clustered on flash which used the default 600K (?) size. With a 500M database the flash test using Genezzo::Contrib::Clustered got 3 commits per second; this requires further investigation...

Monday, October 1, 2007

Updated Clustered Genezzo on CPAN

Revision 0.34 of Genezzo-Contrib-Clustered has been posted on CPAN. One module moved, one test fixed.

Monday, July 16, 2007

Intel C++ Compiler

I recompiled my generic Ray Tracer code using the Intel C++ compiler. Using SSE3 auto-vectorization I obtained a 21% speedup over GCC.

Wednesday, July 4, 2007

Cell PPC Hardware Threads

The PowerPC unit in the PS3 Cell processor supports two hardware threads. Earlier I added pthread support to the generic ray tracer code. I have updated Real-Time Ray Tracing on the Playstation 3 Cell Processor with PPC performance measurements with pthreads and the IBM XLC compiler. Pthreads gives a 63% speedup, and XLC gives a 26% speedup, and together they give an 89% speedup: