From: Thomas M. <tsm...@us...> - 2002-11-20 02:44:15
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv30495/maxent Modified Files: GISModel.java Log Message: Added eval method so distribution could be passed in rathar then allocated durring each call. Left old interface in place but modified it to use the new eval method. Also made numfeats a class level variable. Index: GISModel.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISModel.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GISModel.java 19 Apr 2002 09:29:24 -0000 1.7 --- GISModel.java 20 Nov 2002 02:44:12 -0000 1.8 *************** *** 38,41 **** --- 38,43 ---- private final double iprob; private final double fval; + + private int[] numfeats; public GISModel (TIntDoubleHashMap[] _params, *************** *** 57,65 **** iprob = Math.log(1.0/numOutcomes); fval = 1.0/correctionConstant; ! } - - /** * Use this model to evaluate a context and return an array of the --- 59,65 ---- iprob = Math.log(1.0/numOutcomes); fval = 1.0/correctionConstant; ! numfeats = new int[numOutcomes]; } /** * Use this model to evaluate a context and return an array of the *************** *** 75,98 **** */ public final double[] eval(String[] context) { ! double[] outsums = new double[numOutcomes]; ! int[] numfeats = new int[numOutcomes]; ! ! for (int oid=0; oid<numOutcomes; oid++) { outsums[oid] = iprob; numfeats[oid] = 0; } - - int[] activeOutcomes; for (int i=0; i<context.length; i++) { ! if (pmap.containsKey(context[i])) { ! TIntDoubleHashMap predParams = ! params[pmap.get(context[i])]; ! activeOutcomes = predParams.keys(); ! for (int j=0; j<activeOutcomes.length; j++) { ! int oid = activeOutcomes[j]; ! numfeats[oid]++; ! outsums[oid] += fval * predParams.get(oid); ! } ! } } --- 75,111 ---- */ public final double[] eval(String[] context) { ! return(eval(context,new double[numOutcomes])); ! } ! ! /** ! * Use this model to evaluate a context and return an array of the ! * likelihood of each outcome given that context. ! * ! * @param context The names of the predicates which have been observed at ! * the present decision point. ! * @param outsums This is where the distribution is stored. ! * @return The normalized probabilities for the outcomes given the ! * context. The indexes of the double[] are the outcome ! * ids, and the actual string representation of the ! * outcomes can be obtained from the method ! * getOutcome(int i). ! */ ! public final double[] eval(String[] context, double[] outsums) { ! int[] activeOutcomes; ! for (int oid=0; oid<numOutcomes; oid++) { outsums[oid] = iprob; numfeats[oid] = 0; } for (int i=0; i<context.length; i++) { ! if (pmap.containsKey(context[i])) { ! TIntDoubleHashMap predParams = ! params[pmap.get(context[i])]; ! activeOutcomes = predParams.keys(); ! for (int j=0; j<activeOutcomes.length; j++) { ! int oid = activeOutcomes[j]; ! numfeats[oid]++; ! outsums[oid] += fval * predParams.get(oid); ! } ! } } |