uschmitt | Urlaub, taichi | Wednesday, August 20th, 2008

I discovered the following anouncement today:

SpringerLink, one of the world’s largest scientific databases, has partnered with CiteULike, the social bookmarking website for researchers. The partnership will ensure that researchers will benefit from CiteULike’s reference management services.

Looks like a nice thing for managing interesting publications. I started using it today because I lost overview of lots of pdfs with cryptical names in my local file system. Here is my account.

Python wrapper for C-SVM from libsvm

uschmitt | machine learning, python | Tuesday, August 19th, 2008

I provide a simple Python module for training a C-SVM at our public subversion repository. I had to write an own wrapper of libsvms C-SVM for some reasons:

  1. There are SVM implementations for Python, but I wanted a lightweight solution which plays well with numpy instead of a full framework such as Orange.
  2. There is a libsvm wrapper in scipy.sandbox, but I did not succeed in building it, further it is based on ctypes.
  3. I wanted to improve my f2py skills by wrapping libsvm. ctypes is great but f2py handles platform dependent compiler setup easyly and converts numpy arrays to C arrays automatically.
  4. I had to modify code, because training in libsvm can not be stopped by providing an upper limit to the number of iterations performed. And I wanted to control output of libsvm during training.

Please ask me in case of problems.

TaiJi in der medizinischen Forschung

Achim | taichi | Sunday, August 17th, 2008

Beruflich habe ich viel mit der Aufbereitung medizinischer Publikationen zu tun. Ein öffentlich zugängliches Ergebnis dieser Bemühungen kann man unter www.biomedexperts.com sehen. Als Martin im Forum für Wu Tai Chi darauf hingewiesen hatte, daß sich in PubMed jede Menge Information zu Tai Chi und Medizin finden lassen, war es für mich daher naheliegend, mal “unseren” Zugang zu PubMed zu testen. Auf Martins Wunsch hin will ich das Ergebnis hier kurz vorstellen:

BiomedExperts ist dazu gedacht, Experten zu bestimmten Themen zu finden. Nach ein paar Fehlversuchen finde ich ‘raus, daß ich doch bitte die Schreibweise “TaiJi” verwenden möge. Dann liefert die Anwendung folgende Definition:

One of the MARTIAL ARTS and also a form of meditative exercise using methodically slow circular stretching movements and positions of body balance.

Für medizinische Software schonmal gar keine schlechte Definition. Zu dem bekomme ich ein Übersichtskarte, wo auf der Welt wieviel zum Thema TaiChi veröffentlicht wurde (Ein Klick auf die Bilder zeigt eine größere Version an).

Dazu gibt’s eine Liste der Wissenschaftler, die sich mit dem Thema beschäftigt haben. Die zwei Spalten rechts geben an, wieviele Publikationen der Experte zum Thema TaiChi veröffentlich hat und wieviele er insgesamt hat. Liegen die Zahlen dicht beieinaner, ist anzunehmen, daß TaiChi zu den Spezialgebieten des Experten gehört - muß aber nicht sein.

Die einzelnen Experten lassen sich aufklappen. Die Details sind im folgenden Screenshot zu sehen:

Ganz links ist die Liste der Publikationen zum Thema TaiChi zu sehen. Die Titel sind direkt mit PubMed verlinkt. Rechts in den zwei Spalten ist zu sehen, womit der Experte sich allgemein beschäftigt. Einmal im Kontext von TaiChi und einmal allgemein. Hier kann man z.B. sehr schön sehen, daß der Experte aus meinem Beispiel sich vorwiegend mit TaiChi im Zusammenhang mit Herzkreislauferkrankungen beschäftigt. Andere Forschungen gehen eher in Richtung Sturzprävention.

