Thursday, June 3, 2010

Multiprocessing

In Python GIL (Global Interpreter Lock) prevents from running more than one thread at a time in a process. If you use Jython or IronPython this limitation is not there. But with CPython it is there. Use the multiprocess module (from Python version 2.6 afterwards) to overcome this limitation and have truly multiprocessing capabilities. If you encounter an error during execution and if your processes become zombies then you could either close the terminal (which will kill the zombies as well), or more elegantly use kill -9 on the "parent process id (PPID" of those zombies. To find the process ids use "ps -epw" command. You can also kill a process within the top window by typing "k" and then entering the corresponding process id.

multiprocessing module has similar API as in threading module. It works on Windows, Linux and OS/X.
The following code shows how to create and start several processes.

from multiprocessing import Process
import os

def info(title):
    print title
    print 'module name:', __name__
    print 'parent process:', os.getppid()
    print 'process id:', os.getpid()

def f(name):
    info('function f')
    print 'hello', name
    c = 0
    for i in range(1,100000):
        for j in range(1, 100000):
            if i == j:
                c += 1
    pass
    

    
if __name__ == "__main__":
    info('main line')
    p = Process(target=f, args=('bob',))
    q = Process(target=f, args=('sam',))
    r = Process(target=f, args=('dan',))
    s = Process(target=f, args=('david',))
    q.start()
    p.start()
    r.start()
    s.start()
    p.join()
    q.join()
    r.join()
    s.join()
    pass



Wednesday, May 26, 2010

Mapping keys in Mac

If you want to set things like HOME, END, Japanese RO key to backslash, etc. on MacBook Pro (with the built-in key board or an external Windows keyboard) then use the following software.

KeyReMap4MacBook.

For example, to remap the Underscore(Ro) key to backslash
For Japanese --> Change Underscore(Ro) Key --> Underscore(Ro) to Backslash(\)

Sunday, May 16, 2010

Invalid annotation object error in PDFs

If you used Adobe acrobat to annotate a PDF file and you had Acrobat crashed or had to restart the computer abruptly during the annotation process then you might experience this problem when you reopen the PDF file from Acrobat. Of course if you use Skim or Preview to open the file then you will not get this popup window and everything will display without a problem. To solve this problem first open the PDF under consideration in Preview and then do a save as for the file. You can give the same file name and replace the file. Now everything will work fine.

Tuesday, May 11, 2010

Gnuplot

The following set of commands will plot two data series in a file using point markers and also write the output to a eps file and further convert it to pdf. You can write these commands into a text file and run gnuplot ($ gnuplot fname) on that file.
set datafile separator ","

set xlabel "value"
set ylabel "probability"


plot "dist.csv" using 1:2
#plot "1000_100_uniform.csv" using 1:1 title "Lin",  "1000_100_uniform.csv" using 1:2 title "Cosine" with points


set terminal postscript eps enhanced color solid rounded
set output "plot.eps"
!epstopdf plot.eps
replot
show output
pause -1


Monday, May 10, 2010

Mac Tricks

Mac Tricks: "This post summarizes some useful tips on mac.

1. quick silver.
    start an application.
   option+space.

2. Command+S can save files in almost any application.

3. Command+Option+ESC will bring the force kill box.

4. When Apple Mail hangs with GMail Recovered Mail
     This can happen when you send large messages and something goes wrong.
     The solution is described here
     Delete the hidden directory,    

    ~/Library/Mail/IMAP-@domain.tld@imap.domain.tld/.OfflineCache
    and then delete the Recovered Messages mail folder in Mail.app

    
"

(Via Danushkas Research Blog.)

Thursday, February 25, 2010

Interesting WWW 2010 papers

  • EXPLORING WEB SCALE LANGUAGE MODELS FOR SEARCH QUERY PROCESSING
    Jian Huang, Jiangbo Miao, Xiaolong Li, Jianfeng Gao and Kuansan Wang
  • CROSS-DOMAIN SENTIMENT CLASSIFICATION VIA SPECTRAL FEATURE ALIGNMENT
    Sinno Pan, Xiaochuan Ni, Jian-Tao Sun, Qiang Yang and Zheng Chen
  • BUILDING TAXONOMY OF WEB SEARCH INTENTS FOR NAME ENTITY QUERIES
    Xiaoxin Yin and Sarthak Shah
  • MULTI-MODALITY IN ONE-CLASS CLASSIFICATION
    Boris Chidlovskii and Matthijs Hovelynck
  • A SCALABLE MACHINE LEARNING APPROACH FOR SEMI-STRUCTURED NAMED ENTITY RECOGNITION
    Utku Irmak and Reiner Kraft
  • FACETED EXPLORATION OF IMAGE SEARCH RESULTS
    Roelof van Zwol and Börkur Sigurbjörnsson
  • TOWARDS NATURAL QUESTION GUIDED SEARCH
    Alexander Kotov and ChengXiang Zhai
  • A LARGE SCALE ACTIVE LEARNING SYSTEM FOR TOPICAL CATEGORIZATION ON THE WEB
    Suju Rajan, Dragomir Yankov, Scott Gaffney and Adwait Ratnaparkhi
  • DIVERSIFYING WEB SEARCH RESULTS
    Davood Rafiei, Krishna Bharat and Anand Shukla
  • A GENERAL FRAMEWORK FOR EXPLORING CATEGORY INFORMATION FOR QUESTION RETRIEVAL IN COMMUNITY QUESTION ANSWER ARCHIVES
    Xin Cao, Gao Cong, Bin Cui and Christian Jensen
  • RANKING SPECIALIZATION FOR WEB SEARCH: A DIVIDE-AND-CONQUER APPROACH BY USING TOPICAL RANKSVM
    Jiang Bian, Xin Li, Fan Li, Zhaohui Zheng and Hongyuan Zha
  • GENERALIZED DISTANCES BETWEEN RANKINGS
    Ravi Kumar and Sergei Vassilvitskii
  • THE ANATOMY OF A LARGE-SCALE SOCIAL SEARCH ENGINE
    Damon Horowitz and Sepandar Kamvar
  • USE TWITTER DATA FOR RECENCY RANKING IMPROVEMENT IN WEB SEARCH
    Anlei Dong, Ruiqiang Zhang, Pranam Kolari, Bai Jing, Yi Chang, Fernando Diaz, Zhaohui Zheng and Hongyuan Zha
  • A CHARACTERIZATION OF ONLINE SEARCH BEHAVIOR
    Ravi Kumar and Andrew Tomkins
  • WHAT IS TWITTER, A SOCIAL NETWORK OR A NEWS MEDIA?
    Haewoon Kwak, Changhyun Lee, Hosung Park and Sue Moon

Wednesday, February 24, 2010

sqlite in Python

Sqlite is a very useful server-less database system that can be accessed from Python as well.

By the way you can combine multiple insert statements in a single transaction to improve performace
as described here.

import sqlite3

def createDB():
    db = sqlite3.connect('people.db')
    db.execute('create table boys(name, age)')
    db.commit()
    db.close()
    pass

def writeDB():
    db = sqlite3.connect('people.db')
    db.execute('insert into boys(name, age) values ("danushka",30)')
    db.commit()
    db.close()
    pass

def readDB():
    db = sqlite3.connect('people.db')
    L = db.execute('select name, age from boys').fetchall()
    print L
    db.close()
    pass

if __name__ == "__main__":
    #createDB()
    #writeDB()
    readDB()

Continuously monitor GPU usage

 For nvidia GPUs do the follwing: nvidia-smi -l 1