Wednesday, September 22, 2010

Scipy curve_fit for easy nonlinear least squares fitting.

Assume we are given input or independent vector x and the repsonse or dependent vector y.
It is desired to fit a non-linear multivariate function of the form y' = f(x, c0, c1,..., c_k) through the points (x, y)
by least squares with the unknown parameters $$c_0, ... c_{k-1}$$ such that

$$T = \sum_{i=0}^{n-1}([y_i- f(x, c_0, c_1, ..., c_{k-1})]^2$$

is minimized. Scipy has an easy to use function from the optimize module to find optimal values of the
fitting parameters by the Levenberg-Marquardt algorithm. It has the following calling format:

curve_fit(f, xdata, ydata, p0=None, sigma=None, **kw)

where the parameters are:

f - The model function, f(x, ...).  
    xdata - an array of predetermined values of length n.
    ydata : an array of dependentdent data.
    p0 : None, scalar, or M-length sequence
        Initial guess for the parameters with a default value of 1 if not given.
    sigma : standard deviation of dependent data which is used as weighting f.
        If not specified,  uniform weights will be applied.

The function returns a pair, (popt, pcov) where

popt : output array of optimal fitted parameters  
    pcov : variance-covariance matrix of fitted parameters. the variances of the parameters are
           along the diagonal.

Here is the built-in example (with known parameters! but with added normal errors) for an exponential function $$y =a e^{-b x} +c$$
with three fitting parameters. It is interesting to see how the curve_fit() function can recover the parameters (not exactly the original
values because of random deviations added to the data).

import numpy as np
from scipy.optimize import curve_fit

def func(x, a, b, c):
    return a*np.exp(-b*x) + c
  
if __name__ == "__main__":  
   x = np.linspace(0,4,50)
   y = func(x, 2.5, 1.3, 0.5)
   yn = y + 0.2*np.random.normal(size=len(x))
   popt, pcov = curve_fit(func, x, yn)

   print "Fitted parameters approximations:", popt
   print "Variance-covariance matrix:"
   print pcov

When the above example is run,it prints the following:

$ python curvefit.py
Fitted parameters approximations: [ 2.29258582 1.34085286 0.58836951]
Variance-covariance matrix:
[[ 0.01242794 0.00585958 -0.00061056]
[ 0.00585958 0.01945042 0.00477259]
[-0.00061056 0.00477259 0.00225576]]
~/Blogs/scipy/fitting$




But there is a catch for Ubuntu 10.04 users. The version of scipy installed is only at 0.7.0-2 while the curve_fit function
is available only with a later version 0.8.0. One has to temporarily remove the scipy-numpy and associated modules
and reinstall them again. I have difficulty installing matplotlib, so let's hope that Ubuntu package maintainers will be able to incorporate the latest statble versions of scipy, numpy and matplotlib in the next Maverick Meerkat version which is available on Monday!

Thursday, August 19, 2010

Matplotlib installing in a web server.

Matplotlib is the most complete 2d plotting package in Python you can find at the moment.
You will not encounter much problems installing and running matplotlib on a desktop but on a remote server, you might encounter problems, like missing or unconfigured tz packages.

So we will document installing from sources the matplotlib plotting package.

Step 1. Get the sources!
wget wget http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0/matplotlib-1.0.0.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmatplotlib%2Ffiles%2F&ts=1282255399&mirror=nchc


Resolving downloads.sourceforge.net... 216.34.181.59
Connecting to downloads.sourceforge.net|216.34.181.59|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://surfnet.dl.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0/matplotlib-1.0.0.tar.gz [following]
--2010-08-19 22:11:56-- http://surfnet.dl.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0/matplotlib-1.0.0.tar.gz
Resolving surfnet.dl.sourceforge.net... 130.59.138.21, 2001:620:0:1b::21
Connecting to surfnet.dl.sourceforge.net|130.59.138.21|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 12918842 (12M) [application/x-gzip]
Saving to: `matplotlib-1.0.0.tar.gz'

100%[==========================================================================================================================================>] 12,918,842 3.26M/s in 6.3s

2010-08-19 22:12:03 (1.95 MB/s) - `matplotlib-1.0.0.tar.gz' saved [12918842/12918842]

Step 2. Untar the package.

tar xzvvf matplotlib-1.0.0.tar.gz. This will create the matplotlib subdirectory.

Step 3. Install and test.

Cd to the matplotlib subdirectory and issue sudo python setup.py install
Don't be alarmed by the many C/C++ warnings you may see.
Now run python and import the matplotlib module. In my system, there are no errors.

I resorted to installing from sources after spending almost a half-day trying to do it from
apt-get and even from easy_install. I guess there are some destination directory mismatches!

Now if you get a display not defined error after installation, issue a export DISPLAY=:1.0, and reinstall again.

We will add our attempts to generate plots and graphs on a web server from matplotlib.
Stay tuned!

Finer details on the installation of matplotlib in a server environment with an example of generating a line graph: Please visit http://linux.byexamples.com/archives/404/python-generating-graphs-with-matplotlib/

Wednesday, August 18, 2010

NLopt on the Rosenbrock function

Here is our first attempt at using nlopt on the Rosenbrock banana function which we
used last time using the Nelder-Meade solver implemented in scipy.optimize.fmin function



import nlopt
from numpy import *

def nlopt_rosen_fg(x, grad):
   return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)


x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
n    = len(x0)
grad = array([0] * n)

opt = nlopt.opt(nlopt.LN_NELDERMEAD, len(x0))
opt.set_min_objective(nlopt_rosen_fg)
opt.set_xtol_rel(1.0e-4)
opt.set_maxeval(500)
opt.optimize(x0)
opt_val= opt.last_optimum_value()
opt_result = opt.last_optimize_result()
print 
print opt_val
print x0
print opt_result

When the above program runs, the following output is obtained:

python rosenbrock-nlopt.py 

1.22270197534e-08
[1.3, 0.69999999999999996, 0.80000000000000004, 1.8999999999999999, 1.2]
4

The return code of 4 means that the xtol has been achieved. We notice that the optimized vector is far from all ones although the function value is near zero. Doubtless we still have much to learn in using nlopt for this simple optimization without derivatives and we welcome any insightful remarks.

In the docs, it is not stated how many function evaluations were actually taken at the point of termination. It is obvious but the optimal vector is the final value of the initial vector variable.

Scipy optimize

Scipy


Scipy is a big Python library often compared with Matlab. Its homepage is at http://www.scipy.org
It is sponsored by the company Enthought but the software itself is open-source. The major field of application is numerical computing, in mathematics, science and engineering.

Scipy depends on NumPy (related to Numeric) which provides fast array manipulation. Yet it is not a pure Python library. Rather than rewriting from scratch in pure Python the reliable algorithms already implemented in Fortran in EISPACK, LAPACk, ATLAS, FFTW libraries, Scipy instead offers Python interfaces to these compiled "native machine" routines. The result is that Scipy is fast!. Scipy installs and runs in most architectures and what's more, it is free. More and more scientific computing people are using Scipy each day. Most users have encountered problems in the installation of Scipy and it will be compounded if you don't have enough memory and hard disk space to install and your chosen OS distribution does not have a good package manager.

