2009-03-25

Updating your Mathematica 7 to 7.0.1 for Fourier Transform

by Forrest Sheng Bao http://fsbao.net

There is a big bug on Fourier Transform in v. 7.
In[1]:= Fourier[{0.007 + 0.01 I, -0.002 - 0.0024 I}]

Out[1]= {0.00353553, 0.00636396}
If you upgrade to 7.0.1, it becomes:
In[1]:= Fourier[{0.007 + 0.01 I, -0.002 - 0.0024 I}]

Out[1]= {0.00353553 + 0.00537401 I, 0.00636396 + 0.00876812 I}

2009-03-22

Random thoughts from the Mathematica password file

by Forrest Sheng Bao http://fsbao.net

Well, it is located here: YOUR_MATHEMATICA_LOCATION/Configuration/Licensing/mathpass

At least on Linux, it is so. I am not sure about Mac and Windows case.

Actually, I think Wolfram Research uses a very weak way to protect their copyright. The password file looks like this: There is not encryption, but total transparent. Thus, anyone just need to copy this file to another machine, then Mathematica will work on that machine.

I think Mathematica did great scientific visualization job. So, if you want to make your biological paper more fancy, maybe you should try my combination: Python (SciPy) for bioinformatics computing + Mathematica to attract girls eyeballs - Just try ProteinData["A2M", "MoleculePlot"] and then rotate the 3-D structure of protein and then ask the girl next to you "Wanna have dinner with me some time?"



A weak point of open source software is visualization while a killer point is their great performance. If you combine open source solutions along with commercial solutions, you can publish great papers while having a pretty girlfriend - This is not a scientific conclusion. LOL.

2009-03-21

Recycling your IT stuffs via HP recycling program

by Forrest Sheng Bao http://fsbao.net

I am a human, one member of a kind of creature that won't act until the problem is on the nose.

Everyone nowadays generates lotta electronics waste. Our computers or electronic stuffs can emit poisonous chemicals to our environment if you simply bury them. You won't want you next generation to have only one eye or no brain. One way to solve this problem is to recycle them and let professional guys treat them properly. For example, effecting Sept. 1, 2008, Texas Recycling Bill (HB 2714) requires all computer manufactures to provide FREE and CONVENIENT recycling for consumers.

For consumers in Canada and the United States, there is a easy and free way to do so, the HP Consumer Buyback and Planet Partner Recycling Program. You can either just give old IT stuffs away to HP for free or trade some cash reward for you next purchase of HP products. The shipping is free if you drop them at UPS drop-off location. You can also pay $10 flat rate to let FedEx pick them up from your location.

The HP Consumer Buyback and Planet Partners Recycling Program accepts products of ANY brand manufacturer in the following product categories:
  • Desktop PCs
  • Workstations
  • Notebook PCs
  • Tablet PCs
  • Monitors, both CRT and LCD
  • Printers, both ink and laser
  • Scanners
  • Digital cameras
  • PDAs
  • Smartphones
So, next time when you have unused IT stuffs, do NOT simply dump them away but please recycle them. For more details, please visit http://hphho.tradeups.com

The author of this article is not affiliated to or paid by Hewlett-Packard Development Company.

2009-03-18

enumerate() array elements rather than indexing them in Python

by Forrest Sheng Bao http://fsbao.net

Recently, I am debugging two Python programs about graphs. I get very confused in many times, whether I am visiting an array element or the index of the array element. For example, I need to get the vertex number by indexing an array, and use that vertex number to index another array.

So, my friend Lay Yuan in Arizona State University told me a trick, using enumerate() in Python. This makes things much much more easier. I guess you are smart enough so this example can explain every thing to you
>>> for i,arr in enumerate([6,3,2,3,4]):
... print i, arr
...
0 6
1 3
2 2
3 3
4 4

Below is an implementation of the Prim's algorithm. In this program, one step is to update the distance of current spanning tree to all neighbors of the newly added vertex. The neighbors of all vertexes are stored in an array neighbors. Without enumerate, I need these two lines to pick neighbors one by one:

for i in xrange(0,len(neighbors)):
w= neighbors[v][i];

With enumerate(), I just need one line to get the w:
for i, w in enumerate(neighbors[v]):

I don't need to struggle on the indexing problem any more.

# Python implementation of Prim's algorithm
# by Forrest Sheng Bao, Dept. of Computer Science, Texas Tech
# http://fsbao.net forrest dot bao at gmail dot com
# This code implements the example on P. 571 of the famous
# "Introduction to Algorithms," 2nd ed., by Cormen, Leiserson, Rivest and Stein
# The connection matrix of the graph is represented as matrix A in the problem
# So it doesn't matter if you don't have the book. The vertexes are indexed from 0.

# The program is a free software. You may use, distribute and copy it under the
# terms of GNU General Public License version 3.
# http://www.gnu.org/copyleft/gpl.html

