public void LoadRFModel(string file_name = "") { if (file_name == "") file_name = RF_model_file_path_; decisionForest = new dforest.decisionforest(); alglib.serializer Serializer = new alglib.serializer(); string modelFile = System.IO.File.ReadAllText(file_name); Serializer.ustart_str(modelFile); dforest.dfunserialize(Serializer, decisionForest); Serializer.stop(); Console.WriteLine("Finish loading the RF model"); Console.WriteLine("Total tree size: {0}", decisionForest.trees.Length); int treeSize = (int)(decisionForest.trees.Length / decisionForest.ntrees); Console.WriteLine("single tree size:{0}", treeSize); Console.WriteLine("Number of variable: {0}", decisionForest.nvars); Console.WriteLine("ntress: {0}", decisionForest.ntrees); Console.WriteLine("nclasses: {0}", decisionForest.nclasses); // turn the tree from double type to int type to make it more efficient trees_int_ = new int[decisionForest.trees.Length]; Console.WriteLine("Length of the original tree: {0}", trees_int_.Length); for (int i = 0; i < decisionForest.trees.Length; i++) trees_int_[i] = (int)Math.Ceiling(decisionForest.trees[i]); }
/* ######################### */ // load the random forest model from the file to the class property decisionForest private void LoadRFModel() { string modelFilePath = feature_lib_obj_.directory + "\\FeatureVectureBlue149.rf.model"; Console.WriteLine("Model file path {0}", modelFilePath); string modelFile = System.IO.File.ReadAllText(modelFilePath); alglib.serializer Serializer = new alglib.serializer(); Serializer.ustart_str(modelFile); dforest.dfunserialize(Serializer, decisionForest); Serializer.stop(); Console.WriteLine("Finish loading the RF model"); }