C#,数值计算——分类与推理,基座向量机的 Svmgenkernel的计算方法与源程序
1 文本格式
using System;
namespace Legalsoft.Truffer
{
public abstract class Svmgenkernel
{
public int m { get; set; }
public int kcalls { get; set; }
public double[,] ker { get; set; }
public double[] y { get; set; }
public double[,] data { get; set; }
public Svmgenkernel(double[] yy, double[,] ddata)
{
this.m = yy.Length;
this.kcalls = 0;
this.ker = new double[m, m];
this.y = yy;
this.data = ddata;
}
public abstract double kernel(double xi, double xj);
public abstract double kernel(double[] xi, double[] xj);
public double kernel(int i, ref double xj)
{
return kernel(data[i, 0], xj);
}
public void fill()
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j <= i; j++)
{
ker[i, j] = ker[j, i] = kernel(data[i, 0], data[j, 0]);
}
}
}
}
}
2 代码格式
using System;
namespace Legalsoft.Truffer
{
public abstract class Svmgenkernel
{
public int m { get; set; }
public int kcalls { get; set; }
public double[,] ker { get; set; }
public double[] y { get; set; }
public double[,] data { get; set; }
public Svmgenkernel(double[] yy, double[,] ddata)
{
this.m = yy.Length;
this.kcalls = 0;
this.ker = new double[m, m];
this.y = yy;
this.data = ddata;
}
public abstract double kernel(double xi, double xj);
public abstract double kernel(double[] xi, double[] xj);
public double kernel(int i, ref double xj)
{
return kernel(data[i, 0], xj);
}
public void fill()
{
for (int i = 0; i < m; i++)
{
for (int j = 0; j <= i; j++)
{
ker[i, j] = ker[j, i] = kernel(data[i, 0], data[j, 0]);
}
}
}
}
}