static void old(string[] args) { double[] d = readfile("data.txt"); var t = from i in d group i by(int) i into gr orderby gr.Key descending select(new { Value = gr.Key, Count = gr.Count() }); analysis(d); // writefile(t,"freq.txt"); var s = d.OrderByDescending(a => a).Distinct().ToArray(); double[,] C = Regression.getArr(s.Length); // d = d.Select(a => Math.Floor(Math.Abs(a))).ToArray(); double[] CC = ChebReg.Solve(C, s); double[] CL = LinearReg.Solve(C, s); double[] E1 = Regression.CalcError(C, CC, s); double[] E2 = Regression.CalcError(C, CL, s); //E2 = E2.Select(a => Math.Floor(Math.Abs(a))).ToArray(); var de1 = E1.Max() - E1.Min(); var de2 = E2.Max() - E2.Min(); Console.WriteLine(de1 + " " + Math.Log(de1, 2)); Console.WriteLine(de2 + " " + Math.Log(de2, 2)); var x = from e in E2 orderby e descending select e; var x1 = x.Take(10); x = from e in E2 orderby e ascending select e; var x2 = x.Take(10); // writefile(diff(d), "diff.txt"); // writefile(sign(d), "sign.txt"); }
static void t() { int[] r = new int[] { 3, 5, 7, 9, 11, 13 }; var E = LinearReg.CalcError(r); }
static long getStorage(IEnumerable <int> num, ArrayList choics, int level) { ArrayList l3 = new ArrayList(); ArrayList l4 = new ArrayList(); if (num.Count() == 1) { return(1); } long[] s = new long[] { long.MaxValue, long.MaxValue, long.MaxValue, long.MaxValue, long.MaxValue, long.MaxValue }; //raw storage s[0] = (long)Math.Ceiling(Math.Log(num.Max() - num.Min(), 2)) * num.Count(); //delta int[] d = diff(num); // int[] dd = diff_all(num).ToArray(); s[1] = (long)Math.Ceiling(Math.Log(d.Max() - d.Min(), 2)) * (num.Count() - 1) + (long)Math.Ceiling(Math.Log(Math.Abs(d.Min()), 2)); //create regression model IEnumerable <int> CL = LinearReg.CalcError(num); if (CL.Count() != 0) { s[2] = sizeof(double) * 2 * 8 + getStorage(CL, choics, level - 1); } //dictionary IEnumerable <int> data = num.Distinct(); long t = num.Count() * (long)Math.Ceiling(Math.Log(data.Count(), 2)); if (level >= 1) { s[3] = getStorage(data, l3, level - 1) + t; data = data.OrderBy(a => a); s[4] = getStorage(data, l4, level - 1) + t; } if (choics != null) { s[5] = huffman(num); } int minpos = 0; long min = s[minpos]; for (int i = 0; i < s.Length; i++) { if (min > s[i]) { min = s[i]; minpos = i; } } if (minpos == 3 || minpos == 4) { Console.WriteLine("getstorage\t" + "level\t" + level + "\t#" + num.Count() + "\tdir" + (min - t) + "\t" + "size" + t); } else { Console.WriteLine("getstorage\t" + "level\t" + level + "\t#" + num.Count() + "\tsize" + (min)); } if (choics != null) { if (minpos == 3) { choics.AddRange(l3); } if (minpos == 4) { choics.AddRange(l4); } choics.Add(minpos); } return(min); }