1 文本格式
using System;
namespace Legalsoft.Truffer
{
public class Svmlinkernel : Svmgenkernel
{
public int n { get; set; }
public double[] mu { get; set; }
public Svmlinkernel(double[,] ddata, double[] yy) : base(yy, ddata)
{
this.n = data.GetLength(1);
this.mu = new double[n];
for (int j = 0; j < n; j++)
{
mu[j] = 0.0;
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
mu[j] += data[i, j];
}
}
for (int j = 0; j < n; j++)
{
mu[j] /= m;
}
fill();
}
public override double kernel(double xi, double xj)
{
return 0.0;
}
public override double kernel(double[] xi, double[] xj)
{
double dott = 0.0;
for (int k = 0; k < n; k++)
{
dott += (xi[k] - mu[k]) * (xj[k] - mu[k]);
}
return dott;
}
}
}
2 代码格式
cs
using System;
namespace Legalsoft.Truffer
{
public class Svmlinkernel : Svmgenkernel
{
public int n { get; set; }
public double[] mu { get; set; }
public Svmlinkernel(double[,] ddata, double[] yy) : base(yy, ddata)
{
this.n = data.GetLength(1);
this.mu = new double[n];
for (int j = 0; j < n; j++)
{
mu[j] = 0.0;
}
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
mu[j] += data[i, j];
}
}
for (int j = 0; j < n; j++)
{
mu[j] /= m;
}
fill();
}
public override double kernel(double xi, double xj)
{
return 0.0;
}
public override double kernel(double[] xi, double[] xj)
{
double dott = 0.0;
for (int k = 0; k < n; k++)
{
dott += (xi[k] - mu[k]) * (xj[k] - mu[k]);
}
return dott;
}
}
}