Ich denke, daß dieser Zugang zu medizinischer Forschung für den einen oder anderen recht spannend sein könnte - und komme somit aber auch zu einem kleine Haken: BiomedExperts ist zwar kostenlos, bietet aber KEINEN direkten Zugang zu den wissenschaftlichen Veröffentlichungen! Alle Links gehen zu PubMed, wo teilweise Volltexte verfügbar sind, oft aber nur Abstracts. Wer sich intensiv mit aktuellen Veröffentlichungen beschäftigen will, braucht immer noch - in der regel kostenpflichtigen - Zugang zu den Publikationen. BiomedExperts macht nur das finden leichter. ;-)

Falls der/die eine oder andere neugierig geworden ist, stehe ich bei Fragen gerne zur Verfügung.

Sparse nonnegative matrix approximation

uschmitt | machine learning, python, signal processing | Tuesday, August 12th, 2008

In addition to the fast FNMAI algorithm, I implemented an algorithm for sparse nonnegative matrix approximation called NNSC. Both are included in the py_nnma package which can be accessed

  • as a python egg. If you have easy_install on your machine, you can get the package by submitting
    easy_install py_nnma

    on your commandline.

  • from our public svn repository, the address is  http://public.procoders.net/nnma

The egg comes without examples which you can get from our subversion repository. For further information about the NNSC algorithm look at this publication.

Python replaces Matlab (at least for me)

uschmitt | python | Monday, August 11th, 2008

The emergence of Matlab during the last decade of the 20th century highly changed the way we develop, implement and test numerical algorithms:

  • In the old days we used C, sometimes  Fortran or C++.  We spent a lot of  time in writing low-level functions and debugging memory leaks. Matlab helped us a lot.
  • Debugging numerical algorithms is hard, because dumping a 100 times 100 matrix will not really give you the information you are looking for. Therefore visualization of data is very important for developing numerical code  efficiently. Gnuplot helped us, but Matlab provided nice interactive 3d graphics and a tight integration.

We naturally moved away from  cumbersome ‘waterfall method‘ alike planing and coding  to some agile ‘lets try things out - we only need a few minutes’ . Matlab gave us the ability to play with  data and algorithms.

(more…)

Installing and upgrading Wordpress with Subversion

uschmitt | others | Thursday, August 7th, 2008

This article explains how to install und upgrade Wordpress with Subversion (SVN), which reduces the work for future updates: “svn up” is much nicer than “download->ftp->unzip”. I just upgraded this blog and had no problems at all.

Python calling C code: py_ica moves from ctypes to f2py

uschmitt | python, signal processing | Tuesday, August 5th, 2008

Due to some problems when deploying my py_ica module to several platforms I changed the way the C-code is called from Python:

  • The existing version of py_ica uses ctypes. ctypes is great, but leaves you alone when writing a Makefile to handle compiling your shared module on different platforms with different compiler sets.
  • I discovered that f2py is not only for wrapping FORTRAN code, it plays well with C code too ! See  http://www.scipy.org/Cookbook/f2py_and_NumPy The f2py and distutils framework provide nice abstractions of the underlying platform and compiler tool set.

(more…)

Python module for nonnegative matrix approximation (NNMA)

uschmitt | machine learning, python, signal processing | Monday, July 28th, 2008

NNMA is a matrix decomposition and approximation method which got some attention during the last years and has many applications as in

Sometimes NNMA is called nonnegative matrix factorization (NMF) which is not fully correct in most cases.

I discovered NNMA in the book Programming Collective Intelligence: Building Smart Web 2.0 Applications” from O’Reilly which is a great book that shows interesting applications and good explanations of important data mining techniques (but talks about NMF and not NNMA ;-) )

Looking for a recent solver, I found the algorithm FNMA/I described in

Dongmin Kim, Suvrit Sra, Inderjit S. Dhillon:
"Fast Projection-Based Methods for the Least Squares Nonnegative Matrix
Approximation Problem", Statistical Analysis and Data Mining, 2008


