// inference new model ~ getting data from a specified dataset public Model inference(LDADataset newData) { System.out.println("init new model"); Model newModel = new Model(); newModel.initNewModel(option, newData, trnModel); this.newModel = newModel; System.out.println("Sampling " + niters + " iteration for inference!"); for (newModel.liter = 1; newModel.liter <= niters; newModel.liter++) { // System.out.println("Iteration " + newModel.liter + " ..."); // for all newz_i for (int m = 0; m < newModel.M; ++m) { for (int n = 0; n < newModel.data.docs[m].length; n++) { // (newz_i = newz[m][n] // sample from p(z_i|z_-1,w) int topic = infSampling(m, n); newModel.z[m].set(n, topic); } } // end foreach new doc } // end iterations System.out.println("Gibbs sampling for inference completed!"); computeNewTheta(); computeNewPhi(); newModel.liter--; return this.newModel; }
// inference new model ~ getting dataset from file specified in option public Model inference() { System.out.println("inference - new"); newModel = new Model(); if (!newModel.initNewModel(option, trnModel)) return null; System.out.println("Sampling " + niters + " iteration for inference!"); for (newModel.liter = 1; newModel.liter <= niters; newModel.liter++) { // System.out.println("Iteration " + newModel.liter + " ..."); // for all newz_i for (int m = 0; m < newModel.M; ++m) { for (int n = 0; n < newModel.data.docs[m].length; n++) { // (newz_i = newz[m][n] // sample from p(z_i|z_-1,w) int topic = infSampling(m, n); newModel.z[m].set(n, topic); } } // end foreach new doc } // end iterations System.out.println("Gibbs sampling for inference completed!"); System.out.println("Saving the inference outputs!"); computeNewTheta(); computeNewPhi(); newModel.liter--; newModel.saveModel(newModel.dfile + "." + newModel.modelName); return newModel; }