Sunday, March 30, 2008

Markov Code

People have been asking about the Markov Chain code so I'll post it here. Note, I use the " " key to store the valid beginning sequences. If you want, change the KEY_LENGTH for more/less intelligible output.


package com.sciortino.fun;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;

public class MarkovChainer {

private static final int KEY_LENGTH = 3;
private static final Random RANDOM = new Random();

public static void main(String[] p_args) throws IOException {

if (p_args.length != 1) {
System.out.println("This program takes exactly one argument: "
+ "The location of the input file which has exactly one name per line.");
System.exit(1);
}

BufferedReader l_br = new BufferedReader(new FileReader(p_args[0]));

HashMap<String, ArrayList<String>> l_map = getMap(l_br);

ArrayList<String> l_startArray = l_map.get(" ");
for (int i = 0; i < 100; i++) {
StringBuilder l_buf = new StringBuilder();
String l_wordPart = l_startArray.get(RANDOM.nextInt(l_startArray.size()));
while (l_wordPart != null) {
l_buf.append(l_wordPart);

String l_key = l_buf.substring(l_buf.length() - KEY_LENGTH,
l_buf.length());
ArrayList<String> l_nextList = l_map.get(l_key);
if (l_nextList == null) {
break;
}
l_wordPart = l_nextList.get(RANDOM.nextInt(l_nextList.size()));
}

System.out.println(l_buf);
}
}

private static HashMap<String, ArrayList<String>> getMap(BufferedReader l_br)
throws IOException {
HashMap<String, ArrayList<String>> l_map = new HashMap<String, ArrayList<String>>();
l_map.put(" ", new ArrayList<String>());
String l_line = null;
while ((l_line = l_br.readLine()) != null) {
if (l_line.length() <= KEY_LENGTH) {
continue;
}
String l_start = l_line.substring(0, KEY_LENGTH);
l_map.get(" ").add(l_start);
for (int i = 0; i + KEY_LENGTH < l_line.length(); i++) {
String l_key = l_line.substring(i, i + KEY_LENGTH);
String l_next = l_line.substring(i + KEY_LENGTH, i + KEY_LENGTH + 1);
if (!l_map.containsKey(l_key)) {
l_map.put(l_key, new ArrayList<String>());
}
l_map.get(l_key).add(l_next);
}
}
return l_map;
}
}

Thursday, March 27, 2008

Markov Chains

Last night my friend Eric challenged me to write a Markov chaining algorithm to create fictitious Italian last names. For those of you not familiar Markov chaining is a simple process whereby you construct a word by looking at the 2 (or 3 or 4) previous letters adding a new letter which is statistically likely to came afterward. You need a reference set of words of course so I stole it from wikipedia. Here's the list. They have been tested to ensure that none of the generated fictitious names coincides with the real names.


abbatti
sabbiano
donardo
fortoni
fontano
posito
espossi
argenovese
spernabò
areschini
spintori
politali
tibalbi
gabrielli
bandretti
tremonte
roti
lombo
baiani
baglianchi
sola
giuliano
loggio
vita
molito
robbiani
gasparelliano
garo
rocchini
ungelista
morossetti
moscarlo
sartelli
giore
battei
bassini
barassano
devitaliparelli
evangenito
macci

cerugini
defendretti
ruso
manci
endretta
mini
mazzo
mily
matti
buonato
ventierrugia
codazzatti
pettista
silviattei
pelli
bocchiavoso
con
colo
cortolamini
costino
coppolini
annunziattei
antoro
anserminnella
flaminnellegri
aneri
anfredini
angenis
gentino
beroni
turielli
farro
famini
benis
pucciolombarbierrarini
belli
andido
sca
chiavonello
dano

bettista
fabriz
amoro
schio
eppola
testoro
davitabile
sclafano
ducciolombo
valcandriz
carlatto
fierrero
cantinola
napoletti
capinelli
vavone
finziatti
cavalcandro
sungaro
caccio
caetano
rizzi
campani
bianchiaparello
cali
ciprio
pacci
ale
lazzi
paladini
grini
picciolo
albernabò
panelli
bondini
bortino
ramacci
pinti
auriero
pisantoroso