which is supposed to be very fast. The algorithm is  easy to implement,  especially if you use matlab, or even better numpy. I provide the numpy based solver plus some sample data and scripts here. In order to test the implementation I took 400 images of handwritten digits 0-9 and decomposed the data into 15 components. The result looks like this:

The data and the correspondig script is included in the download.

How to blog mathematical formulas in Wordpress

uschmitt | others | Thursday, July 24th, 2008

Showing mathematical formulas in wordpress based blogs is easy if you have this plugin installed. I discovered it yesterday for writing this posting.

If you post you inclulde forumulas in LaTeX code like this

$$ \sum_{i=0}^\infty q^i = \frac{1}{1-q}$$

which is rendered as

\sum_{i=0}^\infty q^i= \frac{1}{1-q}

The author says:

This plugin use the public latex server(default is the service
provided by wordpress.com) which means you don't need to install
any Latex module in your own server which is hard for newbie

For more information about \LaTeX look here.

Nonnegative least squares : A Recipe for calling numerical FORTRAN code from Python

uschmitt | numerics, python | Wednesday, July 23rd, 2008

Searching the web for  a python based solver for a non negative least squares problem

 ||A x - b ||_2 \to \min \quad \textrm{with} \quad x\ge 0
I found some Fortran code from www.netlib.org only. F2PY is a great tool but due to compiler issues it did not work in my case. So I used ctypes, which was easy because numpy has a sub module ctypeslib which provides some nice convenience routines for using ctypes together with numpy.

I tried  to document my code well in order to provide a recipe for calling Fortran code with numpy’s arrays. You can browse the code in our subversion repository.

The full code is available from here. You need a FORTRAN compiler like the free g77. If you use Windows I recommend the cygwin environment which ships with g77.

Buch: Programmieren in C

uschmitt | others | Tuesday, July 22nd, 2008

Here comes spam: Ich möchte hier auf das Buch “Programmieren in C - eine mathematikorientierte Einführung” aufmerksam machen, schließlich bin ich einer der beiden Autoren :-)

Das Buch richtet sich in erster Linie an Studenten vor dem Vordiplom, und ist speziell auf die Umsetzung mathematischer Verfahren ausgerichtet. Das hört sich jetzt trocken an, ist es aber nicht. Am Ende des Buches werden alle erworbenen Kenntnisse zusammen gebracht um Planetenbahnen zu berechnen und darzustellen, sowie Warteschlangen an Supermarktkassen zu simulieren.

Eine Website zum Buch gibt es auch, und wer mal reinschauen möchte, kann dies auf Google Booksearch tun.

compute *sorted* eigenvalues and eigenvectors with numpy

uschmitt | python | Monday, July 21st, 2008

numpy is great for linear algebra as it provides not only the almighty data container type array, but also  lots of elegant functions for working with array ’s and routines for several matrix decompositions as cholesky, qr or svd.

Unfortunately the eigenvectors returned from routines like linalg.eig oder linalg.eigh are not sorted.
But here comes numpys argsort() function to our rescue: It computes a permutation which sorts a given vector instead of sorting the vector itself.

So we can compute a PCA with little code:

from numpy import *

def pca(data):
    """ assume one sample per column """
    values, vecs = linalg.eigh(cov(data))
    perm = argsort(-values)  # sort in descending order
    return values[perm], vecs[:, perm]

Distributing ctypes based modules

uschmitt | python | Monday, July 21st, 2008

Ctypes is great. I use it a lot for speeding up numerical computations, and numpy provides some nice helpers which ease the usage of ctypes when passing multidimensional data.

I had some problems when writing a setup script for distributing a ctypes based module: the first problem was to get my dll into the site-packages folder of my python installation. get_python_lib from distutils.sysconfigs helps, and my setup.py looks like this:

from distutils.core import setup
from distutils.sysconfig import get_python_lib
import glob
setup(name="py_ica",
    …
    py_modules=["py_ica"],
    data_files=[(get_python_lib(), ["wrap_ica.dll"]), ]
)

