Definition at line 1664 of file svm.cpp. References info(), and Malloc. Referenced by svm_predict_probability(). 01665 { 01666 int t; 01667 int iter = 0, max_iter=100; 01668 double **Q=Malloc(double *,k); 01669 double *Qp=Malloc(double,k); 01670 double pQp, eps=0.001; 01671 01672 for (t=0;t<k;t++) 01673 { 01674 p[t]=1.0/k; // Valid if k = 1 01675 Q[t]=Malloc(double,k); 01676 Q[t][t]=0; 01677 int j; 01678 for ( j=0;j<t;j++) 01679 { 01680 Q[t][t]+=r[j][t]*r[j][t]; 01681 Q[t][j]=Q[j][t]; 01682 } 01683 for ( j=t+1;j<k;j++) 01684 { 01685 Q[t][t]+=r[j][t]*r[j][t]; 01686 Q[t][j]=-r[j][t]*r[t][j]; 01687 } 01688 } 01689 for (iter=0;iter<max_iter;iter++) 01690 { 01691 // stopping condition, recalculate QP,pQP for numerical accuracy 01692 pQp=0; 01693 for (t=0;t<k;t++) 01694 { 01695 Qp[t]=0; 01696 for (int j=0;j<k;j++) 01697 Qp[t]+=Q[t][j]*p[j]; 01698 pQp+=p[t]*Qp[t]; 01699 } 01700 double max_error=0; 01701 for (t=0;t<k;t++) 01702 { 01703 double error=fabs(Qp[t]-pQp); 01704 if (error>max_error) 01705 max_error=error; 01706 } 01707 if (max_error<eps) break; 01708 01709 for (t=0;t<k;t++) 01710 { 01711 double diff=(-Qp[t]+pQp)/Q[t][t]; 01712 p[t]+=diff; 01713 pQp=(pQp+diff*(diff*Q[t][t]+2*Qp[t]))/(1+diff)/(1+diff); 01714 for (int j=0;j<k;j++) 01715 { 01716 Qp[j]=(Qp[j]+diff*Q[t][j])/(1+diff); 01717 p[j]/=(1+diff); 01718 } 01719 } 01720 } 01721 if (iter>=max_iter) 01722 info("Exceeds max_iter in multiclass_prob\n"); 01723 for(t=0;t<k;t++) free(Q[t]); 01724 free(Q); 01725 free(Qp); 01726 }
Here is the call graph for this function:
|