Friday, December 10, 2010

2010 MacBook Air fan speed issue

After copying my data from the 15inch MBP to my new MBA, I found that the fan runs at full speed irrespective of what processes are running. So I decided to reset the System Management Controller (SMC) and this actually helped.

What you must do is switch off MBA while it is still plugged in to the power adapter and press
ctrl+option+shift and the power button (top left corner) just once. The light on the power adapter will
turn into green and after couple of seconds back to orange. Now switch the machine on.

Further info is here

Saturday, November 27, 2010

Spectral graph theory

Transfer learning for collective link prediction

Compressing and Decompressing Files

To decompress tar.gz (tgz) do (tar combines multiple files in a directory to a single file and gz compresses it)
  • tar xzvf filename
To compress to tar.gz do
  • tar czvf filename.tgz directory/
To decompress bz2 files do
  • bunzip2 filename.bz2
  • if it is tar.bz2 then do tar -xjvf filename.tar.bz2
To compress into tar.bz2 do
  • tar cjvf filename.tar.bz2 directory/

Thursday, November 11, 2010

How to link external libraries in C/C++

If you want to link /usr/local/lib/liblbfgs.so and compile quadratic.cpp then you have several options.
(include libbfgs.h in quadratic.cpp first)
g++  -Wall quadratic.cpp /usr/local/lib/liblbfgs.so -o quadratic

Or if this library is on your LD_LIBRARY_PATH, then you can simply do the following
g++ -Wall quadratic -llbfgs -o quadratic

Sunday, September 19, 2010

Flusing output in Python

When you use "print" statement to output messages to terminal during the execution of a python program, those messages might not get outputted promptly. This is true for time consuming programs that perform a lot of work in between print statements. To promptly flush the text to terminal invoke the python interpreter with "-u" option. For example, if your program is myprogram.py then do the following.

python -u myprogram.py
Alternatively, if you are using sys.stdout.write to print messages to the terminal, then you can do sys.stdout.flush() right after the sys.stdout.write() to do the same. This works even with file I/O.
file.flush() immediately writes the text that is in buffer. This is particularly useful when you are writing log files.

Thursday, September 9, 2010

emacs useful commands

Here are some useful tips from this site.


  1. C-s incremental search. Once you have reached the end of the buffer it will perform an overlap search from the start.
  2. Use fn+left arrow to move to the end of the current line.
  3. Use fn+right arrow to move to the start of the current line.
  4. Use fn+up arrow to move to the start of the buffer.
  5. Use fn+down arrow to move to the end of the buffer. (These are tested on Aquamacs)
  6. M-x grep is extremely useful. It will bring the grep -n -e command to which you must append the filename and the 'string to match' and hit return. The grepped results will be shown in a separate buffer which you can click to move to the appropriate position in the source file.
  7. M-x shell opens a remote/local shell on a separate buffer.
  8. If a file is in version control then emacs shows that in the bottom buffer bar. (e.g. SVN).
  9. C-x v = shows the modifications that you have done since the last commit to the current file.
  10. C-x v v will perform the next appropriate version control action to the current file. If it is a commit then you will get a buffer to write a commit note and then hit C-c C-c to make the commit.
  11. To enter/exit from full screen mode use: command+shift and return.

Thursday, September 2, 2010

bash script to convert encoding of all files in a directory

The following bash script calls iconv on each text file in the input directory and converts them from shift-jis (sjis) to Unicode UTF-8 (utf-8).


#! /bin/bash

inputDir="danu-summaries"
outputDir="danu"

for file in ../$inputDir/*; do
    if [ -f $file ]; then
fname=`echo "$file" | cut -d '/' -f3`
echo $fname
iconv -f sjis -t utf-8 ../$inputDir/$fname > ./$outputDir/$fname
    fi
done

Monday, June 21, 2010

ANOVA and Tukey HSD in MATLAB

To perform ANOVA followed up by Tukey HSD in MATLAB do the following.


  1. Create a table where each column represents a different system and each row represents a different domain (data source upon which the evaluations are performed).
  2. Save this file in csv and import it into MATLAB using the data import wizard or dlmread function.
  3. Now call one way ANOVA as follows.
    [p,t,st] = anova1(dataMatrix)
  4. Now run Tukey HSD using st as follows,
    [c,m,h,nms] = multcompare(st)

Sunday, June 20, 2010

TexShop

In TexShop to autocomplete a bibliography reference or a label just type some part of the reference and press F5 to get a list of candidates.

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()

Snow Leopard NumPy, SciPy, matplotlib

Installing the above mentioned packages in Snow Leopard can be quite difficult.

An easy solution is to use the script mentioned here
There is a very good description here if you want to do it step by step.

Saturday, January 2, 2010

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

5. To hide all windows except for the current window do Command+Alt+H

6. In terminal, open fname will open the fname in the default application. If you want to open with TextEdit do open -a fname.
   

Continuously monitor GPU usage

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