本文整理汇总了Java中de.bwaldvogel.liblinear.Model.getNrClass方法的典型用法代码示例。如果您正苦于以下问题:Java Model.getNrClass方法的具体用法?Java Model.getNrClass怎么用?Java Model.getNrClass使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类de.bwaldvogel.liblinear.Model
的用法示例。
在下文中一共展示了Model.getNrClass方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: predict
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
@Override
protected double[] predict(Model model, FeatureNode[] featuresNodes) {
double[] temp,probs;
int classes,label;
double sum = 0;
classes = model.getNrClass();
temp = new double[classes];
Linear.predictValues(model, featuresNodes, temp);
for (int i = 0; i < classes; i++) {
temp[i] = 1 / (1 + Math.exp(-temp[i]));
sum += temp[i];
}
probs=new double[classes];
for(int i=0;i<classes;i++){
label = model.getLabels()[i];
if (label > 0)
probs[label-1]=temp[i]/sum;
}
return probs;
}
示例2: liblinear_predict_with_kbestlist
import de.bwaldvogel.liblinear.Model; //导入方法依赖的package包/类
public void liblinear_predict_with_kbestlist(Model model, FeatureNode[] x, KBestList kBestList) throws MaltChainedException {
int i;
final int nr_class = model.getNrClass();
final double[] dec_values = new double[nr_class];
Linear.predictValues(model, x, dec_values);
final int[] labels = model.getLabels();
int[] predictionList = new int[nr_class];
for(i=0;i<nr_class;i++) {
predictionList[i] = labels[i];
}
double tmpDec;
int tmpObj;
int lagest;
for (i=0;i<nr_class-1;i++) {
lagest = i;
for (int j=i;j<nr_class;j++) {
if (dec_values[j] > dec_values[lagest]) {
lagest = j;
}
}
tmpDec = dec_values[lagest];
dec_values[lagest] = dec_values[i];
dec_values[i] = tmpDec;
tmpObj = predictionList[lagest];
predictionList[lagest] = predictionList[i];
predictionList[i] = tmpObj;
}
int k = nr_class-1;
if (kBestList.getK() != -1) {
k = kBestList.getK() - 1;
}
for (i=0; i<nr_class && k >= 0; i++, k--) {
if (kBestList instanceof ScoredKBestList) {
((ScoredKBestList)kBestList).add(predictionList[i], (float)dec_values[i]);
} else {
kBestList.add(predictionList[i]);
}
}
}