@Override public double regress(FeatureVector features) { requireNonNull(model, "model is null"); return svm.svm_predict(model, toSvmNodes(features)); }
public static double svm_predict_probability(svm_model model, svm_node[] x, double[] prob_estimates) { if ((model.param.svm_type == svm_parameter.C_SVC || model.param.svm_type == svm_parameter.NU_SVC) && model.probA!=null && model.probB!=null) { int i; int nr_class = model.nr_class; double[] dec_values = new double[nr_class*(nr_class-1)/2]; svm_predict_values(model, x, dec_values); double min_prob=1e-7; double[][] pairwise_prob=new double[nr_class][nr_class]; int k=0; for(i=0;i<nr_class;i++) for(int j=i+1;j<nr_class;j++) { pairwise_prob[i][j]=Math.min(Math.max(sigmoid_predict(dec_values[k],model.probA[k],model.probB[k]),min_prob),1-min_prob); pairwise_prob[j][i]=1-pairwise_prob[i][j]; k++; } multiclass_probability(nr_class,pairwise_prob,prob_estimates); int prob_max_idx = 0; for(i=1;i<nr_class;i++) if(prob_estimates[i] > prob_estimates[prob_max_idx]) prob_max_idx = i; return model.label[prob_max_idx]; } else return svm_predict(model, x); }
int predictedLabel = (int) svm.svm_predict(model, x); double[] probs = new double[x.length]; svm.svm_predict_probability(model, x, probs);
@Override public Integer classify(FeatureVector features) { requireNonNull(model, "model is null"); return (int) svm.svm_predict(model, toSvmNodes(features)); }
@Override LabelledVector doPredict(final boolean withProbabilities, final Vector vector) { final svm_node[] nodes = encodeVector(this.dictionary, vector); if (withProbabilities) { final int numLabels = getParameters().getNumLabels(); final double[] p = new double[numLabels]; final int label = (int) svm.svm_predict_probability(this.model, nodes, p); final float[] probabilities = new float[numLabels]; for (int i = 0; i < p.length; ++i) { final int labelIndex = this.model.label[i]; probabilities[labelIndex] = (float) p[i]; } return vector.label(label, probabilities); } else { final int label = (int) svm.svm_predict(this.model, nodes); return vector.label(label); } }
return svm_predict(model, x);
@Override public Object classify(Instance instance) { svm_node[] x = convert(instance); double d = svm.svm_predict(model, x); Object out = data.classValue((int) d); return out; }
int winner = (int)svm.svm_predict(model, svm_nodes);
public static double svm_predict_probability(svm_model model, svm_node[] x, double[] prob_estimates) { if ((model.param.svm_type == svm_parameter.C_SVC || model.param.svm_type == svm_parameter.NU_SVC) && model.probA!=null && model.probB!=null) { int i; int nr_class = model.nr_class; double[] dec_values = new double[nr_class*(nr_class-1)/2]; svm_predict_values(model, x, dec_values); double min_prob=1e-7; double[][] pairwise_prob=new double[nr_class][nr_class]; int k=0; for(i=0;i<nr_class;i++) for(int j=i+1;j<nr_class;j++) { pairwise_prob[i][j]=Math.min(Math.max(sigmoid_predict(dec_values[k],model.probA[k],model.probB[k]),min_prob),1-min_prob); pairwise_prob[j][i]=1-pairwise_prob[i][j]; k++; } multiclass_probability(nr_class,pairwise_prob,prob_estimates); int prob_max_idx = 0; for(i=1;i<nr_class;i++) if(prob_estimates[i] > prob_estimates[prob_max_idx]) prob_max_idx = i; return model.label[prob_max_idx]; } else return svm_predict(model, x); }
@Override public Integer classify(FeatureVector features) { requireNonNull(model, "model is null"); return (int) svm.svm_predict(model, toSvmNodes(features)); }
@Override public double regress(FeatureVector features) { requireNonNull(model, "model is null"); return svm.svm_predict(model, toSvmNodes(features)); }
public boolean isTextual(ConnectedComponent ele){ return (int)(svm.svm_predict(model,getFeature(ele))+0.5)==1; } public static svm_node[] getFeature(ConnectedComponent ele){
@Override public Category classify(Observation obs) { if(this.model != null) return new DoubleCategory(svm.svm_predict(this.model, obs.toSvmNode())); throw new RuntimeException("Support Vector Machine is not initialized"); }
/** * {@inheritDoc} * @see org.openimaj.ml.annotation.Annotator#annotate(java.lang.Object) */ @Override public List<ScoredAnnotation<ANNOTATION>> annotate( final OBJECT object ) { // Extract the feature and convert to a svm_node[] final svm_node[] nodes = SVMAnnotator.featureToNode( this.extractor.extractFeature( object ) ); // Use the trained SVM model to predict the new buffer's annotation final double x = svm.svm_predict( this.model, nodes ); // Create a singleton list to contain the classified annotation. return Collections.singletonList( new ScoredAnnotation<ANNOTATION>( x > 0 ? this.classMap.get(SVMAnnotator.POSITIVE_CLASS) : this.classMap.get(SVMAnnotator.NEGATIVE_CLASS), 1.0f ) ); }
BxZoneLabel predictZoneLabel(BxZone zone) { svm_node[] instance = buildDatasetForClassification(zone); double predictedVal = svm.svm_predict(model, instance); return BxZoneLabel.values()[(int)predictedVal]; }
public OUTCOME_TYPE classify(List<Feature> features) throws CleartkProcessingException { FeatureVector featureVector = this.featuresEncoder.encodeAll(features); ENCODED_OUTCOME_TYPE encodedOutcome = decodePrediction(libsvm.svm.svm_predict( this.model, convertToLIBSVM(featureVector))); return outcomeEncoder.decode(encodedOutcome); }
public OUTCOME_TYPE classify(List<Feature> features) throws CleartkProcessingException { FeatureVector featureVector = this.featuresEncoder.encodeAll(features); ENCODED_OUTCOME_TYPE encodedOutcome = decodePrediction(libsvm.svm.svm_predict( this.model, convertToLIBSVM(featureVector))); return outcomeEncoder.decode(encodedOutcome); }
@Override public BxDocument classifyZones(BxDocument document) throws AnalysisException { for (BxZone zone: document.asZones()) { svm_node[] instance = buildDatasetForClassification(zone); double predictedVal = svm.svm_predict(model, instance); System.out.println("predictedVal " + predictedVal + " " + BxZoneLabel.values()[(int)predictedVal/100] + " (" + zone.getLabel() + ")"); zone.setLabel(BxZoneLabel.values()[(int)predictedVal/100]); } return document; }
@Override public NavigableSet<CharacterCandidate> recognize(ConnectedComponent component,Object model,CharacterList list){ SvmModel svmModel=(SvmModel)model; int variables=svmModel.getFeatures().stream().mapToInt((name)->((VectorFeature)Features.REGISTRY.get(name)).getDimension()).sum(); svm_node[] vector=new svm_node[variables]; int j=0; for(String name:svmModel.getFeatures()){ double[] sub=(double[])Features.REGISTRY.get(name).extract(component); for(double d:sub){ svm_node node=new svm_node(); node.index=j; node.value=d; vector[j++]=node; } } int candidate=(int)(svm.svm_predict(svmModel.getModel(),vector)+0.5); if(candidate>=0&&candidate<list.getCharacters().size()){ TreeSet<CharacterCandidate> treeSet=new TreeSet<>(); treeSet.add(list.getCharacters().get(candidate).toCandidate(component.getBox(),1.0)); return treeSet; }else{ return Collections.emptyNavigableSet(); } } @Override
public double classifyTest(IIndex testIndex, int docID) { ClassificationResult res = new ClassificationResult(); IIntIterator feats = testIndex.getContentDB() .getDocumentFeatures(docID); svm_node[] doc = new svm_node[testIndex.getContentDB() .getDocumentFeaturesCount(docID)]; int i = 0; int featID = 0; while (feats.hasNext()) { featID = feats.next(); svm_node node = new svm_node(); node.index = featID + 1; node.value = testIndex.getWeightingDB().getDocumentFeatureWeight( docID, featID); doc[i++] = node; } res.documentID = docID; double prediction = svm.svm_predict(_model, doc); return prediction; }