Saturday, May 3, 2014

PL/Java, So we meet again...

Now that I have Matlab and Java playing nice, it is time to bring PostgreSQL into the mix. What could possibly go wrong?

I do have PostgreSQL and pljava working on my home laptop, but I keep getting blue screens and black screens with gibberish on them at random times. I think it is safe to say that, at a minimum, the hard drive on that one will need to be replaced soon.  Maybe I can get Steve to spill a beer on it? Anyway, back to the task at hand: a computer with Matlab, Eclipse, PostgreSQL and PL/Java all working together in harmony.

Nothing ever goes as easily as I hope it will. Since user guides never given you the full story, I figured I would enter some lessons learned just in case anyone else in foolish enough to try this (or for me to use as reference later when I do this yet again).

In your Environment Variables, make sure that you have (or at least something like):

In your postgresql.conf file, you need to add something like:

I think the message I hate most is: “ERROR:  could not load library "C:/Program Files/Postgres/8.3/lib/pljava.dll": The specified procedure could not be found.” It is a lot like Oracle’s tnsnames.ora error: not very informative and usually isn’t the real problem. The causes I have had for this error include, but are not limited to:
  • I had the wrong version of Java installed,
  • The pljava.jar file was for the a different version of PostgreSQL,
  • All of my variables weren’t set exactly right,
  • I had the 64 bit version of Java, but PostgreSQL was still at 32 bit,
  • I’m sure there are others.
Once you think you have it working, here is a nice test using one of the default sqlj functions, just to make sure:
CREATE FUNCTION getsysprop(VARCHAR)
  RETURNS VARCHAR
  AS 'java.lang.System.getProperty'
  LANGUAGE java;
SELECT getsysprop('user.home'); 
If this function doesn’t work, you have issues. Now it is time to try to put one of your own functions in!

Once your function is written in java, export it as a jar file. Then the fun begins. Do not forget to do what I always seem to which is to set your class path. Then you can create and test your function. It is generally good to have a basic “test function” that really doesn’t do much to help you test that your jar loaded properly.

Now, getting PostgreSQL and Matlab working together is another story…

Matlab and Java: Can’t everyone just get along?

I’m still not certain of the answer. I had come up with, what I thought, was a great idea of calling the Matlab implementations of the OSD and OCBA algorithms instead of trying to recreate them in Java. Great idea, right? Well, I have had a few hiccups along the way. Using the library created by Joshua Kaplan, I was excited when I was completed his “Hello World” example. I was so excited when I was able to call my Matlab functions from Java passing in arrays of data. Then the hard part came: passing in the stochastic function. Since I’m passing it in as a string, Matlab doesn’t want to just accept that I’m right and the string is actually a function. I was on the train so didn’t have any internet connectivity so I started searching through the Matlab help files. I found the function “Execute” that I foolishly believed was the answer to my prayers, for about 5 minutes. It did evaluate the function I sent in as a string, but then it returned a string. That was useless since I needed the evaluation later in the Matlab code. Of course this problem was bugging me so I Googled and found the wonderful function eval. This function truly is the answer to my problems so far. Just in case anyone else needed to do something as strange as this, I figured I would post some code samples to help. It is still a work in progress, but might serve as someone’s lifeline.
Java
RemoteMatlabProxyFactory factory = new RemoteMatlabProxyFactory();
RemoteMatlabProxy proxy = factory.getProxy(240000);
String functioName = "experiments";
Vector<Object> entries = new Vector<Object>();
entries.add(-1);
entries.add(-0.8);
entries.add(-0.6);
entries.add(-0.4);
entries.add(-0.2);
entries.add(0);
entries.add(0.2);
entries.add(0.4);
entries.add(0.6);
entries.add(0.8);
entries.add(1);
Vector<Object> newArray = new Vector<Object>();
newArray.add("ProbDistUnivParam('normal',[0 .6])");
newArray.add(entries.toArray());
Object[] input = newArray.toArray();
Object result = proxy.returningFeval(functioName,input);
 
Matlab
function m=experiments(probDistdb)
    pd=eval(probDist);
    [~,dim2]=size(db);
    db2=zeros(dim2,1);
    for i=1:dim2  db2(i)=db{i}; end
    m=osd(pd,db2,1,1000)
end         

I did notice during some of my experiments to see what all I could do that, if you pass back a double array (ans(3,3)), it becomes a single array with the second column just being appended to the end of the first. Just something to be aware of if you are passing back an array of arrays.

Italy 2010 (Naples to Rome)

October 25: Picture of the day Part I (from last night actually)


Naples could be livable as long as you had no sense of sight or smell and didn't mind the constant honking of car horns. Pompeii, on the other hand, is awesome! It's like a slightly larger Cortona. The B&B is very nice and the owner is like the ones we had in Ireland who were very helpful. It turns out that we took the wrong train so it took a little longer to walk there than expected, but we got to see a lot of the town. Today we're going to explore the ruins of Pompeii!

October 25: Not an official picture of the day


but still a nice one. It's a steel girder from the world trade center and commemorates the lives lost in Sept 11. A number of people from Pompeii died as well.

October 25: Picture of the day Part II (Pompeii Ruins)


We managed to get lost in the ruins of Pompeii. The city was massive! Luckily there were some other tourists to follow so we found our way out. As Pompeii is known for its stray dogs, we weren't surprised when one of them followed us back to our B&B. We didn't think Fabio would appreciate the additional guest so we left him outside. Tomorrow we head to Sorento and Capri, assuming the weather cooperates.

October 26: Picture of the day (a bit late) (Pompeii)


Well, my Crackberry charger went TU overnight so my Crackberry had to stay back at the B&B today. Luckily, Steve's charger worked for it so I'm connected to the outside world again!
The weatherman claimed that we would have light showers today, but, as usual, they were wrong. So, we swam through the streets of Pompeii to catch the train to Sorento and the ferry to Capri. Because of the weather, we were not able to take the boat tours of the grottos so we just walked around the town admiring the views. The rain didn't let up except when we were inside eating lunch so we headed back to Sorento to do some shopping (Dave's favorite pastime) and then back to Pompeii.
The rain has stopped and we are now sitting at dinner discussing why vampires are better than werewolves (vampires don't get fleas). Tomorrow we start the final leg of the trip - Rome.

October 27: Picture of the day Part I (Train Station in Naples)

An Italian post office is something of an adventure. It was made more fun by the fact that the postal workers knew as much English as we did Italian. Brandy and I got our packages shipped and now we just have to hope they find their way to the US.

Then back on the commuter train to Naples so we can catch the train to Rome. We still didn't see any of the riots the newspapers are reporting, but there's still plenty of trash. Dave feels cheated about not being able to join the fun. As long as we stay in the train station, we're safe from the smell. I think we're going to wait till Rome for lunch. :)

October 27: Picture of the day Part II (Riot Gear)


We have police in riot gear in the train station, but I don't think the riders are to that point yet. One train is 75 minutes late, but the VRE has managed to be a lot later without the need for professionals.

October 27: Picture of the day Part III (Rome)


After navigating the catacombs of Rome, we made it through the metro system and up to the streets and finally made it to our hotel. Brandy is happy that she doesn't have to share a room with Dave and I. Apparently his snoring was drowning out the street noise.

Tomorrow we get to wake early to head for the Vatican. We're also going to the Spanish Steps and to see a beautiful garden. There aren't supposed to be any statues of naked midgets on turtles so Steve is disappointed. So, off to bed so we can get up early!

Italy 2010 (Rome to Naples)

October 18: Italian Travel Sucks!

We have voted Italy the worst country to visit and the voting pool includes people who have been to Algeria, Bosnia during a war, and Guatemala during hurricane Mitch and the resulting mud slides. We have been at this stupid train station for 2 hours now and just finally found the ticket station. We're still in line so we're hoping we are finally at the right place. We have actually been involved in what is quite humorous in a movie where we go to one place, they send us to the other side of the station which then says we have to go back to point A for validation. Then point A says we have to go back to point B because they don't do validation either. Oh well. Here's hoping this is the right place. I think we are on point F or G now. There's a group from Japan following us and we were just joined by another group of lost Americans.

October 19: Picture of the Day (Venice)

No internet yet so here's a picture of Venice I took with my phone. Tomorrow we head to Florence. Hopefully we will have an easier time with the train. :)

October 20: Picture of the Day (Leaving Venice)

We came all the way to Italy to see this? We are finally escaping the train station in Florence, with Steve now found, and are on our way to Cortona. We should be there in about 1.5 hours. The train is not user friendly here, but it is providing adventure. Tomorrow we are heading out with Brandy's uncle Scott and his students from UGA.

October 21: Picture of the day Part I (Church of Saint Margaret)

Obviously, we have made it to Cortona after the train debacle yesterday with Steve in tow. Today we went hiking uphill to the fortress, but were turned away by their defenses. Dave was going to try to toss Brandy through a window, but we talked him out of it. Thwarted but not discouraged, we head to the monastery.

October 21: Picture of the day Part II (Monastery of Saint Francis)

