Tuesday, May 6, 2008

[C++] Markov Chains Implementation

This is a 4th Order (I plan to make it N order when exams are over) implementation of markov chains. (think JMegaHAL) I wrote it as a semester project (last night, no sleep) for algorithms class. It can be used for a lot of cool things, I'd like to make an IRC bot out of it one day when I get time (haha). It is implemented as a class anyone can use in their own C++ programs, but a minimal driver is provided.

README:
Author: Travis Burtrum (moparisthebest)

I use no 3rd party libraries or system calls in this, only standard c++.
So if you have a c++ compiler (I use g++) then this should compile fine for you.

generic compiling:
./configure
make

compile using g++:
g++ markovchains.cpp -o markovchains

run as you would any app from the command line:
./markovchains

compile using mingw (for windows):
i586-mingw32msvc-g++ markovchains.cpp -o markovchains.exe

sample run (refer to test.txt for input):
./markovchains
commands:
'exit' exits the program
'load filename' loads all sentances in filename into the system (test.txt is provided)
any other input is loaded into the system, and a sentance is output based on the first word typed if possible
# load test.txt
name it charles barkely.
# my teachers name is john.
hello my name is bob.
# name
what is your name?
# name
my friends name is sam.
# name
my friends name is bob.
# name
hello my name is john.
# exit
Yes, it is licensed under the GPL.

Things that need done:
  • Implement saving/loading mechanism
  • Clean up code, try not to copy objects as much
  • Make it N order

If anyone could give me some feedback on my code it would be much appreciated, I am most interested in a better way to store the Quads in memory, the way I do it know requires a lot of extra memory because the Quads I use as keys are copied because I can't store them by pointer like I want since I need to look them up by value and not by memory location. I'm sure there is a better way to handle this somewhere, thanks much.

http://www.moparisthebest.com/downloads/markovchains.tar.gz

No comments: