Archive for the 'coding' Category

Newscientist: Horizontal and vertical: The evolution of evolution

http://www.newscientist.com/article/mg20527441.500-horizontal-and-vertical-the-evolution-of-evolution.html?full=true&print=true

Lately, I’m increasingly thinking, especially after reading this article, that evolutionary computing would benefit greatly from using a more bacterial type of evolution, where genes are shared between often unrelated organisms, rather than brute inheritance. Another way of looking at it, is it might be good to deal with the complexities of subroutine sharing (which functional programming would make easier) than the complexities of sexual reproduction which make my eyes glaze over to read the solutions offered for. Maybe I’m just not clever enough (my earlier post on genetic programming had a little ruby script and it only uses asexual reproduction).

I am skeptical of the article’s claim that the shared genetic code of all organisms must mean that genes were shared between organisms like bacterium do today. Firstly, bacterium don’t all share some common genes due to the passing of genes between species as it is. Secondly, clade evolution – where clades that are just better at evolving edge out others over time could be sufficient explanation. Surely DNA-based life had immense advantages over life with less fault-tolerant code. Just the same, the article makes a good point that biologists are, being human macro-centric – they focus on multi-cellular organisms even though most of the biomass, even more of the variety, along with the vast, vast majority of the history of life on this planet, is prokaryotic.

Exercise 3-6: Sorting Lists & 3-7 Using Library Modules

It looks like there’s one other guy on the internet who’s posting his answers for the exercises in this book. So, I’ll be linking to his so you (and I) can compare our answers. He knows what he’s doing. In his posts, he talks about, e.g., what he’d do in Haskell. I’m not a functional programming guy (lisp gives me the heebie-geebies, my earlier post on evolutionary programming where I used it notwithstanding). So, below are my answers (click to see more if you’re looking at the blog and not this post by itself) and here is the Japanese guy’s answers.

Continue reading ‘Exercise 3-6: Sorting Lists & 3-7 Using Library Modules’

Exercise 3-5: Manipulating Lists

Next installment in my “Thomas does your homework” series…

Continue reading ‘Exercise 3-5: Manipulating Lists’

Exercise 3-4 Database Handling Using Lists

Here’s my clumsy attempt at the database handling exercise. Man, I must be a nerd, but I actually like these exercises.. I’m also enjoying my biology class. Is there something wrong with me?
Continue reading ‘Exercise 3-4 Database Handling Using Lists’

Erlang Exercises – Chapter 3

I learn by doing much more than by reading or listening, so as I go through O’Reilly’s Erlang Programming, I take the exercises at the end seriously. Generally, when I learn a new programming language, while I read, I’ll make a program of my own choosing, perhaps something that will be useful to me or that I could sell. However, with Erlang, I don’t even know where to begin using it yet. I want to get really, really good at it before I even attempt to make anything with it (I think remembering the mistakes I made with my first Ruby on Rails project caused this shift in attitude.. and let’s not forget the triumphs of reading Mastering Regular Expressions in its entirety).

I will be posting my attempts at the exercises, in case others might find it useful or seasoned Erlang programmers might tell me what I may be doing wrong. I’ll be spacing out my answers to chapter 3 over the week to keep things interesting. Here are the first three exercises from Chapter 3:
Continue reading ‘Erlang Exercises – Chapter 3′

Update (on Earlier Post on Evolutionary Programming)

Apparently, without realizing it, I implemented a technique known as grammatical evolution, and the thing I’ve been aiming to do is called a genetic programming problem solver. More on this later, but here is the earlier post.

I Created Life!

Here is a ruby script I quickly whipped up to teach myself genetic programming/evolutionary programming, and also to demonstrate basic principles of biology (please see below to see how it works.. if you’re on my front page, click to read more first). I think I’m going to write something more sophisticated in erlang (I don’t know erlang, but I’m intrigued) after I get further down the road in gp, but here’s what I quickly whipped up. Since writing it, I have started reading A Field Guide to Genetic Programming and already notice some things I should have done a little different. But in some respects, having a simple string of characters change their role in different modes is elegant and I think I prefer that way of doing things, despite shortfalls in statistical bias. Here are some observations I have at this point:

I know the people researching gp are really smart, so there’s probably something I’m missing, but I don’t see how genetic programming is supposed to quickly find solutions. Evolution is as slow as molasses. You need to dig through millions of years of dirt to see actual changes. I can only see gp quickly finding solutions if the process is being run continually, with multiple challenges or “resources”. I was glad to see, after having this thought, mention of multi-objective (5.1.3) and coevolution (5.4) in the book. It makes me think I’m on the right track. I also remember a while back reading in the article Discover had about Avida that when there was only one resource, one species would quickly capitalize on that and then the evolution would stagnate, but having multiple resources would create diversity and even better solutions at attacking that one resource. The ability of organisms to repurpose adaptations is important in evolution and without it, most complexity would not have been possible.

