tuffy.learn
Class Learner

java.lang.Object
  extended by tuffy.main.Infer
      extended by tuffy.learn.Learner
Direct Known Subclasses:
DNLearner, NaiveDNLearner, NaiveGDLearner

public abstract class Learner
extends Infer

The abstract class of learning a weight of MLN. A runnable learner should extend this abstract class by specifying some ad-hoc functions. This class extends Infer class, because it uses inference as subroutines. NOTE: this class has static variables. Parallell running of multiple learner instances may cause problems.

Author:
Ce Zhang

Field Summary
 java.util.HashMap<java.lang.String,java.lang.Double> _oldWeight
          Map from clause name to clause weight learned in last iteration.
 int backtrackCount_
          Number of past backtracked steps.
 boolean backtracked
          Whether current step is a backtracked step.
static java.util.HashMap<java.lang.String,java.lang.Double> currentWeight
          Map from clause name to current clause weight.
static java.util.HashMap<java.lang.String,java.lang.Double> finalWeight
          Map from clause name to final weight.
static java.util.HashMap<java.lang.String,java.lang.Boolean> isHardMappings
          Map from clause name to whether it is assigned to hard weight clause while learning.
(package private)  java.util.HashMap<java.lang.String,java.lang.Long> negativeWeightSatisfication
          Map from clause name to training data satisfaction of negative weight.
(package private)  java.util.HashMap<java.lang.String,java.lang.Long> negativeWeightViolation
          Map from clause name to training data violation of negative weight.
 double odds
          FOR JUNIT TEST ONLY.
static java.util.HashMap<java.lang.String,java.lang.Double> oriWeight
          Map from clause name to the clause weight read originally from MLN program.
(package private)  java.util.HashMap<java.lang.String,java.lang.Long> positiveWeightSatisfication
          Map from clause name to training data satisfaction of positive weight.
(package private)  java.util.HashMap<java.lang.String,java.lang.Long> positiveWeightViolation
          Map from clause name to training data violation of positive weight.
 java.util.HashMap<java.lang.String,java.lang.Long> trainingSatisification
          Map from clause name to current training data satisfaction.
 java.util.HashMap<java.lang.String,java.lang.Long> trainingViolation
          Map from clause name to current training data violation.
 
Fields inherited from class tuffy.main.Infer
db, dmover, grounding, mln, options
 
Constructor Summary
Learner()
           
 
Method Summary
 void calcCurrentTrainingViolation()
          Calculate current training violations according to current sign of weight.
 void dumpAnswers(java.lang.String fout)
          Dump the learning result to file CommandOptions.fout.
 void fillInCurrentWeight(MRF _mcsat)
          Initialize weight according to the log odd of training data.
abstract  void loadingTrainingData(MRF _mcsat)
          Reading from training data and fill it into MRF.atoms.
 void run(CommandOptions opt)
          run the learner
abstract  boolean updateWeight(MRF mcsat)
          Update currentWeight to new weights according to information provided by mcsat instance, e.g., MCSAT#expectationOfViolation; This is a virtual function, each instance of Learner should materialize an adhoc version of this function.
 
Methods inherited from class tuffy.main.Infer
cleanUp, ground, loadMLN, setUp
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentWeight

public static java.util.HashMap<java.lang.String,java.lang.Double> currentWeight
Map from clause name to current clause weight.


oriWeight

public static java.util.HashMap<java.lang.String,java.lang.Double> oriWeight
Map from clause name to the clause weight read originally from MLN program.


isHardMappings

public static java.util.HashMap<java.lang.String,java.lang.Boolean> isHardMappings
Map from clause name to whether it is assigned to hard weight clause while learning.


_oldWeight

public java.util.HashMap<java.lang.String,java.lang.Double> _oldWeight
Map from clause name to clause weight learned in last iteration.


finalWeight

public static java.util.HashMap<java.lang.String,java.lang.Double> finalWeight
Map from clause name to final weight. Here by final weight, it means the the average of the weights in each iteration.


odds

public double odds
FOR JUNIT TEST ONLY.


backtracked

public boolean backtracked
Whether current step is a backtracked step.


backtrackCount_

public int backtrackCount_
Number of past backtracked steps.


trainingViolation

public java.util.HashMap<java.lang.String,java.lang.Long> trainingViolation
Map from clause name to current training data violation.


trainingSatisification

public java.util.HashMap<java.lang.String,java.lang.Long> trainingSatisification
Map from clause name to current training data satisfaction.


positiveWeightViolation

java.util.HashMap<java.lang.String,java.lang.Long> positiveWeightViolation
Map from clause name to training data violation of positive weight.


positiveWeightSatisfication

java.util.HashMap<java.lang.String,java.lang.Long> positiveWeightSatisfication
Map from clause name to training data satisfaction of positive weight.


negativeWeightViolation

java.util.HashMap<java.lang.String,java.lang.Long> negativeWeightViolation
Map from clause name to training data violation of negative weight.


negativeWeightSatisfication

java.util.HashMap<java.lang.String,java.lang.Long> negativeWeightSatisfication
Map from clause name to training data satisfaction of negative weight.

Constructor Detail

Learner

public Learner()
Method Detail

run

public void run(CommandOptions opt)
         throws java.sql.SQLException
run the learner

Parameters:
opt - Command line Options
Throws:
java.sql.SQLException

dumpAnswers

public void dumpAnswers(java.lang.String fout)
Dump the learning result to file CommandOptions.fout. The format of this file is consistent with inference part.


updateWeight

public abstract boolean updateWeight(MRF mcsat)
Update currentWeight to new weights according to information provided by mcsat instance, e.g., MCSAT#expectationOfViolation; This is a virtual function, each instance of Learner should materialize an adhoc version of this function. This function should return whether the learner thinks this iteration should terminate.

Parameters:
mcsat - MCSAT instance after this iteration.
Returns:
Whether terminate.

loadingTrainingData

public abstract void loadingTrainingData(MRF _mcsat)
Reading from training data and fill it into MRF.atoms. This function should be materialized by an instance of abstract class Learner.

Parameters:
_mcsat - The MCSAT object to be filled in.

calcCurrentTrainingViolation

public void calcCurrentTrainingViolation()
Calculate current training violations according to current sign of weight. This function will fill trainingViolation and trainingSatisification.


fillInCurrentWeight

public void fillInCurrentWeight(MRF _mcsat)
Initialize weight according to the log odd of training data.

Parameters:
_mcsat - MCSAT instance containing the vio/sat informaiton.