public PerLabelFeatureCounts (InstanceList ilist) { dataAlphabet = ilist.getDataAlphabet(); targetAlphabet = ilist.getTargetAlphabet(); double[][] counts = calcFeatureCounts (ilist); fc = new FeatureCounts[targetAlphabet.size()]; for (int i = 0; i < fc.length; i++) fc[i] = new FeatureCounts (dataAlphabet, counts[i]); }
public RankedFeatureVector newRankedFeatureVector (InstanceList ilist) { assert (ilist.getTargetAlphabet() == classifications[0].getAlphabet()); return new ExpGain (ilist, classifications, gaussianPriorVariance); }
public TokenSequence randomTokenSequence (Random r, int length) { FeatureSequence fs = randomFeatureSequence (r, length); TokenSequence ts = new TokenSequence (length); for (int i = 0; i < length; i++) ts.add (fs.getObjectAtPosition(i)); return ts; }
public Instance nextInstance () { final Instance instance = iter.nextInstance (); Instance ret = new Instance (instance.getData(), instance.getTarget(), instance.getName(), instance.getSource()); ret.setPropertyList (instance.getPropertyList ()); return ret; }
public Node (InstanceList ilist, Node parent, FeatureSelection fs) { InfoGain ig = new InfoGain (ilist); this.featureIndex = ig.getMaxValuedIndexIn (fs); this.infoGain = ig.value(featureIndex); this.ilist = ilist; this.dictionary = ilist.getDataAlphabet(); this.parent = parent; this.labeling = ig.getBaseLabelDistribution(); this.labelEntropy = ig.getBaseEntropy(); this.child0 = this.child1 = null; }
public PerLabelInfoGain (InstanceList ilist) { double[][] pcig = calcPerLabelInfoGains (ilist); Alphabet v = ilist.getDataAlphabet(); int numClasses = ilist.getTargetAlphabet().size(); ig = new InfoGain[numClasses]; for (int i = 0; i < numClasses; i++) ig[i] = new InfoGain (v, pcig[i]); }
protected DenseVector getDenseVectorOf (int ri, Matrix2 matrix) { int dims[] = new int [2]; matrix.getDimensions(dims); DenseVector vec = new DenseVector (dims[1]); for (int i=0; i < dims[1]; i++) { vec.setValue (i, matrix.value(ri,i)); } return vec; }
/** Constructs and appends an instance to this list, passing it through this * list's pipe and assigning it the specified weight. * @return <code>true</code> */ public boolean add (Object data, Object target, Object name, Object source, double instanceWeight) { return add (new Instance (data, target, name, source, pipe), instanceWeight); }
public AugmentableFeatureVector (FeatureSequence fs, boolean binary) { this (fs.getAlphabet(), binary); for (int i = fs.size()-1; i >= 0; i--) add (fs.getIndexAtPosition(i), 1.0); }
public Instance pipe (Instance carrier) { FeatureSequence fs = (FeatureSequence) carrier.getData(); carrier.setData(new FeatureVector (fs, binary)); return carrier; }
public Instance pipe (Instance carrier) { carrier.setData(new TokenSequence((CharSequence[]) carrier.getData())); return carrier; }
public double valueOfCorrectLabel () { Labeling correctLabeling = instance.getLabeling(); int correctLabelIndex = correctLabeling.getBestIndex(); return labeling.value (correctLabelIndex); }
public GradientGain (InstanceList ilist, Classification[] classifications) { super (ilist.getDataAlphabet(), calcGradientGains (ilist, getLabelVectorsFromClassifications(classifications))); }
public KLGain (InstanceList ilist, Classification[] classifications) { super (ilist.getDataAlphabet(), calcKLGains (ilist, getLabelVectorsFromClassifications(classifications))); }
public void add (Object key) { int fi = dictionary.lookupIndex (key); if (fi >= 0) // This will happen if the dictionary is frozen, // and key is not already in the dictionary. add (fi); // xxx Should we raise an exception if the appending doesn't happen? }
public void add (Object key, double value) { //System.out.println ("AugmentableFeatureVector dictionary = "+dictionary+", size = "+dictionary.size()); int index = dictionary.lookupIndex (key); //System.out.println ("AugmentableFeatureVector index("+key+") = "+index); assert (index != -1); add (index, value); }
public DenseFeatureVector (FeatureVector sfv, int numColumns) { super (denseValues(sfv, numColumns)); this.dictionary = sfv.getAlphabet(); }
public FeatureSequence randomFeatureSequence (Random r, int length) { Multinomial m = randomMultinomial (r); return m.randomFeatureSequence (r, length); }
public InfoGain (InstanceList ilist) { super (ilist.getDataAlphabet(), calcInfoGains (ilist)); baseEntropy = staticBaseEntropy; baseLabelDistribution = staticBaseLabelDistribution; }
protected DenseVector getDenseVectorOf (int ri, Matrix2 matrix) { int dims[] = new int [2]; matrix.getDimensions(dims); DenseVector vec = new DenseVector (dims[1]); for (int i=0; i < dims[1]; i++) { vec.setValue (i, matrix.value(ri,i)); } return vec; }