示例#1
0
        static double simSeasonal(Model pa, Model pb)
        {
            double sim_index;
            double a_scale, a_shift;
            double b_scale, b_shift;
            a_scale = 0; a_shift = 0;
            b_scale = 0; b_shift = 0;
            double[] aV = new double[pa.len];
            double[] bV = new double[pb.len];

            for (int i = 0; i < pa.len; i++)
            {
                aV[i] = pa.EvalS(i);
                bV[i] = pb.EvalS(i);
            }
            double[] tsa = Utils.normalize(aV, ref a_scale, ref a_shift);
            double[] tsb = Utils.normalize(bV, ref b_scale, ref b_shift);
            sim_index = Utils.sim(tsa, tsb);
            return sim_index;
        }
示例#2
0
        static double simSeasonalOLD(Model a, Model b)
        {
            Debug.Assert(a.len == -1);
            Debug.Assert(b.len == -1);
            Debug.Assert(b.freq == a.freq);
            double sim_index;
            double a_scale, a_shift;
            double b_scale, b_shift;
            a_scale = 0; a_shift = 0;
            b_scale = 0; b_shift = 0;
            Model pa = models[getParent(a)];
            Model pb = models[getParent(b)];
            double[] aV = new double[pa.len];
            double[] bV = new double[pb.len];

            for (int i = 0; i < pa.len; i++)
            {
                aV[i] = pa.EvalS(i);
                bV[i] = pb.EvalS(i);
            }
            double[] tsa = Utils.normalize(aV, ref a_scale, ref a_shift);
            double[] tsb = Utils.normalize(bV, ref b_scale, ref b_shift);
            sim_index = Utils.sim(tsa, tsb);
            return sim_index;

            return 0;
        }
示例#3
0
        static double sim(Model a, Model b)
        {
            Debug.Assert(comaprable(a, b) == true);
            double sim_index;
            double a_scale, a_shift;
            double b_scale, b_shift;
            a_scale = 0; a_shift = 0;
            b_scale = 0; b_shift = 0;

            // determine whihch array to use
            if ((a.seasonal == -1) && (b.seasonal == -1) && (a.nv == 0) && (b.nv == 0))
            {
                // in this case, we use the ts of a and b
                double[] tsa = Utils.normalize(a.ts, ref a_scale, ref a_shift);
                double[] tsb = Utils.normalize(b.ts, ref b_scale, ref b_shift);
                sim_index = Utils.sim(tsa, tsb);
                return sim_index;
            }
            else if ((a.seasonal == -1) && (b.seasonal == -1))
            {
                // in this case, we use the ts of a and b
                double[] tsa = Utils.normalize(a.values, ref a_scale, ref a_shift);
                double[] tsb = Utils.normalize(b.values, ref b_scale, ref b_shift);
                sim_index = Utils.sim(tsa, tsb);
                return sim_index;
            }
            else if (a.type == ModelType.EXPLICIT)
            {
                double[] tsa = Utils.normalize(a.values, ref a_scale, ref a_shift);
                double[] tsb = Utils.normalize(b.values, ref b_scale, ref b_shift);
                sim_index = Utils.sim(tsa, tsb);
                sim_index += simSeasonal(a, b);
                return sim_index;
            }
            else if ((a.type == ModelType.IMPLICIT) || ((a.type == ModelType.TREND)))
            {
                double[] tsa = Utils.normalize(a.values, ref a_scale, ref a_shift);
                double[] tsb = Utils.normalize(b.values, ref b_scale, ref b_shift);
                sim_index = Utils.sim(tsa, tsb);// sim(models[a.seasonal], models[b.seasonal]);
                sim_index += simSeasonal(a, b);
                return sim_index;
            }

            return double.MaxValue;
        }
