本文整理汇总了Java中cc.mallet.types.LabelAlphabet.size方法的典型用法代码示例。如果您正苦于以下问题:Java LabelAlphabet.size方法的具体用法?Java LabelAlphabet.size怎么用?Java LabelAlphabet.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cc.mallet.types.LabelAlphabet
的用法示例。
在下文中一共展示了LabelAlphabet.size方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: print
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
public void print ()
{
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
System.out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (li));
System.out.println (" <default> "+parameters [li*numFeatures + defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
System.out.println (" "+name+" "+weight);
}
}
}
示例2: createLabelVector
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
/** Constructs a LabelVector which is a distribution over indices of
* the "positive" Instance. */
private LabelVector createLabelVector (LabelAlphabet labelAlphabet, double[] scores) {
if (labelAlphabet.growthStopped())
labelAlphabet.startGrowth();
for (int i=0; i < scores.length; i++)
labelAlphabet.lookupIndex(String.valueOf(i), true);
double[] allScores = new double[labelAlphabet.size()];
for (int i=0; i < labelAlphabet.size(); i++)
allScores[i] = 0.0;
for (int i=0; i < scores.length; i++) {
int index = labelAlphabet.lookupIndex(String.valueOf(i), true);
allScores[index] = scores[i];
}
return new LabelVector(labelAlphabet, allScores);
}
示例3: print
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
public void print ()
{
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = (LabelAlphabet)getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
//for (int li = 0; li < numLabels; li++) {
System.out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (0));
System.out.println (" <default> "+parameters [defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [i];
System.out.println (" "+name+" "+weight);
}
}
示例4: print
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
public void print (PrintStream out)
{
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (li));
out.println (" <default> "+parameters [li*numFeatures + defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
out.println (" "+name+" "+weight);
}
}
}
示例5: print
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
@Override
public void print(PrintWriter out) {
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
out.println ("FEATURES FOR CLASS "+labelDict.lookupObject (li));
out.println (" <default> "+parameters [li*numFeatures + defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
out.println (" "+name+" "+weight);
}
}
}
示例6: printExcel
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
public void printExcel (String directory, String fileName) throws FileNotFoundException
{
File parentDir = new File(directory);
if (!parentDir.exists())
parentDir.mkdirs();
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
File outputFile = new File(directory+labelDict.lookupObject (li)+fileName);
PrintStream out = new PrintStream (outputFile);
out.println (labelDict.lookupObject (li)+",FeatureName,FeatureWeight,Default Parameters :,"+parameters [li*numFeatures + defaultFeatureIndex]);
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
out.println ((i+1)+","+name+","+weight);
}
out.close();
}
}
示例7: printExcelOne
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
public void printExcelOne (String fileName) throws FileNotFoundException
{
final Alphabet dict = getAlphabet();
final LabelAlphabet labelDict = getLabelAlphabet();
int numFeatures = dict.size() + 1;
int numLabels = labelDict.size();
File outputFile = new File(fileName);
PrintStream out = new PrintStream (outputFile);
out.println ("TopicNo,F_No,FeatureName,FeatureWeight,Topic Default Parameter");
// Include the feature weights according to each label
for (int li = 0; li < numLabels; li++) {
for (int i = 0; i < defaultFeatureIndex; i++) {
Object name = dict.lookupObject (i);
double weight = parameters [li*numFeatures + i];
out.println (labelDict.lookupObject (li)+","+(i+1)+","+name+","+weight+","+parameters [li*numFeatures + defaultFeatureIndex]);
}
}
out.close();
}
示例8: Variable
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
public Variable (Universe universe, LabelAlphabet outs)
{
this.universe = universe;
this.outcomes = outs;
if (outs.size() < 1) {
throw new IllegalArgumentException
("Attempt to create variable with "+outs.size()+" outcomes.");
}
setName ();
index = universe.add (this);
}
示例9: ROCData
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
/**
* Constructs a new object
*
* @param thresholds Array of thresholds to track counts for
* @param labelAlphabet Label alphabet for instances in {@link Trial}
*/
public ROCData(double[] thresholds, final LabelAlphabet labelAlphabet) {
// ensure that thresholds are sorted
Arrays.sort(thresholds);
this.counts = new int[labelAlphabet.size()][thresholds.length][4];
this.labelAlphabet = labelAlphabet;
this.thresholds = thresholds;
}
示例10: determineFieldNames
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
private static String[] determineFieldNames (LabelAlphabet dict)
{
List l = new ArrayList ();
for (int i = 0; i < dict.size (); i++) {
String lname = dict.lookupLabel (i).toString ();
if (!lname.startsWith ("B-") && !lname.startsWith ("I-")) {
l.add (lname);
}
}
return (String[]) l.toArray (new String [l.size ()]);
}
示例11: eval
import cc.mallet.types.LabelAlphabet; //导入方法依赖的package包/类
public double[] eval(String[] features) {
Alphabet dataAlphabet = classifer.getAlphabet();
List<Integer> malletFeatureList = new ArrayList<>(features.length);
for (String feature : features) {
int featureId = dataAlphabet.lookupIndex(feature);
if (featureId != -1) {
malletFeatureList.add(featureId);
}
}
int malletFeatures[] = new int[malletFeatureList.size()];
for (int i = 0; i < malletFeatureList.size(); i++) {
malletFeatures[i] = malletFeatureList.get(i);
}
FeatureVector fv = new FeatureVector(classifer.getAlphabet(),
malletFeatures);
Instance instance = new Instance(fv, null, null, null);
Classification result = classifer.classify(instance);
LabelVector labeling = result.getLabelVector();
LabelAlphabet targetAlphabet = classifer.getLabelAlphabet();
double outcomes[] = new double[targetAlphabet.size()];
for (int i = 0; i < outcomes.length; i++) {
Label label = targetAlphabet.lookupLabel(i);
int rank = labeling.getRank(label);
outcomes[i] = labeling.getValueAtRank(rank);
}
return outcomes;
}