# Expected output:
# $ python maxspanning.py
# vertex 0 has just been added into the growing spanning tree
# vertex 1 has just been added into the growing spanning tree
# vertex 2 has just been added into the growing spanning tree
# vertex 8 has just been added into the growing spanning tree
# vertex 5 has just been added into the growing spanning tree
# vertex 6 has just been added into the growing spanning tree
# vertex 7 has just been added into the growing spanning tree
# vertex 3 has just been added into the growing spanning tree
# vertex 4 has just been added into the growing spanning tree

from numpy import *

def spanningTree(n,A):
# neighbors[n]: // neighbors[i] is the list of neighbors of i in graph A
neighbors=[];# neighbors[n], neighbors[i] is the list of neighbors of i in graph A
for i in xrange(0,n):
for j in xrange(0,n):
neighbors.append([]);
if( A[i,j] != 0):
neighbors[i].append(j)

treeNeighbor=[];
# initially treeNeighbor[i] = -1;
# during spanningTree(),
# treeNeighbor[i] == p if selected[p] is true and A[i,p]
# is the shortest distance from i to the current tree.
# treeNeighbor[i] == -1 if p is not a neighbor of any node of
# the current spanning tree.
# exception: 0 is always seleted first and treeNeighbor[0] is -1

selected=[];#selected[i]=1: i is in spanning tree; 0: otherwise , initialized to be 0
distance=[];#distance[i]: the shortest distance from i to tree, initialized to be +1

for i in xrange(0,n):
treeNeighbor.append(-1);
selected.append(0);
distance.append(100); # \infty for positive case, 1 for negative case

first = 1; # a marker to mark, first =1 if the abitrary starting point is to be selected.
for i in xrange(0,n):
v = findMin(n,first,selected,treeNeighbor,distance);
print "vertex", v, "has just been added into the growing spanning tree"

first = 0;
selected[v] = 1;

# add neighbors of v to treeNeighbor[] and update their distance to current spanning tree
for i, w in enumerate(neighbors[v]):#each w \in neighbors[v]
#w= neighbors[v][i];
if selected[w]==0 : #only update vertexes that are NOT on the tree now
if A[v,w] < distance[w]:
distance[w] = A[v,w];
treeNeighbor[w] = v; #treeNeighbor, neighbors to current spanning tree
#A[w,v]is the shortest path from w to current tree.
return treeNeighbor;

def findMin(n,first,selected,treeNeighbor,distance):
if (first == 1):
v = 0;
treeNeighbor[0] = -1;
return v ;
else:
min_distance=100; #\infty for postive case, 0 for negative case
for v in xrange(0,n):
if (selected[v]==0) and (treeNeighbor[v] != -1) and (distance[v] < min_distance):
# the new node must be not on the current tree and be reachable to the tree in one hop and the shortest one to the current tree
min_v = v;
min_distance = distance[v]
return min_v;

A=[\
[0, 4, 0, 0, 0, 0, 0, 8, 0],\
[4, 0, 8, 0, 0, 0, 0, 11, 0],\
[0, 8, 0, 7, 0, 4, 0, 0, 2],\
[0, 0, 7, 0, 9, 14, 0, 0, 0], \
[0, 0, 0, 9, 0, 10, 0, 0, 0],\
[0, 0, 4, 14, 10, 0, 2, 0, 0],\
[0, 0, 0, 0, 0, 2, 0, 1, 6],\
[8, 11, 0, 0, 0, 0, 1, 0, 7],\
[0, 0, 2, 0, 0, 0, 6, 7, 0]\
]

A=array(A)
R= spanningTree(9, A)

2009-03-17

Geeks, call me on Ekiga!

by Forrest Sheng Bao http://fsbao.net

I am really tired of the stupid Skype, though Skype has many users around the world - people are stupid. The problem of Skype to me is
  1. No native 64-bit support for Linux and I need hacking to make 32-bit Skype like my webcam in 64-bit Linux - We have been waiting for this for at least 2 years.
  2. Closed source code and protocol
  3. Unknown mechanism on managing our privacy - because of problem #2
  4. Not friendly with some hardware on Linux - I am tried of struggling on this
According to my experience, open source solution can work better than proprietary solution if the developers themselves need this solution very much. So it is. Geeks need to talk and video each other. Then here comes the Ekiga! http://ekiga.org

What is Ekiga? It is a software/solution thru which you can video chat your friends on another PC, if both of you are using Ekiga. And it is free, free as Skype and free as in freedom - totally open source solution.

I tried it tonight. Great! I don't have to struggle on hardware problem - everything works perfectly with my 64-bit Ubuntu Linux.

So, geeks, if you want to call me next time, do NOT use Skype but Ekiga. My Ekiga username is my first name and last name @ekiga.net

In most Linux distributions, you can find it under the "Internet" application menu. Now set it up and try a test voice: "1,2,3, Ekiga rocks!"