We did make it to the monastery and were let in (obviously they didn't know us). We just made it down the hill and are now sitting at a local pizza joint waiting for lunch. Tomorrow we are heading back to the train (God help us) and on to Florence.

October 22: Picture of the day Part I (Florence)

I think we managed to find the worst hotel in Florence. The fact that it was recommended makes me worry about how the others rate. We will just don our hazmat suites before bed and pray the antibiotics my doctor gave me won't be needed. We are escaping the smell and are heading out to do some touristy stuff. Amy and Brandy are strategizing the plan of attack now.

October 22: Picture of the day Part II (Basilica di Santa Maria del Fiore)

I figured I should send something better than a picture of Amy in our questionable hotel room, so here's a picture of the Duomo.

Otober 23: Picture of the day Part I (Boboli Gardens)

We made it through the night without being carried off by bed bugs or any other creatures hiding under our beds. So, once we made sure we all survived unscathed, out we went for more tourism. Since we are in Tuscan country, we are still looking for the School of Olive Garden like we saw in the commercials, but no one seems to know what we are talking about. Maybe we'll find it tomorrow while we walk the gauntlet in Naples hoping to avoid a mugging.

October 23: Picture of the day Part II (Basilica di Santa Maria del Fiore)

Worry when the table next to you has the following conversation: "How much wine will we drink tonight?" "As much as we want!" Luckily, we left before they finished their third bottle. Talk about rowdy!   Now that dinner is over, back to the hotel to pack for tomorrow's train ride!

October 24: Picture of the day Part I

And we are on the train again leaving Florence. In preparation of Naples, we watched a few episodes of Chuck Norris, Texas Ranger to pick up some moves for handling the pick pockets. Turns out it is a good thing we prepared for hand to hand combat as there are riots in Naples over the building of a second landfill. I do know from Matthew's experience to not take pictures during one as it is frowned upon by the rioters. I think we'll be able to safely avoid them as it looks like they are on the outskirts of town far away from where we will be. The good news is that we escaped the Florence hotel unscathed. We never did figure out what the organic substance on the walls were. I guess some mysteries are best left unsolved. The bed and breakfast run by Fabio in Pompeii should be a vast improvement though the bar has been set rather low by Florence.

October 24: Picture of the day Part II (Streets of Naples)

I have to say that the gypsies are quite efficient. They board the train while people are getting on and leave a piece of paper with each group of seats with their story in both Italian and English and then come back through a few minutes later to pick up the sheets (they recycle) and money.
This is a picture I snapped while crossing the street to the train station. The bum on the right is for reference for the height. The trash is everywhere.

Naples is definitely not a place to visit. It reminds me a lot of Mexico with piles of trash everywhere and no real traffic laws. I was surprised our taxi driver didn't wreck on the way to the museum. I can understand why people would be rioting though we missed out on seeing any rioters. We are very happy to be heading to Pompeii.

PhD Cookies

Lindsay and Randy came up with this recipe after I survived quals and they are quite tasty.
  • 1 C. toasted chopped pecans                         
  • 1 C. chopped sweetened dried cherries
  • 1 C. firmly packed dark brown sugar            
  • 1 C. granulated sugar
  • 2 large eggs                                                   
  • 1 tablespoon vanilla extract
  • 2 1/3 C. all purpose flour                               
  • 1 ¼ teaspoon baking soda
  • 1 scant teaspoon salt                                     
  • 3 cups chocolate chips
  • 1 C. (2 sticks) unsalted butter at room temp 
Preheat the oven to 350. Arrange the nuts on a baking sheet in a single layer and toast them for *7 to 9 minutes*, until golden brown and aromatic. Cool the nuts and then coarsely chop.
Line baking sheets with parchment paper or silicon mats, or grease generously with butter or cooking spray. Using a mixer fitted with a paddle attachment, cream the butter and both sugars in a large bowl on medium speed about 1 minute, until fluffy. Add the eggs and vanilla and beat on medium speed for 1 minute. Add the flour, baking soda and salt. Mix on medium-l0w speed until incorporated. Stir in the cherries, pecans, and chocolate chips. The dough is relatively stiff, so don't be surprised if this takes some muscle.

Drop the dough onto the prepared baking sheets in golf-ball sized scoops. Space the cookies about 1 ½ inches apart as they will spread. Bake for 10 to 12 minutes, until the cookies are medium brown around the edges. (As long as the edges are brown, don't worry about a little bit of raw-looking dough in the middle. It will disappear as the cookies cool). The cookies will spread to about 3 1/2 inches in diameter.

PhD Comics

As some of you may have already found, there is a lot of truth in the PhD Comic series. I know that I haven't done any writing in almost two weeks, but I have done a lot of reading. I'm still working on how to mathematically define what I am doing. It is rather frustrating that I know programmatically how to do what I want, but not mathematically. Hopefully I'll get some insight with a little more reading.

The Notebook


Unfortunately, I'm not referring to the contemporary romance novel by Nicholas Sparks. I'm speaking of the notebook where I am collecting possible articles for my comprehensive exam. As those who know me found out during qualifiers, I like to be organized (insert laughter from John and Mark). Not having done this before (who would go through comps twice?), I decided to put everything into a notebook with tabs for the different areas I am covering like OCBA and Probabilistic Databases. Then I have articles in each of their respective sections with smaller tabs labeling the individual articles. Of course, I have the usual highlighting of what I consider important and underlined what I considered REALLY important and little baby tabs on pages with facts and equations that I really want to remember or perhaps user in a future paper. Not all of the articles will be used for my comps, but are useful to help study and provide some additional background information. I heard that I will need around ten articles so hopefully this will give me a good start. I'm sure it will get a lot bigger as I go along. Good thing I picked out a two inch notebook! :)