Changeset 11607:8ecd4831def9 in orange for source/orange/libsvm_interface.cpp
 Timestamp:
 07/01/13 16:25:11 (10 months ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

source/orange/libsvm_interface.cpp
r11606 r11607 727 727 PExampleTable supportVectors = extract_support_vectors(model, examples); 728 728 729 PVariable classVar; 730 731 if (param.svm_type == ONE_CLASS) { 732 classVar = mlnew TFloatVariable("one class"); 733 } else { 734 classVar = examples>domain>classVar; 735 } 736 737 return PClassifier(createClassifier(classVar, examples, supportVectors, model)); 729 PDomain domain = examples>domain; 730 731 return PClassifier(createClassifier(examples>domain, model, supportVectors, examples)); 738 732 } 739 733 … … 766 760 767 761 TSVMClassifier* TSVMLearner::createClassifier( 768 P Variable classVar, PExampleTable examples, PExampleTable supportVectors, svm_model* model) {762 PDomain domain, svm_model* model, PExampleTable supportVectors, PExampleTable examples) { 769 763 if (kernel_type != PRECOMPUTED) { 770 764 examples = NULL; 771 765 } 772 return mlnew TSVMClassifier( classVar, examples, supportVectors, model, kernelFunc);766 return mlnew TSVMClassifier(domain, model, supportVectors, kernelFunc, examples); 773 767 } 774 768 … … 790 784 791 785 TSVMClassifier* TSVMLearnerSparse::createClassifier( 792 P Variable classVar, PExampleTable examples, PExampleTable supportVectors, svm_model* model) {786 PDomain domain, svm_model* model, PExampleTable supportVectors, PExampleTable examples) { 793 787 if (kernel_type != PRECOMPUTED) { 794 788 examples = NULL; 795 789 } 796 return mlnew TSVMClassifierSparse( classVar, examples, supportVectors, model, useNonMeta, kernelFunc);790 return mlnew TSVMClassifierSparse(domain, model, useNonMeta, supportVectors, kernelFunc, examples); 797 791 } 798 792 799 793 800 794 TSVMClassifier::TSVMClassifier( 801 const PVariable &var, 802 PExampleTable examples, 795 PDomain domain, svm_model * model, 803 796 PExampleTable supportVectors, 804 svm_model* model, 805 PKernelFunc kernelFunc) { 806 this>classVar = var; 797 PKernelFunc kernelFunc, 798 PExampleTable examples 799 ) : TClassifierFD(domain) { 800 this>model = model; 801 this>supportVectors = supportVectors; 802 this>kernelFunc = kernelFunc; 807 803 this>examples = examples; 808 this>supportVectors = supportVectors; 809 this>model = model; 810 this>kernelFunc = kernelFunc; 811 812 domain = supportVectors>domain; 804 813 805 svm_type = svm_get_svm_type(model); 814 806 kernel_type = model>param.kernel_type; 815 807 808 if (svm_type == ONE_CLASS) { 809 this>classVar = mlnew TFloatVariable("one class"); 810 } 811 816 812 computesProbabilities = model && svm_check_probability_model(model) && \ 817 (svm_type != NU_SVR && svm_type != EPSILON_SVR); // Disable prob. estimation for regression813 (svm_type != NU_SVR && svm_type != EPSILON_SVR); // Disable prob. estimation for regression 818 814 819 815 int nr_class = svm_get_nr_class(model); … … 823 819 * class interface. 824 820 */ 825 if (svm_type == C_SVC  svm_type == NU_SVC){ 826 nSV = mlnew TIntList(nr_class); // num of SVs for each class (sum = model>l) 827 for(i = 0;i < nr_class; i++) 828 nSV>at(i) = model>nSV[i]; 829 } 821 if (svm_type == C_SVC  svm_type == NU_SVC) { 822 nSV = mlnew TIntList(nr_class); // num of SVs for each class (sum(nSV) == model>l) 823 for(i = 0;i < nr_class; i++) { 824 nSV>at(i) = model>nSV[i]; 825 } 826 } 830 827 831 828 coef = mlnew TFloatListList(nr_class1); 832 for(i = 0; i < nr_class  1; i++) {829 for(i = 0; i < nr_class  1; i++) { 833 830 TFloatList *coefs = mlnew TFloatList(model>l); 834 for(int j = 0;j < model>l; j++) 831 for(int j = 0;j < model>l; j++) { 835 832 coefs>at(j) = model>sv_coef[i][j]; 836 coef>at(i)=coefs; 837 } 838 rho = mlnew TFloatList(nr_class*(nr_class1)/2); 839 for(i = 0; i < nr_class*(nr_class1)/2; i++) 833 } 834 coef>at(i) = coefs; 835 } 836 837 // Number of binary classifiers in the model 838 int nr_bin_cls = nr_class * (nr_class  1) / 2; 839 840 rho = mlnew TFloatList(nr_bin_cls); 841 for(i = 0; i < nr_bin_cls; i++) { 840 842 rho>at(i) = model>rho[i]; 841 if(model>probA){ 842 probA = mlnew TFloatList(nr_class*(nr_class1)/2); 843 if (model>param.svm_type != NU_SVR && model>param.svm_type != EPSILON_SVR && model>probB) // Regression has only probA 844 probB = mlnew TFloatList(nr_class*(nr_class1)/2); 845 for(i=0; i<nr_class*(nr_class1)/2; i++){ 843 } 844 845 if(model>probA) { 846 probA = mlnew TFloatList(nr_bin_cls); 847 if (model>param.svm_type != NU_SVR && model>param.svm_type != EPSILON_SVR && model>probB) { 848 // Regression only has probA 849 probB = mlnew TFloatList(nr_bin_cls); 850 } 851 852 for(i=0; i<nr_bin_cls; i++) { 846 853 probA>at(i) = model>probA[i]; 847 if (model>param.svm_type != NU_SVR && model>param.svm_type != EPSILON_SVR && model>probB) 854 if (model>param.svm_type != NU_SVR && model>param.svm_type != EPSILON_SVR && model>probB) { 848 855 probB>at(i) = model>probB[i]; 849 } 850 } 851 } 856 } 857 } 858 } 859 } 860 852 861 853 862 TSVMClassifier::~TSVMClassifier(){ … … 856 865 } 857 866 } 867 858 868 859 869 PDistribution TSVMClassifier::classDistribution(const TExample & example){
Note: See TracChangeset
for help on using the changeset viewer.