Update: I ran my squelch newsflashes through the Markov Chainer. I got these:
"Bush would have to go on a group of unarmed shoppers Friday at a loss to retrieve the missing item."
"Though the 23rd meta extension of irony a level first reached by a Wisconsin machinist in June 2000 the fact that he just rambles a lot better said Kenyan orphan Mutheru Ubatto through an interpreter."
"Really what's a couple of pints of blood compared to a very difficult thing to do."
"While Greenberg's decision to purchase the single Kimberly Diaz a noted expert on irony explains because that song is still a pretty crappy song."
"Chameny blankly replied Will & Grace."
"Like many Americans who never considered African AIDS orphans to be a good topic joining the ideas of Chomsky and Searle in a bid for a diff'rent era."
"A needle was misplaced in a purely post modern constructivist framework."
"Said one Pentecostal Christian All we want is to get him to just answer your question without using knowledge only a dedicated grad student Josh Greenberg purchased the song after a child ..."

Update: Here the code to the original Markov Chainer for names. If anyone sees any problems with it let me know.

*snip*

I'm going to move the code in different post.

Saturday, March 22, 2008

Happy Easter

Pictured above: A skeptic witnesses enough evidence to allay his doubt.


Happy Easter y'all!

Tuesday, March 18, 2008

She's the terror of this Boulevard. This one. Right here.

I've been in Pasadena for about 24 hours now and I have that one beach boy's song stuck in my head the whole time. You know which one I mean. The one about the diminutive woman of advanced years who hails from this place.

Though similar to "Do you know the way to San Jose?" syndrome my current predicament is many orders of magnitude worse since Pasadena isn't really noteworthy in any other way (besides maybe hosting the rose bowl which I don't care about because of a mutation disabling the sport-loving gene which I should have inherited as any normal Italian.)

I mean, honestly! Does this town deserve a song? Compare this song to the songs commemorating say, San Francisco, and it becomes clear that Pasadena is punching above it's weight song wise.

In order to get this Beach Boy's song out of my head I've written a song of my own about this city:

Pasadena, Ohh ohh,
Pasadena, Ohh ohh,
You have a surprising number of Indian restaurants.
You are reasonably walkable for a So Cal town,
You have many Irish haunts,
and not a single clown,

Pasadena, Ohh ohh,
Pa-sa-de-na.

Whenever I see lyrics written down without music I instinctually skip over them because I realize that I will never be able to figure out the tune and I know I will spend hours puzzling over it in vain. If you did the same with my song rest assured that I have no tune in mind and that in fact it has no internal meter or rhythm of any kind. I did it on purpose. If you wasted your time pondering this song than I guess you might know what it feels like to be me. A writer is supposed to clearly communicate his message, right? What better then to make his readers physically undergo the same experience as he is trying to convey? I'm some kind of genius.

For those of you who want to hear the beach boys song I mentioned, here's the link.

Monday, March 17, 2008

Pasadena!

I'm heading down to Pasadena today. I will seek out the little old lady there.

Sunday, March 09, 2008

Back from Tennessee

I usually don't talk about my clients on my blog and today is no exception. I will say that, in general, the issues I run into most often are missing hardware, firewalls, and inaccessible system administrators. Specifically, you'd be amazed how often I find myself needing someone to do something that they apparently don't have time to do. Really? You have something more important? You spent the cash to fly me out here, put me up in a hotel and you're telling me your LDAP guy can't be bothered to make a group for the product? Really? I guess maybe he has a sleepy Spanish village to save from the Banditos that have been pillaging it for years. Hopefully, he will help them learn that the town had the ability to defend themselves the whole time.

All this is a round-about way of thanking the people I just finished working with for having their act together. Seriously. It gave me more time to admire the fine Waffle houses of Cookeville Tennessee.

Thursday, March 06, 2008

More writing

Here's another scene from the script I'm writing.



INT. KINGMAN CO-OP HALL  NIGHT

Outside the Guru room at Kingman.

HOLMANI


It's named after a real guru you know. The USCA bought it off of the "Berkeley Living Love Center". The cult leader lived in this room and all the followers worked day and night fixing it up with... I don't know... hippy beads and crap.

JOE


Whoa.

HOLMANI


This room goes for 35 points and counting.

JOE


That is the most ridiculous thing I've ever heard.

Holmani knocks on the door. After a pause the door opens a crack. The guru peaks one eye through the gap.

Guru


Who is it? I'm kind of busy right now.

HOLMANI


We need some information.

Holmani turns to Joe.

HOLMANI


Oh... let me do the talking. This guy has... time management issues.

JOE


What does that mean?

GURU


No time!

HOLMANI


(looks at Joe knowingly)


Oww! Your forehead!

GURU


(opening the door a little)


What?

Holmani kicks the door in with his foot hitting the guru on the forehead. She stumbles back on to the bed. Holmani and Joe enter.

INT. GURU ROOM NIGHT

The Guru is recovering from the blow on his bed. He is clearly at least 35 years old, balding and has a pen behind each ear, in his pocket, and on a chain around his neck. The walls of his room are covered with graphs showing various points and connections between them.

GURU


OWW!

HOLMANI


That was because you were being retarded. Hopefully, you will grow to understand in time.

GURU


Ok. First of all, that really hurts. Second of all this is a really busy time for me. I've got a mess of questionnaires to input and Casa Z's having a room-to-room tonight. Third of all... I... well, those two things are enough.

HOLMANI


I'd hate it if my questions were to delay your thesis by another 10 years.

GURU


Hey. This is important work even if you don't appreciate it.

HOLMANI


I do appreciate it! In fact, I've come to help you. My friend Joe is a lightening round admit to Stebbins. He hasn't answered your questionnaire yet.

JOE


Questionaire?

GURU


You haven't heard of my study?

HOLMANI


You thought he would know?

JOE


Huh?

GURU


What?

There is a pause as everyone tries to figure out what's going on.

HOLMANI


He studies houscest!

GURU


Romance and relationships at the Co-ops.

Holmani points to the various graphs on the walls.

HOLMANI


This is Casa Z, Hoyt, Loth...

GURU


All compiled anonymously with the strictest adherence to scientific guidelines.

The Guru pulls out a clipboard and begins questioning Joe who is looking at the various maps.

GURU


Ok. have you ever been to a Co-op party before and if so how many?

JOE


Just two. The room-to-room at Loth and the 80's party at Stebbins.

GURU


And how many people did you make out there?

JOE


What? None. I didn't make out with anyone.

GURU


Ok. I should clarify that making out with the Loth make-out girl does count.

JOE


Still none.

GURU


Ok. What's an 9 letter word meaning "immobile impatient"?

JOE


Huh?

GURU


Oh, that's just for this crossword puzzle I just started. I have time management issues.

JOE


I've heard about that.

Joe turns to look at the Guru who is now playing a game boy. Holmani walks over and slap it out of his hands.

HOLMANI


Ok. I'm just going to ask: We're looking for some extremely blue purple.

JOE


Why would he know about that?

HOLMANI


Do you have any idea how alcohol and marijuana use affect make-out?

GURU


I do! It increases it by thirty percent.

JOE


Really?

HOLMANI


Ok. Let's not get sidetracked. Do you know?

INT. KINGMAN CO-OP HALL  NIGHT

The Guru checks the hallway to make sure no one is watching. He closes the door silently.

INT. GURU ROOM NIGHT

The Guru turns down the lights and speaks in hushed tones.

GURU


I can't tell you how I know, but word has it that there's a fellow whose got his hands on some very fine Chihuahua blue. Local grown and it should just about be ready to harvest now. His name's Mark Geghiemer he lives at Stebbins.

HOLMANI


Are you trying to be unhelpful?

GURU


I'm making no special effort, no.

JOE


Geg's plants were stolen. We're looking for them.

HOLMANI


You're not holding info back on us are you? 'Cause I can have you PNG'd from Stebbins.

GURU


What?!

JOE


What's a PNG?

GURU


Persona Non Gratis.

HOLMANI


