本文整理汇总了Java中cc.mallet.types.InstanceList.size方法的典型用法代码示例。如果您正苦于以下问题:Java InstanceList.size方法的具体用法?Java InstanceList.size怎么用?Java InstanceList.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.InstanceList
的用法示例。
在下文中一共展示了InstanceList.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: induceFeatures
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public void induceFeatures (InstanceList ilist, boolean withFeatureShrinkage, boolean inducePerClassFeatures)
{
if (inducePerClassFeatures) {
int numClasses = ilist.getTargetAlphabet().size();
// int numFeatures = ilist.getDataAlphabet().size();
FeatureSelection[] pcfs = new FeatureSelection[numClasses];
for (int j = 0; j < numClasses; j++)
pcfs[j] = (FeatureSelection) ilist.getPerLabelFeatureSelection()[j].clone();
for (int i = 0; i < ilist.size(); i++) {
Object data = ilist.get(i).getData();
AugmentableFeatureVector afv = (AugmentableFeatureVector) data;
root.induceFeatures (afv, null, pcfs, ilist.getFeatureSelection(), ilist.getPerLabelFeatureSelection(),
withFeatureShrinkage, inducePerClassFeatures, addFeaturesClassEntropyThreshold);
}
} else {
throw new UnsupportedOperationException ("Not yet implemented");
}
}
示例2: printInstanceLists
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public void printInstanceLists ()
{
for (int i = 0; i < memm.numStates(); i++) {
State state = (State) memm.getState (i);
InstanceList training = state.trainingSet;
System.out.println ("State "+i+" : "+state.getName());
if (training == null) {
System.out.println ("No data");
continue;
}
for (int j = 0; j < training.size(); j++) {
Instance inst = training.get (j);
System.out.println ("From : "+state.getName()+" To : "+inst.getTarget());
System.out.println ("Instance "+j);
System.out.println (inst.getTarget());
System.out.println (inst.getData());
}
}
}
示例3: preProcess
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count
int ii = 0;
int fi;
FeatureVector fv;
BitSet bitSet = new BitSet(data.size());
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
for (int ip = 0; ip < fvs.size(); ip++) {
fv = fvs.get(ip);
for (int loc = 0; loc < fv.numLocations(); loc++) {
fi = fv.indexAtLocation(loc);
if (constraints.containsKey(fi)) {
constraints.get(fi).count += 1;
bitSet.set(ii);
}
}
}
ii++;
}
return bitSet;
}
示例4: CRFOptimizableByGE
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public CRFOptimizableByGE(CRF crf, ArrayList<GEConstraint> constraints, InstanceList data, StateLabelMap map, int numThreads, double weight) {
this.crf = crf;
this.constraints = constraints;
this.cache = Integer.MAX_VALUE;
this.cachedValue = Double.NaN;
this.cachedGradient = new CRF.Factors(crf);
this.data = data;
this.numThreads = numThreads;
this.weight = weight;
instancesWithConstraints = new BitSet(data.size());
for (GEConstraint constraint : constraints) {
constraint.setStateLabelMap(map);
BitSet bitset = constraint.preProcess(data);
instancesWithConstraints.or(bitset);
}
this.gpv = DEFAULT_GPV;
if (numThreads > 1) {
this.executor = (ThreadPoolExecutor)Executors.newFixedThreadPool(numThreads);
}
createReverseTransitionMatrices(crf);
}
示例5: preProcess
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count
BitSet bitSet = new BitSet(data.size());
int ii = 0;
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
for (int ip = 1; ip < fvs.size(); ip++) {
for (int fi : constraintsMap.keys()) {
// binary constraint features
if (fvs.get(ip).location(fi) >= 0) {
constraintsList.get(constraintsMap.get(fi)).count += 1;
bitSet.set(ii);
}
}
}
ii++;
}
return bitSet;
}
示例6: averageTokenAccuracy
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/**
* Runs inference across all the instances and returns the average token
* accuracy.
*/
public double averageTokenAccuracy (InstanceList ilist)
{
double accuracy = 0;
for (int i = 0; i < ilist.size(); i++) {
Instance instance = ilist.get(i);
Sequence input = (Sequence) instance.getData();
Sequence output = (Sequence) instance.getTarget();
assert (input.size() == output.size());
Sequence predicted = maxLatticeFactory.newMaxLattice(this, input).bestOutputSequence();
double pathAccuracy = Sequences.elementwiseAccuracy(output, predicted);
accuracy += pathAccuracy;
logger.fine ("Transducer path accuracy = "+pathAccuracy);
}
return accuracy/ilist.size();
}
示例7: predict
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/** This method is deprecated. */
// But it is here as a reminder to do something about induceFeaturesFor(). */
@Deprecated
public Sequence[] predict (InstanceList testing) {
testing.setFeatureSelection(this.globalFeatureSelection);
for (int i = 0; i < featureInducers.size(); i++) {
FeatureInducer klfi = (FeatureInducer)featureInducers.get(i);
klfi.induceFeaturesFor (testing, false, false);
}
Sequence[] ret = new Sequence[testing.size()];
for (int i = 0; i < testing.size(); i++) {
Instance instance = testing.get(i);
Sequence input = (Sequence) instance.getData();
Sequence trueOutput = (Sequence) instance.getTarget();
assert (input.size() == trueOutput.size());
Sequence predOutput = new MaxLatticeDefault(this, input).bestOutputSequence();
assert (predOutput.size() == trueOutput.size());
ret[i] = predOutput;
}
return ret;
}
示例8: trainSample
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
private double trainSample(InstanceList trainingSample, int numIterations,
double rate) {
double lambda = trainingSample.size();
double t = 1 / (lambda * rate);
double loglik = Double.NEGATIVE_INFINITY;
for (int i = 0; i < numIterations; i++) {
loglik = 0.0;
for (int j = 0; j < trainingSample.size(); j++) {
rate = 1 / (lambda * t);
loglik += trainIncrementalLikelihood(trainingSample.get(j),
rate);
t += 1.0;
}
}
return loglik;
}
开发者ID:kostagiolasn,项目名称:NucleosomePatternClassifier,代码行数:19,代码来源:CRFTrainerByStochasticGradient.java
示例9: sampleClustering
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
/**
* Sample a InstanceList and its true clustering.
* @param alph
* @return
*/
private Clustering sampleClustering (Alphabet alph) {
InstanceList instances =
new InstanceList(random,
alph,
new String[]{"foo", "bar"},
30).subList(0, 20);
Clustering singletons = ClusterUtils.createSingletonClustering(instances);
// Merge instances that both have feature0
for (int i = 0; i < instances.size(); i++) {
FeatureVector fvi = (FeatureVector)instances.get(i).getData();
for (int j = i + 1; j < instances.size(); j++) {
FeatureVector fvj = (FeatureVector)instances.get(j).getData();
if (fvi.contains("feature0") && fvj.contains("feature0")) {
singletons = ClusterUtils.mergeClusters(singletons,
singletons.getLabel(i),
singletons.getLabel(j));
} else if (!(fvi.contains("feature0") || fvj.contains("feature0"))
&& random.nextUniform() < noise) {
// Random noise.
singletons = ClusterUtils.mergeClusters(singletons,
singletons.getLabel(i),
singletons.getLabel(j));
}
}
}
return singletons;
}
示例10: Trial
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public Trial (Classifier c, InstanceList ilist)
{
super (ilist.size());
this.classifier = c;
for (Instance instance : ilist)
this.add (c.classify (instance));
}
示例11: collectConstraints
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
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);
}
}
示例12: main
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
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());
}
}
示例13: preProcess
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count
int ii = 0;
int fi;
FeatureVector fv;
BitSet bitSet = new BitSet(data.size());
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
for (int ip = 0; ip < fvs.size(); ip++) {
fv = fvs.get(ip);
for (int loc = 0; loc < fv.numLocations(); loc++) {
fi = fv.indexAtLocation(loc);
if (constraints.containsKey(fi)) {
constraints.get(fi).count += 1;
bitSet.set(ii);
}
}
if (constraints.containsKey(fv.getAlphabet().size())) {
bitSet.set(ii);
constraints.get(fv.getAlphabet().size()).count += 1;
}
}
ii++;
}
return bitSet;
}
示例14: preProcess
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public BitSet preProcess(InstanceList data) {
// count number of tokens
BitSet bitSet = new BitSet(data.size());
bitSet.set(0, data.size(), true);
for (Instance instance : data) {
FeatureVectorSequence fvs = (FeatureVectorSequence)instance.getData();
this.numTokens += fvs.size();
}
return bitSet;
}
示例15: mergeInstancesWithSameLabel
import cc.mallet.types.InstanceList; //导入方法依赖的package包/类
public static Clustering mergeInstancesWithSameLabel (Clustering clustering) {
InstanceList list = clustering.getInstances();
for (int i = 0; i < list.size(); i++) {
Instance ii = list.get(i);
int li = clustering.getLabel(i);
for (int j = i + 1; j < list.size(); j++) {
Instance ij = list.get(j);
int lj = clustering.getLabel(j);
if (li != lj && ii.getLabeling().equals(ij.getLabeling()))
clustering = ClusterUtils.mergeClusters(clustering, li, lj);
}
}
return clustering;
}