package phrase; import io.FileUtil; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.Arrays; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.zip.GZIPOutputStream; public class PhraseCluster { public int K; public double scale; private int n_phrase; private int n_words; public PhraseCorpus c; private ExecutorService pool; /**@brief * emit[tag][position][word] */ private double emit[][][]; private double pi[][]; public static void main(String[] args) { String input_fname = args[0]; int tags = Integer.parseInt(args[1]); String output_fname = args[2]; int iterations = Integer.parseInt(args[3]); double scale = Double.parseDouble(args[4]); int threads = Integer.parseInt(args[5]); boolean runEM = Boolean.parseBoolean(args[6]); PhraseCorpus corpus = new PhraseCorpus(input_fname); PhraseCluster cluster = new PhraseCluster(tags, corpus, scale, threads); //PhraseObjective.ps = FileUtil.openOutFile(outputDir + "/phrase_stat.out"); double last = 0; for(int i=0;i 0) pool = Executors.newFixedThreadPool(threads); emit=new double [K][c.numContexts][n_words]; pi=new double[n_phrase][K]; for(double [][]i:emit){ for(double []j:i){ arr.F.randomise(j); } } for(double []j:pi){ arr.F.randomise(j); } } public void finish() { if (pool != null) pool.shutdown(); } public double EM(){ double [][][]exp_emit=new double [K][c.numContexts][n_words]; double [][]exp_pi=new double[n_phrase][K]; double loglikelihood=0; //E for(int phrase=0;phrase 0; loglikelihood+=Math.log(z); arr.F.l1normalize(p); int contextCnt=context[context.length-1]; //increment expected count for(int tag=0;tag expectations = new LinkedBlockingQueue(); double [][][]exp_emit=new double [K][c.numContexts][n_words]; double [][]exp_pi=new double[n_phrase][K]; double loglikelihood=0; double primal=0; //E for(int phrase=0;phrase 1e-10) ps.print(c.wordList[word]+"="+emit[i][position][word]+"\t"); } ps.println(); } ps.println(); } } double posterior_l1lmax() { double sum=0; for(int phrase=0;phrase