This script installs py_ica.py and wrap_ica.dll to the site-packages/ folder.

The other problem was how to find the dll when loading with ctypes.CDLL

import os.path
ctypes.CDLL(os.path.join(os.path.dirname(__file__), "./wrap_ica.dll"))

If you load your DLL like this, your python module will find it in your local development folder as well as after installation with python setup.py install.

Both solutions are platform independent, so don’t be disguided by the .dll extensions appearing in the example  code.

PythonMagickWand on PyPi

Achim | python | Sunday, July 20th, 2008

Today I have created my first python egg! It’s a PythonMagickWand egg and can be found on PyPi. I have also created a first version of a Sphinx based documentation which can be found in our subversion repository.

Get process listening on a certain port

Achim | others | Saturday, July 19th, 2008

The following command was quite useful to me, to figure out which process was running on port 8080 on my Mac OS X:

sudo lsof -i :8080

Tar file scanner for tar archives with *many* files

uschmitt | python | Friday, July 18th, 2008

In comp.lang.python Terry Caroll stated a memory problem when iterating over the file information of a 4GB tar file. This is because the standard libs tarfile module caches all header blocks which results in  memory consumption linear to the number of files in the archive. The module tarfile_scanner solves this problem. Its purpose is  iteratring over the file infos inside the tar file, other functionalities as untaring oder adding files are not implemented.

Update of ICA packages

uschmitt | python, signal processing | Thursday, July 17th, 2008

Thanks to Scott Grant I found an error in the Python ICA module concerning installation.
I provide the following updates:

For further information about this module  please look at the first announcement of the module.

Europython 2008 - Ende

Achim | python | Wednesday, July 9th, 2008

Heute hab’ ich noch einen sehr guten, spannenden Vortrag gehört und ein weitere steht noch auf dem Plan. Danach geht’s dann ab zum Flughafen, d.h. mit diesem Posting endet der Europython-Bericht. Gegen 21 Uhr sollten wir in Frankfurt landen und hoffentlich zwischen 23 und 24 Uhr wieder in SB sein.

Nochmal viele Grüße aus Litauen,
Achim

Europython 2008 - Skybar

Achim | python | Wednesday, July 9th, 2008

Nach einem sehr leckeren Conferenz Dinner hat’s uns gestern Abend - nach kurzer Verdauungspause - in die …

… im 22. Stock verschlagen. Immerhin war die Fahrt mit dem Fahrstuhl vom 17. Stock aus recht schnell. Nach unten nerven die Aufzüge mittlerweile nämlich extrem. Der Eingang wird dem Namen durchaus gerecht.

Auch die Aussicht kann sich sehen lassen:

Europython 2008 - Hans Rosling

Achim | python | Tuesday, July 8th, 2008

Heute waren die Vorträg für meinen Geschmack ein gutes Stück spannender. Details dazu will sicher niemand wissen - außer zu einem. Die heutige Keynote wurde von Hans Rosling gehalten. Hans Rosling? Hat mir vorher auch nicht viel gesagt. Wer’s genau wissen will kann bei Wikipedia nachlesen.

Den Vortrag in aller Kürze widergeben kann ich natürlich nicht, aber hier gibt’s eine Aufzeichnung von einer früheren Präsentation. Im Prinzip hat Hans Rosling mit seinem Team langweilige, trockene Statsitiken visuell so aufbereitet, daß man z.B. sehen kann, daß es die angebliche Lücke zwischen armen und reichen Ländern in dem Sinne nicht mehr gibt.

Ich kann nur sagen: Es war wohl der beeindruckendste Vortrag, den ich bisher gehört habe. Wer sich auch nur ein bißchen dafür interessiert, was auf unserer Welt passiert und wie die Zusammenhänge sind, sollte sich den Vortrag anhören!

Powered by WordPress | Theme by Roy Tanck

Stoppt die Vorratsdatenspeicherung! Jetzt klicken & handeln!Willst du auch bei der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien: