public int GenerateTrees(int count, string resolutionFeatureName, int maxItemCountInCategory, float itemSubsetCountRatio) { _trees.Clear(); var nameGenerator = new NameGenerator(); _treeBulder = new TreeBuilder(resolutionFeatureName, maxItemCountInCategory, nameGenerator, _splitter); for (int i = 0; i < count; i++) { ItemNumericalSet subset = _set.GetRandomSubset(itemSubsetCountRatio, true); TreeGenerative tg = _treeBulder.Build(subset); _trees.Add(tg.ToTree()); nameGenerator.Reset(); } return(TreeCount()); }
public void Export(TreeGenerative tree, string path) { FileInfo fi = new FileInfo(path); if (fi.Exists) { fi.Delete(); } string json = JsonConvert.SerializeObject(tree.ToTree(), Formatting.Indented); using (StreamWriter sw = new StreamWriter(fi.FullName)) { sw.WriteLine(json); sw.Close(); } var exportCompleted = ExportCompleted; if (exportCompleted != null) { exportCompleted(this, fi.Name); } }
public int GenerateTreesTPL(int treeCount, string resolutionFeatureName, int maxItemCountInCategory, float itemSubsetCountRatio) { _trees.Clear(); Parallel.For(0, treeCount, (i) => { NameGenerator nameGenerator = new NameGenerator(); ItemNumericalSet subset = _set.GetRandomSubset(itemSubsetCountRatio, true); _treeBulder = new TreeBuilder(resolutionFeatureName, maxItemCountInCategory, nameGenerator, _splitter); _treeBulder.BuildComplete += OnTreeBuildComplete; TreeGenerative tg = _treeBulder.Build(subset); _treeBulder.BuildComplete -= OnTreeBuildComplete; _trees.Add(tg.ToTree()); }); var forestGrowComplete = ForestGrowComplete; if (forestGrowComplete != null) { forestGrowComplete(this, EventArgs.Empty); } return(TreeCount()); }