/** Returns the <code>Instance</code> at the specified index. If * this Instance is not in memory, swap a block of instances back * into memory. */ public Instance get (int index) { InstanceList page = getPageForIndex (index, false); return page.get (index % this.instancesPerPage); }
public InstanceList getInstances() { InstanceList ret = new InstanceList(m_ilist.getPipe()); for (int ii = 0; ii < m_instIndices.length; ii++) ret.add(m_ilist.get(m_instIndices[ii])); return ret; }
/** Returns the <code>Instance</code> at the specified index. If * this Instance is not in memory, swap a block of instances back * into memory. */ public Instance get (int index) { InstanceList page = getPageForIndex (index, false); return page.get (index % this.instancesPerPage); }
/** Return an list of instances with a particular label. */ public InstanceList getCluster(int label) { InstanceList cluster = new InstanceList(instances.getPipe()); for (int n=0 ; n<instances.size() ; n++) if (labels[n] == label) cluster.add(instances.get(n)); return cluster; }
public double getInstanceWeight (int index) { if (index > this.size()) { throw new IllegalArgumentException("Index out of bounds: index="+index+" size="+this.size()); } if (instWeights != null) { Double value = instWeights.get(get(index)); if (value != null) { return value; } } return 1.0; }
public List getBestLabels (InstanceList lst) { List ret = new ArrayList (lst.size()); for (int i = 0; i < lst.size(); i++) { ret.add (getBestLabels (lst.get (i))); } return ret; }
public void sampleTopicsForDocs (int start, int length, Randoms r) { assert (start+length <= docTopicCounts.length); double[] topicWeights = new double[numTopics]; // Loop over every word in the corpus for (int di = start; di < start+length; di++) { sampleTopicsForOneDoc ((FeatureSequence)ilist.get(di).getData(), topics[di], docTopicCounts[di], topicWeights, r); } }
public void sampleTopicsForAllDocs (Randoms r) { double[] topicWeights = new double[numTopics]; // Loop over every word in the corpus for (int di = 0; di < topics.length; di++) { sampleTopicsForOneDoc ((FeatureSequence)ilist.get(di).getData(), topics[di], docTopicCounts[di], topicWeights, r); } }
public InstanceList sampleWithReplacement (java.util.Random r, int numSamples) { InstanceList ret = this.cloneEmpty(); for (int i = 0; i < numSamples; i++) ret.add (this.get(r.nextInt(this.size()))); return ret; }
public InstanceList subList (double proportion) { if (proportion > 1.0) throw new IllegalArgumentException ("proportion must by <= 1.0"); InstanceList other = (InstanceList) clone(); other.shuffle(new java.util.Random()); proportion *= other.size(); for (int i = 0; i < proportion; i++) other.add (get(i)); return other; }
public Void call() throws Exception { for (int ii = start; ii < end; ii++) { if (instancesWithConstraints.get(ii)) { SumLattice lattice = lattices.get(ii); FeatureVectorSequence fvs = (FeatureVectorSequence)data.get(ii).getData(); new GELattice(fvs, lattice.getGammas(), lattice.getXis(), crf, reverseTrans, reverseTransIndices, gradient,this.constraints, false); } } return null; } }
public Double call() throws Exception { double value = 0; for (int ii = start; ii < end; ii++) { Instance inst = trainingSet.get(ii); Sequence input = (Sequence) inst.getData(); // logZ value -= new SumLatticePR(crf, ii, input, null, modelCopy, cachedDots[ii], true, null, null, false).getTotalWeight(); } return value; }
public void collectConstraints (InstanceList ilist) { for (int inum = 0; inum < ilist.size(); inum++) { logger.finest ("*** Collecting constraints for instance "+inum); Instance inst = ilist.get (inum); ACRF.UnrolledGraph unrolled = new ACRF.UnrolledGraph (inst, templates, null, true); Assignment assn = unrolled.getAssignment (); collectConstraintsForGraph (unrolled, assn); } }
public void dumpUnrolledGraphs (InstanceList lst) { for (int i = 0; i < lst.size(); i++) { Instance inst = lst.get (i); System.out.println("INSTANCE "+i+" : "+inst.getName ()); UnrolledGraph unrolled = unroll (inst); dumpOneGraph (unrolled); } }
private void collectWeightsPresent (InstanceList ilist, BitSet[] weightsPresent) { for (int inum = 0; inum < ilist.size(); inum++) { Instance inst = ilist.get (inum); UnrolledGraph unrolled = new UnrolledGraph (inst, new Template[] { this }, null, false); collectTransitionsPresentForGraph (unrolled); collectWeightsPresentForGraph (unrolled, weightsPresent); } }
public Sequence pipeInput (Object input) { InstanceList all = new InstanceList (getFeaturePipe ()); all.add (input, null, null, null); return (Sequence) all.get (0).getData(); } }
public Sequence pipeInput (Object input) { InstanceList all = new InstanceList (getFeaturePipe ()); all.add (input, null, null, null); return (Sequence) all.get (0).getData(); } }
public void testFixedNumLabels () throws IOException, ClassNotFoundException { Pipe p = new GenericAcrfData2TokenSequence (2); InstanceList training = new InstanceList (p); training.addThruPipe (new LineGroupIterator (new StringReader (sampleFixedData), Pattern.compile ("^$"), true)); assertEquals (1, training.size ()); Instance inst1 = training.get (0); LabelsSequence ls1 = (LabelsSequence) inst1.getTarget (); assertEquals (4, ls1.size ()); }
public static void main(String[] args) { String htmldir = args[0]; Pipe pipe = new SerialPipes(new Pipe[] { new Input2CharSequence(), new CharSequenceRemoveHTML() }); InstanceList list = new InstanceList(pipe); list.addThruPipe(new FileIterator(htmldir, FileIterator.STARTING_DIRECTORIES)); for (int index = 0; index < list.size(); index++) { Instance inst = list.get(index); System.err.println(inst.getData()); } }
public static void main(String[] args) { String htmldir = args[0]; Pipe pipe = new SerialPipes(new Pipe[] { new Input2CharSequence(), new CharSequenceRemoveHTML() }); InstanceList list = new InstanceList(pipe); list.addThruPipe(new FileIterator(htmldir, FileIterator.STARTING_DIRECTORIES)); for (int index = 0; index < list.size(); index++) { Instance inst = list.get(index); System.err.println(inst.getData()); } }