Due Friday, December 9 at 11:59 PM via Canvas. PDF format required.

In this assignment, you will complete the implementation of a multi-layer Markov Net trained using Gibbs Sampling, and perform a handful of experiments with your code.

You'll want to start by reviewing the notes on the model clarifying the discussion of the model from class.

Then download the code for the assignment. Compile the code with:
javac -classpath "trove-3.0.3.jar;junit.jar" *.java

Then you can run the code with:
java -classpath "trove-3.0.3.jar;junit.jar;." LayeredFlatSequenceModel testSampleZ

Note, these classpath statements are specified in the Windows command-line syntax, if you're using a unix variant you'll need slightly different syntax.

The code will give you an error message saying sampleZ isn't implemented; that's the piece you need to complete for the assignment. Then answer the following questions:

  1. (5 points) Complete the implementation of sampleZ, by following the instructions in the code. SampleZ should return an integer value corresponding to the sample generated from the given variable based on its Markov blanket. Refer to the pdf linked above for more details. Include your implementation of the function in your PDF.
  2. (2 point) Using the configuration files given with the download, try training a single-layer model using the configuration hard-coded in the Java file you downloaded:
    java -classpath "trove-3.0.3.jar;junit.jar;." LayeredFlatSequenceModel train penn_train.dat ptb.model ptb.config
    Then test it using:
    java -classpath "trove-3.0.3.jar;junit.jar;." LayeredFlatSequenceModel test ptb.model penn_test.dat test.config 3761 30
    Compare those results to what you get for:
    java -classpath "trove-3.0.3.jar;junit.jar;." LayeredFlatSequenceModel test test_model.dat penn_test.dat test.config 3761 30
    test_model.dat is a four-layer model with the same number of states (13) at the bottommost layer. These tests might take a few minutes. Report the final test perplexity of each model. What is frustrating about the results?
  3. (1 point) When you use multiple layers with the same number of states in each layer, the model tends to exhibit a particularly problematic behavior. Try an experiment training a model with 20 states in each layer, and two layers (see the comment "LAYER CONFIGURATION" toward the top of the code). The training may take several minutes. The code outputs the "second doc samples," you should be able to spot the general trend from that output at the end of the training.
  4. (4 points) Try something else with the code that you find interesting. You might experiment with different model architectures, try to see how the latent states correspond to word meanings (using the supplied dict.txt), or investigate why the layered models seem to be working or not working. Report on what you did, and include any new code you wrote if applicable.