Changeset 8133:479a89d80e6f in orange


Ignore:
Timestamp:
08/01/11 17:33:34 (3 years ago)
Author:
ales_erjavec <ales.erjavec@…>
Branch:
default
Convert:
d684382cb1658324874ddbbdc171ee8566074d28
Message:

Fixed handling of probability models in SVMClassifier (fixes #874).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • source/orange/svm.cpp

    r7160 r8133  
    37273727    model->param.learner=NULL; 
    37283728    currentExample=NULL; 
    3729     computesProbabilities = model && model->param.svm_type!=EPSILON_SVR && 
    3730         model->param.svm_type!=NU_SVR &&  (model->param.probability != 0); 
     3729    int svm_type = svm_get_svm_type(model); 
     3730    computesProbabilities = model && svm_check_probability_model(model) && \ 
     3731            (svm_type != NU_SVR && svm_type != EPSILON_SVR); // Disable prob. estimation for regression 
    37313732    if(!classVar && model->param.svm_type==ONE_CLASS) 
    37323733        classVar=mlnew TFloatVariable(); 
     
    37433744        } 
    37443745    } 
    3745     int svm_type=model->param.svm_type; 
     3746     
    37463747    if (svm_type==C_SVC || svm_type==NU_SVC){ 
    37473748        nSV=mlnew TIntList(nr_class); // num of SVs for each class (sum = model->l) 
     
    37803781 
    37813782PDistribution TSVMClassifier::classDistribution(const TExample & example){ 
     3783    if(!model) 
     3784        raiseError("No Model"); 
     3785 
    37823786    if(!computesProbabilities) 
    37833787        return TClassifierFD::classDistribution(example); 
    3784     if(!model) 
    3785         raiseError("No Model"); 
     3788 
    37863789    currentExample=&example; 
    37873790    int exlen=getNumOfElements(example); 
    37883791    int svm_type=svm_get_svm_type(model); 
    37893792    int nr_class=svm_get_nr_class(model); 
    3790     if(svm_type==NU_SVR || svm_type==EPSILON_SVR) 
    3791         raiseError("Model does not support probabilities for regression"); 
     3793 
    37923794    int *labels=(int *) malloc(nr_class*sizeof(int)); 
    37933795    double *prob_estimates=NULL; 
    37943796    svm_node *x=Malloc(svm_node, exlen); 
    3795     svm_get_labels(model,labels); 
     3797    svm_get_labels(model, labels); 
    37963798    prob_estimates = (double *) malloc(nr_class*sizeof(double)); 
    37973799    example_to_svm(example, x, -1.0, (model->param.kernel_type==CUSTOM)? 1:0); 
     
    38183820    example_to_svm(example, x, -1.0, (model->param.kernel_type==CUSTOM)? 1:0); 
    38193821    double v; 
    3820     if(model->param.probability){ 
     3822    if(svm_check_probability_model(model)){ 
    38213823        double *prob=(double *) malloc(nr_class*sizeof(double)); 
    38223824        v=svm_predict_probability(model,x, prob); 
Note: See TracChangeset for help on using the changeset viewer.