double f=0;
int *y=prob->y;
int l=prob->l;
- int n=prob->n;
+ int w_size=get_nr_variable();
Xv(w, z);
for(i=0;i<l;i++)
f += C[i]*(-yz+log(1 + exp(yz)));
}
f = 2*f;
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
f += w[i]*w[i];
f /= 2.0;
int i;
int *y=prob->y;
int l=prob->l;
- int n=prob->n;
+ int w_size=get_nr_variable();
for(i=0;i<l;i++)
{
}
XTv(z, g);
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
g[i] = w[i] + g[i];
}
{
int i;
int l=prob->l;
- int n=prob->n;
+ int w_size=get_nr_variable();
double *wa = new double[l];
Xv(s, wa);
wa[i] = C[i]*D[i]*wa[i];
XTv(wa, Hs);
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
Hs[i] = s[i] + Hs[i];
delete[] wa;
}
{
int i;
int l=prob->l;
- int n=prob->n;
+ int w_size=get_nr_variable();
feature_node **x=prob->x;
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
XTv[i]=0;
for(i=0;i<l;i++)
{
double f=0;
int *y=prob->y;
int l=prob->l;
- int n=prob->n;
+ int w_size=get_nr_variable();
Xv(w, z);
for(i=0;i<l;i++)
f += C[i]*d*d;
}
f = 2*f;
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
f += w[i]*w[i];
f /= 2.0;
int i;
int *y=prob->y;
int l=prob->l;
- int n=prob->n;
+ int w_size=get_nr_variable();
sizeI = 0;
for (i=0;i<l;i++)
}
subXTv(z, g);
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
g[i] = w[i] + 2*g[i];
}
{
int i;
int l=prob->l;
- int n=prob->n;
+ int w_size=get_nr_variable();
double *wa = new double[l];
subXv(s, wa);
wa[i] = C[I[i]]*wa[i];
subXTv(wa, Hs);
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
Hs[i] = s[i] + 2*Hs[i];
delete[] wa;
}
void l2loss_svm_fun::subXTv(double *v, double *XTv)
{
int i;
- int n=prob->n;
+ int w_size=get_nr_variable();
feature_node **x=prob->x;
- for(i=0;i<n;i++)
+ for(i=0;i<w_size;i++)
XTv[i]=0;
for(i=0;i<sizeI;i++)
{
void solve_sub_problem(double A_i, int yi, double C_yi, int active_i, double *alpha_new);
bool be_shrunk(int m, int yi, double alpha_i, double minG);
double *B, *C, *G;
- int n, l;
+ int w_size, l;
int nr_class;
int max_iter;
double eps;
Solver_MCSVM_CS::Solver_MCSVM_CS(const problem *prob, int nr_class, double *C, double eps, int max_iter)
{
- this->n = prob->n;
+ this->w_size = prob->n;
this->l = prob->l;
this->nr_class = nr_class;
this->eps = eps;
// initial
for(i=0;i<l*nr_class;i++)
alpha[i] = 0;
- for(i=0;i<n*nr_class;i++)
+ for(i=0;i<w_size*nr_class;i++)
w[i] = 0;
for(i=0;i<l;i++)
{
// calculate objective value
double v = 0;
int nSV = 0;
- for(i=0;i<n*nr_class;i++)
+ for(i=0;i<w_size*nr_class;i++)
v += w[i]*w[i];
v = 0.5*v;
for(i=0;i<l*nr_class;i++)
double Cp, double Cn, int solver_type)
{
int l = prob->l;
- int n = prob->n;
+ int w_size = prob->n;
int i, s, iter = 0;
double C, d, G;
double *QD = new double[l];
upper_bound_p = Cp; upper_bound_n = Cn;
}
- for(i=0; i<n; i++)
+ for(i=0; i<w_size; i++)
w[i] = 0;
for(i=0; i<l; i++)
{
double v = 0;
int nSV = 0;
- for(i=0; i<n; i++)
+ for(i=0; i<w_size; i++)
v += w[i]*w[i];
for(i=0; i<l; i++)
{
int i,j;
int l = prob->l;
int n = prob->n;
+ int w_size = prob->n;
model *model_ = Malloc(model,1);
if(prob->bias>=0)
{
if(nr_class == 2)
{
- model_->w=Malloc(double, n);
+ model_->w=Malloc(double, w_size);
int e0 = start[0]+count[0];
k=0;
}
else
{
- model_->w=Malloc(double, n*nr_class);
- double *w=Malloc(double, n);
+ model_->w=Malloc(double, w_size*nr_class);
+ double *w=Malloc(double, w_size);
for(i=0;i<nr_class;i++)
{
int si = start[i];
train_one(&sub_prob, param, w, weighted_C[i], param->C);
- for(int j=0;j<n;j++)
+ for(int j=0;j<w_size;j++)
model_->w[j*nr_class+i] = w[j];
}
free(w);
n=nr_feature+1;
else
n=nr_feature;
+ int w_size = n;
FILE *fp = fopen(model_file_name,"w");
if(fp==NULL) return -1;
fprintf(fp, "bias %.16g\n", model_->bias);
fprintf(fp, "w\n");
- for(i=0; i<n; i++)
+ for(i=0; i<w_size; i++)
{
int j;
for(j=0; j<nr_w; j++)
n=nr_feature+1;
else
n=nr_feature;
-
+ int w_size = n;
int nr_w;
if(nr_class==2 && param.solver_type != MCSVM_CS)
nr_w = 1;
else
nr_w = nr_class;
- model_->w=Malloc(double, n*nr_w);
- for(i=0; i<n; i++)
+ model_->w=Malloc(double, w_size*nr_w);
+ for(i=0; i<w_size; i++)
{
int j;
for(j=0; j<nr_w; j++)