示例#4
0
        static Model ReadModel(TextReader f, int j)
        {
            Model m = new Model();
            int i;
            string line = f.ReadLine();
            string[] p = line.Split(' ');
            int count = 0;
            for (i = 0; i < p.Length; i++)
            {
                if (p[i] != "") count++;
            }
            string[] parts = new string[count];
            int k = 0;
            for (i = 0; i < p.Length; i++)
            {
                if (p[i] != "") { parts[k] = p[i]; k++; }
            }

            int ti;
            double tf;
            k = 0;
            ti = ReadInt(parts[k++]);
            m.id = ti;
            ti = ReadInt(parts[k++]);

            if (ti == 0) m.type = ModelType.EXPLICIT;
            if (ti == 1) m.type = ModelType.TREND;
            if (ti == 2) m.type = ModelType.IMPLICIT;

            ti = ReadInt(parts[k++]);
            m.len = ti;

            tf = ReadDouble(parts[k++]);
            m.err = tf;

            ti = ReadInt(parts[k++]);
            m.freq = ti;

            ti = ReadInt(parts[k++]);
            m.seasonal = ti;

            //read v
            ti = ReadInt(parts[k++]);
            m.nv = ti;
            m.values = new double[m.nv];
            for (i = 0; i < m.nv; i++)
            {
                tf = ReadDouble(parts[k++]);
                m.values[i] = tf;
            }
            //read ts
            ti = ReadInt(parts[k++]);
            m.nts = ti;
            m.ts = new double[m.nts];
            for (i = 0; i < m.nts; i++)
            {
                tf = ReadDouble(parts[k++]);
                m.ts[i] = tf;
            }
            //read c
            ti = ReadInt(parts[k++]);
            m.nc = ti;
            m.children = new int[m.nc];
            for (i = 0; i < m.nc; i++)
            {
                ti = ReadInt(parts[k++]);
                m.children[i] = ti;
            }
            //ReadString(f);
            return m;
        }
示例#5
0
        static Model OldReadModel(TextReader f, int j)
        {
            Model m = new Model();

            int ti;
            double tf;
            int i;
            ti = ReadInt(f);
            m.id = ti;
            ti = ReadInt(f);

            if (ti == 0) m.type = ModelType.EXPLICIT;
            if (ti == 1) m.type = ModelType.TREND;
            if (ti == 2) m.type = ModelType.IMPLICIT;

            ti = ReadInt(f);
            m.len = ti;

            tf = ReadDouble(f);
            m.err = tf;

            ti = ReadInt(f);
            m.freq = ti;

            ti = ReadInt(f);
            m.seasonal = ti;

            //read v
            ti = ReadInt(f);
            m.nv = ti;
            m.values = new double[m.nv];
            for (i = 0; i < m.nv; i++)
            {
                tf = ReadDouble(f);
                m.values[i] = tf;
            }
            //read ts
            ti = ReadInt(f);
            m.nts = ti;
            m.ts = new double[m.nts];
            for (i = 0; i < m.nts; i++)
            {
                tf = ReadDouble(f);
                m.ts[i] = tf;
            }
            //read c
            ti = ReadInt(f);
            m.nc = ti;
            m.children = new int[m.nc];
            for (i = 0; i < m.nc; i++)
            {
                ti = ReadInt(f);
                m.children[i] = ti;
            }
            ReadString(f);
            return m;
        }
示例#6
0
        static int getParent(Model pa)
        {
            int p = pa.sparent;
            Debug.Assert(p != -1);

            if (models[p].len == -1) return getParent(p);
            else return p;
            //return -1;
        }
示例#7
0
 // must everything be the same,
 static bool comaprable(Model a, Model b)
 {
     // may need to add len and frequency too
     if (b.len != a.len) return false;
     if (a.type != b.type) return false;
     if ((a.seasonal == -1) && (b.seasonal == -1) && (a.nv == 0) && (b.nv == 0)) return true;
     if ((a.seasonal == -1) && (b.seasonal == -1)) return true;
     if ((a.seasonal != -1) && (b.seasonal != -1) && (a.nv > 0) && (b.nv > 0)) return true;
     return false;
 }