Example #1
0
 static void t()
 {
     int[] r = new int[] { 3, 5, 7, 9, 11, 13 };
     var   E = LinearReg.CalcError(r);
 }
Example #2
0
        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);
        }