本文整理汇总了C#中Encog.MathUtil.LIBSVM.svm_parameter.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# svm_parameter.Clone方法的具体用法?C# svm_parameter.Clone怎么用?C# svm_parameter.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Encog.MathUtil.LIBSVM.svm_parameter
的用法示例。
在下文中一共展示了svm_parameter.Clone方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: svm_svr_probability
// Return parameter of a Laplace distribution
private static double svm_svr_probability(svm_problem prob, svm_parameter param)
{
int i;
int nr_fold = 5;
var ymv = new double[prob.l];
double mae = 0;
var newparam = (svm_parameter) param.Clone();
newparam.probability = 0;
svm_cross_validation(prob, newparam, nr_fold, ymv);
for (i = 0; i < prob.l; i++)
{
ymv[i] = prob.y[i] - ymv[i];
mae += Math.Abs(ymv[i]);
}
mae /= prob.l;
double std = Math.Sqrt(2*mae*mae);
int count = 0;
mae = 0;
for (i = 0; i < prob.l; i++)
if (Math.Abs(ymv[i]) > 5*std)
count = count + 1;
else
mae += Math.Abs(ymv[i]);
mae /= (prob.l - count);
Console.Error.Write(
"Prob. model for test data: target value = predicted value + z,\nz: Laplace distribution e^(-|z|/sigma)/(2sigma),sigma=" +
mae + "\n");
return mae;
}
示例2: svm_binary_svc_probability
// Cross-validation decision values for probability estimates
private static void svm_binary_svc_probability(svm_problem prob, svm_parameter param, double Cp, double Cn,
double[] probAB)
{
int i;
int nr_fold = 5;
var perm = new int[prob.l];
var dec_values = new double[prob.l];
// random shuffle
for (i = 0; i < prob.l; i++)
perm[i] = i;
for (i = 0; i < prob.l; i++)
{
//UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1042_3"'
int j = i + (int) (SupportClass.Random.NextDouble()*(prob.l - i));
do
{
int _ = perm[i];
perm[i] = perm[j];
perm[j] = _;
} while (false);
}
for (i = 0; i < nr_fold; i++)
{
int begin = i*prob.l/nr_fold;
int end = (i + 1)*prob.l/nr_fold;
int j, k;
var subprob = new svm_problem();
subprob.l = prob.l - (end - begin);
subprob.x = new svm_node[subprob.l][];
subprob.y = new double[subprob.l];
k = 0;
for (j = 0; j < begin; j++)
{
subprob.x[k] = prob.x[perm[j]];
subprob.y[k] = prob.y[perm[j]];
++k;
}
for (j = end; j < prob.l; j++)
{
subprob.x[k] = prob.x[perm[j]];
subprob.y[k] = prob.y[perm[j]];
++k;
}
int p_count = 0, n_count = 0;
for (j = 0; j < k; j++)
if (subprob.y[j] > 0)
p_count++;
else
n_count++;
if (p_count == 0 && n_count == 0)
for (j = begin; j < end; j++)
dec_values[perm[j]] = 0;
else if (p_count > 0 && n_count == 0)
for (j = begin; j < end; j++)
dec_values[perm[j]] = 1;
else if (p_count == 0 && n_count > 0)
for (j = begin; j < end; j++)
dec_values[perm[j]] = - 1;
else
{
var subparam = (svm_parameter) param.Clone();
subparam.probability = 0;
subparam.C = 1.0;
subparam.nr_weight = 2;
subparam.weight_label = new int[2];
subparam.weight = new double[2];
subparam.weight_label[0] = + 1;
subparam.weight_label[1] = - 1;
subparam.weight[0] = Cp;
subparam.weight[1] = Cn;
svm_model submodel = svm_train(subprob, subparam);
for (j = begin; j < end; j++)
{
var dec_value = new double[1];
svm_predict_values(submodel, prob.x[perm[j]], dec_value);
dec_values[perm[j]] = dec_value[0];
// ensure +1 -1 order; reason not using CV subroutine
dec_values[perm[j]] *= submodel.label[0];
}
}
}
sigmoid_train(prob.l, dec_values, prob.y, probAB);
}