Rough Book

random musings of just another computer nerd

Tag: perl

The new vivin.net

Well, I finally did it. I decided to migrate over to WordPress! For a long time I was thinking of rewriting my homegrown blogging-engine (that I initially designed over seven years ago). I never got around to doing it because it was just so much work! I know part of it has to do with the “reinventing the wheel” syndrome. There is a certain pride that a developer has in coming up with his own solution for a problem. But then I realized that the problem has already been solved, but other people, with more resources than I, and in a much nicer way that I could ever do. I also realized that any new design would be a constant work in progress, and frankly, that just gets tiring after a while.

So, I made the decision to use WordPress. This meant that I would have to migrate all my old posts from my old database into WordPress’s database. Thanks to WordPress’s excellent database-schema documentation, this wasn’t hard at all. I wrote a Perl migration-script to move all my posts, comments, and tags into WordPress. I also had to make some changes to my .htaccess file (and write a redirect php page) to ensure that links in the old format would get translated into the new format. Everything seems to be working pretty well so far! I know there are a few rough edges to sand down (basically the old project pages, which aren’t visible now) but I don’t think it should be that difficult.

To my readers (the two or three of you!) if you spot anything out of the ordinary in my old posts (bad formatting, unparsed tags, broken links) please let me know so that I can fix it! Oh and another thing, since WordPress makes it so easy to add new posts, I think I will be writing a whole lot more!

Sulekha: A text-based Markov-chain generator

I’ve finished work on the projects page. Sometimes I’ll have a passing interest in something that leads me to write some code for fun. Yes, you read right. I like to code… for fun. Anyway, this is something I’ve done ever since I started programming way back in 1991. I’ve written a bunch of cool little programs over the years. Most of these have been throwaway scripts that I wrote just to “see what would happen”. A few of these, however, have had some serious effort put into them. I’ve decided to showcase these on my site. Hopefully people will find them interesting :).

The project I’ve just uploaded is called Sulekha, and is a text-based Markov-chain generator. You can check it out here. The comments for this journal entry are mirrored on the Sulekha project page, so anything you post here will be visible there (and vice versa). Let me know what you think. Oh, and it’s interactive so you can generate your own text-based Markov-chains too!

Over Here – Day 114

I guess this would be my first post from Iraq. I am in Baghdad right now, but I can’t get more specific than that. If I told you, I would have to kill you. God… I’ve always wanted to say that! Right, so I’ve been here from the 6th of this month. We left our camp in Kuwait and drove for about an hour to the airstrip. On the way, we went through the desert (no way!) and saw wreckage from the first war. It was pretty neat. After we got to the airstrip, we unloaded all our stuff, and then loaded it into a C-130. It was my first trip ever, in a C-130. I guess now when we sing cadences of going on a C-130, I will be saying the truth now. Like almost anything in the Army, the C-130 is not made for comfort. It is completely utilitarian and only serves to transport troops without any regard for comfort or aesthetics. In fact, it almost seems that the seating was added there as an afterthought. The flight was very cramped, and very loud. To get an idea of the experience, squeeze yourself and five people into a garbage can, and then have someone bang on the outside for one and a half hours. We touched down at BIAP (Baghdad International Airport, or “bye-op” as it is known and pronounced here) and proceeded to unload our stuff and then load it into the back of a truck. My first view of Baghdad was the airport and the bombed out bunkers at the airport. It was rapidly getting dark, and so I couldn’t see much on the way to the barracks. We had no idea if we were “inside the wire” (in a safe-zone) or not, and so we were saying how much it would suck to get hit by an IED. Typical Military Black Humour. Once we reached our barracks, we got the keys to our rooms. I was only going to be there for one night since I would be leaving with 2nd platoon to another FOB (Forward Operating Base) the next morning.

The next morning the unit at the other FOB came to escort us over to our new location. We travelled through the red-zone to our destination in the IZ (International Zone). It is hard to describe the feeling of being in a combat-zone and of being in imminent danger. I didn’t feel scared, but only highly focused and alert. I mean, this was the real thing. I might have seen movies before about being in a war, but now I was in one for real. Our journey was pretty uneventful, but exciting. In Iraq, the military pretty much owns the road. A good analogy would be ambulances and fire trucks back home. You know how we move out of the way when we hear a siren? It’s pretty much like that here. The civilian vehicles move out of way when the convoy passes through the road. The gunners wave the cars out of the way from their turret. It’s pretty funny at times – some Iraqis don’t move at all, and then suddenly they notice the convoy almost on them, and you see them swerve out of the way. We are actually authorized to push cars out of the way if need be. You might think that’s not a “nice” thing to do, but niceness has nothing to do with it – it is a question of survival. We get hit by VBIED’s (“vee-beds”, Vehicle Borne IED’s) and IED’s, so slowing down only increases our chances of getting hit and also increases the damage, which is why we stop for nothing. If need be, we even cut across curbs and go on the opposite side of the road, against the flow of traffic.

