Application on OS X

I finally manage to run the application on OS X 10.5. I should say it was not easy. First of all I needed macports, the I installed the following packages:

  • boost
  • log4cxx
  • cppunit
  • argp-standalone

The last one was a little bit tricky since argp is part of the is part of the gnu C library, which means that in linux one does not need to do anything for it, just include the header.

Since macports does not install the files in standard folders (like /usr/lib) but in its own "/opt/local/lib" and "opt/local/include" one need to add these directories to the eclipse path. To do that one needs to right click (I'm using a windows mouse) on the project icon in eclipse, select Properties -> C/C++ General -> Paths and Symbols. In the includes tab select GNU C++ and there add the folder "/opt/local/include" then in the library paths tab add the folder "/opt/local/lib" and as I mentioned before, one need to specific add libargp.a to the linker options.

For some reason I still don't understand, I also needed to change the Command line pattern in the linker options. This is the one that worked for me:

${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}
And that was pretty much all. I still need to build the link to prolog (I will use eclipse prolog) and GiNaC but I will tell about it when I'm done with that.

Shared pointers hell

I just fixed a problem in my program which was causing a lot of runtime exceptions thanks to my ignorance on how to use the boost::shared_ptr class and I think is important to prevent people of going through the same. When I created or reset a shared pointer using the contents of other pointer this is what I did:

shared_ptr source(new int);
*source = 3;
// here begin my problems
shared_ptr
destination(source.get());
destination.reset(source.get());

So, what's wrong with the code here? Well, basically that in this way, since I was using the raw pointers, the counter (which is used to free the memory) is not updated which would lead to a double call to the destructor of the objects (which was exactly my problem). The right way of doing that is:

shared_ptr source(new int);
*source = 3;
shared_ptr
destination = source.get();
destination = source;

In this way, the pointer counters are updated and no problems occur while running the program, since the operator = is properly overrided in the class.

Wyld is alive and parsing

The last few days have been a mixture of failure and success. Failure in the sense that I couldn't give as much time to my project as I would have liked to. This because I had to work this week and yesterday was my gf birthday so I came to bed really late and woke up really late; on top of it, it was so hot that I couldn't concentrate.

The success story is much more interesting. At the beginning I was thinking I had to write the parser from scratch. I already made a parser once for a very simple calculator and I know how such a pain in the ass that could be. However, at some point I saw some libraries that help you to produce parsers. Finally, in order to reduce the program libraries needs I decided to use boost::spirit. The first day I tried to use the version 2.0 of the library but it stills in beta but the documentation seems to be in pre alpha. I liked it a lot, but I faced a problem which couldn't be solved with the documentation, therefore I decided to go back to the classic stable version. It was not as nice designed as the 2.0 but it worked and it took me less than one day to have a test application running and another half day to add the parser to the trunk of the application. I was really simple to define the grammar, the operators are overload in a way that is almost like defining a mathematical grammar. I really recommend using spirit when you have to write a parser. So yes, now we have a parser of a small prolog language which I built modifying a C parser example. The nicest part of all is that it is a header only library so you don't need to add more linker requirements (although it the compilation is really slower).

I've been also relearning a lot of C++ and a lot of quirks that I don't like and that I forgot completely about. Specially in the behavior of objects attributes and the sort. Well, it is nice to see one of the modules already working and not having to worry about it again.

I also decided to do some other modifications to the architecture of the application. I added a package common which will contain the structures of the logic programs. I also decided to create a new module, which would be the most reusable, it is called garou and it is the one in charge of the neural networks. At the beginning I won't include any king of backpropagation training but I think I will do it some time in the future. Garou will be loosely based in the neural network implementation of weka. Curiously enough, this will be the next module I will work on, starting right now. So, I leave now to work on it.

The first steps

Finally I was granted a project by my adviser. It finished the last month of not knowing anything that was killing me. Now I am supposed to implement a set of algorithms that perform abduction using neural networks (therefore the logo of this site). I'm pretty sure I can succeed with at least two of the methods I have to implement, however I never understood the third paper and I am a little bit scared about it, however, I would have plenty of time before I reach that stage.

In respect to the tools I'm going to use, I decided to use C++ as the default programming language, why? because I want to become "fluent" in that language, I may like it less than Java, but definitely the jobs that use C++ tend to be much more interesting than those which use java. I will make a strong use of the Boost libraries. Specially I will replace all pointer variables to shared_ptr in order to have some garbage collection and not thinking about memory management. Not to mention that the Boost library has become the defacto standard, along with the stl, in C++ libraries. I will use cppunit in order to provide test cases since I had experience from junit and the change is really easy. My previous experience with java is also the reason why I choose log4cxx as the logging tool, but I know this is also the standard tool in C++. The development will be done in ubuntu linux (intrepid) with eclipse using the cdt plugin. Finally, version control (and backup) will be done using svn and trac for ticketing system. The last two have become my personal work environment for everything I do.

Now about the project per se. I decided to call the engine umbra. Umbra is divided in three subsystems:

Wyld
This is the engine that manages the input of the engine. Its function is to parse a file, which I haven't completely specified but which looks pretty much like a strip down, propositional only version of prolog. Anyway, I sill need to figure out how to manage the abductibles and observations sets. After parsing the file, it creates a representation of a clause that can be use for the rest of the engine. It should also have the possibility to parse files in other languages (like xml).
Weaver
The weaver is probably the mos complete and complicate subsystem of the engine. Its task is to transform the elements generated by the wyld and create the network representation of the logic program using each of the algorithms implemented. Of course scalability is a must.
Wyrm
This subsystem controls the output of the engine. Initially it outputs the files in tikz format so the networks can be painted after a run of the pdflatex command. The direct pdf option is not encourage since the images need to be easily included in LaTeX documents. Again, scalability is a must.

The coding of the project already started with Wyld being the first module to be implemented. The program representation is almost finished and Wyld should be done in no more than 3 days. The next module will be Wyrm and the last would be Weaver.