From 5558d8fc9b67eb4dd98414587082ff3df27daaf9 Mon Sep 17 00:00:00 2001 From: desaicwtf Date: Mon, 12 Jul 2010 17:22:03 +0000 Subject: bug fix in agreement model git-svn-id: https://ws10smt.googlecode.com/svn/trunk@223 ec762483-ff6d-05da-a07a-a48fb63a330f --- .../prjava/src/phrase/Agree.java | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'gi') diff --git a/gi/posterior-regularisation/prjava/src/phrase/Agree.java b/gi/posterior-regularisation/prjava/src/phrase/Agree.java index 091875ce..1d56cf18 100644 --- a/gi/posterior-regularisation/prjava/src/phrase/Agree.java +++ b/gi/posterior-regularisation/prjava/src/phrase/Agree.java @@ -17,6 +17,8 @@ public class Agree { Corpus c; private int K,n_phrases, n_words, n_contexts, n_positions1,n_positions2; + private double llh; + /** * * @param numCluster @@ -40,7 +42,8 @@ public class Agree { * */ public static void main(String args[]){ - String in="../pdata/canned.con"; + //String in="../pdata/canned.con"; + String in="../pdata/btec.con"; String out="../pdata/posterior.out"; int numCluster=25; Corpus corpus = null; @@ -86,7 +89,7 @@ public class Agree { double [][][]exp_emit2=new double [K][n_positions2][n_words]; double [][]exp_pi2=new double[n_contexts][K]; - double loglikelihood=0; + llh=0; //E for(int context=0; context< n_contexts; context++){ @@ -99,7 +102,7 @@ public class Agree { double p[]=posterior(edge); double z = arr.F.l1norm(p); assert z > 0; - loglikelihood += edge.getCount() * Math.log(z); + llh += edge.getCount() * Math.log(z); arr.F.l1normalize(p); int count = edge.getCount(); @@ -134,12 +137,23 @@ public class Agree { arr.F.l1normalize(j); } + for(double [][]i:exp_emit2){ + for(double []j:i){ + arr.F.l1normalize(j); + } + } + + for(double []j:exp_pi2){ + arr.F.l1normalize(j); + } + + model1.emit=exp_emit1; model1.pi=exp_pi1; model2.emit=exp_emit2; model2.pi=exp_pi2; - return loglikelihood; + return llh; } public double[] posterior(Corpus.Edge edge) @@ -147,6 +161,11 @@ public class Agree { double[] prob1=model1.posterior(edge); double[] prob2=model2.posterior(edge); + llh+=edge.getCount()*Math.log(arr.F.l1norm(prob1)); + llh+=edge.getCount()*Math.log(arr.F.l1norm(prob2)); + arr.F.l1normalize(prob1); + arr.F.l1normalize(prob2); + for(int i=0;i