Example #1
0
 //print tree (for testing wether we make is correctly)
 private void PrintTheTree_helper()
 {
     if (this.root.GetChildsNode().Count == 0)
     {
         this.path.ForEach(Console.Write);
         Console.WriteLine();
         AugmentedTrie.total_printing_row++; // counting how many row were printed
     }
     else
     {
         foreach (TreeNode node_child in this.root.GetChildsNode())
         {
             List <char> path_child = new List <char>(this.path);
             path_child.Add(node_child.GetKeyNode());
             AugmentedTrie tree_child = new AugmentedTrie(node_child, path_child);
             tree_child.PrintTheTree_helper();
         }
     }
 }
Example #2
0
 public void PrintTheTree_WithData()
 {
     if (this.root.GetChildsNode().Count == 0)
     {
         this.path.ForEach(Console.Write);
         Console.Write("\t" + "data:");
         foreach (int index_data in this.root.GetDataNode())
         {
             Console.Write(index_data + " ");
         }
         Console.WriteLine();
     }
     else
     {
         foreach (TreeNode node_child in this.root.GetChildsNode())
         {
             List <char> path_child = new List <char>(this.path);
             path_child.Add(node_child.GetKeyNode());
             AugmentedTrie tree_child = new AugmentedTrie(node_child, path_child);
             tree_child.PrintTheTree_WithData();
         }
     }
 }
Example #3
0
        }//end OuterArrangement

        // inner loop
        private static List <int> InnerArrangement(Dictionary <int, string> total_table, Dictionary <string, int> count_table, AugmentedTrie tree, string word)
        {
            TreeNode   the_leaf   = tree.FindtheLeaf(word);
            List <int> inner_list = new List <int>(the_leaf.GetDataNode());//go through the data first

            bool[] over_arr = new bool[total_table.Count];
            for (int i = 0; i < total_table.Count; i++)
            {
                over_arr[i] = false;
            }

            foreach (int element in inner_list)
            {
                over_arr[element] = true;
            }

            List <int> inner_random = new List <int>();

            for (int i = 0; i < total_table.Count; i++)
            {
                if (over_arr[i] == false)
                {
                    inner_random.Add(i);
                }
            }

            //make random_inner randomly
            inner_random.Shuffle();

            inner_list = inner_list.Concat(inner_random).ToList();

            return(inner_list);
        }//end innerArrangement
Example #4
0
        static private Random random_obj = new Random();// helping for making a random order


        // Make the tree and tables function
        static public void MakeTree_And_Table_Function(List <double> data, int N_LENGTH, out AugmentedTrie tree, out Dictionary <string, int> count_table, out Dictionary <int, string> total_table)
        {
            double min = data.Min();
            double max = data.Max();


            count_table = new Dictionary <string, int>();
            total_table = new Dictionary <int, string>();

            List <double> C_n;
            List <double> C_w = new List <double>();//  w dimension


            //convert time series C of length into a w dimensional, then transform to SAX word:
            for (int start_point_subtimeseries = 0; start_point_subtimeseries + N_LENGTH - 1 <= data.Count - 1; start_point_subtimeseries++) //go through timeseries by the window "N_LENGTH"
            {
                C_n = data.GetRange(start_point_subtimeseries, N_LENGTH);                                                                    //get the sub_timeseries
                C_w.Clear();                                                                                                                 // reset C_w
                string s = String.Empty;                                                                                                     //initialize the SAX word


                //if  N_LENGTH % Constants.W_DIMENSION != 0, then we do PAA as the formala (quite complex and take time):
                if (N_LENGTH % Constants.W_DIMENSION != 0)
                {
                    for (int i = 0; i < Constants.W_DIMENSION; i++)
                    {
                        C_w.Add(0); //set initial value for C_w
                    }
                    for (int i = 0; i < N_LENGTH * Constants.W_DIMENSION; i++)
                    {
                        C_w[i / N_LENGTH] += C_n[i / Constants.W_DIMENSION];
                    }

                    for (int i = 0; i < Constants.W_DIMENSION; i++)
                    {
                        C_w[i] = MathFunctions.MinMax_Normalization(C_w[i], min, max);
                        //Convert  c_i to SAX
                        if (C_w[i] <= Constants.GAUSS_1)
                        {
                            s += "a";
                        }
                        else if (C_w[i] >= Constants.GAUSS_2)
                        {
                            s += "c";
                        }
                        else
                        {
                            s += "b";
                        }
                    }
                }
                else //else, we can simple split it into the same size, this help to reduce the execution time*/
                {
                    double c_i;
                    int    from_index, to_index;

                    //Calculate C_w
                    for (int start_point_w = 0; start_point_w < Constants.W_DIMENSION; start_point_w++)
                    {
                        from_index = (N_LENGTH / Constants.W_DIMENSION) * start_point_w;
                        to_index   = (N_LENGTH / Constants.W_DIMENSION) * (start_point_w + 1) - 1;

                        c_i = 0;
                        for (int i = from_index; i <= to_index; i++)
                        {
                            c_i += C_n.ElementAt(i);
                        }
                        c_i = c_i * (Constants.W_DIMENSION / (double)(N_LENGTH));

                        c_i = MathFunctions.MinMax_Normalization(c_i, min, max);

                        //Convert  c_i to SAX
                        if (c_i <= Constants.GAUSS_1)
                        {
                            s += "a";
                        }
                        else if (c_i >= Constants.GAUSS_2)
                        {
                            s += "c";
                        }
                        else
                        {
                            s += "b";
                        }

                        C_w.Add(c_i);
                    } //end for loop-calc SAX word
                }     //end else


                total_table.Add(start_point_subtimeseries, s);

                if (count_table.ContainsKey(s))
                {
                    count_table[s]++;//if it did have, just plus 1 to 'count_table'
                }
                else
                {
                    count_table.Add(s, 1);// else, we make a new one
                }
            }// end for _ go through time series  by the window

            //Making the root node:
            TreeNode root = new TreeNode('R');

            //init the path (to print the tree later)
            List <char> path = new List <char>();

            // Making the augmented tree:
            tree = new AugmentedTrie(root, path);

            tree.CreateTheAugmentedTrie();

            // appending the indice to the tree.
            foreach (KeyValuePair <int, string> pair in total_table)
            {
                tree.AddTheDataToLeaf(pair.Value, pair.Key);
            }
        } //end MakeTree_AND_Table function