Reimplemented from Solver. Definition at line 892 of file svm.cpp. References Solver::active_size, Solver::eps, Solver::G, INF, Solver::is_lower_bound(), Solver::is_upper_bound(), max, and Solver::y. 00893 { 00894 // return i,j which maximize -grad(f)^T d , under constraint 00895 // if alpha_i == C, d != +1 00896 // if alpha_i == 0, d != -1 00897 00898 double Gmax1 = -INF; // max { -grad(f)_i * d | y_i = +1, d = +1 } 00899 int Gmax1_idx = -1; 00900 00901 double Gmax2 = -INF; // max { -grad(f)_i * d | y_i = +1, d = -1 } 00902 int Gmax2_idx = -1; 00903 00904 double Gmax3 = -INF; // max { -grad(f)_i * d | y_i = -1, d = +1 } 00905 int Gmax3_idx = -1; 00906 00907 double Gmax4 = -INF; // max { -grad(f)_i * d | y_i = -1, d = -1 } 00908 int Gmax4_idx = -1; 00909 00910 for(int i=0;i<active_size;i++) 00911 { 00912 if(y[i]==+1) // y == +1 00913 { 00914 if(!is_upper_bound(i)) // d = +1 00915 { 00916 if(-G[i] > Gmax1) 00917 { 00918 Gmax1 = -G[i]; 00919 Gmax1_idx = i; 00920 } 00921 } 00922 if(!is_lower_bound(i)) // d = -1 00923 { 00924 if(G[i] > Gmax2) 00925 { 00926 Gmax2 = G[i]; 00927 Gmax2_idx = i; 00928 } 00929 } 00930 } 00931 else // y == -1 00932 { 00933 if(!is_upper_bound(i)) // d = +1 00934 { 00935 if(-G[i] > Gmax3) 00936 { 00937 Gmax3 = -G[i]; 00938 Gmax3_idx = i; 00939 } 00940 } 00941 if(!is_lower_bound(i)) // d = -1 00942 { 00943 if(G[i] > Gmax4) 00944 { 00945 Gmax4 = G[i]; 00946 Gmax4_idx = i; 00947 } 00948 } 00949 } 00950 } 00951 00952 if(std::max(Gmax1+Gmax2,Gmax3+Gmax4) < eps) 00953 return 1; 00954 00955 if(Gmax1+Gmax2 > Gmax3+Gmax4) 00956 { 00957 out_i = Gmax1_idx; 00958 out_j = Gmax2_idx; 00959 } 00960 else 00961 { 00962 out_i = Gmax3_idx; 00963 out_j = Gmax4_idx; 00964 } 00965 return 0; 00966 }
Here is the call graph for this function:
|