We finally got to our new location and found out that there wasn’t really any room for us. So there were 28 of us cramped into a little bay. I was a little disappointed, but I figured I could hold out for a couple of weeks. Being in the IZ was interesting. I got to drive around and see a lot of landmarks, like the Ba’ath Party Headquarters, the Crossed Sabres, the Al-Rashid Hotel, and the American Embassy in Baghdad. The IZ is a huge fortified zone, and I guess it would be the safest place in Baghdad. It was a pretty neat place to be stationed in, but unfortunately it wasn’t for us. In typical Army fashion, our mission changed and we had to come back to our original base to join the rest of the company. However, the day before we left, we got to do some weapons qualification. I got to fire the M2 and the M249 and qualified well on both of the weapons system. Oh yeah, while we were at the range, we saw a mortar hit in the distance. But that’s part of the usual flow of things here. On the way back from the range, I got to drive. It was pretty exciting. We were going along at a really fast clip, and had to cut the curb and jump over the median a few times and go against the flow of traffic. Definitely an experience.

The next day, we convoyed back to our original location and joined the rest of the company. I was also detached from 2nd platoon and re-attached to Headquarters. I was happy to be back with my old friends, but I have to say that being in a line platoon was pretty exciting and that I did enjoy the experience immensely. In addition, I was with the best line platoon in our company – they have a bunch of good soldiers, and learnt a lot of stuff from them. After I came back, I found out that I had a room, but no furniture. In fact, it’s been like that for about four or five days now. I have been sleeping on the floor, with my sleeping bag. There were some cots for me to use, but they were full of dust and dirt, missing poles, and didn’t seem very stable. But the floor isn’t that bad. Anyway, I alerted my leadership to the shortages and so now I’m just waiting to get my furniture. But it still sucks and I’m a little annoyed. I’ve been living out of my duffel bag for about 3 weeks now. Oh well – it’s what we’re trained to do anyway.

Right now I’m doing what I’m normally supposed to do; working in the motor pool. It’s not too bad, since I’m with my friends, but it’s not exactly the most exciting job either, especially when you’ve been out driving like a maniac on the streets of Baghdad. But it’s safe, and that makes my friends and family happy. I also have a free reign of the operations in the motor pool and so I can streamline and structure the operation the way I want. The Army’s current logistics software, called ULLS-G, written sometime before the extinction of the dinosaurs, is about as smart as a retarded house-plant. So I’ve taken the liberty of automating different processes. I’ve been able to use SDI (another tool made by the Army, but this one is actually pretty neat) program to talk to the database and dump the data into text files. After that, all I need is some Perl (of course!) magic to transform it into an Excel Spreadsheet (using the Spreadsheet::WriteExcel module). My section chief was pretty impressed with what I was able to do. Now I just need to find a way to actually write to the SAGE database files. The data is either encrypted or packaged into some binary format and so I can’t seem to access it. If I could, I could make changes really quickly instead of using the brain-dead ULLS-G interface. I’m not sure if anyone out there knows the file-structure of a SAGE database file, but if you do, please let me know.

Oh, and by the way, since I moved back to my original FOB, my address has changed back to what it was originally. So here it is again:

Vivin Paliath
504th MP – HHB 1/180th FA FWD
APO AE 09344

That’s about it for now. Here are some more pictures, and a video. I have the video for download using BitTorrent. I don’t want to offer a direct link because my server only has so much bandwidth, and I don’t want to clog it all up. If you want to download the file, download the BitTorrent client from the link I just provided. The client is a small download, and trust me, it will be faster than just download the file directly. I won’t tell you what the video is, so you’ll just have to watch it. I made it myself, and I hope you like it! I’ll post more videos here as I take them.

Loading Up
Loading our stuff into the trailers, in Kuwait.

In C130
Inside the C130.

Me inside the C130
That’s me, inside the C130.

C130
The C130 Hercules.

Baath House
The Ba’ath House.

Crossed Sabres
The Crossed Sabres.

Pedestal
This is the pedestal that Saddam’s statue used to be on.

