You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(5) |
Sep
|
Oct
(14) |
Nov
(37) |
Dec
(13) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(14) |
Feb
|
Mar
|
Apr
(15) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(3) |
Dec
(2) |
2003 |
Jan
(4) |
Feb
|
Mar
(1) |
Apr
(2) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(4) |
2004 |
Jan
(1) |
Feb
(3) |
Mar
|
Apr
|
May
(4) |
Jun
(3) |
Jul
(1) |
Aug
(6) |
Sep
|
Oct
|
Nov
|
Dec
|
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(17) |
Nov
(3) |
Dec
|
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(23) |
Dec
|
2007 |
Jan
|
Feb
|
Mar
(7) |
Apr
(17) |
May
(1) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2008 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
(3) |
Sep
(20) |
Oct
|
Nov
(15) |
Dec
(2) |
2009 |
Jan
(38) |
Feb
(4) |
Mar
(20) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2010 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(4) |
Jul
|
Aug
(17) |
Sep
(26) |
Oct
|
Nov
(2) |
Dec
|
From: Thomas M. <tsm...@us...> - 2004-08-29 18:59:21
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15107/src/java/opennlp/maxent Modified Files: TObjectIndexHashMap.java AbstractDataIndexer.java OnePassDataIndexer.java TwoPassDataIndexer.java TIntParamHashMap.java Log Message: fixed or added some javadoc Index: TObjectIndexHashMap.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/TObjectIndexHashMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TObjectIndexHashMap.java 11 Jun 2004 20:51:37 -0000 1.1 --- TObjectIndexHashMap.java 29 Aug 2004 18:59:12 -0000 1.2 *************** *** 4,7 **** --- 4,8 ---- import gnu.trove.TObjectIntHashMap; + /** Data structure storing the mapping between a context and its integer value. */ public class TObjectIndexHashMap extends TObjectIntHashMap { Index: AbstractDataIndexer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/AbstractDataIndexer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** AbstractDataIndexer.java 13 Dec 2003 16:41:29 -0000 1.1 --- AbstractDataIndexer.java 29 Aug 2004 18:59:12 -0000 1.2 *************** *** 1,6 **** ! /* ! * Created on Dec 12, 2003 ! * ! */ package opennlp.maxent; --- 1,19 ---- ! /////////////////////////////////////////////////////////////////////////////// ! //Copyright (C) 2003 Thomas Morton ! // ! //This library is free software; you can redistribute it and/or ! //modify it under the terms of the GNU Lesser General Public ! //License as published by the Free Software Foundation; either ! //version 2.1 of the License, or (at your option) any later version. ! // ! //This library is distributed in the hope that it will be useful, ! //but WITHOUT ANY WARRANTY; without even the implied warranty of ! //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! //GNU General Public License for more details. ! // ! //You should have received a copy of the GNU Lesser General Public ! //License along with this program; if not, write to the Free Software ! //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ! ////////////////////////////////////////////////////////////////////////////// package opennlp.maxent; *************** *** 12,24 **** /** ! * @author Tom Morton * */ public abstract class AbstractDataIndexer implements DataIndexer { protected int[][] contexts; protected int[] outcomeList; protected int[] numTimesEventsSeen; protected String[] predLabels; protected String[] outcomeLabels; --- 25,42 ---- /** ! * Abstract class for collecting event and context counts used in training. * */ public abstract class AbstractDataIndexer implements DataIndexer { + /** The integer contexts associated with each unique event. */ protected int[][] contexts; + /** The integer outcome associated with each unique event. */ protected int[] outcomeList; + /** The number of times an event occured in the training data. */ protected int[] numTimesEventsSeen; + /** The predicate/context names. */ protected String[] predLabels; + /** The names of the outcomes. */ protected String[] outcomeLabels; Index: OnePassDataIndexer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/OnePassDataIndexer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** OnePassDataIndexer.java 13 Dec 2003 16:41:29 -0000 1.1 --- OnePassDataIndexer.java 29 Aug 2004 18:59:12 -0000 1.2 *************** *** 36,40 **** * constructor assuming no cutoff. * ! * @param events An Event[] which contains the a list of all the Events * seen in the training data. */ --- 36,40 ---- * constructor assuming no cutoff. * ! * @param eventStream An Event[] which contains the a list of all the Events * seen in the training data. */ *************** *** 46,50 **** * Two argument constructor for DataIndexer. * ! * @param events An Event[] which contains the a list of all the Events * seen in the training data. * @param cutoff The minimum number of times a predicate must have been --- 46,50 ---- * Two argument constructor for DataIndexer. * ! * @param eventStream An Event[] which contains the a list of all the Events * seen in the training data. * @param cutoff The minimum number of times a predicate must have been Index: TwoPassDataIndexer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/TwoPassDataIndexer.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TwoPassDataIndexer.java 6 Jul 2004 12:26:21 -0000 1.2 --- TwoPassDataIndexer.java 29 Aug 2004 18:59:12 -0000 1.3 *************** *** 31,37 **** import gnu.trove.*; ! /** ! * @author Tom Morton ! * */ public class TwoPassDataIndexer extends AbstractDataIndexer{ --- 31,41 ---- import gnu.trove.*; ! /** ! * Collecting event and context counts by making two passes over the events. The ! * first pass determines which contexts will be used by the model, and the ! * second pass creates the events in memory containing only the contexts which ! * will be used. This greatly reduces the amount of memory required for storing ! * the events. During the first pass a temporary event file is created which ! * is read during the second pass. */ public class TwoPassDataIndexer extends AbstractDataIndexer{ *************** *** 41,59 **** * constructor assuming no cutoff. * ! * @param events An Event[] which contains the a list of all the Events * seen in the training data. */ ! public TwoPassDataIndexer(EventStream eventStream1) { ! this(eventStream1, 0); } /** ! * Two argument constructor for DataIndexer. ! * ! * @param events An Event[] which contains the a list of all the Events ! * seen in the training data. ! * @param cutoff The minimum number of times a predicate must have been ! * observed in order to be included in the model. ! */ public TwoPassDataIndexer(EventStream eventStream, int cutoff) { TObjectIntHashMap predicateIndex; --- 45,63 ---- * constructor assuming no cutoff. * ! * @param eventStream An Event[] which contains the a list of all the Events * seen in the training data. */ ! public TwoPassDataIndexer(EventStream eventStream) { ! this(eventStream, 0); } /** ! * Two argument constructor for DataIndexer. ! * ! * @param eventStream An Event[] which contains the a list of all the Events ! * seen in the training data. ! * @param cutoff The minimum number of times a predicate must have been ! * observed in order to be included in the model. ! */ public TwoPassDataIndexer(EventStream eventStream, int cutoff) { TObjectIntHashMap predicateIndex; Index: TIntParamHashMap.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/TIntParamHashMap.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TIntParamHashMap.java 11 Jun 2004 20:51:44 -0000 1.1 --- TIntParamHashMap.java 29 Aug 2004 18:59:12 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- import gnu.trove.TIntDoubleHashMap; + /** + * Data structure for storing a models parameters for each outcome associated with a specific context. + */ public class TIntParamHashMap extends TIntDoubleHashMap { |
From: Thomas M. <tsm...@us...> - 2004-07-06 12:26:31
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26302/src/java/opennlp/maxent Modified Files: TwoPassDataIndexer.java Log Message: remove unused variables. Index: TwoPassDataIndexer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/TwoPassDataIndexer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TwoPassDataIndexer.java 13 Dec 2003 16:41:29 -0000 1.1 --- TwoPassDataIndexer.java 6 Jul 2004 12:26:21 -0000 1.2 *************** *** 58,62 **** public TwoPassDataIndexer(EventStream eventStream, int cutoff) { TObjectIntHashMap predicateIndex; - TLinkedList events; List eventsToCompare; --- 58,61 ---- *************** *** 74,79 **** eventsToCompare = index(numEvents, new FileEventStream(tmp), predicateIndex); - // done with event list - events = null; // done with predicates predicateIndex = null; --- 73,76 ---- *************** *** 131,135 **** TObjectIntHashMap omap = new TObjectIntHashMap(); int outcomeCount = 0; - int predCount = 0; List eventsToCompare = new ArrayList(numEvents); TIntArrayList indexedContext = new TIntArrayList(); --- 128,131 ---- *************** *** 139,143 **** ComparableEvent ce; ! int predID, ocID; String oc = ev.getOutcome(); --- 135,139 ---- ComparableEvent ce; ! int ocID; String oc = ev.getOutcome(); |
From: Thomas M. <tsm...@us...> - 2004-06-14 20:52:54
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19038/src/java/opennlp/maxent Modified Files: GISTrainer.java Log Message: fixed smoothing code and changed docs to javadoc format. Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** GISTrainer.java 11 Jun 2004 20:51:37 -0000 1.14 --- GISTrainer.java 14 Jun 2004 20:52:41 -0000 1.15 *************** *** 106,118 **** private final double LLThreshold = 0.0001; ! // Stores the output of the current model on a single event durring ! // training. This we be reset for every event for every itteration. double[] modelDistribution; ! // Stores the number of features that get fired per event int[] numfeats; ! // initial probability for all outcomes. double iprob; ! // make all values in an TIntDoubleHashMap return to 0.0 private TDoubleFunction backToZeros = new TDoubleFunction() { public double execute(double arg) { --- 106,118 ---- private final double LLThreshold = 0.0001; ! /** Stores the output of the current model on a single event durring ! * training. This we be reset for every event for every itteration. */ double[] modelDistribution; ! /** Stores the number of features that get fired per event. */ int[] numfeats; ! /** Initial probability for all outcomes. */ double iprob; ! /** Make all values in an TIntDoubleHashMap return to 0. */ private TDoubleFunction backToZeros = new TDoubleFunction() { public double execute(double arg) { *************** *** 121,125 **** }; ! // update the extected values of the features based on the modelDistribution for this event values private TIntDoubleProcedure updateModelExpect = new TIntDoubleProcedure() { public boolean execute(int oid, double arg) { --- 121,125 ---- }; ! /** Updates the extected values of the features based on the modelDistribution for this event values. */ private TIntDoubleProcedure updateModelExpect = new TIntDoubleProcedure() { public boolean execute(int oid, double arg) { *************** *** 129,133 **** }; ! // update the params based on the newly computed model expected values private TIntDoubleProcedure updateParams = new TIntDoubleProcedure() { public boolean execute(int oid, double arg) { --- 129,133 ---- }; ! /** Updates the params based on the newly computed model expected values. */ private TIntDoubleProcedure updateParams = new TIntDoubleProcedure() { public boolean execute(int oid, double arg) { *************** *** 269,273 **** // feature during training. final double smoothingObservation = _smoothingObservation; - final double logSmoothingObservation = Math.log(_smoothingObservation); // Get the observed expectations of the features. Strictly speaking, --- 269,272 ---- *************** *** 305,309 **** params[PID].put(OID, 0.0); modelExpects[PID].put(OID, 0.0); ! observedExpects[PID].put(OID, logSmoothingObservation); } } --- 304,308 ---- params[PID].put(OID, 0.0); modelExpects[PID].put(OID, 0.0); ! observedExpects[PID].put(OID,smoothingObservation); } } |
From: Thomas M. <tsm...@us...> - 2004-06-11 20:52:16
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15112/src/java/opennlp/maxent/io Modified Files: GISModelWriter.java GISModelReader.java OldFormatGISModelReader.java Log Message: maxent specific trove extensions for optimization. Index: GISModelWriter.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/io/GISModelWriter.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GISModelWriter.java 27 Dec 2001 19:20:26 -0000 1.4 --- GISModelWriter.java 11 Jun 2004 20:51:36 -0000 1.5 *************** *** 32,36 **** */ public abstract class GISModelWriter { ! protected TIntDoubleHashMap[] PARAMS; protected String[] OUTCOME_LABELS; protected int CORRECTION_CONSTANT; --- 32,36 ---- */ public abstract class GISModelWriter { ! protected TIntParamHashMap[] PARAMS; protected String[] OUTCOME_LABELS; protected int CORRECTION_CONSTANT; *************** *** 42,46 **** Object[] data = model.getDataStructures(); ! PARAMS = (TIntDoubleHashMap[])data[0]; TObjectIntHashMap pmap = (TObjectIntHashMap)data[1]; OUTCOME_LABELS = (String[])data[2]; --- 42,46 ---- Object[] data = model.getDataStructures(); ! PARAMS = (TIntParamHashMap[])data[0]; TObjectIntHashMap pmap = (TObjectIntHashMap)data[1]; OUTCOME_LABELS = (String[])data[2]; Index: GISModelReader.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/io/GISModelReader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** GISModelReader.java 27 Dec 2001 19:20:26 -0000 1.4 --- GISModelReader.java 11 Jun 2004 20:51:36 -0000 1.5 *************** *** 18,25 **** package opennlp.maxent.io; - import gnu.trove.*; - import opennlp.maxent.*; import java.util.StringTokenizer; /** * Abstract parent class for readers of GISModels. --- 18,26 ---- package opennlp.maxent.io; import java.util.StringTokenizer; + import opennlp.maxent.GISModel; + import opennlp.maxent.TIntParamHashMap; + /** * Abstract parent class for readers of GISModels. *************** *** 79,83 **** int[][] outcomePatterns = getOutcomePatterns(); String[] predLabels = getPredicates(); ! TIntDoubleHashMap[] params = getParameters(outcomePatterns); return new GISModel(params, --- 80,84 ---- int[][] outcomePatterns = getOutcomePatterns(); String[] predLabels = getPredicates(); ! TIntParamHashMap[] params = getParameters(outcomePatterns); return new GISModel(params, *************** *** 134,146 **** } ! protected TIntDoubleHashMap[] getParameters (int[][] outcomePatterns) throws java.io.IOException { ! TIntDoubleHashMap[] params = new TIntDoubleHashMap[NUM_PREDS]; int pid=0; for (int i=0; i<outcomePatterns.length; i++) { for (int j=0; j<outcomePatterns[i][0]; j++) { ! params[pid] = new TIntDoubleHashMap(); for (int k=1; k<outcomePatterns[i].length; k++) { double d = readDouble(); --- 135,147 ---- } ! protected TIntParamHashMap[] getParameters (int[][] outcomePatterns) throws java.io.IOException { ! TIntParamHashMap[] params = new TIntParamHashMap[NUM_PREDS]; int pid=0; for (int i=0; i<outcomePatterns.length; i++) { for (int j=0; j<outcomePatterns[i][0]; j++) { ! params[pid] = new TIntParamHashMap(); for (int k=1; k<outcomePatterns[i].length; k++) { double d = readDouble(); Index: OldFormatGISModelReader.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/io/OldFormatGISModelReader.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OldFormatGISModelReader.java 27 Dec 2001 19:20:26 -0000 1.2 --- OldFormatGISModelReader.java 11 Jun 2004 20:51:36 -0000 1.3 *************** *** 18,24 **** package opennlp.maxent.io; ! import gnu.trove.*; ! import java.io.*; ! import java.util.zip.*; /** --- 18,28 ---- package opennlp.maxent.io; ! import java.io.DataInputStream; ! import java.io.File; ! import java.io.FileInputStream; ! import java.io.IOException; ! import java.util.zip.GZIPInputStream; ! ! import opennlp.maxent.TIntParamHashMap; /** *************** *** 45,57 **** } ! protected TIntDoubleHashMap[] getParameters (int[][] outcomePatterns) throws java.io.IOException { ! TIntDoubleHashMap[] params = new TIntDoubleHashMap[NUM_PREDS]; int pid=0; for (int i=0; i<outcomePatterns.length; i++) { for (int j=0; j<outcomePatterns[i][0]; j++) { ! params[pid] = new TIntDoubleHashMap(); for (int k=1; k<outcomePatterns[i].length; k++) { double d = paramsInput.readDouble(); --- 49,61 ---- } ! protected TIntParamHashMap[] getParameters (int[][] outcomePatterns) throws java.io.IOException { ! TIntParamHashMap[] params = new TIntParamHashMap[NUM_PREDS]; int pid=0; for (int i=0; i<outcomePatterns.length; i++) { for (int j=0; j<outcomePatterns[i][0]; j++) { ! params[pid] = new TIntParamHashMap(); for (int k=1; k<outcomePatterns[i].length; k++) { double d = paramsInput.readDouble(); |
From: Thomas M. <tsm...@us...> - 2004-06-11 20:51:53
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15112/src/java/opennlp/maxent Modified Files: GISTrainer.java GISModel.java Added Files: TObjectIndexHashMap.java TIntParamHashMap.java Log Message: maxent specific trove extensions for optimization. --- NEW FILE: TObjectIndexHashMap.java --- package opennlp.maxent; import gnu.trove.TObjectHashingStrategy; import gnu.trove.TObjectIntHashMap; public class TObjectIndexHashMap extends TObjectIntHashMap { public TObjectIndexHashMap() { super(); } public TObjectIndexHashMap(TObjectHashingStrategy arg0) { super(arg0); } public TObjectIndexHashMap(int arg0) { super(arg0); } public TObjectIndexHashMap(int arg0, float arg1) { super(arg0, arg1); } public TObjectIndexHashMap(int arg0, float arg1, TObjectHashingStrategy arg2) { super(arg0, arg1, arg2); } public TObjectIndexHashMap(int arg0, TObjectHashingStrategy arg1) { super(arg0, arg1); } public int get(Object key) { int index = index(key); return index < 0 ? (int)-1 : _values[index]; } } --- NEW FILE: TIntParamHashMap.java --- package opennlp.maxent; import gnu.trove.TIntDoubleHashMap; public class TIntParamHashMap extends TIntDoubleHashMap { public TIntParamHashMap() { super(); } public TIntParamHashMap(int initialCapacity) { super(initialCapacity); } public TIntParamHashMap(int initialCapacity, float loadFactor) { super(initialCapacity, loadFactor); } public double get(int key) { int hash, probe, index, length; int[] set; byte[] states; states = _states; set = _set; length = states.length; hash = key & 0x7fffffff; index = hash % length; if (states[index] != FREE && (states[index] == REMOVED || set[index] != key)) { // see Knuth, p. 529 probe = 1 + (hash % (length - 2)); do { index -= probe; if (index < 0) { index += length; } } while (states[index] != FREE && (states[index] == REMOVED || set[index] != key)); } return states[index] == FREE ? 0d : _values[index]; } } Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** GISTrainer.java 10 May 2004 03:11:54 -0000 1.13 --- GISTrainer.java 11 Jun 2004 20:51:37 -0000 1.14 *************** *** 58,64 **** private int OID; - /** A global variable for adding probabilities in an array.*/ - private double SUM; - /** Records the array of predicates seen in each event. */ private int[][] contexts; --- 58,61 ---- *************** *** 86,99 **** /** Stores the observed expected values of the features based on training data. */ ! private TIntDoubleHashMap[] observedExpects; /** Stores the estimated parameter value of each predicate during iteration */ ! private TIntDoubleHashMap[] params; /** Stores the expected values of the features based on the current models */ ! private TIntDoubleHashMap[] modelExpects; - /** A helper object for storing predicate indexes. */ - private int[] predkeys; /** The maximum number of feattures fired in an event. Usually refered to a C.*/ --- 83,94 ---- /** Stores the observed expected values of the features based on training data. */ ! private TIntParamHashMap[] observedExpects; /** Stores the estimated parameter value of each predicate during iteration */ ! private TIntParamHashMap[] params; /** Stores the expected values of the features based on the current models */ ! private TIntParamHashMap[] modelExpects; /** The maximum number of feattures fired in an event. Usually refered to a C.*/ *************** *** 281,287 **** // implementation, this is cancelled out when we compute the next // iteration of a parameter, making the extra divisions wasteful. ! params = new TIntDoubleHashMap[numPreds]; ! modelExpects = new TIntDoubleHashMap[numPreds]; ! observedExpects = new TIntDoubleHashMap[numPreds]; int initialCapacity; --- 276,282 ---- // implementation, this is cancelled out when we compute the next // iteration of a parameter, making the extra divisions wasteful. ! params = new TIntParamHashMap[numPreds]; ! modelExpects = new TIntParamHashMap[numPreds]; ! observedExpects = new TIntParamHashMap[numPreds]; int initialCapacity; *************** *** 298,304 **** } for (PID = 0; PID < numPreds; PID++) { ! params[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); ! modelExpects[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); ! observedExpects[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); for (OID = 0; OID < numOutcomes; OID++) { if (predCount[PID][OID] > 0) { --- 293,299 ---- } for (PID = 0; PID < numPreds; PID++) { ! params[PID] = new TIntParamHashMap(initialCapacity, loadFactor); ! modelExpects[PID] = new TIntParamHashMap(initialCapacity, loadFactor); ! observedExpects[PID] = new TIntParamHashMap(initialCapacity, loadFactor); for (OID = 0; OID < numOutcomes; OID++) { if (predCount[PID][OID] > 0) { *************** *** 406,410 **** int[] activeOutcomes; for (int i = 0; i < context.length; i++) { ! TIntDoubleHashMap predParams = params[context[i]]; activeOutcomes = predParams.keys(); for (int j = 0; j < activeOutcomes.length; j++) { --- 401,405 ---- int[] activeOutcomes; for (int i = 0; i < context.length; i++) { ! TIntParamHashMap predParams = params[context[i]]; activeOutcomes = predParams.keys(); for (int j = 0; j < activeOutcomes.length; j++) { Index: GISModel.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISModel.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GISModel.java 9 Dec 2003 23:13:53 -0000 1.12 --- GISModel.java 11 Jun 2004 20:51:44 -0000 1.13 *************** *** 1,4 **** /////////////////////////////////////////////////////////////////////////////// ! // Copyright (C) 2001 Jason Baldridge and Gann Bierner // // This library is free software; you can redistribute it and/or --- 1,4 ---- /////////////////////////////////////////////////////////////////////////////// ! // Copyright (C) 2004 Jason Baldridge, Gann Bierner, and Tom Morton // // This library is free software; you can redistribute it and/or *************** *** 18,22 **** package opennlp.maxent; - import gnu.trove.*; import java.text.DecimalFormat; --- 18,21 ---- *************** *** 29,38 **** */ public final class GISModel implements MaxentModel { ! private final TIntDoubleHashMap[] params; ! private final TObjectIntHashMap pmap; private final String[] ocNames; private final double correctionConstant; private final double correctionParam; ! private final int numOutcomes; private final double iprob; --- 28,41 ---- */ public final class GISModel implements MaxentModel { ! /** Mapping between outcomes and paramater values for each context. ! * The integer representation of the context can be found using <code>pmap</code>.*/ ! private final TIntParamHashMap[] params; ! /** Maping between predicates/contexts and an integer representing them. */ ! private final TObjectIndexHashMap pmap; ! /** The names of the outcomes. */ private final String[] ocNames; private final double correctionConstant; private final double correctionParam; ! /** The number of outcomes. */ private final int numOutcomes; private final double iprob; *************** *** 42,46 **** private int[] numfeats; ! public GISModel (TIntDoubleHashMap[] _params, String[] predLabels, String[] _ocNames, --- 45,49 ---- private int[] numfeats; ! public GISModel (TIntParamHashMap[] _params, String[] predLabels, String[] _ocNames, *************** *** 48,52 **** double _correctionParam) { ! pmap = new TObjectIntHashMap(predLabels.length); for (int i=0; i<predLabels.length; i++) pmap.put(predLabels[i], i); --- 51,55 ---- double _correctionParam) { ! pmap = new TObjectIndexHashMap(predLabels.length); for (int i=0; i<predLabels.length; i++) pmap.put(predLabels[i], i); *************** *** 90,119 **** * 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); ! } ! } } double normal = 0.0; for (int oid=0; oid<numOutcomes; oid++) { ! outsums[oid] = Math.exp(outsums[oid] ! + ((1.0 - ! (numfeats[oid]/correctionConstant)) * correctionParam)); normal += outsums[oid]; --- 93,121 ---- * 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++) { ! int contextIndex = pmap.get(context[i]); ! if (contextIndex >= 0) { ! TIntParamHashMap predParams = params[contextIndex]; ! activeOutcomes = predParams.keys(); ! for (int j=0; j<activeOutcomes.length; j++) { ! int oid = activeOutcomes[j]; ! numfeats[oid]++; ! outsums[oid] += predParams.get(oid); ! } ! } } double normal = 0.0; for (int oid=0; oid<numOutcomes; oid++) { ! outsums[oid] = Math.exp((outsums[oid]*fval) ! + ((1.0 -(numfeats[oid]/correctionConstant)) * correctionParam)); normal += outsums[oid]; |
From: Thomas M. <tsm...@us...> - 2004-05-10 03:12:03
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5870/src/java/opennlp/maxent Modified Files: GISTrainer.java BasicEventStream.java DataIndexer.java BasicContextGenerator.java Log Message: added or fixed javadoc Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** GISTrainer.java 17 Dec 2003 19:37:10 -0000 1.12 --- GISTrainer.java 10 May 2004 03:11:54 -0000 1.13 *************** *** 20,24 **** import gnu.trove.*; - /** * An implementation of Generalized Iterative Scaling. The reference paper --- 20,23 ---- *************** *** 32,471 **** class GISTrainer { ! // This can improve model accuracy, though training will potentially take ! // longer and use more memory. Model size will also be larger. Initial ! // testing indicates improvements for models built on small data sets and ! // few outcomes, but performance degradation for those with large data ! // sets and lots of outcomes. ! private boolean _simpleSmoothing = false; ! // If we are using smoothing, this is used as the "number" of ! // times we want the trainer to imagine that it saw a feature that it ! // actually didn't see. Defaulted to 0.1. ! private double _smoothingObservation = 0.1; ! ! private boolean printMessages = false; ! ! private int numTokens; // # of event tokens ! private int numPreds; // # of predicates ! private int numOutcomes; // # of outcomes ! private int TID; // global index variable for Tokens ! private int PID; // global index variable for Predicates ! private int OID; // global index variable for Outcomes ! // a global variable for adding probabilities in an array ! private double SUM; ! // records the array of predicates seen in each event ! private int[][] contexts; ! // records the array of outcomes seen in each event ! private int[] outcomes; ! ! private int[] outcomeList; ! // records the num of times an event has been seen, paired to ! // int[][] contexts ! private int[] numTimesEventsSeen; ! // stores the String names of the outcomes. The GIS only tracks outcomes ! // as ints, and so this array is needed to save the model to disk and ! // thereby allow users to know what the outcome was in human ! // understandable terms. ! private String[] outcomeLabels; ! // stores the String names of the predicates. The GIS only tracks ! // predicates as ints, and so this array is needed to save the model to ! // disk and thereby allow users to know what the outcome was in human ! // understandable terms. ! private String[] predLabels; ! // stores the observed expections of each of the events ! private TIntDoubleHashMap[] observedExpects; ! // stores the estimated parameter value of each predicate during iteration ! private TIntDoubleHashMap[] params; ! // stores the modifiers of the parameter values, paired to params ! private TIntDoubleHashMap[] modifiers; ! // a helper object for storing predicate indexes ! private int[] predkeys; ! // GIS constant number of feattures fired ! private int constant; ! // stores inverse of constant after it is determined ! private double constantInverse; ! // the correction parameter of the model ! private double correctionParam; ! // observed expectation of correction feature ! private double cfObservedExpect; ! // a global variable to help compute the amount to modify the correction ! // parameter ! private double CFMOD; ! private final double NEAR_ZERO = 0.01; ! private final double LLThreshold = 0.0001; ! // Stores the output of the current model on a single event durring ! // training. This we be reset for every event for every itteration. ! double[] modelDistribution; ! // Stores the number of features that get fired per event ! int[] numfeats; ! // initial probability for all outcomes. ! double iprob; ! // make all values in an TIntDoubleHashMap return to 0.0 ! private TDoubleFunction backToZeros = ! new TDoubleFunction() { ! public double execute(double arg) { return 0.0; } ! }; ! // update the modifiers based on the modelDistribution for this event values ! private TIntDoubleProcedure updateModifiers = ! new TIntDoubleProcedure() { ! public boolean execute(int oid, double arg) { ! modifiers[PID].put(oid, ! arg ! + (modelDistribution[oid] ! * numTimesEventsSeen[TID])); ! return true; ! } ! }; ! // update the params based on the newly computed modifiers ! private TIntDoubleProcedure updateParams = ! new TIntDoubleProcedure() { ! public boolean execute(int oid, double arg) { ! params[PID].put(oid, ! arg +(observedExpects[PID].get(oid) ! - Math.log(modifiers[PID].get(oid)))); ! return true; ! } ! }; ! /** ! * Creates a new <code>GISTrainer</code> instance which does ! * not print progress messages about training to STDOUT. ! * ! */ ! GISTrainer() { ! super(); ! } ! /** ! * Creates a new <code>GISTrainer</code> instance. ! * ! * @param printMessages sends progress messages about training to ! * STDOUT when true; trains silently otherwise. ! */ ! GISTrainer(boolean printMessages) { ! this(); ! this.printMessages = printMessages; } ! /** ! * Sets whether this trainer will use smoothing while training the model. ! * This can improve model accuracy, though training will potentially take ! * longer and use more memory. Model size will also be larger. ! * ! * @param smooth true if smoothing is desired, false if not ! */ ! public void setSmoothing (boolean smooth) { ! _simpleSmoothing = smooth; } ! /** ! * Sets whether this trainer will use smoothing while training the model. ! * This can improve model accuracy, though training will potentially take ! * longer and use more memory. Model size will also be larger. ! * ! * @param timesSeen the "number" of times we want the trainer to imagine ! * it saw a feature that it actually didn't see ! */ ! public void setSmoothingObservation (double timesSeen) { ! _smoothingObservation = timesSeen; } ! ! public GISModel trainModel(EventStream eventStream, ! int iterations, ! int cutoff) { ! return trainModel(iterations,new OnePassDataIndexer(eventStream, cutoff)); } ! /** ! * Train a model using the GIS algorithm. ! * ! * @param eventStream The EventStream holding the data on which this model ! * will be trained. ! * @param iterations The number of GIS iterations to perform. ! * @param cutoff The number of times a predicate must be seen in order ! * to be relevant for training. ! * @param di The data indexer used to compress events in memory. ! * @return The newly trained model, which can be used immediately or saved ! * to disk using an opennlp.maxent.io.GISModelWriter object. ! */ ! public GISModel trainModel(int iterations,DataIndexer di) { ! /************** Incorporate all of the needed info ******************/ ! display("Incorporating indexed data for training... \n"); ! contexts = di.getContexts(); ! outcomes = di.getOutcomeList(); ! numTimesEventsSeen = di.getNumTimesEventsSeen(); ! numTokens = contexts.length; ! ! //printTable(contexts); ! // determine the correction constant and its inverse ! constant = contexts[0].length; ! for (TID=1; TID<contexts.length; TID++) { ! if (contexts[TID].length > constant) { ! constant = contexts[TID].length; ! } ! } ! constantInverse = 1.0/constant; ! ! ! display("done.\n"); ! outcomeLabels = di.getOutcomeLabels(); ! outcomeList = di.getOutcomeList(); ! numOutcomes = outcomeLabels.length; ! iprob = Math.log(1.0/numOutcomes); ! predLabels = di.getPredLabels(); ! numPreds = predLabels.length; ! ! display("\tNumber of Event Tokens: " + numTokens +"\n"); ! display("\t Number of Outcomes: " + numOutcomes +"\n"); ! display("\t Number of Predicates: " + numPreds +"\n"); ! // set up feature arrays ! int[][] predCount = new int[numPreds][numOutcomes]; ! for (TID=0; TID<numTokens; TID++) ! for (int j=0; j<contexts[TID].length; j++) ! predCount[contexts[TID][j]][outcomeList[TID]] ! += numTimesEventsSeen[TID]; ! //printTable(predCount); ! di = null; // don't need it anymore ! // A fake "observation" to cover features which are not detected in ! // the data. The default is to assume that we observed "1/10th" of a ! // feature during training. ! final double smoothingObservation = _smoothingObservation; ! final double logSmoothingObservation = Math.log(_smoothingObservation); ! // Get the observed expectations of the features. Strictly speaking, ! // we should divide the counts by the number of Tokens, but because of ! // the way the model's expectations are approximated in the ! // implementation, this is cancelled out when we compute the next ! // iteration of a parameter, making the extra divisions wasteful. ! params = new TIntDoubleHashMap[numPreds]; ! modifiers = new TIntDoubleHashMap[numPreds]; ! observedExpects = new TIntDoubleHashMap[numPreds]; ! int initialCapacity; ! float loadFactor = (float)0.9; ! if (numOutcomes < 3) { ! initialCapacity = 2; ! loadFactor = (float)1.0; ! } else if (numOutcomes < 5) { ! initialCapacity = 2; ! } else { ! initialCapacity = (int)numOutcomes/2; ! } ! for (PID=0; PID<numPreds; PID++) { ! params[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); ! modifiers[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); ! observedExpects[PID] = ! new TIntDoubleHashMap(initialCapacity, loadFactor); ! for (OID=0; OID<numOutcomes; OID++) { ! if (predCount[PID][OID] > 0) { ! params[PID].put(OID, 0.0); ! modifiers[PID].put(OID, 0.0); ! observedExpects[PID].put(OID,Math.log(predCount[PID][OID])); ! } ! else if (_simpleSmoothing) { ! params[PID].put(OID, 0.0); ! modifiers[PID].put(OID, 0.0); ! observedExpects[PID].put(OID, logSmoothingObservation); ! } ! } ! params[PID].compact(); ! modifiers[PID].compact(); ! observedExpects[PID].compact(); ! } ! // compute the expected value of correction ! int cfvalSum = 0; ! for (TID=0; TID<numTokens; TID++) { ! for (int j=0; j<contexts[TID].length; j++) { ! PID = contexts[TID][j]; ! if (!modifiers[PID].containsKey(outcomes[TID])) { ! cfvalSum+=numTimesEventsSeen[TID]; ! } ! } ! cfvalSum += (constant - contexts[TID].length) ! * numTimesEventsSeen[TID]; ! } ! if (cfvalSum == 0) { ! cfObservedExpect = Math.log(NEAR_ZERO);//nearly zero so log is defined ! } ! else { ! cfObservedExpect = Math.log(cfvalSum); ! } ! correctionParam = 0.0; ! predCount = null; // don't need it anymore ! ! display("...done.\n"); ! modelDistribution = new double[numOutcomes]; ! numfeats = new int[numOutcomes]; ! /***************** Find the parameters ************************/ ! display("Computing model parameters...\n"); ! findParameters(iterations); ! ! /*************** Create and return the model ******************/ ! return new GISModel(params, ! predLabels, ! outcomeLabels, ! constant, ! correctionParam); ! } ! ! ! /* Estimate and return the model parameters. */ ! private void findParameters(int iterations) { ! double prevLL = 0.0; ! double currLL = 0.0; ! display("Performing " + iterations + " iterations.\n"); ! for (int i=1; i<=iterations; i++) { ! if (i<10) display(" " + i + ": "); ! else if (i<100) display(" " + i + ": "); ! else display(i + ": "); ! currLL=nextIteration(); ! if (i > 1) { ! if (prevLL > currLL) { ! System.err.println("Model Diverging: loglikelihood decreased"); ! break; ! } ! if (currLL-prevLL < LLThreshold) { ! break; ! } ! } ! prevLL=currLL; } ! // kill a bunch of these big objects now that we don't need them ! observedExpects = null; ! modifiers = null; ! numTimesEventsSeen = null; ! contexts = null; } ! /** ! * Use this model to evaluate a context and return an array of the ! * likelihood of each outcome given that context. ! * ! * @param context The integers of the predicates which have been ! * observed at the present decision point. ! * @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 void eval(int[] context, double[] outsums) { ! for (int oid=0; oid<numOutcomes; oid++) { ! outsums[oid] = iprob; ! numfeats[oid] = 0; ! } ! int[] activeOutcomes; ! for (int i=0; i<context.length; i++) { ! TIntDoubleHashMap predParams = params[context[i]]; ! activeOutcomes = predParams.keys(); ! for (int j=0; j<activeOutcomes.length; j++) { ! int oid = activeOutcomes[j]; ! numfeats[oid]++; ! outsums[oid] += constantInverse * predParams.get(oid); ! } } ! double SUM = 0.0; ! for (int oid=0; oid<numOutcomes; oid++) { ! outsums[oid] = Math.exp(outsums[oid] ! + ((1.0 - ! ((double) numfeats[oid]/constant)) ! * correctionParam)); ! SUM += outsums[oid]; } ! for (int oid=0; oid<numOutcomes; oid++) ! outsums[oid] /= SUM; ! } - ! /* Compute one iteration of GIS and retutn log-likelihood.*/ ! private double nextIteration() { ! // compute contribution of p(a|b_i) for each feature and the new ! // correction parameter ! double loglikelihood = 0.0; ! CFMOD=0.0; ! int numEvents=0; ! int numCorrect = 0; ! for (TID=0; TID<numTokens; TID++) { ! // TID, modeldistribution and PID are globals used in ! // the updateModifiers procedure. They need to be set. ! eval(contexts[TID],modelDistribution); ! for (int j=0; j<contexts[TID].length; j++) { ! PID = contexts[TID][j]; ! modifiers[PID].forEachEntry(updateModifiers); ! for (OID=0;OID<numOutcomes;OID++) { ! if (!modifiers[PID].containsKey(OID)) { ! CFMOD+=modelDistribution[OID]*numTimesEventsSeen[TID]; ! } ! } ! } ! CFMOD+=(constant-contexts[TID].length)*numTimesEventsSeen[TID]; ! loglikelihood+=Math.log(modelDistribution[outcomes[TID]])*numTimesEventsSeen[TID]; ! numEvents+=numTimesEventsSeen[TID]; ! if (printMessages) { ! int max = 0; ! for (OID=1;OID<numOutcomes;OID++) { ! if (modelDistribution[OID] > modelDistribution[max]) { ! max = OID; ! } ! } ! if (max == outcomes[TID]) { ! numCorrect+=numTimesEventsSeen[TID]; } } - } ! display("."); ! ! // compute the new parameter values ! for (PID=0; PID<numPreds; PID++) { ! params[PID].forEachEntry(updateParams); ! modifiers[PID].transformValues(backToZeros); // re-initialize to 0.0's } ! if (CFMOD > 0.0) ! correctionParam +=(cfObservedExpect - Math.log(CFMOD)); ! display(". loglikelihood="+loglikelihood+"\t"+((double) numCorrect/numEvents)+"\n"); ! return(loglikelihood); ! } ! private void display (String s) { ! if (printMessages) System.out.print(s); } ! } --- 31,491 ---- class GISTrainer { ! // This can improve model accuracy, though training will potentially take ! // longer and use more memory. Model size will also be larger. Initial ! // testing indicates improvements for models built on small data sets and ! // few outcomes, but performance degradation for those with large data ! // sets and lots of outcomes. ! private boolean _simpleSmoothing = false; ! private boolean _useSlackParameter = false; ! private double sigma = 2.0; ! // If we are using smoothing, this is used as the "number" of ! // times we want the trainer to imagine that it saw a feature that it ! // actually didn't see. Defaulted to 0.1. ! private double _smoothingObservation = 0.1; ! private boolean printMessages = false; ! private int numTokens; // # of event tokens ! private int numPreds; // # of predicates ! private int numOutcomes; // # of outcomes ! /** A global index variable for Tokens. */ ! private int TID; ! /** A global index variable for Predicates. */ ! private int PID; ! /** A global index variable for Outcomes. */ ! private int OID; ! /** A global variable for adding probabilities in an array.*/ ! private double SUM; ! /** Records the array of predicates seen in each event. */ ! private int[][] contexts; ! /** Records the array of outcomes seen in each event. */ ! private int[] outcomes; ! private int[] outcomeList; ! // records the num of times an event has been seen, paired to ! // int[][] contexts ! private int[] numTimesEventsSeen; ! /** Stores the String names of the outcomes. The GIS only tracks outcomes ! as ints, and so this array is needed to save the model to disk and ! thereby allow users to know what the outcome was in human ! understandable terms. */ ! private String[] outcomeLabels; ! /** Stores the String names of the predicates. The GIS only tracks ! predicates as ints, and so this array is needed to save the model to ! disk and thereby allow users to know what the outcome was in human ! understandable terms. */ ! private String[] predLabels; ! /** Stores the observed expected values of the features based on training data. */ ! private TIntDoubleHashMap[] observedExpects; ! /** Stores the estimated parameter value of each predicate during iteration */ ! private TIntDoubleHashMap[] params; ! /** Stores the expected values of the features based on the current models */ ! private TIntDoubleHashMap[] modelExpects; ! /** A helper object for storing predicate indexes. */ ! private int[] predkeys; ! /** The maximum number of feattures fired in an event. Usually refered to a C.*/ ! private int constant; ! /** Stores inverse of constant, 1/C. */ ! private double constantInverse; ! /** The correction parameter of the model. */ ! private double correctionParam; ! /** Observed expectation of correction feature. */ ! private double cfObservedExpect; ! /** A global variable for the models expected value of the correction feature. */ ! private double CFMOD; ! private final double NEAR_ZERO = 0.01; ! private final double LLThreshold = 0.0001; ! // Stores the output of the current model on a single event durring ! // training. This we be reset for every event for every itteration. ! double[] modelDistribution; ! // Stores the number of features that get fired per event ! int[] numfeats; ! // initial probability for all outcomes. ! double iprob; ! // make all values in an TIntDoubleHashMap return to 0.0 ! private TDoubleFunction backToZeros = new TDoubleFunction() { ! public double execute(double arg) { ! return 0.0; } + }; + // update the extected values of the features based on the modelDistribution for this event values + private TIntDoubleProcedure updateModelExpect = new TIntDoubleProcedure() { + public boolean execute(int oid, double arg) { + modelExpects[PID].put(oid, arg + (modelDistribution[oid] * numTimesEventsSeen[TID])); + return true; + } + }; ! // update the params based on the newly computed model expected values ! private TIntDoubleProcedure updateParams = new TIntDoubleProcedure() { ! public boolean execute(int oid, double arg) { ! params[PID].put(oid, arg + (Math.log(observedExpects[PID].get(oid)) - Math.log(modelExpects[PID].get(oid)))); ! return true; } + }; ! private TIntDoubleProcedure updateParamsWithSmoothing = new TIntDoubleProcedure() { ! public boolean execute(int oid, double arg) { ! double x = 0.0; ! double x0 = 0.0; ! double tmp; ! double f; ! double fp; ! for (int i = 0; i < 50; i++) { ! // check what domain these parameters are in ! tmp = modelExpects[PID].get(oid) * Math.exp(constant * x0); ! f = tmp + (arg + x0) / sigma - observedExpects[PID].get(oid); ! fp = tmp * constant + 1 / sigma; ! if (fp == 0) { ! break; ! } ! x = x0 - f / fp; ! if (Math.abs(x - x0) < 0.000001) { ! x0 = x; ! break; ! } ! x0 = x; ! } ! params[PID].put(oid, arg + x0); ! return true; } ! }; ! ! /** ! * Creates a new <code>GISTrainer</code> instance which does ! * not print progress messages about training to STDOUT. ! * ! */ ! GISTrainer() { ! super(); } + /** + * Creates a new <code>GISTrainer</code> instance. + * + * @param printMessages sends progress messages about training to + * STDOUT when true; trains silently otherwise. + */ + GISTrainer(boolean printMessages) { + this(); + this.printMessages = printMessages; + } ! /** ! * Sets whether this trainer will use smoothing while training the model. ! * This can improve model accuracy, though training will potentially take ! * longer and use more memory. Model size will also be larger. ! * ! * @param smooth true if smoothing is desired, false if not ! */ ! public void setSmoothing(boolean smooth) { ! _simpleSmoothing = smooth; ! } ! /** ! * Sets whether this trainer will use smoothing while training the model. ! * This can improve model accuracy, though training will potentially take ! * longer and use more memory. Model size will also be larger. ! * ! * @param timesSeen the "number" of times we want the trainer to imagine ! * it saw a feature that it actually didn't see ! */ ! public void setSmoothingObservation(double timesSeen) { ! _smoothingObservation = timesSeen; ! } ! public GISModel trainModel(EventStream eventStream, int iterations, int cutoff) { ! return trainModel(iterations, new OnePassDataIndexer(eventStream, cutoff)); ! } ! /** ! * Train a model using the GIS algorithm. ! * ! * @param eventStream The EventStream holding the data on which this model ! * will be trained. ! * @param iterations The number of GIS iterations to perform. ! * @param cutoff The number of times a predicate must be seen in order ! * to be relevant for training. ! * @param di The data indexer used to compress events in memory. ! * @return The newly trained model, which can be used immediately or saved ! * to disk using an opennlp.maxent.io.GISModelWriter object. ! */ ! public GISModel trainModel(int iterations, DataIndexer di) { ! /************** Incorporate all of the needed info ******************/ ! display("Incorporating indexed data for training... \n"); ! contexts = di.getContexts(); ! outcomes = di.getOutcomeList(); ! numTimesEventsSeen = di.getNumTimesEventsSeen(); ! numTokens = contexts.length; ! //printTable(contexts); ! // determine the correction constant and its inverse ! constant = contexts[0].length; ! for (TID = 1; TID < contexts.length; TID++) { ! if (contexts[TID].length > constant) { ! constant = contexts[TID].length; ! } ! } ! constantInverse = 1.0 / constant; + display("done.\n"); ! outcomeLabels = di.getOutcomeLabels(); ! outcomeList = di.getOutcomeList(); ! numOutcomes = outcomeLabels.length; ! iprob = Math.log(1.0 / numOutcomes); ! predLabels = di.getPredLabels(); ! numPreds = predLabels.length; ! display("\tNumber of Event Tokens: " + numTokens + "\n"); ! display("\t Number of Outcomes: " + numOutcomes + "\n"); ! display("\t Number of Predicates: " + numPreds + "\n"); ! // set up feature arrays ! int[][] predCount = new int[numPreds][numOutcomes]; ! for (TID = 0; TID < numTokens; TID++) ! for (int j = 0; j < contexts[TID].length; j++) ! predCount[contexts[TID][j]][outcomeList[TID]] += numTimesEventsSeen[TID]; ! //printTable(predCount); ! di = null; // don't need it anymore ! // A fake "observation" to cover features which are not detected in ! // the data. The default is to assume that we observed "1/10th" of a ! // feature during training. ! final double smoothingObservation = _smoothingObservation; ! final double logSmoothingObservation = Math.log(_smoothingObservation); ! // Get the observed expectations of the features. Strictly speaking, ! // we should divide the counts by the number of Tokens, but because of ! // the way the model's expectations are approximated in the ! // implementation, this is cancelled out when we compute the next ! // iteration of a parameter, making the extra divisions wasteful. ! params = new TIntDoubleHashMap[numPreds]; ! modelExpects = new TIntDoubleHashMap[numPreds]; ! observedExpects = new TIntDoubleHashMap[numPreds]; ! ! int initialCapacity; ! float loadFactor = (float) 0.9; ! if (numOutcomes < 3) { ! initialCapacity = 2; ! loadFactor = (float) 1.0; } ! else if (numOutcomes < 5) { ! initialCapacity = 2; ! } ! else { ! initialCapacity = (int) numOutcomes / 2; ! } ! for (PID = 0; PID < numPreds; PID++) { ! params[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); ! modelExpects[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); ! observedExpects[PID] = new TIntDoubleHashMap(initialCapacity, loadFactor); ! for (OID = 0; OID < numOutcomes; OID++) { ! if (predCount[PID][OID] > 0) { ! params[PID].put(OID, 0.0); ! modelExpects[PID].put(OID, 0.0); ! observedExpects[PID].put(OID, predCount[PID][OID]); ! } ! else if (_simpleSmoothing) { ! params[PID].put(OID, 0.0); ! modelExpects[PID].put(OID, 0.0); ! observedExpects[PID].put(OID, logSmoothingObservation); } + } + params[PID].compact(); + modelExpects[PID].compact(); + observedExpects[PID].compact(); + } ! // compute the expected value of correction ! if (_useSlackParameter) { ! int cfvalSum = 0; ! for (TID = 0; TID < numTokens; TID++) { ! for (int j = 0; j < contexts[TID].length; j++) { ! PID = contexts[TID][j]; ! if (!modelExpects[PID].containsKey(outcomes[TID])) { ! cfvalSum += numTimesEventsSeen[TID]; ! } ! } ! cfvalSum += (constant - contexts[TID].length) * numTimesEventsSeen[TID]; ! } ! if (cfvalSum == 0) { ! cfObservedExpect = Math.log(NEAR_ZERO); //nearly zero so log is defined ! } ! else { ! cfObservedExpect = Math.log(cfvalSum); ! } ! ! correctionParam = 0.0; } + predCount = null; // don't need it anymore + display("...done.\n"); ! modelDistribution = new double[numOutcomes]; ! numfeats = new int[numOutcomes]; ! ! /***************** Find the parameters ************************/ ! display("Computing model parameters...\n"); ! findParameters(iterations); ! ! /*************** Create and return the model ******************/ ! return new GISModel(params, predLabels, outcomeLabels, constant, correctionParam); ! ! } ! ! /* Estimate and return the model parameters. */ ! private void findParameters(int iterations) { ! double prevLL = 0.0; ! double currLL = 0.0; ! display("Performing " + iterations + " iterations.\n"); ! for (int i = 1; i <= iterations; i++) { ! if (i < 10) ! display(" " + i + ": "); ! else if (i < 100) ! display(" " + i + ": "); ! else ! display(i + ": "); ! currLL = nextIteration(); ! if (i > 1) { ! if (prevLL > currLL) { ! System.err.println("Model Diverging: loglikelihood decreased"); ! break; ! } ! if (currLL - prevLL < LLThreshold) { ! break; ! } } + prevLL = currLL; + } ! // kill a bunch of these big objects now that we don't need them ! observedExpects = null; ! modelExpects = null; ! numTimesEventsSeen = null; ! contexts = null; ! } ! ! /** ! * Use this model to evaluate a context and return an array of the ! * likelihood of each outcome given that context. ! * ! * @param context The integers of the predicates which have been ! * observed at the present decision point. ! * @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 void eval(int[] context, double[] outsums) { ! for (int oid = 0; oid < numOutcomes; oid++) { ! outsums[oid] = iprob; ! numfeats[oid] = 0; ! } ! int[] activeOutcomes; ! for (int i = 0; i < context.length; i++) { ! TIntDoubleHashMap predParams = params[context[i]]; ! activeOutcomes = predParams.keys(); ! for (int j = 0; j < activeOutcomes.length; j++) { ! int oid = activeOutcomes[j]; ! numfeats[oid]++; ! outsums[oid] += constantInverse * predParams.get(oid); } + } ! double SUM = 0.0; ! for (int oid = 0; oid < numOutcomes; oid++) { ! outsums[oid] = Math.exp(outsums[oid]); ! if (_useSlackParameter) { ! outsums[oid] += ((1.0 - ((double) numfeats[oid] / constant)) * correctionParam); ! } ! SUM += outsums[oid]; } ! for (int oid = 0; oid < numOutcomes; oid++) ! outsums[oid] /= SUM; ! } ! ! /* Compute one iteration of GIS and retutn log-likelihood.*/ ! private double nextIteration() { ! // compute contribution of p(a|b_i) for each feature and the new ! // correction parameter ! double loglikelihood = 0.0; ! CFMOD = 0.0; ! int numEvents = 0; ! int numCorrect = 0; ! for (TID = 0; TID < numTokens; TID++) { ! // TID, modeldistribution and PID are globals used in ! // the updateModelExpects procedure. They need to be set. ! eval(contexts[TID], modelDistribution); ! for (int j = 0; j < contexts[TID].length; j++) { ! PID = contexts[TID][j]; ! modelExpects[PID].forEachEntry(updateModelExpect); ! if (_useSlackParameter) { ! for (OID = 0; OID < numOutcomes; OID++) { ! if (!modelExpects[PID].containsKey(OID)) { ! CFMOD += modelDistribution[OID] * numTimesEventsSeen[TID]; } } } ! } ! if (_useSlackParameter) ! CFMOD += (constant - contexts[TID].length) * numTimesEventsSeen[TID]; ! ! loglikelihood += Math.log(modelDistribution[outcomes[TID]]) * numTimesEventsSeen[TID]; ! numEvents += numTimesEventsSeen[TID]; ! if (printMessages) { ! int max = 0; ! for (OID = 1; OID < numOutcomes; OID++) { ! if (modelDistribution[OID] > modelDistribution[max]) { ! max = OID; ! } } ! if (max == outcomes[TID]) { ! numCorrect += numTimesEventsSeen[TID]; ! } ! } ! } ! display("."); ! // compute the new parameter values ! for (PID = 0; PID < numPreds; PID++) { ! params[PID].forEachEntry(updateParams); ! modelExpects[PID].transformValues(backToZeros); // re-initialize to 0.0's } ! if (CFMOD > 0.0 && _useSlackParameter) ! correctionParam += (cfObservedExpect - Math.log(CFMOD)); ! ! display(". loglikelihood=" + loglikelihood + "\t" + ((double) numCorrect / numEvents) + "\n"); ! return (loglikelihood); ! } ! ! private void display(String s) { ! if (printMessages) ! System.out.print(s); ! } ! } Index: BasicEventStream.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/BasicEventStream.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** BasicEventStream.java 20 Nov 2001 17:05:37 -0000 1.1 --- BasicEventStream.java 10 May 2004 03:11:54 -0000 1.2 *************** *** 22,26 **** * that each event is represented as a space separated list containing * all the contextual predicates, with the last item being the ! * outcome, e.g.: * * <p> cp_1 cp_2 ... cp_n outcome --- 22,27 ---- * that each event is represented as a space separated list containing * all the contextual predicates, with the last item being the ! * outcome. ! * e.g.: * * <p> cp_1 cp_2 ... cp_n outcome Index: DataIndexer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/DataIndexer.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** DataIndexer.java 13 Dec 2003 16:41:29 -0000 1.11 --- DataIndexer.java 10 May 2004 03:11:54 -0000 1.12 *************** *** 21,28 **** --- 21,54 ---- */ public interface DataIndexer { + /** + * Returns the array of predicates seen in each event. + * @return a 2-D array whose first dimenstion is the event index and array this refers to contains + * the contexts for that event. + */ public int[][] getContexts(); + + /** + * Returns an array indicating the number of times a particular event was seen. + * @return an array indexed by the event index indicating the number of times a particular event was seen. + */ public int[] getNumTimesEventsSeen(); + + /** + * Returns an array indicating the number of outcomes found with a particular event. + * @return an array indexed by event index indicating the number of outcomes found with a particular event. + */ public int[] getOutcomeList(); + + /** + * Returns an array of predicate/context names. + * @return an array of predicate/context names indexed by context index. These indices are the + * value of the array returned by <code>getContexts</code>. + */ public String[] getPredLabels(); + + /** + * Returns an array of outcome names. + * @return an array of outcome names indexed by outcome index. + */ public String[] getOutcomeLabels(); } \ No newline at end of file Index: BasicContextGenerator.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/BasicContextGenerator.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** BasicContextGenerator.java 30 Apr 2002 08:48:35 -0000 1.2 --- BasicContextGenerator.java 10 May 2004 03:11:54 -0000 1.3 *************** *** 23,28 **** * Generate contexts for maxent decisions, assuming that the input * given to the getContext() method is a String containing contextual ! * predicates separated by spaces, e.g: ! * * <p> * cp_1 cp_2 ... cp_n --- 23,28 ---- * Generate contexts for maxent decisions, assuming that the input * given to the getContext() method is a String containing contextual ! * predicates separated by spaces. ! * e.g: * <p> * cp_1 cp_2 ... cp_n |
From: Thomas M. <tsm...@us...> - 2004-05-10 03:12:02
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5870/src/java/opennlp/maxent/io Modified Files: SuffixSensitiveGISModelReader.java Log Message: added or fixed javadoc Index: SuffixSensitiveGISModelReader.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/io/SuffixSensitiveGISModelReader.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SuffixSensitiveGISModelReader.java 23 Oct 2001 14:06:53 -0000 1.1.1.1 --- SuffixSensitiveGISModelReader.java 10 May 2004 03:11:54 -0000 1.2 *************** *** 96,100 **** /** ! * To convert between different formats of the new style: * * <p>java opennlp.maxent.io.SuffixSensitiveGISModelReader old_model_name new_model_name --- 96,100 ---- /** ! * To convert between different formats of the new style. * * <p>java opennlp.maxent.io.SuffixSensitiveGISModelReader old_model_name new_model_name |
From: Thomas M. <tsm...@us...> - 2004-05-10 03:11:24
|
Update of /cvsroot/maxent/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5788 Modified Files: build.xml Log Message: modifed doctitle to prevent javadoc error Index: build.xml =================================================================== RCS file: /cvsroot/maxent/maxent/build.xml,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** build.xml 2 Feb 2004 19:43:25 -0000 1.21 --- build.xml 10 May 2004 03:11:15 -0000 1.22 *************** *** 8,14 **** <target name="init"> <tstamp/> ! <property name="Name" value="Maxent"/> ! <property name="name" value="maxent"/> ! <property name="version" value="2.2.0"/> <property name="year" value="2004"/> --- 8,14 ---- <target name="init"> <tstamp/> ! <property name="Name" value="Maxent" /> ! <property name="name" value="maxent" /> ! <property name="version" value="2.2.0" /> <property name="year" value="2004"/> *************** *** 168,173 **** noindex="false" windowtitle="opennlp.${name}" ! doctitle="The <a href="http://opennlp.sf.net">OpenNLP</a> ${Name} API v${version}" ! bottom="Copyright © ${year} Jason Baldridge and Gann Bierner. All Rights Reserved." /> </target> --- 168,173 ---- noindex="false" windowtitle="opennlp.${name}" ! doctitle="The OpenNLP ${Name} API v${version}" ! bottom="Copyright © ${year} Jason Baldridge, Gann Bierner, and Thomas Morton. All Rights Reserved." /> </target> |
From: Thomas M. <tsm...@us...> - 2004-05-10 03:10:14
|
Update of /cvsroot/maxent/maxent/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5518/lib Removed Files: jaxp.readme jaxp.license.html crimson.readme crimson.license-asf crimson.license-w3c.html jaxp.jar jaxp.relnotes.html crimson.jar Log Message: removed jars which we're only used in common code. --- jaxp.readme DELETED --- --- jaxp.license.html DELETED --- --- crimson.readme DELETED --- --- crimson.license-asf DELETED --- --- crimson.license-w3c.html DELETED --- --- jaxp.jar DELETED --- --- jaxp.relnotes.html DELETED --- --- crimson.jar DELETED --- |
From: Thomas M. <tsm...@us...> - 2004-02-02 19:45:48
|
Update of /cvsroot/maxent/maxent/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5911/lib Modified Files: trove.jar LIBNOTES Log Message: updated for release Index: trove.jar =================================================================== RCS file: /cvsroot/maxent/maxent/lib/trove.jar,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 Binary files /tmp/cvsNboQo2 and /tmp/cvszfDiMF differ Index: LIBNOTES =================================================================== RCS file: /cvsroot/maxent/maxent/lib/LIBNOTES,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** LIBNOTES 9 Apr 2002 09:15:08 -0000 1.10 --- LIBNOTES 2 Feb 2004 19:43:42 -0000 1.11 *************** *** 29,33 **** trove.jar ! GNU Trove, version 0.1.4 Homepage: http://trove4j.sf.net License: LGPL --- 29,33 ---- trove.jar ! GNU Trove, version 1.0.2 Homepage: http://trove4j.sf.net License: LGPL |
From: Thomas M. <tsm...@us...> - 2004-02-02 19:45:37
|
Update of /cvsroot/maxent/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5688 Modified Files: build.xml Log Message: updated for release Index: build.xml =================================================================== RCS file: /cvsroot/maxent/maxent/build.xml,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** build.xml 17 Jan 2003 16:40:05 -0000 1.20 --- build.xml 2 Feb 2004 19:43:25 -0000 1.21 *************** *** 4,8 **** <!-- =================================================================== --> ! <!-- Initialization target --> <!-- =================================================================== --> <target name="init"> --- 4,8 ---- <!-- =================================================================== --> ! <!-- Initialization target --> <!-- =================================================================== --> <target name="init"> *************** *** 10,21 **** <property name="Name" value="Maxent"/> <property name="name" value="maxent"/> ! <property name="version" value="2.1.1"/> ! <property name="year" value="2003"/> <echo message="----------- ${Name} ${version} [${year}] ------------"/> ! <property name="build.compiler" value="classic"/> ! <property name="debug" value="on"/> ! <property name="optimize" value="off"/> <property name="deprecation" value="on"/> --- 10,20 ---- <property name="Name" value="Maxent"/> <property name="name" value="maxent"/> ! <property name="version" value="2.2.0"/> ! <property name="year" value="2004"/> <echo message="----------- ${Name} ${version} [${year}] ------------"/> ! <property name="debug" value="off"/> ! <property name="optimize" value="on"/> <property name="deprecation" value="on"/> |
From: Thomas M. <tsm...@us...> - 2004-02-02 19:45:14
|
Update of /cvsroot/maxent/maxent In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5566 Modified Files: CHANGES Log Message: updated for release Index: CHANGES =================================================================== RCS file: /cvsroot/maxent/maxent/CHANGES,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** CHANGES 17 Jan 2003 16:40:04 -0000 1.18 --- CHANGES 2 Feb 2004 19:43:08 -0000 1.19 *************** *** 1,8 **** ! 2.1.1 ----- ! ! ! 2.1.0 (Major bug fixes) --- 1,10 ---- ! 2.2.0 ----- + Added TwoPassDataIndexer to use a temorpy file for storing the events. This + allows much larger models to be trained in a smaller amount of memory with no + noticible decrease in performance for large models. ! Made minor additions to interface to allow more flexible access to model ! outcomes. 2.1.0 (Major bug fixes) |
From: Jason B. <jas...@us...> - 2004-01-06 10:28:48
|
Update of /cvsroot/maxent/maxent/samples/sports In directory sc8-pr-cvs1:/tmp/cvs-serv21609 Modified Files: README Log Message: Added info about setting classpaths to the README. Index: README =================================================================== RCS file: /cvsroot/maxent/maxent/samples/sports/README,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** README 16 Nov 2001 10:38:21 -0000 1.2 --- README 6 Jan 2004 10:28:42 -0000 1.3 *************** *** 14,18 **** To play with this sample application, do the following: ! Be sure that opennlp.maxent is in your classpath. Compile the java files: --- 14,19 ---- To play with this sample application, do the following: ! Be sure that opennlp.maxent and trove.jar (found in the lib directory) ! are in your classpath. Compile the java files: *************** *** 24,30 **** > jikes *.java ! (If you have it installedon your system, jikes is faster!) ! Build the models: > java CreateModel gameLocation.dat --- 25,37 ---- > jikes *.java ! (If you have it installed on your system, jikes is faster!) ! Note: the following will avoid the need to setup you classpath in your ! environment (be sure to fix the maxent jar for the correct version ! number): ! ! > javac -classpath .:../../lib/trove.jar:../../output/maxent-2.1.1.jar *.java ! ! Now, build the models: > java CreateModel gameLocation.dat *************** *** 32,36 **** This will produce the two models "gameLocationModel.txt" and ! "footballModel.txt" in this directory. You can then test the models on the data itself to see what sort of --- 39,46 ---- This will produce the two models "gameLocationModel.txt" and ! "footballModel.txt" in this directory. Again, to fix classpath issues ! on the command line, do the following instead: ! ! > java -cp .:../../lib/trove.jar:../../output/classes CreateModel football.dat You can then test the models on the data itself to see what sort of *************** *** 39,42 **** --- 49,56 ---- > java Predict gameLocation.dat > java Predict football.dat + + or, with command line classpath: + + > java -cp .:../../lib/trove.jar:../../output/classes Predict football.test You'll get output such as the following: |
From: Thomas M. <tsm...@us...> - 2003-12-17 19:37:14
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv25478/src/java/opennlp/maxent Modified Files: GISTrainer.java Log Message: added performance on training data output when printing messages. Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GISTrainer.java 13 Dec 2003 16:41:29 -0000 1.11 --- GISTrainer.java 17 Dec 2003 19:37:10 -0000 1.12 *************** *** 420,423 **** --- 420,424 ---- CFMOD=0.0; int numEvents=0; + int numCorrect = 0; for (TID=0; TID<numTokens; TID++) { // TID, modeldistribution and PID are globals used in *************** *** 437,440 **** --- 438,453 ---- loglikelihood+=Math.log(modelDistribution[outcomes[TID]])*numTimesEventsSeen[TID]; numEvents+=numTimesEventsSeen[TID]; + if (printMessages) { + int max = 0; + for (OID=1;OID<numOutcomes;OID++) { + if (modelDistribution[OID] > modelDistribution[max]) { + max = OID; + } + } + if (max == outcomes[TID]) { + numCorrect+=numTimesEventsSeen[TID]; + } + } + } display("."); *************** *** 448,452 **** correctionParam +=(cfObservedExpect - Math.log(CFMOD)); ! display(". loglikelihood="+loglikelihood+"\n"); return(loglikelihood); } --- 461,465 ---- correctionParam +=(cfObservedExpect - Math.log(CFMOD)); ! display(". loglikelihood="+loglikelihood+"\t"+((double) numCorrect/numEvents)+"\n"); return(loglikelihood); } |
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv31316/src/java/opennlp/maxent Modified Files: GISTrainer.java DataIndexer.java GIS.java Added Files: AbstractDataIndexer.java OnePassDataIndexer.java TwoPassDataIndexer.java Log Message: Made DataIndexer interface and updated referencing classes. This was done is support of a new DataIndexer, TwoPassDataIndexer which has a much smaller memory foot print than the old DataIndexer, now rename OnePassDataIndexer. --- NEW FILE: AbstractDataIndexer.java --- /* * Created on Dec 12, 2003 * */ package opennlp.maxent; import gnu.trove.TObjectIntHashMap; import gnu.trove.TObjectIntProcedure; import java.util.Collections; import java.util.List; /** * @author Tom Morton * */ public abstract class AbstractDataIndexer implements DataIndexer { protected int[][] contexts; protected int[] outcomeList; protected int[] numTimesEventsSeen; protected String[] predLabels; protected String[] outcomeLabels; public int[][] getContexts() { return contexts; } public int[] getNumTimesEventsSeen() { return numTimesEventsSeen; } public int[] getOutcomeList() { return outcomeList; } public String[] getPredLabels() { return predLabels; } public String[] getOutcomeLabels() { return outcomeLabels; } /** * Sorts and uniques the array of comparable events. This method * will alter the eventsToCompare array -- it does an in place * sort, followed by an in place edit to remove duplicates. * * @param eventsToCompare a <code>ComparableEvent[]</code> value * @since maxent 1.2.6 */ protected void sortAndMerge(List eventsToCompare) { Collections.sort(eventsToCompare); int numEvents = eventsToCompare.size(); int numUniqueEvents = 1; // assertion: eventsToCompare.length >= 1 if (numEvents <= 1) { return; // nothing to do; edge case (see assertion) } ComparableEvent ce = (ComparableEvent) eventsToCompare.get(0); for (int i = 1; i < numEvents; i++) { ComparableEvent ce2 = (ComparableEvent) eventsToCompare.get(i); if (ce.compareTo(ce2) == 0) { ce.seen++; // increment the seen count eventsToCompare.set(i, null); // kill the duplicate } else { ce = ce2; // a new champion emerges... numUniqueEvents++; // increment the # of unique events } } System.out.println("done. Reduced " + numEvents + " events to " + numUniqueEvents + "."); contexts = new int[numUniqueEvents][]; outcomeList = new int[numUniqueEvents]; numTimesEventsSeen = new int[numUniqueEvents]; for (int i = 0, j = 0; i < numEvents; i++) { ComparableEvent evt = (ComparableEvent) eventsToCompare.get(i); if (null == evt) { continue; // this was a dupe, skip over it. } numTimesEventsSeen[j] = evt.seen; outcomeList[j] = evt.outcome; contexts[j] = evt.predIndexes; ++j; } } /** * Utility method for creating a String[] array from a map whose * keys are labels (Strings) to be stored in the array and whose * values are the indices (Integers) at which the corresponding * labels should be inserted. * * @param labelToIndexMap a <code>TObjectIntHashMap</code> value * @return a <code>String[]</code> value * @since maxent 1.2.6 */ protected static String[] toIndexedStringArray(TObjectIntHashMap labelToIndexMap) { final String[] array = new String[labelToIndexMap.size()]; labelToIndexMap.forEachEntry(new TObjectIntProcedure() { public boolean execute(Object str, int index) { array[index] = (String)str; return true; } }); return array; } } --- NEW FILE: OnePassDataIndexer.java --- /////////////////////////////////////////////////////////////////////////////// // Copyright (C) 2001 Jason Baldridge and Gann Bierner // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ////////////////////////////////////////////////////////////////////////////// package opennlp.maxent; import gnu.trove.*; import java.util.*; /** * An indexer for maxent model data which handles cutoffs for uncommon * contextual predicates and provides a unique integer index for each of the * predicates. The data structures built in the constructor of this class are * used by the GIS trainer. * * @author Jason Baldridge * @version $Revision: 1.1 $, $Date: 2003/12/13 16:41:29 $ */ public class OnePassDataIndexer extends AbstractDataIndexer { /** * One argument constructor for DataIndexer which calls the two argument * constructor assuming no cutoff. * * @param events An Event[] which contains the a list of all the Events * seen in the training data. */ public OnePassDataIndexer(EventStream eventStream) { this(eventStream, 0); } /** * Two argument constructor for DataIndexer. * * @param events An Event[] which contains the a list of all the Events * seen in the training data. * @param cutoff The minimum number of times a predicate must have been * observed in order to be included in the model. */ public OnePassDataIndexer(EventStream eventStream, int cutoff) { TObjectIntHashMap predicateIndex; TLinkedList events; List eventsToCompare; predicateIndex = new TObjectIntHashMap(); System.out.println("Indexing events using cutoff of " + cutoff + "\n"); System.out.print("\tComputing event counts... "); events = computeEventCounts(eventStream,predicateIndex,cutoff); System.out.println("done. "+events.size()+" events"); System.out.print("\tIndexing... "); eventsToCompare = index(events,predicateIndex); // done with event list events = null; // done with predicates predicateIndex = null; System.out.println("done."); System.out.print("Sorting and merging events... "); sortAndMerge(eventsToCompare); System.out.println("Done indexing."); } /** * Reads events from <tt>eventStream</tt> into a linked list. The * predicates associated with each event are counted and any which * occur at least <tt>cutoff</tt> times are added to the * <tt>predicatesInOut</tt> map along with a unique integer index. * * @param eventStream an <code>EventStream</code> value * @param predicatesInOut a <code>TObjectIntHashMap</code> value * @param cutoff an <code>int</code> value * @return a <code>TLinkedList</code> value */ private TLinkedList computeEventCounts(EventStream eventStream, TObjectIntHashMap predicatesInOut, int cutoff) { TObjectIntHashMap counter = new TObjectIntHashMap(); TLinkedList events = new TLinkedList(); int predicateIndex = 0; while (eventStream.hasNext()) { Event ev = eventStream.nextEvent(); events.addLast(ev); String[] ec = ev.getContext(); for (int j=0; j<ec.length; j++) { if (! predicatesInOut.containsKey(ec[j])) { if (counter.increment(ec[j])) { } else { counter.put(ec[j], 1); } if (counter.get(ec[j]) >= cutoff) { predicatesInOut.put(ec[j], predicateIndex++); counter.remove(ec[j]); //if (predicateIndex %1000 == 0) { // System.err.println(predicateIndex+ " predicates"+ "event.length="+ec.length+" "+Arrays.asList(ec)); // counter.trimToSize(); //} } } } } predicatesInOut.trimToSize(); return events; } private List index(TLinkedList events, TObjectIntHashMap predicateIndex) { TObjectIntHashMap omap = new TObjectIntHashMap(); int numEvents = events.size(); int outcomeCount = 0; int predCount = 0; List eventsToCompare = new ArrayList(numEvents); TIntArrayList indexedContext = new TIntArrayList(); for (int eventIndex=0; eventIndex<numEvents; eventIndex++) { Event ev = (Event)events.removeFirst(); String[] econtext = ev.getContext(); ComparableEvent ce; int predID, ocID; String oc = ev.getOutcome(); if (omap.containsKey(oc)) { ocID = omap.get(oc); } else { ocID = outcomeCount++; omap.put(oc, ocID); } for (int i=0; i<econtext.length; i++) { String pred = econtext[i]; if (predicateIndex.containsKey(pred)) { indexedContext.add(predicateIndex.get(pred)); } } // drop events with no active features if (indexedContext.size() > 0) { ce = new ComparableEvent(ocID, indexedContext.toNativeArray()); eventsToCompare.add(ce); } else { System.err.println("Dropped event "+ev.getOutcome()+":"+Arrays.asList(ev.getContext())); } // recycle the TIntArrayList indexedContext.resetQuick(); } outcomeLabels = toIndexedStringArray(omap); predLabels = toIndexedStringArray(predicateIndex); return eventsToCompare; } } --- NEW FILE: TwoPassDataIndexer.java --- /////////////////////////////////////////////////////////////////////////////// //Copyright (C) 2003 Thomas Morton // //This library is free software; you can redistribute it and/or //modify it under the terms of the GNU Lesser General Public //License as published by the Free Software Foundation; either //version 2.1 of the License, or (at your option) any later version. // //This library is distributed in the hope that it will be useful, //but WITHOUT ANY WARRANTY; without even the implied warranty of //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //GNU General Public License for more details. // //You should have received a copy of the GNU Lesser General Public //License along with this program; if not, write to the Free Software //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ////////////////////////////////////////////////////////////////////////////// package opennlp.maxent; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; import gnu.trove.*; /** * @author Tom Morton * */ public class TwoPassDataIndexer extends AbstractDataIndexer{ /** * One argument constructor for DataIndexer which calls the two argument * constructor assuming no cutoff. * * @param events An Event[] which contains the a list of all the Events * seen in the training data. */ public TwoPassDataIndexer(EventStream eventStream1) { this(eventStream1, 0); } /** * Two argument constructor for DataIndexer. * * @param events An Event[] which contains the a list of all the Events * seen in the training data. * @param cutoff The minimum number of times a predicate must have been * observed in order to be included in the model. */ public TwoPassDataIndexer(EventStream eventStream, int cutoff) { TObjectIntHashMap predicateIndex; TLinkedList events; List eventsToCompare; predicateIndex = new TObjectIntHashMap(); System.out.println("Indexing events using cutoff of " + cutoff + "\n"); System.out.print("\tComputing event counts... "); try { File tmp = File.createTempFile("events", null); tmp.deleteOnExit(); int numEvents = computeEventCounts(eventStream, new FileWriter(tmp), predicateIndex, cutoff); System.out.println("done. " + numEvents + " events"); System.out.print("\tIndexing... "); eventsToCompare = index(numEvents, new FileEventStream(tmp), predicateIndex); // done with event list events = null; // done with predicates predicateIndex = null; tmp.delete(); System.out.println("done."); System.out.print("Sorting and merging events... "); sortAndMerge(eventsToCompare); System.out.println("Done indexing."); } catch(IOException e) { System.err.println(e); } } /** * Reads events from <tt>eventStream</tt> into a linked list. The * predicates associated with each event are counted and any which * occur at least <tt>cutoff</tt> times are added to the * <tt>predicatesInOut</tt> map along with a unique integer index. * * @param eventStream an <code>EventStream</code> value * @param eventStore a writer to which the events are written to for later processing. * @param predicatesInOut a <code>TObjectIntHashMap</code> value * @param cutoff an <code>int</code> value */ private int computeEventCounts(EventStream eventStream, Writer eventStore, TObjectIntHashMap predicatesInOut, int cutoff) throws IOException { TObjectIntHashMap counter = new TObjectIntHashMap(); int predicateIndex = 0; int eventCount = 0; while (eventStream.hasNext()) { Event ev = eventStream.nextEvent(); eventCount++; eventStore.write(FileEventStream.toLine(ev)); String[] ec = ev.getContext(); for (int j = 0; j < ec.length; j++) { if (!predicatesInOut.containsKey(ec[j])) { if (counter.increment(ec[j])) {} else { counter.put(ec[j], 1); } if (counter.get(ec[j]) >= cutoff) { predicatesInOut.put(ec[j], predicateIndex++); counter.remove(ec[j]); } } } } predicatesInOut.trimToSize(); eventStore.close(); return eventCount; } private List index(int numEvents, EventStream es, TObjectIntHashMap predicateIndex) { TObjectIntHashMap omap = new TObjectIntHashMap(); int outcomeCount = 0; int predCount = 0; List eventsToCompare = new ArrayList(numEvents); TIntArrayList indexedContext = new TIntArrayList(); while (es.hasNext()) { Event ev = es.nextEvent(); String[] econtext = ev.getContext(); ComparableEvent ce; int predID, ocID; String oc = ev.getOutcome(); if (omap.containsKey(oc)) { ocID = omap.get(oc); } else { ocID = outcomeCount++; omap.put(oc, ocID); } for (int i = 0; i < econtext.length; i++) { String pred = econtext[i]; if (predicateIndex.containsKey(pred)) { indexedContext.add(predicateIndex.get(pred)); } } // drop events with no active features if (indexedContext.size() > 0) { ce = new ComparableEvent(ocID, indexedContext.toNativeArray()); eventsToCompare.add(ce); } else { System.err.println("Dropped event " + ev.getOutcome() + ":" + Arrays.asList(ev.getContext())); } // recycle the TIntArrayList indexedContext.resetQuick(); } outcomeLabels = toIndexedStringArray(omap); predLabels = toIndexedStringArray(predicateIndex); return eventsToCompare; } } class FileEventStream implements EventStream { BufferedReader reader; String line; public FileEventStream(String fileName) throws IOException { reader = new BufferedReader(new FileReader(fileName)); } public FileEventStream(File file) throws IOException { reader = new BufferedReader(new FileReader(file)); } public boolean hasNext() { try { return (null != (line = reader.readLine())); } catch (IOException e) { System.err.println(e); return (false); } } public Event nextEvent() { StringTokenizer st = new StringTokenizer(line); String outcome = st.nextToken(); int count = st.countTokens(); String[] context = new String[count]; for (int ci = 0; ci < count; ci++) { context[ci] = st.nextToken(); } return (new Event(outcome, context)); } public static String toLine(Event e) { StringBuffer sb = new StringBuffer(); sb.append(e.getOutcome()); String[] context = e.getContext(); for (int ci=0,cl=context.length;ci<cl;ci++) { sb.append(" "+context[ci]); } sb.append(System.getProperty("line.separator")); return sb.toString(); } } Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GISTrainer.java 5 Apr 2003 13:33:38 -0000 1.10 --- GISTrainer.java 13 Dec 2003 16:41:29 -0000 1.11 *************** *** 61,64 **** --- 61,66 ---- // records the array of outcomes seen in each event private int[] outcomes; + + private int[] outcomeList; // records the num of times an event has been seen, paired to *************** *** 185,188 **** --- 187,197 ---- _smoothingObservation = timesSeen; } + + public GISModel trainModel(EventStream eventStream, + int iterations, + int cutoff) { + return trainModel(iterations,new OnePassDataIndexer(eventStream, cutoff)); + } + /** *************** *** 194,211 **** * @param cutoff The number of times a predicate must be seen in order * to be relevant for training. * @return The newly trained model, which can be used immediately or saved * to disk using an opennlp.maxent.io.GISModelWriter object. */ ! public GISModel trainModel(EventStream eventStream, ! int iterations, ! int cutoff) { ! ! DataIndexer di = new DataIndexer(eventStream, cutoff); ! /************** Incorporate all of the needed info ******************/ display("Incorporating indexed data for training... \n"); ! contexts = di.contexts; ! outcomes = di.outcomeList; ! numTimesEventsSeen = di.numTimesEventsSeen; numTokens = contexts.length; --- 203,216 ---- * @param cutoff The number of times a predicate must be seen in order * to be relevant for training. + * @param di The data indexer used to compress events in memory. * @return The newly trained model, which can be used immediately or saved * to disk using an opennlp.maxent.io.GISModelWriter object. */ ! public GISModel trainModel(int iterations,DataIndexer di) { /************** Incorporate all of the needed info ******************/ display("Incorporating indexed data for training... \n"); ! contexts = di.getContexts(); ! outcomes = di.getOutcomeList(); ! numTimesEventsSeen = di.getNumTimesEventsSeen(); numTokens = contexts.length; *************** *** 224,232 **** display("done.\n"); ! outcomeLabels = di.outcomeLabels; numOutcomes = outcomeLabels.length; iprob = Math.log(1.0/numOutcomes); ! predLabels = di.predLabels; numPreds = predLabels.length; --- 229,238 ---- display("done.\n"); ! outcomeLabels = di.getOutcomeLabels(); ! outcomeList = di.getOutcomeList(); numOutcomes = outcomeLabels.length; iprob = Math.log(1.0/numOutcomes); ! predLabels = di.getPredLabels(); numPreds = predLabels.length; *************** *** 239,243 **** for (TID=0; TID<numTokens; TID++) for (int j=0; j<contexts[TID].length; j++) ! predCount[contexts[TID][j]][di.outcomeList[TID]] += numTimesEventsSeen[TID]; --- 245,249 ---- for (TID=0; TID<numTokens; TID++) for (int j=0; j<contexts[TID].length; j++) ! predCount[contexts[TID][j]][outcomeList[TID]] += numTimesEventsSeen[TID]; Index: DataIndexer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/DataIndexer.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** DataIndexer.java 20 Nov 2002 02:41:30 -0000 1.10 --- DataIndexer.java 13 Dec 2003 16:41:29 -0000 1.11 *************** *** 1,241 **** /////////////////////////////////////////////////////////////////////////////// ! // Copyright (C) 2001 Jason Baldridge and Gann Bierner // ! // This library is free software; you can redistribute it and/or ! // modify it under the terms of the GNU Lesser General Public ! // License as published by the Free Software Foundation; either ! // version 2.1 of the License, or (at your option) any later version. // ! // This library is distributed in the hope that it will be useful, ! // but WITHOUT ANY WARRANTY; without even the implied warranty of ! // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! // GNU General Public License for more details. // ! // You should have received a copy of the GNU Lesser General Public ! // License along with this program; if not, write to the Free Software ! // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ////////////////////////////////////////////////////////////////////////////// package opennlp.maxent; ! import gnu.trove.*; ! import java.util.*; ! ! /** ! * An indexer for maxent model data which handles cutoffs for uncommon ! * contextual predicates and provides a unique integer index for each of the ! * predicates. The data structures built in the constructor of this class are ! * used by the GIS trainer. ! * ! * @author Jason Baldridge ! * @version $Revision$, $Date$ */ ! public class DataIndexer { ! public int[][] contexts; ! public int[] outcomeList; ! public int[] numTimesEventsSeen; ! public String[] predLabels; ! public String[] outcomeLabels; ! ! /** ! * One argument constructor for DataIndexer which calls the two argument ! * constructor assuming no cutoff. ! * ! * @param events An Event[] which contains the a list of all the Events ! * seen in the training data. ! */ ! public DataIndexer(EventStream eventStream) { ! this(eventStream, 0); ! } ! ! /** ! * Two argument constructor for DataIndexer. ! * ! * @param events An Event[] which contains the a list of all the Events ! * seen in the training data. ! * @param cutoff The minimum number of times a predicate must have been ! * observed in order to be included in the model. ! */ ! public DataIndexer(EventStream eventStream, int cutoff) { ! TObjectIntHashMap predicateIndex; ! TLinkedList events; ! List eventsToCompare; ! ! predicateIndex = new TObjectIntHashMap(); ! System.out.println("Indexing events using cutoff of " + cutoff + "\n"); ! ! System.out.print("\tComputing event counts... "); ! events = computeEventCounts(eventStream,predicateIndex,cutoff); ! System.out.println("done. "+events.size()+" events"); ! ! System.out.print("\tIndexing... "); ! eventsToCompare = index(events,predicateIndex); ! // done with event list ! events = null; ! // done with predicates ! predicateIndex = null; ! ! System.out.println("done."); ! ! System.out.print("Sorting and merging events... "); ! sortAndMerge(eventsToCompare); ! System.out.println("Done indexing."); ! } ! ! /** ! * Sorts and uniques the array of comparable events. This method ! * will alter the eventsToCompare array -- it does an in place ! * sort, followed by an in place edit to remove duplicates. ! * ! * @param eventsToCompare a <code>ComparableEvent[]</code> value ! * @since maxent 1.2.6 ! */ ! private void sortAndMerge(List eventsToCompare) { ! Collections.sort(eventsToCompare); ! int numEvents = eventsToCompare.size(); ! int numUniqueEvents = 1; // assertion: eventsToCompare.length >= 1 ! ! if (numEvents <= 1) { ! return; // nothing to do; edge case (see assertion) ! } ! ! ComparableEvent ce = (ComparableEvent)eventsToCompare.get(0); ! for (int i=1; i<numEvents; i++) { ! ComparableEvent ce2 = (ComparableEvent)eventsToCompare.get(i); ! ! if (ce.compareTo(ce2) == 0) { ! ce.seen++; // increment the seen count ! eventsToCompare.set(i, null); // kill the duplicate ! } else { ! ce = ce2; // a new champion emerges... ! numUniqueEvents++; // increment the # of unique events ! } ! } ! ! System.out.println("done. Reduced " + numEvents ! + " events to " + numUniqueEvents + "."); ! ! contexts = new int[numUniqueEvents][]; ! outcomeList = new int[numUniqueEvents]; ! numTimesEventsSeen = new int[numUniqueEvents]; ! ! for (int i = 0, j = 0; i<numEvents; i++) { ! ComparableEvent evt = (ComparableEvent)eventsToCompare.get(i); ! if (null == evt) { ! continue; // this was a dupe, skip over it. ! } ! numTimesEventsSeen[j] = evt.seen; ! outcomeList[j] = evt.outcome; ! contexts[j] = evt.predIndexes; ! ++j; ! } ! } ! ! ! /** ! * Reads events from <tt>eventStream</tt> into a linked list. The ! * predicates associated with each event are counted and any which ! * occur at least <tt>cutoff</tt> times are added to the ! * <tt>predicatesInOut</tt> map along with a unique integer index. ! * ! * @param eventStream an <code>EventStream</code> value ! * @param predicatesInOut a <code>TObjectIntHashMap</code> value ! * @param cutoff an <code>int</code> value ! * @return a <code>TLinkedList</code> value ! */ ! private TLinkedList computeEventCounts(EventStream eventStream, ! TObjectIntHashMap predicatesInOut, ! int cutoff) { ! TObjectIntHashMap counter = new TObjectIntHashMap(); ! TLinkedList events = new TLinkedList(); ! int predicateIndex = 0; ! ! while (eventStream.hasNext()) { ! Event ev = eventStream.nextEvent(); ! events.addLast(ev); ! String[] ec = ev.getContext(); ! for (int j=0; j<ec.length; j++) { ! if (! predicatesInOut.containsKey(ec[j])) { ! if (counter.increment(ec[j])) { ! } else { ! counter.put(ec[j], 1); ! } ! if (counter.get(ec[j]) >= cutoff) { ! predicatesInOut.put(ec[j], predicateIndex++); ! counter.remove(ec[j]); ! } ! } ! } ! } ! predicatesInOut.trimToSize(); ! return events; ! } ! ! private List index(TLinkedList events, ! TObjectIntHashMap predicateIndex) { ! TObjectIntHashMap omap = new TObjectIntHashMap(); ! ! int numEvents = events.size(); ! int outcomeCount = 0; ! int predCount = 0; ! List eventsToCompare = new ArrayList(numEvents); ! TIntArrayList indexedContext = new TIntArrayList(); ! ! for (int eventIndex=0; eventIndex<numEvents; eventIndex++) { ! Event ev = (Event)events.removeFirst(); ! String[] econtext = ev.getContext(); ! ComparableEvent ce; ! ! int predID, ocID; ! String oc = ev.getOutcome(); ! ! if (omap.containsKey(oc)) { ! ocID = omap.get(oc); ! } else { ! ocID = outcomeCount++; ! omap.put(oc, ocID); ! } ! ! for (int i=0; i<econtext.length; i++) { ! String pred = econtext[i]; ! if (predicateIndex.containsKey(pred)) { ! indexedContext.add(predicateIndex.get(pred)); ! } ! } ! ! // drop events with no active features ! if (indexedContext.size() > 0) { ! ce = new ComparableEvent(ocID, indexedContext.toNativeArray()); ! eventsToCompare.add(ce); ! } ! else { ! System.err.println("Dropped event "+ev.getOutcome()+":"+Arrays.asList(ev.getContext())); ! } ! // recycle the TIntArrayList ! indexedContext.resetQuick(); ! } ! outcomeLabels = toIndexedStringArray(omap); ! predLabels = toIndexedStringArray(predicateIndex); ! return eventsToCompare; ! } ! ! /** ! * Utility method for creating a String[] array from a map whose ! * keys are labels (Strings) to be stored in the array and whose ! * values are the indices (Integers) at which the corresponding ! * labels should be inserted. ! * ! * @param labelToIndexMap a <code>TObjectIntHashMap</code> value ! * @return a <code>String[]</code> value ! * @since maxent 1.2.6 ! */ ! static String[] toIndexedStringArray(TObjectIntHashMap labelToIndexMap) { ! final String[] array = new String[labelToIndexMap.size()]; ! labelToIndexMap.forEachEntry(new TObjectIntProcedure() { ! public boolean execute(Object str, int index) { ! array[index] = (String)str; ! return true; ! } ! }); ! return array; ! } ! } --- 1,28 ---- /////////////////////////////////////////////////////////////////////////////// ! //Copyright (C) 2003 Thomas Morton // ! //This library is free software; you can redistribute it and/or ! //modify it under the terms of the GNU Lesser General Public ! //License as published by the Free Software Foundation; either ! //version 2.1 of the License, or (at your option) any later version. // ! //This library is distributed in the hope that it will be useful, ! //but WITHOUT ANY WARRANTY; without even the implied warranty of ! //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ! //GNU General Public License for more details. // ! //You should have received a copy of the GNU Lesser General Public ! //License along with this program; if not, write to the Free Software ! //Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ////////////////////////////////////////////////////////////////////////////// package opennlp.maxent; ! /** Object which compresses events in memory and performs feature selection. */ ! public interface DataIndexer { ! public int[][] getContexts(); ! public int[] getNumTimesEventsSeen(); ! public int[] getOutcomeList(); ! public String[] getPredLabels(); ! public String[] getOutcomeLabels(); ! } \ No newline at end of file Index: GIS.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GIS.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** GIS.java 16 Nov 2001 10:37:43 -0000 1.3 --- GIS.java 13 Dec 2003 16:41:29 -0000 1.4 *************** *** 98,101 **** --- 98,115 ---- return trainer.trainModel(eventStream, iterations, cutoff); } + + public static GISModel trainModel(int iterations, + DataIndexer indexer, + boolean printMessagesWhileTraining) { + GISTrainer trainer = new GISTrainer(printMessagesWhileTraining); + trainer.setSmoothing(SMOOTHING); + trainer.setSmoothingObservation(SMOOTHING_OBSERVATION); + return trainer.trainModel(iterations, indexer); + } + + public static GISModel trainModel(int iterations, DataIndexer indexer) { + return trainModel(iterations,indexer,true); + } + } |
From: Thomas M. <tsm...@us...> - 2003-12-09 23:13:56
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv12079/src/java/opennlp/maxent Modified Files: MaxentModel.java GISModel.java Log Message: moved getNumOutcomes up to MaxentModel Index: MaxentModel.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/MaxentModel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** MaxentModel.java 30 Nov 2001 14:33:29 -0000 1.3 --- MaxentModel.java 9 Dec 2003 23:13:53 -0000 1.4 *************** *** 26,94 **** public interface MaxentModel { ! /** * Evaluates a context. * * @param context A list of String names of the contextual predicates * which are to be evaluated together. ! * @return an array of the probabilities for each of the different * outcomes, all of which sum to 1. ! * ! **/ ! public double[] eval (String[] context); ! ! /** ! * Simple function to return the outcome associated with the index ! * containing the highest probability in the double[]. ! * ! * @param outcomes A <code>double[]</code> as returned by the ! * <code>eval(String[] context)</code> ! * method. ! * @return the String name of the best outcome **/ ! public String getBestOutcome (double[] outcomes); ! /** ! * Return a string matching all the outcome names with all the ! * probabilities produced by the <code>eval(String[] ! * context)</code> method. ! * ! * @param outcomes A <code>double[]</code> as returned by the ! * <code>eval(String[] context)</code> ! * method. ! * @return String containing outcome names paired with the normalized ! * probability (contained in the <code>double[] ocs</code>) ! * for each one. ! **/ ! public String getAllOutcomes (double[] outcomes); ! ! /** ! * Gets the String name of the outcome associated with the index ! * i. ! * ! * @param i the index for which the name of the associated outcome is ! * desired. ! * @return the String name of the outcome ! **/ ! public String getOutcome (int i); ! /** ! * Gets the index associated with the String name of the given ! * outcome. ! * ! * @param outcome the String name of the outcome for which the ! * index is desired ! * @return the index if the given outcome label exists for this ! * model, -1 if it does not. ! **/ ! public int getIndex (String outcome); - /** - * Returns the data structures relevant to storing the model. - **/ - public Object[] getDataStructures (); - } --- 26,107 ---- public interface MaxentModel { ! /** ! * Evaluates a context. ! * ! * @param context A list of String names of the contextual predicates ! * which are to be evaluated together. ! * @return an array of the probabilities for each of the different ! * outcomes, all of which sum to 1. ! * ! **/ ! public double[] eval(String[] context); ! ! /** * Evaluates a context. * * @param context A list of String names of the contextual predicates * which are to be evaluated together. ! * @param probs An array which is populated with the probabilities for each of the different * outcomes, all of which sum to 1. ! * @return an array of the probabilities for each of the different ! * outcomes, all of which sum to 1. The <code>probs</code> is returned if it is appropiately sized. **/ ! public double[] eval(String[] context, double probs[]); + /** + * Simple function to return the outcome associated with the index + * containing the highest probability in the double[]. + * + * @param outcomes A <code>double[]</code> as returned by the + * <code>eval(String[] context)</code> + * method. + * @return the String name of the best outcome + **/ + public String getBestOutcome(double[] outcomes); ! /** ! * Return a string matching all the outcome names with all the ! * probabilities produced by the <code>eval(String[] ! * context)</code> method. ! * ! * @param outcomes A <code>double[]</code> as returned by the ! * <code>eval(String[] context)</code> ! * method. ! * @return String containing outcome names paired with the normalized ! * probability (contained in the <code>double[] ocs</code>) ! * for each one. ! **/ ! public String getAllOutcomes(double[] outcomes); ! /** ! * Gets the String name of the outcome associated with the index ! * i. ! * ! * @param i the index for which the name of the associated outcome is ! * desired. ! * @return the String name of the outcome ! **/ ! public String getOutcome(int i); + /** + * Gets the index associated with the String name of the given + * outcome. + * + * @param outcome the String name of the outcome for which the + * index is desired + * @return the index if the given outcome label exists for this + * model, -1 if it does not. + **/ + public int getIndex(String outcome); ! /** ! * Returns the data structures relevant to storing the model. ! **/ ! public Object[] getDataStructures(); + /** Returns the number of outcomes for this model. + * @return The number of outcomes. + **/ + public int getNumOutcomes(); } Index: GISModel.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISModel.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** GISModel.java 5 Apr 2003 13:33:39 -0000 1.11 --- GISModel.java 9 Dec 2003 23:13:53 -0000 1.12 *************** *** 199,208 **** } ! /** Returns the number of outcomes for this model. ! * @return The number of outcomes. ! **/ ! public int getNumOutcomes() { ! return(numOutcomes); ! } --- 199,205 ---- } ! public int getNumOutcomes() { ! return(numOutcomes); ! } |
From: Thomas M. <tsm...@us...> - 2003-12-09 23:13:11
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv11989/src/java/opennlp/maxent Modified Files: Event.java Log Message: made toString informative Index: Event.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/Event.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Event.java 15 Nov 2001 18:08:20 -0000 1.2 --- Event.java 9 Dec 2003 23:13:08 -0000 1.3 *************** *** 18,21 **** --- 18,23 ---- package opennlp.maxent; + import java.util.Arrays; + /** * The context of a decision point during training. This includes *************** *** 36,39 **** --- 38,45 ---- public String getOutcome() { return outcome; } public String[] getContext() { return context; } + + public String toString() { + return outcome+" "+Arrays.asList(context); + } } |
From: Thomas M. <tsm...@us...> - 2003-04-07 05:07:36
|
Update of /cvsroot/maxent/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv473 Modified Files: .cvsignore Log Message: added enties for . files created by eclipse ide Index: .cvsignore =================================================================== RCS file: /cvsroot/maxent/maxent/.cvsignore,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** .cvsignore 2 Jan 2002 11:31:29 -0000 1.2 --- .cvsignore 7 Apr 2003 05:07:33 -0000 1.3 *************** *** 1 **** --- 1,3 ---- output + .classpath + .project |
From: Thomas M. <tsm...@us...> - 2003-04-05 13:33:43
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv8342/src/java/opennlp/maxent Modified Files: TrainEval.java GISTrainer.java EventCollector.java Counter.java GISModel.java Log Message: removed some unused imports. Index: TrainEval.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/TrainEval.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TrainEval.java 25 Apr 2002 15:01:07 -0000 1.3 --- TrainEval.java 5 Apr 2003 13:33:38 -0000 1.4 *************** *** 20,24 **** import opennlp.maxent.io.*; import java.io.*; - import java.util.*; /** --- 20,23 ---- Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GISTrainer.java 8 Jan 2003 15:44:47 -0000 1.9 --- GISTrainer.java 5 Apr 2003 13:33:38 -0000 1.10 *************** *** 20,27 **** import gnu.trove.*; - import java.io.*; - import java.util.*; - import java.util.zip.*; - /** --- 20,23 ---- Index: EventCollector.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/EventCollector.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** EventCollector.java 23 Oct 2001 14:06:53 -0000 1.1.1.1 --- EventCollector.java 5 Apr 2003 13:33:39 -0000 1.2 *************** *** 18,22 **** package opennlp.maxent; - import java.util.*; --- 18,21 ---- Index: Counter.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/Counter.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** Counter.java 23 Oct 2001 14:06:53 -0000 1.1.1.1 --- Counter.java 5 Apr 2003 13:33:39 -0000 1.2 *************** *** 18,22 **** package opennlp.maxent; - import java.util.*; --- 18,21 ---- Index: GISModel.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISModel.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** GISModel.java 11 Mar 2003 03:05:03 -0000 1.10 --- GISModel.java 5 Apr 2003 13:33:39 -0000 1.11 *************** *** 19,23 **** import gnu.trove.*; - import java.util.*; import java.text.DecimalFormat; --- 19,22 ---- |
From: Thomas M. <tsm...@us...> - 2003-03-11 03:05:07
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv2209/src/java/opennlp/maxent Modified Files: GISModel.java Log Message: Fixed formatting bug in getAllOutcomes. Problem pointed out by Leif Arda Nielsen in help forum. Thanks Leif. Index: GISModel.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISModel.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** GISModel.java 11 Dec 2002 16:18:41 -0000 1.9 --- GISModel.java 11 Mar 2003 03:05:03 -0000 1.10 *************** *** 20,23 **** --- 20,24 ---- import gnu.trove.*; import java.util.*; + import java.text.DecimalFormat; /** *************** *** 38,41 **** --- 39,43 ---- private final double iprob; private final double fval; + private DecimalFormat df; private int[] numfeats; *************** *** 159,172 **** } else { StringBuffer sb = new StringBuffer(ocs.length*2); ! String d = Double.toString(ocs[0]); ! if (d.length() > 6) ! d = d.substring(0,7); ! sb.append(ocNames[0]).append("[").append(d).append("]"); for (int i = 1; i<ocs.length; i++) { ! d = Double.toString(ocs[i]); ! if (d.length() > 6) ! d = d.substring(0,7); ! sb.append(" ").append(ocNames[i]).append("[").append(d).append("]"); } return sb.toString(); --- 161,171 ---- } else { + if (df == null) { //lazy initilazation + df = new DecimalFormat("0.0000"); + } StringBuffer sb = new StringBuffer(ocs.length*2); ! sb.append(ocNames[0]).append("[").append(df.format(ocs[0])).append("]"); for (int i = 1; i<ocs.length; i++) { ! sb.append(" ").append(ocNames[i]).append("[").append(df.format(ocs[i])).append("]"); } return sb.toString(); |
From: Jason B. <jas...@us...> - 2003-01-17 16:40:09
|
Update of /cvsroot/maxent/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv23840 Modified Files: CHANGES build.xml Log Message: Update version number to 2.1.1 Index: CHANGES =================================================================== RCS file: /cvsroot/maxent/maxent/CHANGES,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** CHANGES 17 Jan 2003 16:10:12 -0000 1.17 --- CHANGES 17 Jan 2003 16:40:04 -0000 1.18 *************** *** 1,2 **** --- 1,9 ---- + 2.1.1 + ----- + + + + + 2.1.0 (Major bug fixes) ----- Index: build.xml =================================================================== RCS file: /cvsroot/maxent/maxent/build.xml,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** build.xml 12 Dec 2002 12:18:31 -0000 1.19 --- build.xml 17 Jan 2003 16:40:05 -0000 1.20 *************** *** 10,15 **** <property name="Name" value="Maxent"/> <property name="name" value="maxent"/> ! <property name="version" value="2.1.0"/> ! <property name="year" value="2002"/> <echo message="----------- ${Name} ${version} [${year}] ------------"/> --- 10,15 ---- <property name="Name" value="Maxent"/> <property name="name" value="maxent"/> ! <property name="version" value="2.1.1"/> ! <property name="year" value="2003"/> <echo message="----------- ${Name} ${version} [${year}] ------------"/> |
From: Jason B. <jas...@us...> - 2003-01-17 16:10:21
|
Update of /cvsroot/maxent/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv18025 Modified Files: CHANGES Log Message: Added description of changes. Index: CHANGES =================================================================== RCS file: /cvsroot/maxent/maxent/CHANGES,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** CHANGES 12 Dec 2002 12:18:31 -0000 1.16 --- CHANGES 17 Jan 2003 16:10:12 -0000 1.17 *************** *** 1,6 **** ! 2.1.0 ----- --- 1,17 ---- ! 2.1.0 (Major bug fixes) ----- + Fixed some bugs with the updating off the corrections paramater. + Namely the expected value needed to check if a particular context was + avalable with the outcome seen in training and if not add a term to + the expected value of the correction constant. (Tom) + Smoothing initial value wasn't in the log domain. (Tom) + + Loglikelihood update as returned by nextIteration wasn't in the right + place so the loglikelihood value it returned was incorrect. (Tom) + + Added cast to integer division in model update. (Tom, fixing bug + pointed out by Zhang Le) |
From: Thomas M. <tsm...@us...> - 2003-01-08 15:44:50
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv8817 Modified Files: GISTrainer.java Log Message: Fixed some bugs with the updating off the corrections paramater. Namely the expected value needed to check if a particular context was avalable with the outcome seen in training and if not add a term to the expected value of the correction constant. Smothing initial value wasn't in the log domain. Loglikelihood update as returned by nextIteration wasn't in the right place so the loglikelihood value it returned was incorrect. Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GISTrainer.java 2 Jan 2003 14:46:30 -0000 1.8 --- GISTrainer.java 8 Jan 2003 15:44:47 -0000 1.9 *************** *** 216,249 **** //printTable(contexts); ! // a boolean to track if all events have same number of active features ! boolean needCorrection = false; ! ! // determine the correction constant and its inverse, and check to see ! // whether we need the correction features constant = contexts[0].length; for (TID=1; TID<contexts.length; TID++) { ! if (contexts[TID].length < constant) { ! needCorrection = true; ! } ! else if (contexts[TID].length > constant) { ! needCorrection = true; ! constant = contexts[TID].length; } } - int cfvalSum = 0; - for (TID=0; TID<numTokens; TID++) - cfvalSum += (constant - contexts[TID].length) - * numTimesEventsSeen[TID]; - if (cfvalSum == 0) { - cfObservedExpect = Math.log(NEAR_ZERO);//nearly zero so log is defined - } - else { - cfObservedExpect = Math.log(cfvalSum); - } display("done.\n"); - constantInverse = 1.0/constant; outcomeLabels = di.outcomeLabels; numOutcomes = outcomeLabels.length; --- 216,231 ---- //printTable(contexts); ! // determine the correction constant and its inverse constant = contexts[0].length; for (TID=1; TID<contexts.length; TID++) { ! if (contexts[TID].length > constant) { ! constant = contexts[TID].length; } } + constantInverse = 1.0/constant; display("done.\n"); outcomeLabels = di.outcomeLabels; numOutcomes = outcomeLabels.length; *************** *** 265,271 **** //printTable(predCount); - di = null; // don't need it anymore // A fake "observation" to cover features which are not detected in // the data. The default is to assume that we observed "1/10th" of a --- 247,253 ---- //printTable(predCount); di = null; // don't need it anymore + // A fake "observation" to cover features which are not detected in // the data. The default is to assume that we observed "1/10th" of a *************** *** 307,311 **** params[PID].put(OID, 0.0); modifiers[PID].put(OID, 0.0); ! observedExpects[PID].put(OID, smoothingObservation); } } --- 289,293 ---- params[PID].put(OID, 0.0); modifiers[PID].put(OID, 0.0); ! observedExpects[PID].put(OID, logSmoothingObservation); } } *************** *** 314,317 **** --- 296,319 ---- observedExpects[PID].compact(); } + + // compute the expected value of correction + int cfvalSum = 0; + for (TID=0; TID<numTokens; TID++) { + for (int j=0; j<contexts[TID].length; j++) { + PID = contexts[TID][j]; + if (!modifiers[PID].containsKey(outcomes[TID])) { + cfvalSum+=numTimesEventsSeen[TID]; + } + } + cfvalSum += (constant - contexts[TID].length) + * numTimesEventsSeen[TID]; + } + if (cfvalSum == 0) { + cfObservedExpect = Math.log(NEAR_ZERO);//nearly zero so log is defined + } + else { + cfObservedExpect = Math.log(cfvalSum); + } + correctionParam = 0.0; predCount = null; // don't need it anymore *************** *** 338,343 **** /* Estimate and return the model parameters. */ private void findParameters(int iterations) { ! double prevLL = 0.0; ! double currLL = 0.0; display("Performing " + iterations + " iterations.\n"); for (int i=1; i<=iterations; i++) { --- 340,345 ---- /* Estimate and return the model parameters. */ private void findParameters(int iterations) { ! double prevLL = 0.0; ! double currLL = 0.0; display("Performing " + iterations + " iterations.\n"); for (int i=1; i<=iterations; i++) { *************** *** 347,357 **** currLL=nextIteration(); if (i > 1) { ! if (prevLL > currLL) { ! System.err.println("Model Diverging: loglikelihood decreased"); ! break; ! } ! if (currLL-prevLL < LLThreshold) { ! break; ! } } prevLL=currLL; --- 349,359 ---- currLL=nextIteration(); if (i > 1) { ! if (prevLL > currLL) { ! System.err.println("Model Diverging: loglikelihood decreased"); ! break; ! } ! if (currLL-prevLL < LLThreshold) { ! break; ! } } prevLL=currLL; *************** *** 415,420 **** double loglikelihood = 0.0; CFMOD=0.0; for (TID=0; TID<numTokens; TID++) { ! // modeldistribution and PID are globals used in // the updateModifiers procedure. They need to be set. eval(contexts[TID],modelDistribution); --- 417,423 ---- double loglikelihood = 0.0; CFMOD=0.0; + int numEvents=0; for (TID=0; TID<numTokens; TID++) { ! // TID, modeldistribution and PID are globals used in // the updateModifiers procedure. They need to be set. eval(contexts[TID],modelDistribution); *************** *** 427,433 **** } } - loglikelihood+=Math.log(modelDistribution[outcomes[TID]]); } ! CFMOD+=constant-contexts[TID].length; } display("."); --- 430,438 ---- } } } ! CFMOD+=(constant-contexts[TID].length)*numTimesEventsSeen[TID]; ! ! loglikelihood+=Math.log(modelDistribution[outcomes[TID]])*numTimesEventsSeen[TID]; ! numEvents+=numTimesEventsSeen[TID]; } display("."); |
From: Thomas M. <tsm...@us...> - 2003-01-02 14:46:33
|
Update of /cvsroot/maxent/maxent/src/java/opennlp/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv21765 Modified Files: GISTrainer.java Log Message: added cast to integer division in model update Index: GISTrainer.java =================================================================== RCS file: /cvsroot/maxent/maxent/src/java/opennlp/maxent/GISTrainer.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** GISTrainer.java 20 Nov 2002 03:05:25 -0000 1.7 --- GISTrainer.java 2 Jan 2003 14:46:30 -0000 1.8 *************** *** 398,402 **** outsums[oid] = Math.exp(outsums[oid] + ((1.0 - ! (numfeats[oid]/constant)) * correctionParam)); SUM += outsums[oid]; --- 398,402 ---- outsums[oid] = Math.exp(outsums[oid] + ((1.0 - ! ((double) numfeats[oid]/constant)) * correctionParam)); SUM += outsums[oid]; |
From: Jason B. <jas...@us...> - 2002-12-12 12:18:34
|
Update of /cvsroot/maxent/maxent In directory sc8-pr-cvs1:/tmp/cvs-serv18160 Modified Files: CHANGES build.xml Log Message: Made release of v2.0 Index: CHANGES =================================================================== RCS file: /cvsroot/maxent/maxent/CHANGES,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CHANGES 30 Apr 2002 08:48:35 -0000 1.15 --- CHANGES 12 Dec 2002 12:18:31 -0000 1.16 *************** *** 1,2 **** --- 1,40 ---- + 2.1.0 + ----- + + + + + 2.0 (Major improvements) + --- + Fixed bug where singleton events are dropped. (Tom) + + 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. (Tom) + + Fixed cases where parameters which only occured with a single output + weren't getting updated. Ended up getting rid of pabi and cfvals + structures. These have been replaced with the data for a single event, + double[] modelDistribution, and this is used to update the modifiers + for a single event and then updated for each additional event. This + change made it easier to initialize the modleDistribution to the + uniform distribution which was necessary to fix teh above problem. + Also moved the computation of modelDistribution into it's own routine + which is name eval and is almost exactly the same as GISModel.eval w/o + doing the context string to integer mappings. (Tom) + + Made correction constant non-optional. When the events all have the same + number of contexts then the model tries to make the expected value of the + correction constant nearly 0. This is needed because while the number of + contexts may be same it is very unlikly that all context occur with all + outcomes. (Tom) + + Made nextIteration return a double which is the log-likelihood from + the previous itteration. At some point there isn't enough accuracy in + a double to make further iterations useful so the routine may stop + prematurly when the decrease in log-likelihood is too small. (Tom) + + 1.2.10 ------ Index: build.xml =================================================================== RCS file: /cvsroot/maxent/maxent/build.xml,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** build.xml 19 Apr 2002 12:34:02 -0000 1.18 --- build.xml 12 Dec 2002 12:18:31 -0000 1.19 *************** *** 10,14 **** <property name="Name" value="Maxent"/> <property name="name" value="maxent"/> ! <property name="version" value="1.2.10"/> <property name="year" value="2002"/> --- 10,14 ---- <property name="Name" value="Maxent"/> <property name="name" value="maxent"/> ! <property name="version" value="2.1.0"/> <property name="year" value="2002"/> |