It means you're not allowed to enter the Co-op. Not for a party, not with a friend, not with a questionnaire.

GURU


Is that a threat?

HOLMANI


Huh? Yes! Of course that's a threat.

GURU


Oh. Ok. I wanted to make sure. I have trouble staying focused some times.

JOE


I've heard about that.

GURU


Anyhow. You can't PNG someone without a house vote. And the worst thing about me is that I'm creepy and old.

HOLMANI


Oh really? What about your newspaper stealing habit?

GURU


What?

HOLMANI


9 letters "immobile inpatient". Are you sure you didn't misread that? It makes more sense if it's "immobile inpatient", with an "n".

The guru puts on his glasses and takes a closer look at his paper.

HOLMANI


"Bedridden". It's easy. Too easy in fact for the Sunday Times. Stands to reason you have the early Monday edition. But how'd you do that? The only newsstand open at this hour is on north side.

JOE


You stole the house paper?

HOLMANI


And in using pen he's ruined it for everybody else. Folks at Stebbins take their crosswords seriously.

Tuesday, March 04, 2008

In Tennesee

Things I like: The Waffle house.
Things I don't like: Torrential Downpours.

I saw a real life bluejay today in the parking lot. We don't have them in California.

Update: My totally random sampling on music stations reveal that 50% of airtime on Cookeville, TN radio is spent playing Kenny Chesney's "Shift work". Be sure to listen to the chorus.

Monday, March 03, 2008

A letter to the Washington Post

RE:On your publishing uninteresting poorly argued editorials

I read the title of Charlotte Allens article on how women are dumb recently in your newspaper and though, "Wow. What a really stupid sounding premise. This topic has inspired thousands of boring writings motivated by misogyny. Hopefully the WaPo has found some really compelling evidence that this idea needs to be reevaluated. Certainly they wouldn't waste our time merely recapping the same tired stereotypes." Well, turns out I was wrong.

The saddest thing about this is that you guys probably think you were being really brave and daring by publishing this. You probably thought that something that offends so many must be a really awesome idea. But if you can't tell the difference between a well-argued defense of an unpopular view and crap like that then the WaPo really is in trouble.

Update: Awesome. The original title "Women aren't very bright" has been changed to "Why do women act so dumb?" That's supposed to make it all better.

Update: The WaPo runs a good counter-point.

Saturday, March 01, 2008

On Africa

I think we all owe the people living in Africa a great big thank you for taking the bullet for the rest of us. Don't get me wrong, there are a lot of nice places to live in Africa, but Africa is where our species evolved and consequently, where a lot of nasty viruses, parasites, and large mean animals with sharps teeth co-evolved with us.

Sure, Australia may have had giant 10 foot tall lizards but let's face it, by the time people got there we were at the top of our game. We were like, "Oh? A reptile the size of ox with a taste for things that stand upright? I think this calls for a sharpened stick." And a call goes back to the boy whose job it is to carry the sharp sticks around (for situations just like this) and a particularly sharp stick is chosen because – hey – who knows how tough it's skin is and meanwhile the giant lizard is thinking "My main worry is that they'll jump away with the tasty little babies they keep in their pouches." Poor sucker.

In Africa the situation is different; when a hippo sees you he's thinking "Oh great. A human. Better stomp it good before it calls its friends." Hippos evolved along side humans and evolutionarily speaking they've had time to learn to defend themselves. And of course this logic goes double for things like lions, HIV, leprosy, ringworm and malaria (a parasite with a life cycle so complicated it makes you wonder if it was intelligently designed by Rube Goldberg). How many diseases evolved in Australia I wonder? Maybe just Paul Hogan fatigue and even that's just a form of PTSD. The twin continents of the Americas could barely scrape together Yellow Fever and Syphilis. Do these compare to the diseases that have come out let's say… Niger? Niger please!

So even though there are lots of nice parts of Africa and I'm sure that science will eventually learn to cure all the really nasty diseases that tend to hang out there and other parts of the world let's all give a nice big thank you to those who manage to eke out a living there be it humble or not. Living on the same continent as all the other great apes may be good for tourism but it's also dangerous: Gorillas do not wash their hands!