PS: Currently, I am not sure whether Ekiga can work with traditional phone network as well as Skype. For example, if I purchased a number, can Ekiga forward the call to another phone? I use this function in Skype. If this problem can be solved, everything is done. Anyway, I know Grandcentral/Google Voice can make it. So, let's see.

2009-03-16

Python editing and debugging on Linux

by Forrest Sheng Bao http://fsbao.net

Python is my favorite programming language. There are many Python editors, debuggers and IDEs. Some good editors/IDE are geditor(comes with Gnome desktop by default), SPE (Stani's Python Editor) and Eric. There is a debugger with GUI called Winpdb. The default debugger is IDLE, developed by Python Software Foundation.

If I don't need to debug my program, I will only use geditor or even vim simply. If I need to debug, I will use Eric. In Eric, I have all the buttons I need on the toolbar and I can debug it without calling other programs. A trick of Eric is that I can use regular expression to hide some variables I don't want to see, as you can see in this snapshot.

The reason I mention Winpdb is because sometimes I am so lazy to hide variables I don't want to see. I just want to view certain varibales I am interested in. Winpdb provides me a way in its command console. I just need to type in "v variable_name" then I can see the value of a perticular variable.

2009-03-10

Ironman visual effects made on Linux

by Forrest Sheng Bao http://fsbao.net

You know the movie Ironman, right? You think it's cool, right? But do you know which OS supports those cool stuffs? The answer is our Linux!

I checked out a DVD from my university library and watched a short video about how those visual effects were made. Then I found the desktop environment they used are just Gnome, a famous desktop environment on Linux.

Here are 3 snapshots.





2009-03-04

PLoS One accepting LaTeX files

by Forrest Sheng Bao http://fsbao.net

The PLoS One editorial office gives a quick response on accepting LaTeX files. Great news for people like me. Thanks, PLoS One editorial office. Now PLoS One is accepting LaTeX files in fields math, physics, engineering, computation biology and chemistry. http://www.plos.org/cms/node/451

But I still have some concerns about the LaTeX template they provide. As everyone knows, the editorial office should give us a LaTeX class file (*.cls) or a style file (*.sty). But I did not see them. We have to play tricks in the TeX file. For example, for the title, you can NOT state as \title{My Paper}. Instead, you have to use several commands:

\begin{flushleft} {\Large \textbf{Title} } \end{flushleft} 

The idea of LaTeX is to delivery authors from typesetting, thru separating the contents and appearance. But now we are doing the same thing, as in Microsoft Word. Here verbose LaTeX commands replaces mouse-click in Microsoft Word. What is a title of a paper in LaTeX? The authors do not have to think about it. They don't have to know the alignment, the font size and the boldness. They just need to simply tell that this is the title by \title{My title}.

The reason I use LaTeX, not only because my papers have "heavy math," but also because I want to separate my contents from the appearance, thus the layout and typesetting. So, I am thinking could someone write a class file or style file for PLoS One, like Elsevier or IEEE. I can volunteer that. It seems not very complex from standard LaTeX article style.

Anyway, it's not the biggest deal. It's way better than asking me convert to Word or RTF. I just need to edit a few LaTeX commands to reach their requirements.

================ Below is my original complaint =================

I got a paper accepted by PLoS One. But I am very uncomfortable about the accepted file format. I am very sad to know that PLoS requires authors to convert LaTeX into RTF. http://www.plosone.org/static/latex.action In many fields, such as math, physics, computer science and electrical engineering, LaTeX is the dominant tool to write papers, because we have way too many equations, plots, diagrams and tables, cross-references and references in a single paper. It is a great waste of time to manage the layout and typesetting manually in Word or RTF.

AMS (American Math Society), AIP (American Institutes of Physics), IEEE (Institute of Electrical and Electronic Engineerings) and ACM (Association for Computing Machinery
), are leading societies in math, physics, electrical engineering and computer science. They journals and conferences all accept LaTeX files and thus give authors full freedom on writing papers. It is a nightmare to write a paper in Word or RTF. You have to do everything manually. Why not leave those stupid things to computers and focus more on intellectual things?

Science, Nature and PNAS also have their own LaTeX templates and accept LaTeX files.

Mainstream publishers, such as Springer or Elsevier, even designed beautiful LaTeX templates.

Not accepting LaTeX files makes PLoS very unfriendly to scientific community. In order to simplify paper writing and save time, authors may turn to other journals.

If you accept LaTeX files, authors can even provide PDF files directly. This could save time of editors too.

Plus, academia should prefer free and open source software, just as we prefer CC license and open access idea. LaTeX is totally free ("free" as in "free speech" and "free" as in "free beer"). It is so ugly to write papers in Microsoft Word.

"I hope to die before I have to use Microsoft Word" - Dr. Donald E. Knuth, Professor Emeritus, Dept. of Computer Science, Stanford University