1 文本格式
using System;
namespace Legalsoft.Truffer
{
public class Plog
{
private int ndat { get; set; }
private double[] dat { get; set; }
private double[] stau { get; set; }
private double[] slogtau { get; set; }
public Plog(double[] data)
{
this.dat = data;
this.ndat = data.Length;
this.stau = new double[ndat];
this.slogtau = new double[ndat];
stau[0] = slogtau[0] = 0.0;
for (int i = 1; i < ndat; i++)
{
stau[i] = dat[i] - dat[0];
slogtau[i] = slogtau[i - 1] + Math.Log(dat[i] - dat[i - 1]);
}
}
public double get(State s)
{
int ilo = 0;
int ihi = ndat - 1;
while (ihi - ilo > 1)
{
int i = (ihi + ilo) >> 1;
if (s.tc > dat[i])
{
ilo = i;
}
else
{
ihi = i;
}
}
int n1 = ihi;
int n2 = ndat - 1 - ihi;
double st1 = stau[ihi];
double st2 = stau[ndat - 1] - st1;
double stl1 = slogtau[ihi];
double stl2 = slogtau[ndat - 1] - stl1;
double ans = n1 * (s.k1 * Math.Log(s.lam1) - Globals.factln(s.k1 - 1)) + (s.k1 - 1) * stl1 - s.lam1 * st1;
ans += n2 * (s.k2 * Math.Log(s.lam2) - Globals.factln(s.k2 - 1)) + (s.k2 - 1) * stl2 - s.lam2 * st2;
return (s.plog = ans);
}
}
}
2 代码格式
using System;
namespace Legalsoft.Truffer
{
public class Plog
{
private int ndat { get; set; }
private double[] dat { get; set; }
private double[] stau { get; set; }
private double[] slogtau { get; set; }
public Plog(double[] data)
{
this.dat = data;
this.ndat = data.Length;
this.stau = new double[ndat];
this.slogtau = new double[ndat];
stau[0] = slogtau[0] = 0.0;
for (int i = 1; i < ndat; i++)
{
stau[i] = dat[i] - dat[0];
slogtau[i] = slogtau[i - 1] + Math.Log(dat[i] - dat[i - 1]);
}
}
public double get(State s)
{
int ilo = 0;
int ihi = ndat - 1;
while (ihi - ilo > 1)
{
int i = (ihi + ilo) >> 1;
if (s.tc > dat[i])
{
ilo = i;
}
else
{
ihi = i;
}
}
int n1 = ihi;
int n2 = ndat - 1 - ihi;
double st1 = stau[ihi];
double st2 = stau[ndat - 1] - st1;
double stl1 = slogtau[ihi];
double stl2 = slogtau[ndat - 1] - stl1;
double ans = n1 * (s.k1 * Math.Log(s.lam1) - Globals.factln(s.k1 - 1)) + (s.k1 - 1) * stl1 - s.lam1 * st1;
ans += n2 * (s.k2 * Math.Log(s.lam2) - Globals.factln(s.k2 - 1)) + (s.k2 - 1) * stl2 - s.lam2 * st2;
return (s.plog = ans);
}
}
}