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
This blog covers various topics from technical tweaks to latest in computational linguistics, Artificial Intelligence, Machine Learning and Wed Data Mining.
Thursday, November 11, 2010
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.
file.flush() immediately writes the text that is in buffer. This is particularly useful when you are writing log files.
python -u myprogram.pyAlternatively, 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.
- C-s incremental search. Once you have reached the end of the buffer it will perform an overlap search from the start.
- Use fn+left arrow to move to the end of the current line.
- Use fn+right arrow to move to the start of the current line.
- Use fn+up arrow to move to the start of the buffer.
- Use fn+down arrow to move to the end of the buffer. (These are tested on Aquamacs)
- 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.
- M-x shell opens a remote/local shell on a separate buffer.
- If a file is in version control then emacs shows that in the bottom buffer bar. (e.g. SVN).
- C-x v = shows the modifications that you have done since the last commit to the current file.
- 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.
- 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
#! /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.
- 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).
- Save this file in csv and import it into MATLAB using the data import wizard or dlmread function.
- Now call one way ANOVA as follows.
[p,t,st] = anova1(dataMatrix) - 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.
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
Subscribe to:
Posts (Atom)
Continuously monitor GPU usage
For nvidia GPUs do the follwing: nvidia-smi -l 1
-
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 p...
-
If you want to assign incremental ids to a list of words then you can define a defultdict as follows: wpids = defaultdict(lambda: len(wpi...
-
There is an excellent software to train/predict a range of ML algorithms including logistic regression with L1 or L2 regularization, pagasos...