Stadium
This is where Saddam used to stand, brandishing his rifle.

An Iraqi kid and I
This kid was trying to sell us DVD’s.

Post Mortar Attack
This was right after a mortar hit a little ways from us.

50 cal rounds
That’s me with some 50 cal rounds.

Update: I have fixed the redirection and caching problem. To ensure that you are able to access the latest entry in my blog, please clear your caches now. My page instructs your browser not to cache, and so whenever you access my website, you will be brought to the latest journal entry.

Artificial Life – some preliminary findings

I fnished my artificial life simulator over the weekend, and I have been running simulations on it. There were a few bugs initially that I quickly fixed. My initial simulations gave me some inexplicable “population explosion”. For example, in one cycle I would have 31 creatures and in the next cycle I would suddenly have around 9,000. It didn’t make very much sense until I analyzed the log files.

If any of you remember, I mentioned earlier that my “creatures” are nothing more than assembly programs. Each of these instructions (and parameters) translate into a bit pattern. Changes in the bit patterns lead to changes in the behaviour of the creature.

One of the instructions is a “reproduce instruction”. This prompts the creature to create a copy of itself, with possible mutations. The instruction has a parameter that tells the creature how many copies to create. During the course of the simulation, certain creatures evolved with the reproduce instruction as their first instruction.

My supervisor program (God program) runs one instruction of every creature during one cycle (sort of like an pre-emptive multitasking operating system). If a creature happens to reproduce during the current cycle, then the supervisor program will execute the child’s instructions as well in that current cycle. This led to an interesting situation. When the mutant that had the reproduce instruction as the first instruction reproduced, its child (if it didn’t have a mutation that changed the instruction) also had the reproduce instruction as the first instruction. So the supervisor program would run the child, and the child would reproduce with a similar offspring. This went on until a mutant that did not have a “reproduce instruction” as the first instruction, evolved. As you can see, this is what led to the population explosion. I corrected this problem by adding “sexual maturity” and “reproductive energy threshold” parameters to the creatures. Basically, a creature can reproduce only if it has been in existence for a certain number of cycles, and if its current energy is above its reproductive energy threshold. This got rid of the population explosion problem.

My simulations gave me some other interesting results. One of the instructions that I have is a MOV instruction. This instruction moves a creature from one cell in the two-dimensional array to another cell. There is a variant of this instruction, known as the MOVA instruction. In the MOV instruction, if the creature tries to move to an occupied cell, it will retreat to its original position. However, in the MOVA instruction the creature will try to kill (and subsequently eat) the occupant if the destination cell is occupied. I had created a creature that simply ate, reproduced, and moved to different cells. I noted that after many generations, this creature had evolved into an aggressive one, that would eat, reproduce, and move aggressively (MOVA) into other cells. That was rather interesting!

I also saw natural selection at work. When I corrected my population explosion problem, I made it so that the reproductive threshold of a creature was higher than its initial (starting) energy. Over the course of many cycles, I saw that the creatures evolved such that the initial energy would be very high, and that their reproductive threshold would be very low. In additon, their reproductive age was lowered. I thought that my creatures were having it too easy, so I modified my code to make reproduction a costly instruction. After running my simulation, I noticed the opposite! Now the creatures evolved such that the reproductive energy threshold would be much higher than their initial energy. It would seem that the creatures wanted to build up enough energy to where they would be able to reproduce successfuly.

There is also one very interesting behaviour that I noticed. I provide branch instructions in my instruction set. A creature can branch to any part of its code. In addition, I also have a Decrement and Branch instruction that is useful for iterative loops. One of my creatures evolved a clever strategy. It would decrement and branch into the middle of the branch instruction. When I analyzed the code, I noticed in doing so, the creature was performing a MOVA instruction in fewer bytes than writing an explicit MOVA instruction. It also had the added benefit of performing the MOVA instruction in an iterative fashion so that it could travel around the two-dimensional array. There was a reason for this kind of behaviour though. A creature consumes energy when it performs an instruction, and the energy consumption is proportional to its code size, so it is amazing, but not surprising that such behaviour could arise.

