using System; namespace StatsSuite { class Program { static void Main(string[] args) { Console.WriteLine("rounded index " + Linearize(416, 65536)); } public static double Linearize(double ct, int N, int dx = 1024) { Console.WriteLine("Ct " + ct); double zx = ct / Math.Sqrt(N); Console.WriteLine("z-score " + zx); return (int)Math.Round(dx * Phi(zx)); } public static double Phi(double x) { // constants double c1 = 2.506628275; double c2 = 0.31938153; double c3 = -0.356563782; double c4 = 1.781477937; double c5 = -1.821255978; double c6 = 1.330274429; double c7 = 0.2316419; // Save the sign of x int sign = 1; if (x < 0) sign = -1; double t = 1 + c7 * sign * x; double y = 1 / t; double cdf = 0.5 + sign * (0.5 - (c2 + (c6 + c5 * t + c4 * Math.Pow(t, 2) + c3 * Math.Pow(t, 3)) / Math.Pow(t, 4)) / (c1 * Math.Exp(0.5 * x * x) * t)); Console.WriteLine("linearized cdf " + cdf); return cdf; } } }