1 文本格式
using System;
using System.Collections.Generic;
namespace Legalsoft.Truffer
{
public class Phylo_nj : Phylagglom
{
public double[] u;
public override void premin(double[,] d, int[] nextp)
{
int ncurr = 0;
for (int i = 0; i >= 0; i = nextp[i])
{
ncurr++;
}
for (int i = 0; i >= 0; i = nextp[i])
{
double sum = 0.0;
for (int j = 0; j >= 0; j = nextp[j])
{
if (i != j)
{
sum += d[i, j];
}
}
u[i] = sum / (ncurr - 2);
}
}
public override double dminfn(double[,] d, int i, int j)
{
return d[i, j] - u[i] - u[j];
}
public override double dbranchfn(double[,] d, int i, int j)
{
return 0.5 * (d[i, j] + u[i] - u[j]);
}
public override double dnewfn(double[,] d, int k, int i, int j, int ni, int nj)
{
return 0.5 * (d[i, k] + d[j, k] - d[i, j]);
}
public override void drootbranchfn(double[,] d, int i, int j, int ni, int nj, ref double bi, ref double bj)
{
bi = d[i, j] * (nj - 1 + 1.0e-15) / (ni + nj - 2 + 2.0e-15);
bj = d[i, j] * (ni - 1 + 1.0e-15) / (ni + nj - 2 + 2.0e-15);
}
public Phylo_nj(double[,] dist, int fsr = -1) : base(dist, fsr)
{
this.u = new double[n];
makethetree(dist);
}
}
}
2 代码格式
using System;
using System.Collections.Generic;
namespace Legalsoft.Truffer
{
public class Phylo_nj : Phylagglom
{
public double[] u;
public override void premin(double[,] d, int[] nextp)
{
int ncurr = 0;
for (int i = 0; i >= 0; i = nextp[i])
{
ncurr++;
}
for (int i = 0; i >= 0; i = nextp[i])
{
double sum = 0.0;
for (int j = 0; j >= 0; j = nextp[j])
{
if (i != j)
{
sum += d[i, j];
}
}
u[i] = sum / (ncurr - 2);
}
}
public override double dminfn(double[,] d, int i, int j)
{
return d[i, j] - u[i] - u[j];
}
public override double dbranchfn(double[,] d, int i, int j)
{
return 0.5 * (d[i, j] + u[i] - u[j]);
}
public override double dnewfn(double[,] d, int k, int i, int j, int ni, int nj)
{
return 0.5 * (d[i, k] + d[j, k] - d[i, j]);
}
public override void drootbranchfn(double[,] d, int i, int j, int ni, int nj, ref double bi, ref double bj)
{
bi = d[i, j] * (nj - 1 + 1.0e-15) / (ni + nj - 2 + 2.0e-15);
bj = d[i, j] * (ni - 1 + 1.0e-15) / (ni + nj - 2 + 2.0e-15);
}
public Phylo_nj(double[,] dist, int fsr = -1) : base(dist, fsr)
{
this.u = new double[n];
makethetree(dist);
}
}
}