People wonder why Scipy is not well known such or as widely adopted as R. I guess we can blame it more on freedom of choice. There is no standard gui for Scipy for example, and there is no SINGLE plotting package for Scipy. You can use MATPLOTLIB, chaco, and others with scipy.

Scipy Optimize optimization library

Well in this article, we shall focus on the optimization library called "optimize". Various algorithms are available from Nelder Mead to BGSS to Newton conjugate gradient and others.
Lets try the example in the tutorial which uses the Nelder Mead algorithm and requires function evaluations only.


The Rosenbrock function and fmin (Nelder-Mead)

The definition of the Rosenbrock function is given by
$$!\sum_{i=1}^{n-1] 100(X_i-X_{i-1}^2)^2 + (1 - x_{i-1})^2$$
Here is the implementation code from the tutorial:

from scipy.optimize import fmin

def rosen(x): # The Rosenbrock function
   return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)



def rosen_der(x):
   xm = x[1:-1]
   xm_m1 = x[:-2]
   xm_p1 = x[2:]
   der = zeros(x.shape,x.typecode())
   der[1:-1] = 200*(xm-xm_m1**2) - 400*(xm_p1 - xm**2)*xm - 2*(1-xm)
   der[0] = -400*x[0]*(x[1]-x[0]**2) - 2*(1-x[0])
   der[-1] = 200*(x[-1]-x[-2]**2)
   return der


x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
xopt = fmin(rosen, x0)
print xopt

Function rosen() evaluates the famous Rosenbrock "Banana" function. The dimension of the function is implied by the size of the input x numpy array. Notice that the function is written in vector form which may not be familiar to most Python programmers outside of scientific computing.
Function rosen_der() returns the derivative or gradient vector which we shall use in the future. Again vector processing is used resulting in more compact code and we hope more understandable as one is more exposed to this kind of programming. When the above code is run it prints in my computer the following output:

python rosenbrock.py
Optimization terminated successfully.
Current function value: 0.000066
Iterations: 141
Function evaluations: 243
[ 0.99910115 0.99820923 0.99646346 0.99297555 0.98600385]

Contrast this with the output from the tutorial:

x0 = [1.3, 0.7, 0.8, 1.9, 1.2]
>>> xopt = fmin(rosen, x0)
Optimization terminated successfully.
Current function value: 0.000000
Iterations: 516
Function evaluations: 825
>>> print xopt
[ 1. 1. 1. 1.
1.]

why the difference. We think that a lot of things have changed like the default values for input arguments since the tutorial. If you look at the help file for fmin under IPython,

Documentation for fmin

fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None)
    Minimize a function using the downhill simplex algorithm.
    
    :Parameters:
    
      func : callable func(x,*args)
          The objective function to be minimized.
      x0 : ndarray
          Initial guess.
      args : tuple
          Extra arguments passed to func, i.e. ``f(x,*args)``.
      callback : callable
          Called after each iteration, as callback(xk), where xk is the
          current parameter vector.
    
    :Returns: (xopt, {fopt, iter, funcalls, warnflag})
    
      xopt : ndarray
          Parameter that minimizes function.
      fopt : float
          Value of function at minimum: ``fopt = func(xopt)``.
      iter : int
          Number of iterations performed.
      funcalls : int
          Number of function calls made.
      warnflag : int
          1 : Maximum number of function evaluations made.
          2 : Maximum number of iterations reached.
      allvecs : list
          Solution at each iteration.
    
    *Other Parameters*:
    
      xtol : float
          Relative error in xopt acceptable for convergence.
      ftol : number
          Relative error in func(xopt) acceptable for convergence.
      maxiter : int
          Maximum number of iterations to perform.
:


Calling the fmin function with both xtol and ftol set to 1.0e-5 resulted in much closer matching output:

python rosenbrock.py
Optimization terminated successfully.
         Current function value: 0.000000
         Iterations: 267
         Function evaluations: 444
[ 1.00000002  0.99999975  0.99999956  0.9999988   0.9999975 ]

Tuesday, July 27, 2010

PyEphem: an ephemeris computation library

I wanted a sunrise-sunset for the day information to be posted in my weather page at Digital Explorations and at Life-Research-Education blogs. I originally wanted to implement some algorithms used by say the US Naval Observatory, but on second thought, I was thinking there might be already Python libraries for doing that or something similar!

PyEphem is a Python library for Python versions < 3.0(Python 3.0 users should install ephem instead). The homepage is at http://rhodesmill.org/pyephem/. Here is our attempt to install pyephem on our Ubuntu 64 bit Lucid Lynx:
sudo easy_install pyephem /usr/lib/python2.6/dist-packages/setuptools/package_index.py:156: UserWarning: Unbuilt egg for setuptools [unknown version] (/usr/lib/python2.6/dist-packages) Environment.__init__(self,*args,**kw) /usr/lib/python2.6/dist-packages/setuptools/command/easy_install.py:216: UserWarning: Unbuilt egg for setuptools [unknown version] (/usr/lib/python2.6/dist-packages) self.local_index = Environment(self.shadow_path+sys.path) Searching for pyephem Reading http://pypi.python.org/simple/pyephem/ Reading http://rhodesmill.org/pyephem/ Best match: pyephem 3.7.3.4 Downloading http://pypi.python.org/packages/source/p/pyephem/pyephem-3.7.3.4.tar.gz Processing pyephem-3.7.3.4.tar.gz Running pyephem-3.7.3.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-aGswju/pyephem-3.7.3.4/egg-dist-tmp-ZGk2Ek libastro-3.7.3/magdecl.c: In function ‘E0000’: libastro-3.7.3/magdecl.c:150: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result libastro-3.7.3/magdecl.c:153: warning: ignoring return value of ‘fgets’, declared with attribute warn_unused_result In file included from libastro-3.7.3/deep.c:5: libastro-3.7.3/satspec.h:16: warning: function declaration isn’t a prototype In file included from libastro-3.7.3/sdp4.c:7: libastro-3.7.3/satspec.h:16: warning: function declaration isn’t a prototype In file included from libastro-3.7.3/sgp4.c:6: libastro-3.7.3/satspec.h:16: warning: function declaration isn’t a prototype zip_safe flag not set; analyzing archive contents... ephem.tests.test_jpl: module references __file__ ephem.tests.test_usno: module references __file__ ephem.tests.test_rst: module references __file__ Adding pyephem 3.7.3.4 to easy-install.pth file Installed /usr/local/lib/python2.6/dist-packages/pyephem-3.7.3.4-py2.6-linux-x86_64.egg


Note the warnings.


$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyephem
Traceback (most recent call last):
  File "", line 1, in 
ImportError: No module named pyephem
>>> 

Crazy!! Why is pyephem not installed?

To be continued ......

Ah ok. it should be import ephem and not pyephem! Nuts!

Ok. Here is an example from http://scienceoss.com/calculate-sunrise-and-sunset-with-pyephem/
to display graphically the day length for the whole year of 2008. (difference of sunset and sunrise times).

