예제 #1
0
        public void BuildTree()
        {
            if (errors == null) return;
            int i = 0;
            int max_branching = int.MaxValue;
            double current_error = errors[errors.Length - 1];
            int f = 0;
            int length = ts.Length;
            int len = 0;
            int best_f = 0;
            double best_cost = double.MaxValue;

            for (i = 0; i < ts.freq.Length; i++)
            {
                f = ts.freq[i];
                if (f == 0) continue;
                for (; ; )
                {
                    ModelSet s = new ModelSet(ts);
                    s.getModels(f, current_error, ref len);
                    //
                    if ((len >= Global.confidence * length) && (s.models.Length <= max_branching))
                    {
                        double cost = s.Cost();
                        if (cost < best_cost)
                        {
                            best_f = f;
                            best_cost = cost;
                        }

                    }
                    else break;

                    f = f * 2;
                    if (len == 0) break;
                    if ((i + 1 < ts.freq.Length) && (f > ts.freq[i + 1])) break;
                }
            }

            Console.WriteLine(best_f);
            if (best_f != 0) { setModels(best_f, errors, 1, 0); }
            else
            {
                int done = 0;
                for (; ; )
                {
                    ModelSet s = new ModelSet(ts);
                    s.getModels(f, current_error, ref len);
                    if (s.models.Length >= max_branching)
                    {
                        f = f * 2;
                    }
                    else { best_f = f; if (s.models.Length == 1) done = 1; break; }
                }

                setModels(best_f, errors, 0, done);
            }
            //Set();
        }
예제 #2
0
        public void BuildTree()
        {
            if (errors == null)
            {
                return;
            }
            int    i             = 0;
            int    max_branching = int.MaxValue;
            double current_error = errors[errors.Length - 1];
            int    f             = 0;
            int    length        = ts.Length;
            int    len           = 0;
            int    best_f        = 0;
            double best_cost     = double.MaxValue;

            for (i = 0; i < ts.freq.Length; i++)
            {
                f = ts.freq[i];
                if (f == 0)
                {
                    continue;
                }
                for (; ;)
                {
                    ModelSet s = new ModelSet(ts);
                    s.getModels(f, current_error, ref len);
                    //
                    if ((len >= Global.confidence * length) && (s.models.Length <= max_branching))
                    {
                        double cost = s.Cost();
                        if (cost < best_cost)
                        {
                            best_f    = f;
                            best_cost = cost;
                        }
                    }
                    else
                    {
                        break;
                    }

                    f = f * 2;
                    if (len == 0)
                    {
                        break;
                    }
                    if ((i + 1 < ts.freq.Length) && (f > ts.freq[i + 1]))
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(best_f);
            if (best_f != 0)
            {
                setModels(best_f, errors, 1, 0);
            }
            else
            {
                int done = 0;
                for (; ;)
                {
                    ModelSet s = new ModelSet(ts);
                    s.getModels(f, current_error, ref len);
                    if (s.models.Length >= max_branching)
                    {
                        f = f * 2;
                    }
                    else
                    {
                        best_f = f; if (s.models.Length == 1)
                        {
                            done = 1;
                        }
                        break;
                    }
                }

                setModels(best_f, errors, 0, done);
            }
            //Set();
        }