Monday, November 18, 2013

I was wrong, matplotlib isn't gnuplot.

Upon review gnuplot, used by octave, just isn't up to the same quality as matplotlib, used by python.  The similarity is due to both trying to easily port code from MatLab.  Here's equivalent python code to the code I produced in "gnuplot, octave, and python":
import numpy as np
import matplotlib.pyplot as plt

plt.figure(1)
plt.clf
x=np.arange(-10.,10.1,0.1)

plt.subplot(2,1,1)
plt.plot(x,np.sin(x))
plt.xlabel('x',fontsize=12)
plt.ylabel('Sin(x)',fontsize=12)
plt.text(-12.3,1,'(1)',fontsize=12)
plt.title('Text Positioning',fontsize=16)

plt.subplot(2,1,2)
plt.plot(x,2 * np.sin(x))
plt.xlabel('x',fontsize=12)
plt.ylabel('2 * Sin(x)',fontsize=12)
plt.text(-12.3,2,'(2)',fontsize=12)
plt.show()

It produces this much nicer plot:
I didn't know about the title function when I did the octave plot.  There is plenty of room for the xlabel on the second subplot.  There are a couple of small differences in behavior and syntax.  The text function seems to position differently, maybe bottom right coordinates in matplotlib as opposed to upper left in gnuplot.
I think this accounts for the xlabel bug in gnuplot.  The same "fontsize" is smaller relative to the plot in matplotlib than in gnuplot.







In addition to syntactic differences there are behavioral differences.  I'm going to have to study matplotlib's event handling.

On a side note... I tried to reproduce the matplotlib histogram example in octave.  I got a stack overflow error when trying to create an array of 10,000 random numbers where numpy had no problem.  Maybe octave has some module I need to add.  Even producing a histogram of 1,000 random numbers took quite a bit of time in octave.  I'm almost ready to buy MatLab again just for the "Computational Neuroscience" course.  I have trouble with trial versions of software because they leave bad things on one's computer to prevent you from just reinstalling it after the trial period has run out.  These things can interfere with normal installation later on.

Saturday, November 16, 2013

gnuplot, octave, and python

Both Octave and Python use gnuplot to produce graphs.  I don't know why I've stayed away from graphs for so long.  They're really quite simple to produce.  Since I'm trying to relearn Octave right now I'm going to show a couple of issues with Octave's implementation.  It might be a problem with gnuplot, I'll do some testing this afternoon.  I only have a few minutes right now so here goes.

This code:


figure(1)
clf
x=-10:0.1:10;

subplot(2,1,1)
plot(x,sin(x))
xlabel('x','fontsize',12)
ylabel('Sin(x)','fontsize',12)
text(-13,1,'(1)','fontsize',12) 

subplot(2,1,2)
plot(x,2 * sin(x))
xlabel('x','fontsize',12)
ylabel('2 * Sin(x)','fontsize',12)
text(-13,1,'(2)','fontsize',12) 


produces this graph:
Notice the text at (-13,1)?  It is positioned based upon the coordinate system used for the plot.  Unless you adjust for this you're going to get bad results like I've shown here.  Fontsize isn't affected so getting the position correct can be complicated if one doesn't use some tricks.  I'll be doing some tests this afternoon to see if I can turn hold on and build the plot using one axis setting and position the text using another.  I'll let you know what I find.

The second issue is the xlabel on the second subplot.  For some reason it gets chopped off.  There may be quite a few details one will need to remember to produce nice plots.  One might want to build a library of sample plots  so the code to produce them is kept handy.

Thursday, November 14, 2013

Making DomainMath IDE work without errors

OK, there is something wrong with the auto-loading of packages.  I followed these instructions from http://wiki.octave.org/Octave_for_Windows

   pkg rebuild -auto
   pkg rebuild -noauto ad windows
   pkg rebuild -noauto nan % shadows many statistics functions
   pkg rebuild -noauto gsl % shadows some core functions
   pkg rebuild -auto java

It didn't work.   Java still wasn't loaded.  I ended up modifying C:\Software\Octave-3.6.4\share\octave\site\m\startup\octaverc.  I added the line

pkg load java

This did the trick.  Now the tool bar works and I'm not getting the error about javaaddpath not being implemented.  I'm not sure why the rebuild with the -auto option didn't work.

It looks like I'm ready to start mucking about with the plots generated by gnuplot as opposed to how I presume the results look in MatLab based upon the commands in the samples from the book I'm reading.

Small steps.

Wednesday, November 13, 2013

I bought a microsoft surface pro 2 last weekend.

I like it.  It's my first tablet.  I'll probably use it for games and e-books.  That's an expensive machine just for those features.  Who knows.  I was thinking I could use it to connect with other computers I need to connect to but SSL VPN doesn't support Win 8.1 yet. 

It appears people are attacking my desktop computer in strange ways.  I don't want to bounce through it. 

This isn't limited to my computers.  Someone even tried to write a convenience check against my credit card.  I'm finding it hard to be open and secure at the same time. 

Maybe the cloud is the way to go.  It seems like a security issue to me but then most of my work leaves my desktop functionally acting like a thin client.  Plus, I don't know what I really own if it isn't on my hardware.  Now my MS Office suite is a one year license.  I guess it's all about cash flow.

Anyway, the Surface is a bit heavy at two pounds.  It seems light to me compared to the books I read.  I'll learn to adjust to the new reading style.  I'll both miss having the books around and enjoy not having to deal with them.

Sunday, November 10, 2013

Computational Neuroscience and Octave.

Early next year I will be taking the Coursera course "Computational Neuroscience.  Rather than using Python it will use MatLab.  MatLab is an expensive product.  I have an old copy of it on the computer that died about a month ago.  I bought MatLab because I got tired of running Octave in line mode on top of Cygwin.  I didn't want to buy MatLab again just for this one course so I gave Octave another look. 

Octave still has the same look and feel I remember but now there is a GUI wrapper for it.  DomainMath IDE provides that wrapper.  My few minutes with it so far looks promising even though it has a few quirks I haven't figured out yet.  DomainMath IDE is a Java project so you will need to have Java running.  I've running Java version 7 update 45.  I installed Octave in its default directory then I put the DomainMathIDE_v0.1.5.7z file in the same directory and unzipped it using WinRAR.  DomainMathIDE.jar comes up and seems to work just fine even though right now I'm getting the error: "'javaaddpath' undefined".  I'll track this down sooner or later.  While I installed the java library when I installed Octave it appears I don't have it registered quite right.  I haven't been able to make DomainMath IDE the default editor for .m files or even right click on the files and edit them with DomainMath IDE.  I can live with this for now.

WinRAR is worth the $29.  It handles all the strange compression formats I've run across so far.  Maybe 7-zip would work as well.  It certainly would work on DomainMathIDE_v0.1.5.7z.

I bought Tutorial on Neural Systems Modeling so I could get up to speed before class begins.  It turns out it is one of the suggested books for the class.  The website has the source files for the "MATLAB BOXes".  That's certainly easier if you don't need to type code to learn from it.  There are plenty of exercises to get you head into the material.  It doesn't cover cable theory so it looks like I'll be exploring point neuron models for now where spike rate is modeled by a number rather than spikes.  I can live with this an learn.  Later I can move to more realistic models when I'm investigating aspects this model doesn't cover.  For now it's the Rosenblatt model, the Perceptron or a variation of it.