import ephem
import datetime

obs = ephem.Observer()
obs.lat = '38.8'
obs.long= '-75.2'

start_date = datetime.datetime(2008, 1, 1)
end_date = datetime.datetime(2008, 12, 31)
td = datetime.timedelta(days=1)

sun = ephem.Sun()

sunrises = []
sunsets = []
dates = []

date = start_date
while date < end_date:
date += td
dates.append(date)
obs.date = date

rise_time = obs.next_rising(sun).datetime()
sunrises.append(rise_time)

set_time = obs.next_setting(sun).datetime()
sunsets.append(set_time)

from pylab import *
daylens = []
for i in range(len(sunrises)):
timediff = sunsets[i] - sunrises[i]
hours = timediff.seconds / 60. / 60.  # to get it in hours
daylens.append(hours)

plot(dates, daylens)

# if you have an older version of matplotlib, you may need
# to convert dates into numbers before plotting:
# dates = [date2num(i) for i in dates]

xlabel('Date')
ylabel('Hours')
title('Day length in 2008')
show()

And here is the nice output courtesy of matplotlib:

Saturday, July 17, 2010

Exploring NLOPT , Part 1

To our readers, the NLOPT software has actually a fairly complete Python reference in

http://ab-initio.mit.edu/wiki/index.php/NLopt_Python_Reference.

I don't know why I missed that reference location and other documentation when I first visited the ab-initio site, hence this article is being severely revised.

The original article stressed the use of IPython to quickly explore what is available in the library.
If in doubt, refer to the reference and official documentation.

We will be back.

Sunday, July 11, 2010

Wolframalpha has a new interface.


We wonder why wolfram alpha changed its web page interface. Instead of an input box where you just enter any expression directly, we are now presented with a strange entry search box with misspelled parts of the title, what is nowledge Base?

Nuts. the url was a severely misspelled  wolframapha.com. Will delete this post in a week. Meanwhile it will remind me to stay humble.

Saturday, July 10, 2010

Xaos, a fractal zoomer

In the good old times of my MS days, Dr. Manlapaz introduced us to chaos, Mandelbrot and Julia sets Sierpinski gaskets,the universal Feigenbaum constant and bifurcations. He was the supreme mental terrorist of masters students who did not share his adventurous mind. As a part of his Math 270 class, we were required to program the Mandelbrot set of complex functions, including roots of polynomials using unoptimized Newton's method. As an illustration of the fear he induced in the students, there were teachers|students who have to take Math 270 more than three times!

I did not get a grade of 1.0 but was happy to pass his course. I used a pirated Turbo BASIC program to program my assignment and it took a long time to display the final output on the slow VGA screens of the past! Remember we were only using the lowly 8086, and the 80386. The 486 was just coming into the market. A little later when I was already in my Ph.D. program, I recall a program called Xaos which run amazingly fast, in real time! on the Mandrake 7.2 OS.

Today the Xaos still survives, and it still reminds me of my dear professor. He actually mentioned some speed techniques in programming in BASIC without resorting to assembly.

Enough of the memories. So what is Xaos? It is a fractal zoomer, just a left mouse button press will zoom the figure in the graph window and a right mouse button will unzoom the figure for a wider scale view. Here is the opening screeen, obtained by selecting Applications/Graphics/Xaos.



and here is a zoomed view:


Of course, Xaos gives other interesting regions to explore aside from the well known $$z_{n+1}= z_{n}^2 + c$$. It even saves your animations to a file for playback later. we live it to the reader to explore on his own the fractal world. We don't want to rob you of the joy of wondering what fascinated the geeks of yersteryears.:)

Tuesday, July 6, 2010

Generate Smith chart on the computer with linSmith

I studied Electrical Engineering at West Negros College but I can't recall using a Smith chart for transmission line calculations and other uses. Instead we use our slide rules and the just coming of age Casio fx-102 (with micro fluorescent glow tubes) or a TI-58 for some lucky classmates, for computing directly the equations involving hyperbolic functions.

Nevertheless, in this modern era, a Smith Chart is still a very useful graphics method for getting a quick grasp of the effects of system design parameters on constant or varying frequency. In this entry we concentrate on linSmith a FREE software for drawing Smith Chart and diagrams superimposed on it by the program. I mean, you don' have to manually plot points on the chart itself, the program will do it for you. Luckily the linSmith program is comprehensive and comes with usefule examples for self study. You can always do self-education after you graduate!

Here is a description from the Ubuntu package which is at version 0.99.7-1,

  • Definition of multiple load impedances (at different frequencies)
  • Addition of discrete (L, C, parallel and series LC, and transformer)
    and line components (open and closed stubs, line segments)
  • Connection in series and parallel
  • Easy experimentation with values using scrollbars
  • A 'virtual' component switches from impedance to admittance to help
    explaining (or understanding) parallel components
  • The chart works in real impedances (not normalized ones)
  • Direct view of the result on the screen
  • Ability to generate publication quality Postscript output
  • A 'log' file with textual results at each intermediate step
  • Load and circuit configuration is stored separately, permitting several
    solutions without re-defining the other



