Posts Tagged ‘Code’

ArgumentList 0.2

Sunday, May 16th, 2010

In version 0.1 of my ArgumentList there was an annoying problem, that is if we want to extract a parameter from command line that wasn’t a string, we had to write a converter by ourselves.
To solve this issue I modified  the getSwitchArgument() method in order to accept a type as a template parameter. I hope this modification can simplify the use of the class.

So now, if we suppose to have something like that in our command line:

some-executable -i 10 -f 0.004

what we have to write in our code, in order to get the numerical values “10″ and “0.004″ is the following:

int i(0);
float f(0.0);
i = args.getSwitchArgument< int >("-i");
f = args.getSwitchArgument< float >("-f");

So right now, to have a string argument like before, it is necessary to pass the string parameter to the template, like in the following example:

string tempString;
tempString = args.getSwitchArgument< std::string >("-s");

An example is presented in the test directory included with the package. CMake is needed to build the package.

ArgumentList 0.2 can be downloaded here.



TV-Shows Name Changer 0.1

Saturday, December 26th, 2009

I have a lot of passions, between them computer science and tv-shows.
I wanted to learn a bit of Python before the holidays so I’ve developed a simple (really simple)  script in Python to change the filenames of my favorite tv-shows on the format that I prefer to archive them, something like “[LANG] TV-SHOW NAME – SEASONxEPISODE.ext“.

I’m not sure the script can be useful for someone else, but I like to share my code. The script can be downloaded here.

Information theory analyzer

Monday, August 24th, 2009

Hello :)

I’ve taken an exam those summer called “Information theory” and as a project I’ve developed, with the help of Alfredo Aiello, a program for evaluating entropy (simple, joint and conditional) and mutual information of random variables (and subset of them) from a sample set.

Like every other time I want to share the code (that is licensed with GNU General Public License 3.0) with the whole world, so this is a zip file containing all the code.
There isn’t a makefile right now but you can easily find a way to compile it, the only external dependencies is my ArgumentList library.

After compiling it you can use it on command line just tiping:

./ITA <[-e] | [-j] | [-c] | [-m]> -n <null_char> <set_file> <input_file> <output_file>

Obviously you have to call your binary :)

The first parameter is for the operation wanted (-e for entropy, -j for joint entropy, -c for conditional entropy and -m for mutual information), the second is for setting the null char of the sample set and last three ones are filename.
The first of them (set_file) permits you to control which variable of the sample set is in which subset, I know I can be a little too enigmatic but I’ll provide an example later; the second (input_file)  is the file which contains the sample set and the third (output_file) is where do you want the output will be written.

The sample set format is really sample, is a text file where the columns are the variable and the rows are the samples, something like that:

1 0 n 1
n 2 n n
a 0 2 2
2 c 1 2

This is the description of a sample set with 4 samples and 4 variables.
The format for the set_file is really simple too, again a text file where the first number is the length of first subset and all the others are the indexes (starting from 0) of the columns in the subset.

Let’s for example evaluate the conditional entropy between those two subset of the previously given sample set:

X = {0, 2, 3}
Y = {1}

Then we’ll have to write a file (let’s call it example.set) like this one:

3 0 2 3 1

And, if our sample set is called example.txt, call the program in that way:

./ITA -c -n n example.set example.txt out.txt

Enjoy!

TSP approximation algorithms

Wednesday, July 1st, 2009

Finally I’ve found some time to publish the code I wrote for my BSc thesys, wow! :)

The problem is not in releasing source code but mainly in my lazyness, because I’ve just found the time to write a bash script to download some other code which my code depends on (my ArgumentList library and BlossomV-1.0 from Vladimir Kolmogorov) and create the right objects.

If you want, you can download the script already as a file from there, the only thing you must change is the BASEDIR variable; after the execution of the script you have just to change the INCLUDE constant on the Makefile and use make to compile to source. It is necessary to have wget and git already installed.

The proper source code of my thesys is available, as you can see, from GitHUB; sorry but all the comments and strings are in Italian.

ArgumentList 0.1

Friday, January 30th, 2009

Some times ago I was reading the book “An Introduction to Design Patterns in C++ with Qt 4” and I found really useful for lazy peoples like me the utility for easily access command line argument list parameters in C++ with the use of QT framework.

So I decided to write from scratch a similar code, but in pure C++.

Using it is quite simple, as you can read in the test available in the package and here:

#include "ArgumentList.h"
#include

using namespace sclocco;
using std::cout;
using std::cin;
using std::endl;
using std::string;

int main(int argc, char *argv[]) {
ArgumentList args = ArgumentList(argc, argv);
string input = "";
char again = 'Y';

cout << "Testing utility for ArgumentList class." << endl;

while ( again == 'Y' ) {
cout << "Do you want to search for a switch, for the argument of a switch or the first remaining argument (1/2/3): ";
cin >> input;

if ( input.compare("1") == 0 ) {
cout << "Insert the switch: ";
cin >> input;

if ( args.getSwitch(input) ) {
cout << "Switch \"" << input << "\" found." << endl;
}
else {
cout << "Switch\ "" << input << "\" not found." << endl;
}
}
else if ( input.compare("2") == 0 ) {
string temp = "";

cout << "Insert the switch: ";
cin >> input;
temp = args.getSwitchArgument(input);
cout << "The argument of switch \"" << input << "\" is: " << temp << endl;
}
else if ( input.compare("3") == 0 ) {
cout << "The first remaining argument is: " << args.getFirst() << endl;
}

cout << "Continue testing (Y/N): ";
cin >> again;
}

return 0;

}

If you want to try it download the package here.