This leads me to another point. It seems gp works best when it works the most like evolution in the real world works. The rate of mutation is low and, despite my initial intuitions that a high mutation rate would lead to a good solution more quickly, I found that it was actually harmful to do so. Even though, in this script, there is a bias towards shorter programs (the longer the chromosomes, the more calories it takes to create just one offspring), when I had a higher mutation rate, like, say, 1 out of 5 copies, the length of the genes would get really, really long as a defense against mutations. This could happen because if the last parenthesis of the mini-lisp program is closed prematurely, the rest of the genes are ignored. Junk dna. In my program, at least, junk dna was a defense against mutation since I would get really short programs that have long tails of junk after them, but decreasing the mutation rate shrunk those tails down to almost insignificant. Weird. Please try downloading this and edit it to see for yourself.

While mutations should be rare, it helps to have variety. I did just substitutions at first and it worked, but it took a while. I also added stutters, insertions and deletions. Once I added stutters, it helped a lot! Even before adding stutters, I found that, when the “challenge” was 6 * x, I would get x + x + x + x + x and something like 7 * x competing with each other for a long time (5x or 7x often becomes the leading candidate after a few generations and it takes forever for any 6x to show up). Adding the stutters seemed to get multiplication through addition happening faster, though.

Download yeasties or copy/paste from below (requires ruby and clisp):

Continue reading ‘I Created Life!’

Bandwidth Detection AS3

ex animo » Blog Archive » Automatic Bandwidth Detection for SMIL + FLVPlayback + Progressive Downloads

I was frustrated trying to get my flash player to do bandwidth detection, then stumbled on this site.. Apparently, there’s a bug in FLVplayback? Psh.

Create iCalendar Files in PHP

I whipped up a php class today to generate iCalendar files. I noticed halfway through making it that there are others (more like other, just iCalcreator). Mine focuses on just being really simple and so far, its output parses in everything I’ve used  (including Google Calendar).

Check it out here.

MusiTone

There’s this cool font you can use to pretty much make your own sheet music. It is a chore making music this way.. hmmm.. if only some robot could type the notes for you *grin* Anyway, on an entirely unrelated note, I made my own modifications to make it have additional unicode mappings, which you can download here.

fucking malloc()!

I am RETARDED! I spent most of today trying to get this app using OpenAL to work with a manually generated buffer (ie, not using a wave-loading function). I kept on trying to figure out why the damn program wouldn’t run without segfaulting. Finally, only after looking in the sources for ALUT, I realize that I should be using malloc instead of new like some sort of C++ baby.

stupid bug

there’s a bug in magpie, which this site uses to print out content from blogger. at least it’s a bug as far as I’m concerned. basically, it seems to convert the html entities into the actual characters (unless the actual php xml parser classes do this..) and as a result, the example wml file in the post below this one doesn’t appear. stupid!

Serving pages to cell phones

If you are bored on the train, never fear! Ugly, slow-loading websites on your cell-phone to the rescue! Seriously, kids. You can make a portable version of your website so easily.

Basically, you make the pages (index.wml) and throw them up. Easy, right? Below is a sample wml:

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="c1" title="Thomas J. Webb" >
        <p>
        <a href="news.wml.php">blog</a>
        </p>
</card>
</wml>

Most webmasters like to put the WAP version of the site in a different subdomain (such as wap.yahoo.com), but I don’t know why they bother. We have a wonderful thing in Apache called content negotiation. Throw everything up there and let the webserver sort it out. First, enable multi-views in httpd.conf:

MultiViews on

Then set the directory index as simply index. This way, the webserver selects from index.html (or index.php or whatever) for regular browsers and index.wml for cell-phone browsers.

DirectoryIndex index

Another higher-performance alternative to MultiViews is to simply use a .var file for the index. See Apache’s documentation for details…

携帯のサイト

つまらなくて電車に乗ってる時、つまらないサイトを見られる。楽しいね!まじめに小さいバージョンを作りやすいだよ。

まず、index.wmlを作ってアップロードして。やさしいね。

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="c1" title="Thomas J. Webb" >
        <p>
        <a href="news.wml.php">blog</a>
        </p>
</card>
</wml>

ウェブマスタはほとんどサブドメーンを作る。たとえばwap.yahoo.com。でも、何でか分かんねえ。ApacheのContent Negotiationはスーパーである。サーバは頭が言い。まずhttpd.confにコレを入れて。

MultiViews on

すると、始め見るページがindexにさせて。サーバはindex.htmlとindex.wmlの中に決心出来る。

DirectoryIndex index