From 3a7d95b3bc27ea07a57f21f26db4e136f5244284 Mon Sep 17 00:00:00 2001 From: "trevor.cohn" Date: Tue, 13 Jul 2010 18:22:59 +0000 Subject: Cleaning up the PC model. git-svn-id: https://ws10smt.googlecode.com/svn/trunk@236 ec762483-ff6d-05da-a07a-a48fb63a330f --- .../prjava/src/phrase/PhraseContextObjective.java | 155 ++++++++++----------- 1 file changed, 74 insertions(+), 81 deletions(-) (limited to 'gi/posterior-regularisation/prjava/src/phrase/PhraseContextObjective.java') diff --git a/gi/posterior-regularisation/prjava/src/phrase/PhraseContextObjective.java b/gi/posterior-regularisation/prjava/src/phrase/PhraseContextObjective.java index ff135a3d..a9d3529c 100644 --- a/gi/posterior-regularisation/prjava/src/phrase/PhraseContextObjective.java +++ b/gi/posterior-regularisation/prjava/src/phrase/PhraseContextObjective.java @@ -32,7 +32,7 @@ public class PhraseContextObjective extends ProjectedObjective private PhraseCluster c; - // un-regularized unnormalized posterior, p[edge][tag] + // un-regularized unnormalized posterior, p[edge][tag] // P(tag|edge) \propto P(tag|phrase)P(context|tag) private double p[][]; @@ -144,7 +144,7 @@ public class PhraseContextObjective extends ProjectedObjective gradient[ic]=-q[e][tag]; } } - //System.out.println("objective " + loglikelihood + " gradient: " + Arrays.toString(gradient)); + //System.out.println("objective " + loglikelihood + " ||gradient||_2: " + arr.F.l2norm(gradient)); objectiveTime += System.currentTimeMillis() - begin; } @@ -154,106 +154,100 @@ public class PhraseContextObjective extends ProjectedObjective long begin = System.currentTimeMillis(); List> tasks = new ArrayList>(); - //System.out.println("projectPoint: " + Arrays.toString(point)); + //System.out.println("\t\tprojectPoint: " + Arrays.toString(point)); Arrays.fill(newPoint, 0, newPoint.length, 0); - if (scalePT > 0) + // first project using the phrase-tag constraints, + // for all p,t: sum_c lambda_ptc < scaleP + if (pool == null) { - // first project using the phrase-tag constraints, - // for all p,t: sum_c lambda_ptc < scaleP - if (pool == null) + for (int p = 0; p < c.c.getNumPhrases(); ++p) { - for (int p = 0; p < c.c.getNumPhrases(); ++p) + List edges = c.c.getEdgesForPhrase(p); + double[] toProject = new double[edges.size()]; + for(int tag=0;tag edges = c.c.getEdgesForPhrase(p); - double[] toProject = new double[edges.size()]; - for(int tag=0;tag edges = c.c.getEdgesForPhrase(phrase); + double toProject[] = new double[edges.size()]; + for(int tag=0;tag edges = c.c.getEdgesForPhrase(phrase); - double toProject[] = new double[edges.size()]; - for(int tag=0;tag 1e-6) + // now project using the context-tag constraints, + // for all c,t: sum_p omega_pct < scaleC + if (pool == null) { - // now project using the context-tag constraints, - // for all c,t: sum_p omega_pct < scaleC - if (pool == null) + for (int ctx = 0; ctx < c.c.getNumContexts(); ++ctx) { - for (int ctx = 0; ctx < c.c.getNumContexts(); ++ctx) + List edges = c.c.getEdgesForContext(ctx); + double toProject[] = new double[edges.size()]; + for(int tag=0;tag edges = c.c.getEdgesForContext(ctx); - double toProject[] = new double[edges.size()]; - for(int tag=0;tag edges = c.c.getEdgesForContext(context); + double toProject[] = new double[edges.size()]; + for(int tag=0;tag edges = c.c.getEdgesForContext(context); - double toProject[] = new double[edges.size()]; - for(int tag=0;tag