package phrase; import java.io.PrintStream; import java.util.Arrays; import optimization.gradientBasedMethods.ProjectedGradientDescent; import optimization.gradientBasedMethods.ProjectedObjective; import optimization.gradientBasedMethods.stats.OptimizerStats; import optimization.linesearch.ArmijoLineSearchMinimizationAlongProjectionArc; import optimization.linesearch.InterpolationPickFirstStep; import optimization.linesearch.LineSearchMethod; import optimization.linesearch.WolfRuleLineSearch; import optimization.projections.SimplexProjection; import optimization.stopCriteria.CompositeStopingCriteria; import optimization.stopCriteria.ProjectedGradientL2Norm; 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 //private double c1=0.0001; // wolf stuff //private double c2=0.9; private static double lambda[][]; private PhraseCluster c; /**@brief * for debugging purposes */ //public static PrintStream ps; /**@brief current phrase being optimzed*/ public int phrase; /**@brief un-regularized posterior * unnormalized * p[edge][tag] * P(tag|edge) \propto P(tag|phrase)P(context|tag) */ private double[][]p; /**@brief regularized posterior * q[edge][tag] propto p[edge][tag]*exp(-lambda) */ private double q[][]; private int data[][]; /**@brief log likelihood of the associated phrase * */ private double loglikelihood; private SimplexProjection projection; double[] newPoint ; private int n_param; /**@brief likelihood under p * */ public double llh; public PhraseObjective(PhraseCluster cluster, int phraseIdx){ phrase=phraseIdx; c=cluster; data=c.c.data[phrase]; n_param=data.length*c.K; if( lambda==null){ lambda=new double[c.c.data.length][]; } if(lambda[phrase]==null){ lambda[phrase]=new double[n_param]; } parameters=lambda[phrase]; newPoint = new double[n_param]; gradient = new double[n_param]; initP(); projection=new SimplexProjection(c.scale); q=new double [data.length][c.K]; setParameters(parameters); } private void initP(){ int countIdx=data[0].length-1; p=new double[data.length][]; 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; } }