Thursday, July 24, 2014

Latex 'pdfpagelabels' turned off when using Hyperref

I received the following error when using ACM's sig-alternate.cls style file and using the PDFLatex command.

Error:
Package hyperref Warning: Option `pdfpagelabels' is turned off
hyperref because \thepage is undefined.

That seems to be caused by an update of the hyperref package. The workaround is to switch this option off.
Instead of using:
\usepackage{hyperref}


Use:
\PassOptionsToPackage{pdfpagelabels=true}{hyperref}

References:
1. http://www.latex-community.org/forum/viewtopic.php?f=5&t=162

Wednesday, July 16, 2014

Gnuplot pdf terminal dashed lines

To set pdf terminal in Gnuplot, check if the output of command "print GPVAL_TERMINALS" contains "pdfcairo" listed. If yes, then you can set the terminal output as PDF using the command

set terminal pdf
set output 'out.pdf'

To enables dashed lines when using PDF terminal in gnuplot, as pointed out in reference [1], set the terminal using the command below

set terminal pdf monochrome dashed
set output 'out.pdf'

References:
1. http://theletterpsi.blogspot.com/2010/11/setting-dashed-line-style-on-pdf.html
2. http://stackoverflow.com/questions/14004797/gnuplot-pdf-output

Wednesday, July 9, 2014

English Word Frequency Lists

Many might have come across a requirement for reasonable sized English word frequency lists. Here is one good and free word frequency list based on  British National Corpus (BNC). This post is just a pointer to the real resource (Reference 1), but I will copy some text from the reference describing the details about the file structure.

-----------------------------------------------
These are all available in 6 forms:
  • sorted alphabetically ("al") or by frequency (highest frequency first) ("num");
  • the complete lists, or a smaller file containing only those items occurring over five times (suffix "o5");
  • all lists are available compressed using gzip (".gz"). The
o5 lists are also available uncompressed (no suffix). The frequencies are for <CLAWS-word, POS> pairs.
For a list and brief descriptions of CLAWS POS-tags, see here.

The format is: four fields, separated by spaces.
 1: frequency
 2: word
 3: pos
 4: number of files the word occurs in
For non-orthographic words, spaces are replaced by underscore, giving eg "in_spite_of".
Lists are provided for the complete BNC (all), and for three subsets, as below:
 cg 'context-governed' spoken material    
  (eg meetings, lectures etc)  6.2M tokens,  79,906 types
 demog   'demographic' spoken material        
  (eg conversation)      4.2M tokens,  54,652 types
        written                             89.7M tokens, 921,074 types
 all                             100.1M tokens, 939,028 types
File sizes in MB ("al" and "num" variants all the same size) are:
  all uncompressed .gz o5 o5.gz
-------------------------------------------------------------
all  18.1   4.8 4.0 1.32
cg   1.4   0.39 0.43 0.15
demog   0.9   0.26 0.25 0.09 
written  17.8   4.7 3.9 1.30
-------------------------------------------------------------
For all.al.gz click here
For all.al.o5 click here
For all.al.o5.gz click here
For all.num.gz click here
For all.num.o5 click here
For all.num.o5.gz click here
For written.al.gz click here
For written.al.o5 click here
For written.al.o5.gz click here
For written.num.gz click here
For written.num.o5 click here
For written.num.o5.gz click here
For cg.al.gz click here
For cg.al.o5 click here
For cg.al.o5.gz click here
For cg.num.gz click here
For cg.num.o5 click here
For cg.num.o5.gz click here
For demog.al.gz click here
For demog.al.o5 click here
For demog.al.o5.gz click here
For demog.num.gz click here
For demog.num.o5 click here
For demog.num.o5.gz click here

References:
1. http://www.kilgarriff.co.uk/bnc-readme.html

Sunday, June 29, 2014

Python Multiprocess programming - A Pool of Workers


Python's Global Interpreter Lock prevents multithreading to actually be parallelizable, and sometimes making it much slower than single thread version. To obtain true parallelism, we need to use multiple processes.

Here is the code to start a certain number of processes, and pass tasks to them through a queue. The done_queue.get() blocking function ensures that the parent process remains active until the child threads finish everything. Once we obtain all the results, we stop the child processes using the "STOP" input (as even the child processes also block on input.get()).


import time
import random

from multiprocessing import Process, Queue, current_process, freeze_support

#
# Function run by worker processes
#

def worker(input, output):
    for func, args in iter(input.get, 'STOP'):
        result = calculate(func, args)
        output.put(result)

#
# Function used to calculate result
#

def calculate(func, args):
    result = func(*args)
    return '%s says that %s%s = %s' % \
        (current_process().name, func.__name__, args, result)

#
# Functions referenced by tasks
#

def mul(a, b):
    time.sleep(2*random.random())
    return a * b

def plus(a, b):
    time.sleep(2*random.random())
    return a + b

#
#
#

def test():
    NUMBER_OF_PROCESSES = 8
    TASKS1 = [(mul, (i, 7)) for i in range(20)]
    TASKS2 = [(plus, (i, 8)) for i in range(10)]

    # Create queues
    task_queue = Queue()
    done_queue = Queue()

    # Submit tasks
    for task in TASKS1:
        task_queue.put(task)

    # Start worker processes
    for i in range(NUMBER_OF_PROCESSES):
        Process(target=worker, args=(task_queue, done_queue)).start()

    # Get and print results
    print 'Unordered results:'
    for i in range(len(TASKS1)):
        print '\t', done_queue.get()

    # Add more tasks using `put()`
    for task in TASKS2:
        task_queue.put(task)

    # Get and print some more results
    for i in range(len(TASKS2)):
        print '\t', done_queue.get()

    # Tell child processes to stop
    for i in range(NUMBER_OF_PROCESSES):
        task_queue.put('STOP')


if __name__ == '__main__':
    freeze_support()
    test()

References: 
1. https://docs.python.org/dev/library/multiprocessing.html

Monday, April 28, 2014

Microsoft Excel Bar/Column Chart Patterns

It is possible to create GNUPlot style bar charts with patterns (shown below)  in Excel.


As discussed in Reference 2, for Excel 2007 you need to download the excel macro file "Pattern Fill Add-In". The usage instructions are provided in Reference 1.

References:
1. http://www.andypope.info/charts/patternfills.htm
2. http://answers.microsoft.com/en-us/office/forum/office_2007-excel/excel-2007-bar-chart-shading/99bab79a-e600-4bbe-a08e-448363d3173d

Microsoft Excel Clustered-Stacked Column/Bar Chart

We can create clustered-stacked column/bar charts -- like those shown below (taken from Reference 1) -- in Excel. It is doable, but the process involves many steps. Follow the instructions in Reference 1.


At one point, the instructions say - "Copy the range, and use paste special to add this data to the chart as a new series", for this if using Excel 2007 you need to click the 'Home' tab on the ribbon, click the 'Paste' drop-down arrow and choose 'Paste Special'.

References:
1. http://peltiertech.com/WordPress/clustered-stacked-column-bar-charts/
2. http://www.mrexcel.com/forum/excel-questions/559998-charts-add-new-data-copy-paste-special.html

Tuesday, April 8, 2014

Changing Windows Internet time synchronization frequency

You might come across situations when you need multiple Windows machines to have their times synchronized. You could setup time synchronization protocols between the machines, making one as the master and the others as slaves.

An easier alternative is to sync all the machine times to Internet times - the NIST time or Windows server time available by default in the Date & Time settings. Once you sync the machines with the Internet time, the machines might start drifting away over a period. Hence Windows periodically syncs the times with the Internet time; however, the default sync duration ranges from few days to weeks.

You can make the time sync happen much more frequently - like few hours. To do this, you need to make system registry changes. The following instructions are for Windows XP machine; for other versions, the process might be similar.

1. Go to Start-> Run and type "regedit" to open the registry settings.

2. Navigate to the following in the Registry:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient

3. The parameter you need to change is SpecialPollInterval
Right click on 'SpecialPollInterval' in the right hand column and select Modify>Decimal. The decimal number is in seconds. For example, you can set it to 86400 to mean 24 hours.

NOTE: Please backup the Registry beforehand to avoid any issues later (I do not know how this can be done).

Reference:
1. http://www.tomshardware.com/forum/55562-45-changing-frequency-internet-time-synchronisation