From e0265b2c2be3173341bdc2ffacdb6847b30890f5 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/PhraseCluster.java | 3 +- .../prjava/src/phrase/PhraseContextObjective.java | 155 ++++++++++----------- .../prjava/src/phrase/PhraseObjective.java | 3 +- 3 files changed, 78 insertions(+), 83 deletions(-) (limited to 'gi/posterior-regularisation/prjava/src/phrase') diff --git a/gi/posterior-regularisation/prjava/src/phrase/PhraseCluster.java b/gi/posterior-regularisation/prjava/src/phrase/PhraseCluster.java index abd868c4..68148248 100644 --- a/gi/posterior-regularisation/prjava/src/phrase/PhraseCluster.java +++ b/gi/posterior-regularisation/prjava/src/phrase/PhraseCluster.java @@ -373,12 +373,13 @@ public class PhraseCluster { return primal; } + + double[] lambda; public double PREM_phrase_context_constraints(double scalePT, double scaleCT) { double[][][] exp_emit = new double [K][n_positions][n_words]; double[][] exp_pi = new double[n_phrases][K]; - double[] lambda = null; //E step PhraseContextObjective pco = new PhraseContextObjective(this, lambda, pool, scalePT, scaleCT); 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