There is still more work that I need to do. I am thinking of giving my creatures some “memory” in the form of stack and RAM. They will have some Store, Load, Push and Pop instructions whereby they can write to and read from memory. Also, I am thinking of adding some more “registers”. Right now, the creatures have two count registers for performing iterative loops. My reason for adding more is this – I want the creatures to be able to act on the data in memory. For example, I can provide instructions that allow the creature to check the status of a particular cell, like if it is occupied, how much food it has, and so on. The creature can load data into the registers, and then use these registers as arguments for the cell checking instructions. This way I am hoping that my creatures will be able to evolve some rudimentary form of “intelligence”, or “intelligent” behavior. This will also increase my instruction set. Right now, if a mutation results in an invalid instruction, the creature dies when it tries to execute it. Actually, that reminds me – I had creatures that evolved with invalid instructions, but they had also evolved branch instructions that would jump over the invalid section of code!

Most of these complex behaviours aren’t that surprising when you consider natural selection… it is only err… natural that such behaviour should arise!

Well I guess that’s all I have for now. I might make a separate page for this project where I can describe this project in more detail. I’ll post more updates here after I run more simulations.

Intel and Artificial Life

This is my fourth day at Intel. I think I will enjoy working here. I haven’t done much yet though, and I still don’t know exactly what it is I am supposed to be doing. I tested some 140 chips yesterday, but that wasn’t too much work. My supervisor is out until Tuesday, so until then I am doing some odd jobs and reading up some documentation about the platforms and tools we use. I am excited to be working here. It looks like it’s going to be hard work, but I think it will also be fun.

Now about the Artificial Life. I have written up some specs on an Artificial Life program. This is different from earlier ones. I am implementing the “creatures” like assembly programs. This code is their “DNA”. It describes how they behave. A “God Program” executes one instruction of each “creature” and moves on to the next. Sort of like a pre-emptive multitasking operating system. The creatures all live in a two-dimensional area of memory. They can reproduce, and there is chance of error during reproduction.

I think I was going about it the wrong way earlier. I was trying to describe behaviour through variables and through discrete quantities. Now, I represent each creature as a bit-pattern – exactly like an assembly program. I have instructions for moving, eating, moving and attacking, reproducing, and sleeping. In addition, I have some very basic branches and loops. So based on the bit pattern, the creature has a certain behaviour. Also, changes in the bit-pattern can cause changes in behaviour. They can be subtle, or drastic. At least, that is what I believe. I need to actually implement my idea before I can find out! My God program is essentially an operating system, and the “creatures” are tasks. There’s a little more to all of this, but I can’t write it all here. If and when I finish the program, I will make a separate page for it and describe it in detail.

I am thinking of calling this program “Eden”. Anyway, that’s all for now!

Whoa

I had my very first code review. It was interesting and slightly unnerving. I had all these people who had gone over my code, tell me what was wrong with it. Luckily, nothing too serious! Just minor issues. I learnt some new stuff though.

THEN, I found out that my highschool friend is GETTING MARRIED! Yeah, he’s getting engaged this year… Crazy stuff… I can’t believe it…

Mandelbrot Sets

I’ve generated a couple of Mandelbrot sets.

f(z) = f(z – 1)2 + c; f(0) = c and c is complex number (x + iy).

They’re pretty sweet looking! I used Perl and GD to generate PNG images. The images are rather huge so please be patient. If you have a dialup connection, be prepared to wait a very long time for some of the images.

Ecological Simulators and Photo Albums

I finished the “Delete Photos” page on the Photo Album Tools page… which of course, none of you can see, since it’s in the admin section. But anyway… It took me this long, because I had other stuff to take care of… namely CSE 421. I only have the “Update Photos” tool to finish… after that, I should start working on the actual photo album display page. In other news, I’m working on a JavaScript version of my Perl Ecological simulator (the one that ran wild on ASU’s general server… ohhh I’m so proud of myself). Except in this case, it’s objects that are killing each other… it should give me a lot more flexibility. My creatures even have randomly generated names like “zexoyiwub” and “xorigewor”. It’s going to be fun… once/if I finish it.

Some updates…

Hey guyz! Will someone write something on that message board? I’m tired of seeing those old messages… What’s happening?? How’s the new semester!! Nimish! I know you’re accessing it! I can see you! Write something! Okay.. on to new stuff. I’ve updated the About Me section. No Pics, I’ve rewritten the entire thing. Read it if you want. I think I will be busy all of new week. I have to figure out the entire process for my classes and essentially get used to the new schedule. Wish me luck! Well, that’s pretty much it! I’m thinking of starting work sometime on the guest book. I’d like to write it in Perl and have a CGI script. I can’t use CGI here as there is a security issue… I’ll think of something! Anywayz, that’s all! I’d better go now! Cya!

All original content on these pages is fingerprinted and certified by Digiprove
%d bloggers like this: