From a034f92b1fe0c6368ebb140bc691f0718dd23a23 Mon Sep 17 00:00:00 2001 From: "trevor.cohn" Date: Thu, 8 Jul 2010 21:46:05 +0000 Subject: New context constraints. git-svn-id: https://ws10smt.googlecode.com/svn/trunk@190 ec762483-ff6d-05da-a07a-a48fb63a330f --- .../prjava/src/phrase/PhraseObjective.java | 120 +++++++++------------ 1 file changed, 53 insertions(+), 67 deletions(-) (limited to 'gi/posterior-regularisation/prjava/src/phrase/PhraseObjective.java') diff --git a/gi/posterior-regularisation/prjava/src/phrase/PhraseObjective.java b/gi/posterior-regularisation/prjava/src/phrase/PhraseObjective.java index 0fdc169b..015ef106 100644 --- a/gi/posterior-regularisation/prjava/src/phrase/PhraseObjective.java +++ b/gi/posterior-regularisation/prjava/src/phrase/PhraseObjective.java @@ -2,6 +2,7 @@ package phrase; import java.io.PrintStream; import java.util.Arrays; +import java.util.List; import optimization.gradientBasedMethods.ProjectedGradientDescent; import optimization.gradientBasedMethods.ProjectedObjective; @@ -17,11 +18,12 @@ import optimization.stopCriteria.StopingCriteria; import optimization.stopCriteria.ValueDifference; import optimization.util.MathUtils; -public class PhraseObjective extends ProjectedObjective{ - - private static final double GRAD_DIFF = 0.00002; - public static double INIT_STEP_SIZE = 10; - public static double VAL_DIFF = 0.000001; // FIXME needs to be tuned +public class PhraseObjective extends ProjectedObjective +{ + static final double GRAD_DIFF = 0.00002; + static double INIT_STEP_SIZE = 10; + static double VAL_DIFF = 1e-6; // FIXME needs to be tuned + static int ITERATIONS = 100; //private double c1=0.0001; // wolf stuff //private double c2=0.9; private static double lambda[][]; @@ -46,7 +48,7 @@ public class PhraseObjective extends ProjectedObjective{ * q[edge][tag] propto p[edge][tag]*exp(-lambda) */ private double q[][]; - private int data[][]; + private List data; /**@brief log likelihood of the associated phrase * @@ -66,14 +68,14 @@ public class PhraseObjective extends ProjectedObjective{ public PhraseObjective(PhraseCluster cluster, int phraseIdx){ phrase=phraseIdx; c=cluster; - data=c.c.data[phrase]; - n_param=data.length*c.K; + data=c.c.getEdgesForPhrase(phrase); + n_param=data.size()*c.K; - if( lambda==null){ - lambda=new double[c.c.data.length][]; + if (lambda==null){ + lambda=new double[c.c.getNumPhrases()][]; } - if(lambda[phrase]==null){ + if (lambda[phrase]==null){ lambda[phrase]=new double[n_param]; } @@ -81,22 +83,17 @@ public class PhraseObjective extends ProjectedObjective{ newPoint = new double[n_param]; gradient = new double[n_param]; initP(); - projection=new SimplexProjection(c.scale); - q=new double [data.length][c.K]; + projection=new SimplexProjection(c.scalePT); + q=new double [data.size()][c.K]; setParameters(parameters); } private void initP(){ - int countIdx=data[0].length-1; - - p=new double[data.length][]; - for(int edge=0;edgemax){ + for(int edge=0;edgemax) max=q[edge][tag]; - } } sum+=max; } - //System.out.println("l1lmax " + sum); -// ps.println(", "+sum); - l=l-c.scale*sum; - return l; + return sum; + } + + public double primal() + { + return loglikelihood() - KL_divergence() - c.scalePT * l1lmax(); } - } -- cgit v1.2.3