public Solve ( int length, |
||
length | int | |
Q | ||
p | double | |
y | sbyte | |
alpha | double | |
Cp | double | |
Cn | double | |
eps | double | |
si | LibSvm.SolutionInfo | |
shrinking | bool | |
return | void |
private static void solve_nu_svr(SvmProblem prob, SvmParameter param, double[] alpha, SolutionInfo si) { int l = prob.Lenght; double C = param.C; double[] alpha2 = new double[2 * l]; double[] linear_term = new double[2 * l]; sbyte[] y = new sbyte[2 * l]; int i; double sum = C * param.Nu * l / 2; for (i = 0; i < l; i++) { alpha2[i] = alpha2[i + l] = Math.Min(sum, C); sum -= alpha2[i]; linear_term[i] = -prob.Y[i]; y[i] = 1; linear_term[i + l] = prob.Y[i]; y[i + l] = -1; } var s = new SolverNu(); s.Solve(2 * l, new SvrQ(prob, param), linear_term, y, alpha2, C, C, param.Eps, si, param.Shrinking); Svm.info("epsilon = " + (-si.R) + "\n"); for (i = 0; i < l; i++) { alpha[i] = alpha2[i] - alpha2[i + l]; } }
private static void solve_nu_svr(SvmProblem prob, SvmParameter param, double[] alpha, SolutionInfo si) { int l = prob.Lenght; double C = param.C; double[] alpha2 = new double[2 * l]; double[] linear_term = new double[2 * l]; sbyte[] y = new sbyte[2 * l]; int i; double sum = C * param.Nu * l / 2; for (i = 0; i < l; i++) { alpha2[i] = alpha2[i + l] = Math.Min(sum, C); sum -= alpha2[i]; linear_term[i] = -prob.Y[i]; y[i] = 1; linear_term[i + l] = prob.Y[i]; y[i + l] = -1; } var s = new SolverNu(); s.Solve(2 * l, new SvrQ(prob, param), linear_term, y, alpha2, C, C, param.Eps, si, param.Shrinking); Svm.info("epsilon = " + (-si.R) + "\n"); for (i = 0; i < l; i++) alpha[i] = alpha2[i] - alpha2[i + l]; }
private static void solve_nu_svc(SvmProblem prob, SvmParameter param, double[] alpha, SolutionInfo si) { int i; int l = prob.Lenght; double nu = param.Nu; sbyte[] y = new sbyte[l]; for (i = 0; i < l; i++) if (prob.Y[i] > 0) y[i] = +1; else y[i] = -1; double sum_pos = nu * l / 2; double sum_neg = nu * l / 2; for (i = 0; i < l; i++) if (y[i] == +1) { alpha[i] = Math.Min(1.0, sum_pos); sum_pos -= alpha[i]; } else { alpha[i] = Math.Min(1.0, sum_neg); sum_neg -= alpha[i]; } double[] zeros = new double[l]; for (i = 0; i < l; i++) zeros[i] = 0; var s = new SolverNu(); s.Solve(l, new SvcQ(prob, param, y), zeros, y, alpha, 1.0, 1.0, param.Eps, si, param.Shrinking); double r = si.R; Svm.info("C = " + 1 / r + "\n"); for (i = 0; i < l; i++) alpha[i] *= y[i] / r; si.Rho /= r; si.Obj /= (r * r); si.UpperBoundP = 1 / r; si.UpperBoundN = 1 / r; }
private static void solve_nu_svc(SvmProblem prob, SvmParameter param, double[] alpha, SolutionInfo si) { int i; int l = prob.Lenght; double nu = param.Nu; sbyte[] y = new sbyte[l]; for (i = 0; i < l; i++) { if (prob.Y[i] > 0) { y[i] = +1; } else { y[i] = -1; } } double sum_pos = nu * l / 2; double sum_neg = nu * l / 2; for (i = 0; i < l; i++) { if (y[i] == +1) { alpha[i] = Math.Min(1.0, sum_pos); sum_pos -= alpha[i]; } else { alpha[i] = Math.Min(1.0, sum_neg); sum_neg -= alpha[i]; } } double[] zeros = new double[l]; for (i = 0; i < l; i++) { zeros[i] = 0; } var s = new SolverNu(); s.Solve(l, new SvcQ(prob, param, y), zeros, y, alpha, 1.0, 1.0, param.Eps, si, param.Shrinking); double r = si.R; Svm.info("C = " + 1 / r + "\n"); for (i = 0; i < l; i++) { alpha[i] *= y[i] / r; } si.Rho /= r; si.Obj /= (r * r); si.UpperBoundP = 1 / r; si.UpperBoundN = 1 / r; }