Ubuntu puts the LinSmith package in the desktop menu at Applications/Other/ (together with gretl, Geomview, and Snappea.Here is a pic of the software:



linSmith has a developer homepage at John Coppens. The developer even recommends you compile from the latest sources! The latest version is already at 0.99.12 making the Ubuntu package out of date.
An Introduction and tutorial are also available from the homepagepage.

Wikipedia has an entry on Smith Chart.

We will hopefully write articles on problemsolving with linsmith in the future, as one of our aims is to present an engineering review in our blogs.

Sunday, July 4, 2010

LyX: A high level gui Latex frontend and document processor

We have described Kile in an earlier post in this blog, and it is a simple, well thought of assemblage of and interactive editor and tools for creating and viewing output of correct Latex source.

Is there a more high level gui for Latex? One which shows superscripts, subscripts in their natural positions and able to help the Latex writer form tables and equations? and even create bibliographies and cross references easily?

Well Lyx is just that tool. Now at 1.6.5 in Ubuntu, Lyx does not leave its users helpless in using its powerful capabilities. The software comes with an introduction, tutorial and even a users's guide all accessible from the graphical menu!


Lyx shows what an equation will look in print right inside the editor! For example, look at the image below.


Instead of just typing $ax^2 + bx + c = 0$ and imagining what it will look like in the output dvi/ps/pdf output, Lyx above shows you how it will look like right inside the editing screen!
Never has a latex processing been made easier and in fact Lyx has found favor by book writers,
who has learned a little latex. The graphical aids can help a newbie to create a typeset formula, much more beautiful than in and openoffice of MS word document.

We will start writing more on LyX, in the near future, stay tuned!

Lazarus: A Free Delphi for Linux!

Those were the days of rampant piracy, of using Turbo Pascal 2.1 to Delphi to Borland C++ Builder, for our programming projects. Later my heart jumped for joy when Kylix was introduced for Linux but that was a shortlived affair! The Kylix project died but the open source project Lazarus woke up Pascal from the dead and delivered a slick high quality sophisticated emulation of Delphi for Linux!

Lazarus is sure to bring smiles to delphi developers. It gives a graphical IDE for the Free Pascal Compiler. The output is a Linux executable in native (not interpreted) code!

Here is a snapshot. You must run lazarus ide from the graphical Applications menu not from the terminal or console.


When it opens, 4 windows are active: Lazarus Ide, source editor,Form1, object inspector and messages. Lazarus faithfully follows the delphi look and feel and we wonder if Borland or its successor approves of the copying.

We have done our PhD computing projects using a pirated copy of Delphi. Now I am not embarassed to use a clean copy in Linux. More power to the Lazarus developers and we hope to start writing more articles on Lazarus.

The version of Lazarus installed is 0.9.28, while the FPC compiler is at version 2.4.0. Don't laugh at the FPC compiler, it is one of the best compilers for creating ultra fast Linux binaries!

We will restart our Pascal love in the near future. Stay tuned for small projects using Lazarus.

Gambas, a free Visualbasic-like fast IDE on Linux!


Recent developments in Linux points out to the power of a community of inspired developers working  to produce and maintain quick IDEs to produce software. Here is one Visuabasic like environment which may give smiles to Linux users. It is exotically named Gambas (Gambas means almost basic like) and it is even already at version 2!
This may give a high quality tool to Linux software developers who are already familiar with the productivity and time efficiency of Delphi, C++Builder, and Visualbasic developers in Windows.

Gambas is easily installed using apt-get or synaptic tool in LInux. You will be presented with an operning screen shown above. Explore the power of Gamas by clicking on the examples.Choosing Timer for example and attempting to run it result in a displayed error box saying "Cannot load class 'Ftimer'. Unable to load class file. It turns out that the examples subdirectory is read only! So do the following:

sudo chmod -R o+w /usr/share/gambas2/examples

and all examples will run fine! Here is a snapshot of the timer example.



Now one can borrow or buy any Visual basic book and start creating fantastic graphical applications!
We just focus first on the installation. Then later we will write blog articles with examples for Gambas.

Saturday, July 3, 2010

qtOctave, another matlab-like computational software, free!

You will find qtoctave in the standard Ubuntu software repositories. And a simple
sudo apt-get install qtoctave will install the software with the need dependencies, all automatically! Life is simple with Linux. Sorry, but I hesitate in showing you how to install in Windows since I don't have a machine with the virus friendly OS around.

Of course, you can run Octave from the primitive looking command line, but why suffer? QtOctave gives you both Octave with an eyecandy Qt gui, making you more productive and wont make you look like a dinosaur when in a room full of Windows or even Mac users.

When you click on qtOctave in Applications/Science/qtOctave in a Gnome desktop, you will be presented with the following screen (with Help/Octave help enabled). qtOctave gave me an opening message that it requires an Octave 3.2.0 version. The Ubuntu version I have is 3.0.5, so hopefully the Ubuntu maintainers will give an update soon! QtOctave itself is at version 0.8.2.


The current version of Octave does not evaluate the expression exp(e * pi) in the terminal window.Will need to download the latest version of Octave!

The home page of Octave is Octave home page

Will come back in a week or two. Stay tuned.

July 4, 2010: I have downloaded the latest stable Octave 3.2.4, but the make process is taking a long time, even with a dual core machine.

-lX11  -lreadline  -lncurses -ldl -lhdf5 -lz -lm  -lfreetype -lz -L/usr/X11R6/lib -lGL -lGLU 
../libcruft/libcruft.so: undefined reference to `r_imag'
../libcruft/libcruft.so: undefined reference to `c_exp'
../libcruft/libcruft.so: undefined reference to `i_len'
../libcruft/libcruft.so: undefined reference to `d_int'
../libcruft/libcruft.so: undefined reference to `c_sqrt'
../libcruft/libcruft.so: undefined reference to `e_wsfi'
../libcruft/libcruft.so: undefined reference to `d_sign'
../libcruft/libcruft.so: undefined reference to `s_wsle'
../libcruft/libcruft.so: undefined reference to `r_mod'
../libcruft/libcruft.so: undefined reference to `c_div'
../libcruft/libcruft.so: undefined reference to `r_cnjg'
../libcruft/libcruft.so: undefined reference to `s_copy'
../libcruft/libcruft.so: undefined reference to `s_cmp'
../src/liboctinterp.so: undefined reference to `s_wsfe'
../libcruft/libcruft.so: undefined reference to `do_lio'
../libcruft/libcruft.so: undefined reference to `c_log'
../libcruft/libcruft.so: undefined reference to `r_int'
../libcruft/libcruft.so: undefined reference to `pow_dd'
../libcruft/libcruft.so: undefined reference to `i_indx'
../libcruft/libcruft.so: undefined reference to `s_wsfi'
../libcruft/libcruft.so: undefined reference to `z_abs'
../libcruft/libcruft.so: undefined reference to `s_stop'
../libcruft/libcruft.so: undefined reference to `r_sign'
../libcruft/libcruft.so: undefined reference to `pow_di'
../libcruft/libcruft.so: undefined reference to `d_lg10'
../libcruft/libcruft.so: undefined reference to `pow_ri'
../libcruft/libcruft.so: undefined reference to `e_wsle'
../libcruft/libcruft.so: undefined reference to `s_cat'
../src/liboctinterp.so: undefined reference to `do_fio'
../src/liboctinterp.so: undefined reference to `e_wsfe'
../libcruft/libcruft.so: undefined reference to `c_abs'
../libcruft/libcruft.so: undefined reference to `d_mod'
collect2: ld returned 1 exit status
make[2]: *** [octave] Error 1
make[2]: Leaving directory `/home/toto/Downloads/octave-3.2.4/src'
make[1]: *** [src] Error 2
make[1]: Leaving directory `/home/toto/Downloads/octave-3.2.4'
make: *** [all] Error 2

Nuts! So we have no choice but to wait for the Ubuntu version??!!

July 4: We removed qtOctave and old versions of Octave via Synaptic,
choosing the latest 3.2 series for Octave.
When we reinstalled qtOctave the terminal now works. For example:

>>> exp(i * pi)
ans = -1.0000e+00 + 1.2246e-16i
>>> sqrt(-1)
ans =  0 + 1i

Now that it runs, we will have impetus to write future articles for octave, the poor man's
matlab-like clone.

Scilab, a matlab-like environment, only it is free!

Scilab is a free (with compatible GPL license) Matlab like software for interactive numerical computation developed by French academics/programmers at INRIA. It has been developed through the years and has acquired sophisticated libraries for various applications, such as optimization, linear algebra, parallel computing, signal processing, simulation and other fields. If you cannot afford MATLAB, then your can afford Scilab. Scilab competes with R, Octave, Euler,Python-Scipy/Scientific, but if you do choose Scilab for your applied mathematics research work, Scilab will not disappoint. The wealth of free tools may make the user dizzy what to choose, in fact, one may resort to a hybrid approach using one or more of the available tools. As if to emphasize the enriched environment, Scilab has interfaces to computational codes in scientific libraries written in various languages such as fortran and C/C++. If you want the cheapest, fastest in implementing a comutational algorithm form conception to implementation and production stage, Scilab might win easily.

Scilab is hosted at Scilab homepage. All documentation, sources, libraries may be found there for quick downloads.

Scilab has a gui-console. Here are some examples. Scilab might take some time to initialize when it is invoked from the command line or graphical shell. Here is what you may see:


If you are very new to Scilab, the easiest way to feel at ease is to let Scilab demonstrate to you what it can do. Click on ?/Scilab Demonstrations. Select introduction. And Scilab will give you a basic tutorial! Press ENTER key to continue.Here is a snapshot of a Scilab introduction session:

 >>//               SCILAB OBJECTS
>>//               SCILAB OBJECTS
>>//               1. SCALARS
>>a=1               //real constant
 a  =
 
    1.  
>>1==1              //boolean
 ans  =
 
  T  

-->
>>'string'          //character string
 ans  =
 
 string   
>>
>>z=poly(0,'z')     // polynomial with variable 'z' and with one root at zero
 z  =
 
    z   
>>
>>p=1+3*z+4.5*z^2   //polynomial 
 p  =
 
                 2  
    1 + 3z + 4.5z   >>r=z/p             //rational
 r  =
 
          z         
    -------------   
                 2  
    1 + 3z + 4.5z   
>>//                2. MATRICES
>>A=[a+1 2 3
>>     0 0 atan(1)
>>     5 9 -1]      //3 x 3 constant matrix
 A  =
 
    2.    2.    3.         
    0.    0.    0.7853982  
    5.    9.  - 1.         
>>b=[%t,%f]         //1 x 2 boolean matrix
 b  =
 
  T F  
>>Mc=['this','is';
>>    'a' ,'matrix']   //2 x 2 matrix of strings
 Mc  =
 
!this  is      !
!              !
!a     matrix  !
>>Mp=[p,1-z;
>>    1,z*p]        //2 x 2 polynomial matrix
 Mp  =
 
                 2                    
    1 + 3z + 4.5z     1 - z           
                                      
                            2      3  
    1                 z + 3z + 4.5z   
>>F=Mp/poly([1+%i 1-%i 1],'z')   //rational matrix
 F  =
 
                  2                       
     1 + 3z + 4.5z        - 1             
    ---------------     ---------         
               2   3              2       
  - 2 + 4z - 3z + z     2 - 2z + z        
                                          
                               2      3   
           1             z + 3z + 4.5z    
   ---------------     ---------------   
               2   3               2   3  
  - 2 + 4z - 3z + z   - 2 + 4z - 3z + z   
>>Sp=sparse([1,2;4,5;3,10],[1,2,3])   //sparse matrix
 Sp  =
 
(    4,   10) sparse matrix
 
(    1,    2)        1. 
(    3,   10)        3. 
(    4,    5)        2. 
>>Sp(1,10)==Sp(1,1)                   //boolean sparse matrix
 ans  =
 
(    1,    1) sparse matrix
 
(    1,    1)    T 
>>//                 3. LISTS
>>L=list(a,-(1:5), Mp,['this','is';'a','list'])   //list
 L  =
 
 
       L(1)
 
    1.  
 
       L(2)
 
  - 1.  - 2.  - 3.  - 4.  - 5.  
 
[Continue display? n (no) to stop, any other key to continue]

We encourage the reader to install scilab using your package installer in Linux. The version I have
is 5.2.1. Scilab is also available for MS Windows.

We will present some tools-libraries available in Scilab in the future. Stay tuned.

Rev. Jul 15: Another optimization library with Python interface: NLopt, installation problem



NLopt is a free/open-source library for nonlinear optimization, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms. Its features include (from the home page of NLopt):

  • Callable from C, C++, Fortran, GNU Octave, Matlab, Python, and GNU Guile.
  • A common interface for many different algorithms—try a different algorithm just by changing one parameter.
  • Support for large-scale optimization (some algorithms scalable to millions of parameters and thousands of constraints).
  • Both global and local optimization algorithms.
  • Algorithms using function values only (derivative-free) and also algorithms exploiting user-supplied gradients.
  • Algorithms for unconstrained optimization, bound-constrained optimization, and general nonlinear inequality/equality constraints.
  • Free/open-source software under the GNU LGPL (and looser licenses for some portions of NLopt).
The homepage of NLopt is at NLopt homepage and the web site is fairly complete with FAQ, Download, Manual, Tutorial, Reference , Algorithms, License and copyright pages. Instructions for installation.
  1. Download the installer file

    wget -ct 0 http://ab-initio.mit.edu/nlopt/nlopt-2.0.2.tar.gz

  2. Unpack the nlopt-2.0.2.tar.gz.

    tar xzvvf nlopt-2.0.2.tar.gz

  3. Cd to the nlopt directory.
    cd nlopt-2.0.2.

  4. Perform standard installation commands. Type ./configure -h for help.

    ./configure --enable-shared
    make;
    sudo make install


  5. Make links to the shared libraries.
    sudo ldconfig



Unfortunately in the last step, we encounter
/bin/bash ../libtool --tag=CXX   --mode=link g++  -g -O2 -module 
-no-undefined -version-info 3:2:3  -o _nlopt.la -rpath /usr/local/lib/python2.6/dist-packages _nlopt_la-nlopt-python.lo ../libnlopt.la -lm 
libtool: link: g++ -shared -nostdlib /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtbeginS.o  .libs/_nlopt_la-nlopt-python.o   ../.libs/libnlopt.a -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3 -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib -L/lib/../lib -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../.. -L/usr/lib/x86_64-linux-gnu -lstdc++ -lm -lc -lgcc_s /usr/lib/gcc/x86_64-linux-gnu/4.4.3/crtendS.o /usr/lib/gcc/x86_64-linux-gnu/4.4.3/../../../../lib/crtn.o    -Wl,-soname -Wl,_nlopt.so.0 -o .libs/_nlopt.so.0.3.2
/usr/bin/ld: ../.libs/libnlopt.a(general.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
../.libs/libnlopt.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[2]: *** [_nlopt.la] Error 1
make[2]: Leaving directory `/home/toto/Downloads/nlopt-2.0.2/swig'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/toto/Downloads/nlopt-2.0.2/swig'
make: *** [install-recursive] Error 1
The error message says we have to recompile with -fPIC flag. A show stopper! Have to review how to insert the compiler flag in the configure file. Will be back this week. Interfacing with Python requires that Numpy is installed. Nevertheless, a Python example is


import nlopt
from numpy import *

def myfunc(x, grad):
    if grad.size > 0:
        grad[0] = 0.0
        grad[1] = 0.5 / sqrt(x[1])
    return sqrt(x[1])

def myconstraint(x, grad, a, b):
    if grad.size > 0:
        grad[0] = 3 * a * (a*x[0] + b)**2
        grad[1] = -1.0
    return (a*x[0] + b)**3 - x[1]

opt = nlopt.opt(nlopt.LD_MMA, 2)
opt.set_lower_bounds([-float('inf'), 0])
opt.set_min_objective(myfunc)
opt.add_inequality_constraint(lambda x,grad: myconstraint(x,grad,2,0), 1e-8)
opt.add_inequality_constraint(lambda x,grad: myconstraint(x,grad,-1,1), 1e-8)
opt.set_xtol_rel(1e-4)

x = opt.optimize([1.234, 5.678])
minf = opt.last_optimum_value()
print "optimum at ", x[0],x[1]
print "minimum value = ", minf
print "result code = ", opt.last_optimize_result()


We would like to compare its performance with OpenOpt which was describe earlier in this blogs.

July 15


Cleaning up previous installation as per suggestion and running the example, we get


python example.py
optimum at 0.333333612374 0.296296070953
minimum value = 0.544330846961
result code = 4


We have to delve deeper into nlopt documentation to understand the various result codes.
We feel that optimization software with the best comprehensive documentation (no suprise principle)
will find wider use. We will try to play with nlopt in the coming days. Stay tuned.

Thanks to the comments from the head of the NLOPT development team.

Monday, June 21, 2010

Exploring Optimization routines in Python: OpenOpt

Scipy comes with a built-in optimization tools in its optimize module but we will sbe using the more modern OpenOpt framework/library with Python. Ubuntu offers two flavors of openopt packages for Python: python-openopt and scikits-openopt and installing one will remove the other package!

OpenOpt has related superb automatic differentiation support in FuncDesigner.

OpenOpt is developed in the Ukraine and its homepage is at http://openopt.org.
It now finds wide adoption and widespread applications.From its Applications page, we see the following:

       
  • Small Aerial Vehicle Trajectory Planning; University of California, Berkeley, & University of Waterloo (pdf)
       
  • sagemath.org, SAGE - a viable free open source alternative to Magma, Maple, Mathematica and Matlab
       
  • pymvpa.org (Multivariate Pattern Analysis)
       
  • PythonXY (www.pythonxy.com)
       
  • Carnegie Mellon University started to teach students OpenOpt
       
  • simplemax.net online services
       
  • enthought.com repository and educational courses . The Enthought guys are very smart! - they ignored to answer my email with proposition of collaboration but involved my soft without even notification to me.
       
  • Measuring Inconsistency in Probabilistic Knowledge Bases; Technische Universitat Dortmund, Germany
       
  • Bayesian Inference Package (probabilistic calculations), Gulbenkian Institute of Science in Portugal
       
  • IdentiPy, parameter optimization and inverse problems for materials computation
       
  • Multiple-Shooting Optimization using the JModelica.org Platform; Lund University, Sweden
       
  • Optimal design of complex energy facilities (Ukraine, pdf, no English translation is available)


If you are a Ubuntu user, then installing openopt is a snap. The version I have is  

Importing openopt in ipython, we see that applying the dir() function provides the following major classes/routines:

'CDFP', 'CGLP', 'CLLAVP', 'CLLSP', 'CLP', 'CLUNP', 'CMILP', 'CMINLP',
 'CMMP', 'CNLLSP', 'CNLP', 'CNLSP', 'CNSP', 'CQP', 'CSDP', 'CSLE', 'CSOCP',
 'DFP', 'GLP',  'LLAVP', 'LLSP', 'LP', 'LUNP', 'MILP', 'MMP', 'NLLSP', 'NLP', 'NLSP', 'NSP', 'OpenOptException',
 'QP', 'SDP',  'SLE', 'SOCP'

Problem classes which may be solve by OpenOpt are the following:


Problems
DFPDataFit Problems
GLPGLobal Problems
LLAVPLinear Least Absolute Value Problems
LUNPLinear Uniform Norm Problems
MINLPMixed Integer Nonlinear Problems
MMP    MiniMax Problems
NLLSPNon-linear Least Square Problems
NLPNon-linear Problems
NLSPNon-linear System Problems
NSPNon-smooth Problems
QPQuadratic Problems
SDPSemi-Definite Problems
SOCPSecond Order Cone Problems


To be continued!


The version Ubuntu installs is .27 when the latest is .29!

We install FuncDesigner separately as it is not in any Ubuntu repository.


This is article is an introduction. We will expound further each important feature of openopt when we have the free time.


Our most pressing application is to use openopt to determine the parameters of an ARMA process. Stay tuned.

You can easily install 3 packages openopt, funcdesigner and derapproximator by typing


sudo easy_install openopt
sudo easy_install FuncDesigner
sudo easy_install DerApproximator


I thought it would get the latest versions. Not!

This set of packages will sure to invite some people who pine for Matlab but cannot afford the hefty price tag!

Sunday, June 20, 2010

Spyder, a new interactive Scientific Python development Environment

Flash! June 26: Latest 1.1.0 version just released! visit latest spyder console



There are more development environments for Python coming into use. What is wrong with TKinter, Eric 4, geanny, even Eclipse? Nothing wrong with these but Python developers will finally choose what suits them personally. Tkinter, I find a little slow, Eric is the best so far but I lose some of my work sometimes(It pays to save your work from time to time)! Geanny and Eclipse actually works for other languages. I suggest you give each editors/environment a try!

The newest I found is Spyder, available from http://code.google.com/p/spyderlib/downloads/detail?name=spyder-1.0.3-py2.6.eggand developed by Pierre Raybaut. When I downloaded it, the egg file was stored in /temp not in ~/Downloads. You type sudo easy_install spyder-1.0.3-py2.6.egg from the command line.

Once you activate it, you will be presented with multi-paned windows for file, classes and functions, Workspace,and Interactive Shell. It has a debugger and an interface to Pylint for your source code. There is also a convenient Tools submenu for Qt Designer and Qt Linguist.



It will take time for me to be familiar with it, and I think its major competitor will be Eric which is also a Qt application.

Try it and submit comments about your experiences with Spyder. The free and open source world depends so much on feed back from users. We hope that Spyder and Eric developers will learn from each other!

Wednesday, March 31, 2010

KIle -an integrated Latex environment

Kile is an integrated Latex environment software with the following features(from
its Kile homepage

  • Compile, convert and view your document with one click.
  • Auto-completion of (La)TeX commands
  • Templates and wizards make starting a new document very little work.
  • Easy insertion of many standard tags and symbols and the option to define (an arbitrary number of) user defined tags.
  • Inverse and forward search: click in the DVI viewer and jump to the corresponding LaTeX line in the editor, or jump from the editor to the corresponding page in the viewer.
  • Finding chapter or sections is very easy, Kile constructs a list of all the chapter etc. in your document. You can use the list to jump to the corresponding section.
  • Collect documents that belong together into a project.
  • Easy insertion of citations and references when using projects.
  • Flexible and smart build system to compile your LaTeX documents.
  • QuickPreview, preview a selected part of your document.
  • Easy access to various help sources.
  • Advanced editing commands.
Although Kile is a KDE application, you can still install it in Ubuntu Koala using the standard
sudo apt-get install kile
command in the command line. The aptitude system will pull in a lot of KDE support softwares even if you are more comfortable with the GNOME Desktop. At this writing, the version I have is 2.0.83 in KDE 4.3.2, while the latest unstable version is already at 2.1 Beta 3. Kile is easy to use but you need to know some rudiments of Knuth's Latex typesetting setting system of denoting mathematical equations. As a simple example, let us write the following in kile: The kinetic energy of a body with mass m and speed v is given by (1/2) mv^2. Now run Kile and start with a new article. Automatically, Kile will give you a blank built in article template like this:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}

%opening
\title{}
\author{}

\begin{document}

\maketitle

\begin{abstract}

\end{abstract}

\section{}

\end{document}




Now edit the above so it will be shown as
 
\documentclass[a4paper,10pt]{article}
\usepackage[utf8x]{inputenc}

%opening
\title{Kinetic Energy of a moving body}
\author{Ali Baba}

\begin{document}

\maketitle

\begin{abstract}
Example Latex article example
\end{abstract}

\section{Definition}
The kinetic energy of a body with mass $m$ and speed $v$ is given by $\frac{1}{2}m\cdot v^2$.

\end{document}

Save the file to myfirst.tex and then click on Quickbuild icon. If everything is allright, Kile will call support programs to generate a pdf file myfirst.pdf. Here is an image of the output.


If you get this far, congratulations!  There is still so much to discuss but we stop here at this moment. We only illustrate that KIle is an easy to use free-software to generate professional looking typeset documents.


To be continued... Chip in your comments so the post will be more useful to you.

Wednesday, March 17, 2010

Stellarium- a complement to Kstars

Let me tell you that my previous experience with Stellarium did not go well three years or more ago. It repeatedly crashed and I got some negative feelings over the software.

But today Stellarium redeemed itself. I was presented with a picture of a pasture in Paris and moving the mouse gave me fantastic various viewing transformations including fisheye view pleasures.

Stellarium will complement Kstars. Thankfully my harddisk (120 Gbytes) is large enough to accommodate the two or I have to pick up Kstars based only on familiarity.

When I wanted to visit Mars, I was presented with a Spirit panoramic view of Gusev crater collated from a lot of pictures.


I thank the developers of Stellarium for finally making Stellarium work flawlessly this time on the latest Ubuntu 9.10 Karmic Koala OS.

Till then, we have to write more posts on both Stellarium and Kstars.

Kalzium- a periodic table of elements viewer

Kalzium is a free software available for Linux systems for viewing properties of the elements and for exploring the periodic table. Properties of the elements can be viewed at a glance either individually or grouped. The information on isotopes are also included and wikipedia articles are referenced. Here is a snapshot.




Click on the image for a fuller view. Kalzium is a KDE application. You should install the Kalzium helpfiles (Kalzium handbook) so as to maximize benefits in using the program. Kalzium also include a free chemical equation balancer! Clever people. Kalzium can be obtained from
http://www.kde.org/kalzium if it is not available as a package for your OS. My version of Kalzium is at 2.2.98.

So dont feel bad using Linux in the scientific computing arena. You have lots of free softwares to help you and it is our job current and future to help you maximize the use of these powerful and FREE softwares.Stay tuned for more articles on Kalzium

Tuesday, March 16, 2010

Maxima, the free computer algebra system

Maxima was inspired by the first successful computer algebra system, Macsyma developed at MIT. It is able to perform symbolic integration, differentiation, expansions, and simplifications of expressions.

There are several available interfaces for maxima. The basic program can be run from the command line. But a better way to use Maxima is via wxMaxima and xMaxima. Between the two, I gravitate towards wxMaxima. Here are some capabilities of Maxima.

Here are some simple outputs from Maxima just to get started.

(%i1) diff(x^3, x);
(%o1) 3*x^2
(%i2) expand((x+y)^3);
(%o2) y^3+3*x*y^2+3*x^2*y+x^3
(%i3) integrate(x^3,x);
(%o3) x^4/4
(%i4) factor(x^2 + 2 *x + 1);
(%o4) (x+1)^2
(%i5) 15!
(%o5) 1307674368000

In the above example, after entering ; we press shift enter, not just the enter key to see the results. The outputs are actually pretty printed.

We will add more entries to using Maxima in the future! Stay tuned.

Wolframalpha computational server -secret weapon of smart students

No, wolframalpha is not a free software but rather a currently free computational server (knowledge engine) from the people who developed and sell Mathematica, a powerful symbolic mathematical software.

When my high school graduating niece wanted to factor some polynomial expressions, I simply told her to fire up her browser and visit http://www.wolframalpha.com and type say ( I have forgotten here original expression) x^3 - y^3. Here are snapshots of parts of the screen output of the comptuational service.



















Doubtless, she may not understand what a contour map is at the moment, but the factoring of x^3 -y^3 is part of the output of the server. Integrals and derivatives are even shown!

Now that Wolframalpha is now better known since it was chosen as the best of What's new for 2009 by Popular Science, smart students now have a semiautomated servant in the Internet to help them in their homework.
Wolframalpha will benefit students and their teachers in the college calculus programs. It can display the steps to some of the results, and the fine resolution graphs is more than ice candy. Wolfram alpha deserves more use.

Note: Our Python computational server is idle at the moment. It differs from Wolframalpha in that the latter is very general in scope from stock market questions, to historical significance of dates and has a nice formatted series of outputs.

So you know now one of our secret weapons. Narrow focused "free" solvers say for calculus include wxMaxima and Axiom to name just two.

Enjoy exploring the capabilities of Wolframalpha. Our concern is whether it will continue to be free in the far future.

There is no need to buy an expensive TI-89 or HP 50G unless the instructor absolutely require them. The problem is that in the PHilippines , Internet access is only enjoyed by so few especially in urban areas. Perhaps cell phones, and USB broadband devices can help accelerate the Internet access of the general population. And they will discover a host of currently free, awesome services like wolframalpha.

Is Kstars the best free desktop planetarium?

Kstars is easily installed if your Linux OS is debian based like my Ubuntu Karmic Koala 9.10. Use synaptic package manager or simply issue from the command line sudo apt-get install kstars and Ubuntu will do all the worrying to completely install the package.
It is a KDE package and if you started with GNOME only, the install might take more than an hour just to install the KDE dependencies. It can interface and control telescopes! and knows the longitude and latitude of most places.




Kstars can display more than a 126,000 stars, 13,0000 deep sky objects, the 88 constellations,
all planets,the Sun , the Moon ,thousand of comets and asteroids and the Milky Way.
At version 1.5.4, Kstars have vastly improved and it is so full of features that we have a problem of presenting a short introduction. We'd rather that the reader install Kstars and not rush doing everything. Instead take time to enjoy the accessiblity of a simulated universe under one's fingertips.

Here is a pic from Kstars. We will write additional blogs on Kstart in the future. We wrote this piece to encourage the reader to install the software.




Want to know where the planets are at now? Just enter the name in the Find utility and Kstars will position the displayed celestial map with the object at the center!

Kstars have evolved and may be useful even to serious astronomy amateurs and professionals alike. Nothing give us satisfaction than a free high quality software that is quite so useful in introducing astronomy to Filipino students.


Stay tuned!

Sunday, March 14, 2010

Euler a compact computational software.

Euler is a computational software with a GUI for real and complex numbers and
matrices and is capable of interval arithmetic. It can visualize
functions in two and three dimensions.

Euler is quite compact and compares favorably in speed with other free
softwares in its class like Octave and Scipy.


The current version installed in my Ubuntu 9.10 Karmic Koala is at 1.61.0.
If you have a different version of Linux, it may be available as a package
or if you prefer to install from sources, is available at
http://euler.sourceforge.net.

When you invoke Euler from Applications/Science you wil be greeted with the
following screen which allows you enter commands.





Euler as a calculator
If you type an expression Euler will echo the computed answer unless you end the
expression with a semicolon.

For example, typing sin(pi) ended with the Enter key will print the answer 1. However,
sin(pi); will just be silent.


To be continued.

Saturday, March 13, 2010

Gretl part2 instant regression with built-in datasets.

Gretl comes with useful datasets and that includes datasets from standard textbooks! So teachers of Econometrics should have a single convenient source of econometrics data for expository purposes.

Let us select the djclose.gdt dataset by clicking on gretl/File/Open data/Sample file... and selecting the djclose (Dow Jones Industrial Average daily close).


Let us add data index variable for the data by clicking on Gretl/Add/Index variable. Gretl will then add the variable index.

Let us view the data. Click on gretl/View/Graph specified vars/X-Y scatter. Select the Index variable for X-axis variable and selcect djclose for Y-axis variable. When you click on the Ok button, the following graph will be displayed.



That is neat! The least squares line is drawn automatically. Right click inside the graph and save it to djclose.png.

Now lets see the standard output of regression of Gretl.
Click on gretl/Model/Ordinary Least Squares and a popup gretl:model 1 window will appear.
Select djclose for dependent variable, constant and index for independent variables and click Ok.
You should get the following output:



Model 1: OLS estimates using the 2528 observations 80/01/02-89/12/29
Dependent variable: djclose

coefficient std. error t-ratio p-value
-------------------------------------------------------
const 554.455 8.47987 65.38 0.0000 ***
index 0.751325 0.00580823 129.4 0.0000 ***

Mean dependent var 1504.506 S.D. dependent var 588.3432
Sum squared resid 1.15e+08 S.E. of regression 213.1174
R-squared 0.868839 Adjusted R-squared 0.868787
F(1, 2526) 16732.79 P-value(F) 0.000000
Log-likelihood −17140.82 Akaike criterion 34285.63
Schwarz criterion 34297.30 Hannan-Quinn 34289.87
rho 0.995548 Durbin-Watson 0.009046




That looks easy to do and it is! Look at the p-values for the const and index variables. This indicates that const and index are significant! Other numeric output measures are shown on the output above but we leave it to future posts to explain further.

We hope that Gretl becomes the standard free software for doing econometrics although this author feels that a Python version would be much more extensible. Gretl will inspire our own future Gui based econometris software written in Python.

Gretl -Gnu Regression, time series library

Gretl is an acronym for Gnu Regression,Econometrics and Time Series library.The home page is at
http://gretl.sourceforge.net/,

It is a complete cross-platform(Windows, Mac OS and Unix-Linux) desktop program with its own gui interface, is written natively in the fast machine code compilable C programming language.
It is is free, open-source software, freely distributable under the GNU General Public License (GPL) as published by the Free Software Foundation.


We have not enough time to discuss Gretl in our Econometrics course in the second semester, 2010 as we used and focused more on the the bigger and more general, powerful R statistical data and visualization software. Gretl available data sets were useful for us, especially making available the data sets of Gujarati.

Hopefully we would be better prepared and Gretl might find more usage by
presenting more educationsl resources in this blog and
our continuing experimentation with this software.

Lets see its features from its well written documentation:


  1. Easy intuitive interface in various European, Turkish languages including English.
  2. A wide variety of estimators: ordinary least squares, ML(maximum likelihood), GMM; single-equation and simulaneous equations system methods
  3. Time series methods: ARMA, GARCH, VARs and VECMs, unit-root and cointegration tests, etc.
  4. Limited dependent variables: logit, probit, tobit, interval regression, models for count and duration data, etc.
  5. Output models as LaTeX files, in tabular or equation format
  6. Integrated scripting language: enter commands either via the gui or via script
  7. Command loop structure for Monte Carlo simulations and iterative estimation procedures
  8. GUI controller for fine-tuning Gnuplot graphs
  9. Interface to GNU R, GNU Octave and Ox for further data analysis


Here is a list of built-in functions in Gretl. We are sure that this list would be growing.


$ahat $aic $bic $chisq $coeff
$compan $datatype $df $dwpval $ess
$Fstat $gmmcrit $h $hausman $hqc
$jalpha $jbeta $jvbeta $lnl $ncoeff
$nobs $nvars $pd $pvalue $rho
$rsq $sample $sargan $sigma $stderr
$stopwatch $sysA $sysB $sysGamma $T
$t1 $t2 $test $trsq $uhat
$unit $vcv $version $windows $xlist
$yhat

abs acos asin atan BFGSmax
bkfilt boxcox cdemean cdf cdiv
ceil cholesky cmult cnorm colnames
cols corr corrgm cos cov
critical cum det diag diff
dnorm dsort dummify eigengen eigensym
exp fdjac fft ffti filter
firstobs floor fracdiff gammafun genpois
getenv gini ginv hpfilt I
imaxc imaxr imhof iminc iminr
infnorm int inv invcdf invpd
islist isnull kfilter ksimul ksmooth
isseries isstring lags lastobs ldet
ldiff lincomb ljungbox lngamma log
log10 log2 lower lrvar makemask
max maxc maxr mcorr mcov
mcovg mean meanc meanr median
mexp min minc minr missing
misszero mlag mnormal mols movavg
mpols mread mshape msortby muniform
mwrite mxtab nelem nobs normal
nullspace obs obsnum ok onenorm
ones orthdev pdf pmax pmean
pmin pnobs polroots princomp psd
psdroot pvalue qform qnorm qrdecomp
quantile rank ranking randgen rcond
readfile replace resample round rows
sd sdc sdiff selifc selifr
seq sin sort sortby sqrt
sst strcmp strlen strncmp strstr
sum sumc sumr svd tan
toepsolv tolower tr transp trimr
uniform unvech upper urcpval values
var varname varnum vec vech
wmean wsd wvar xmax xmin
xpx zeromiss zeros




Gretl is available as an add-on package for the Ubuntu-Linux OS. You can instal it via synaptic or simply via apt-get:

apt-get install gretl


and all dependencies should be installed by the software package manager. In my 9.04 Karmic, It is installed in Applications/Other menu.


March 13: To be continued with examples!

Welcome to Free Software Explorations!

I am starting a new blog hosted by blogger.com. This will complement my other blog at dr-adorio-adventures.blogger.com This blog will focus on the effective use of free software (not just open source) where there is no payment for the use of the software.

You might be surprised that free software exists for a broad range of applications in various fields: scientific, academic and commercial use. A catalog of free software might list more than 4000 entries. So we will never run out of topics to write.

This educational blog will include instructions for installation, tutorials and special tips and techniques.

Stay tuned! We will start adding posts this week!