/** Current size of the Vocabulary */ public int size() { return dataAlphabet.size(); } }
public boolean isDataAlphabetSet() { if (dataAlphabet != null && dataAlphabet.size() > 0) return true; return false; }
public Logged (double[] probabilities, Alphabet dictionary, int size, boolean areLoggedAlready) { super (probabilities, dictionary, size, true, !areLoggedAlready); assert (dictionary == null || dictionary.size() == size); if (!areLoggedAlready) for (int i = 0; i < size; i++) values[i] = Math.log (values[i]); }
public int increment (int featureIndex, int incr) { if (featureIndex < 0 || featureIndex > alphabet.size()) throw new IllegalArgumentException ("featureIndex "+featureIndex+" out of range"); return featureCounts.adjustOrPutValue(featureIndex, incr, incr); }
public HMM(Alphabet inputAlphabet, Alphabet outputAlphabet) { inputAlphabet.stopGrowth(); logger.info("HMM input dictionary size = " + inputAlphabet.size()); this.inputAlphabet = inputAlphabet; this.outputAlphabet = outputAlphabet; }
public boolean structureMatches (Factors other) { if (weightAlphabet.size() != other.weightAlphabet.size()) return false; if (weights.length != other.weights.length) return false; // gsc: checking each SparseVector's size within weights. for (int i = 0; i < weights.length; i++) if (weights[i].numLocations() != other.weights[i].numLocations()) return false; // Note that we are not checking the indices of the SparseVectors in weights if (defaultWeights.length != other.defaultWeights.length) return false; assert (initialWeights.length == finalWeights.length); if (initialWeights.length != other.initialWeights.length) return false; return true; }
public int put (int featureIndex, int value) { if (featureIndex < 0 || featureIndex > alphabet.size()) throw new IllegalArgumentException ("featureIndex "+featureIndex+" out of range"); return featureCounts.put (featureIndex, value); }
public void addFullyConnectedStatesForLabels() { String[] labels = new String[outputAlphabet.size()]; // This is assuming the the entries in the outputAlphabet are Strings! for (int i = 0; i < outputAlphabet.size(); i++) { labels[i] = (String) outputAlphabet.lookupObject(i); } addFullyConnectedStates(labels); }
/** Constructor that takes an alphabet representing the * meaning of each dimension */ public Dirichlet (double[] alphas, Alphabet dict) { this(alphas); if (dict != null && alphas.length != dict.size()) throw new IllegalArgumentException ("alphas and dict sizes do not match."); this.dict = dict; if (dict != null) dict.stopGrowth(); }
public int increment (int featureIndex) { if (featureIndex < 0 || featureIndex > alphabet.size()) throw new IllegalArgumentException ("featureIndex "+featureIndex+" out of range"); return featureCounts.adjustOrPutValue(featureIndex, 1, 1); }
public int increment (int featureIndex, int incr) { if (featureIndex < 0 || featureIndex > alphabet.size()) throw new IllegalArgumentException ("featureIndex "+featureIndex+" out of range"); return featureCounts.adjustOrPutValue(featureIndex, incr, incr); }
public void addFullyConnectedStatesForLabels () { String[] labels = new String[outputAlphabet.size()]; // This is assuming the the entries in the outputAlphabet are Strings! for (int i = 0; i < outputAlphabet.size(); i++) { logger.fine ("CRF: outputAlphabet.lookup class = "+ outputAlphabet.lookupObject(i).getClass().getName()); labels[i] = (String) outputAlphabet.lookupObject(i); } addFullyConnectedStates (labels); }
public void addFullyConnectedStatesForLabels () { String[] labels = new String[outputAlphabet.size()]; // This is assuming the the entries in the outputAlphabet are Strings! for (int i = 0; i < outputAlphabet.size(); i++) { logger.info ("CRF: outputAlphabet.lookup class = "+ outputAlphabet.lookupObject(i).getClass().getName()); labels[i] = (String) outputAlphabet.lookupObject(i); } addFullyConnectedStates (labels); }
public void printParameters(String filename) throws IOException { Alphabet alphabet = data.getDataAlphabet(); PrintWriter out = new PrintWriter(filename); for (int feature = 0; feature < alphabet.size(); feature++) { out.printf("%s\t%.8f\n", alphabet.lookupObject(feature), coefficients[feature]); } out.close(); }
public CRF (Alphabet inputAlphabet, Alphabet outputAlphabet) { super (new Noop(inputAlphabet, outputAlphabet), null); inputAlphabet.stopGrowth(); logger.info ("CRF input dictionary size = "+inputAlphabet.size()); //xxx outputAlphabet.stopGrowth(); this.inputAlphabet = inputAlphabet; this.outputAlphabet = outputAlphabet; }
TestResults (Instance inst) { alphabet = new Alphabet (); setupAlphabet (inst); numClasses = alphabet.size (); confusion = new int [numClasses][numClasses]; precision = new double [numClasses]; recall = new double [numClasses]; f1 = new double [numClasses]; }
public static RankedFeatureVector gradientGainRatioFrom(InstanceList ilist, CRF crf) { int numFeatures = ilist.getDataAlphabet().size(); double[] gradientgains = new double[numFeatures]; double[] gradientlosses = new double[numFeatures]; fillResults(ilist, crf, null, gradientgains, gradientlosses); return makeRatioVector(ilist, numFeatures, gradientgains, gradientlosses); }
public static Pair<RankedFeatureVector, RankedFeatureVector> gradientsFrom(InstanceList ilist, CRF crf) { int numFeatures = ilist.getDataAlphabet().size(); double[] gradientgains = new double[numFeatures]; double[] pos = new double[numFeatures]; double[] neg = new double[numFeatures]; fillResults(ilist, crf, gradientgains, pos, neg); return Pair.of(new RankedFeatureVector(ilist.getDataAlphabet(), gradientgains), makeRatioVector(ilist, numFeatures, pos, neg)); }
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]); }
public void testConcatenatePipes () { Pipe p1 = new StupidPipe (); Pipe p2 = new SimpleTagger.SimpleTaggerSentence2FeatureVectorSequence (); // initialize p2's dict p2.instanceFrom(new Instance (data, null, null, null)); assertEquals (3, p2.getDataAlphabet ().size()); Pipe serial = PipeUtils.concatenatePipes (p1, p2); Alphabet dict = serial.getDataAlphabet (); assertEquals (3, dict.size ()); assertTrue (dict == p2.getDataAlphabet ()); }