private async void BtnGenerate_Click(object obj) { IsBtnGenerateEnable = false; IsBtnResolveEnable = false; ForestGrowParameters p = new ForestGrowParameters { ExportDirectoryPath = ExportFolder, ExportToJson = true, ResolutionFeatureName = ResolutionFeatureName, ItemSubsetCountRatio = TrainingSubsetCountRatio, TrainingDataPath = TrainingSet, MaxItemCountInCategory = MaxNumberOfTainingItemsInCategory, TreeCount = NumberOfTrees, SplitMode = SplitMode.GINI }; if (_forest == null) { _forest = ForestFactory.Create(); _forest.TreeBuildComplete += _forest_TreeBuildComplete; _forest.ForestGrowComplete += _forest_ForestGrowComplete; } try { int x = await _forest.GrowAsync(p); //int x = _forest.Grow(p); } catch (Exception ex) { } }
public void Grow_TrainingDataXlsx_Gini() { // arrange IForest forest = new Forest(); ForestGrowParameters parameters = new ForestGrowParameters { ExportDirectoryPath = @"temp\cross-gini", ExportToJson = true, ResolutionFeatureName = "Z", ItemSubsetCountRatio = 0.3f, TrainingDataPath = @"data\test-3x1000-cross.xlsx", MaxItemCountInCategory = 10, TreeCount = 50, SplitMode = SplitMode.GINI }; ItemNumerical item1 = ItemNumerical.Create(); item1.AddValue("X", 1.1); item1.AddValue("Y", 2.1); item1.AddValue("Z", 0); ItemNumerical item2 = ItemNumerical.Create(); item2.AddValue("X", 1.9); item2.AddValue("Y", 3.1); item2.AddValue("Z", 0); // act int treeCount = forest.Grow(parameters); var d1 = Math.Round(forest.Resolve(item1), 0); var d2 = Math.Round(forest.Resolve(item2), 0); // assert Assert.AreEqual(50, treeCount); Assert.AreEqual(2, d1); Assert.AreEqual(1, d2); }
public int Grow(ForestGrowParameters growParameters) { if (growParameters == null) { throw new Exception(); } int qty = 0; switch (growParameters.SplitMode) { case SplitMode.GINI: _splitter = new SplitterGini(); break; case SplitMode.RSS: _splitter = new SplitterRss(); break; default: _splitter = new SplitterRss(); break; } InitializeItemSet(growParameters.TrainingDataPath); qty = GenerateTreesTPL( growParameters.TreeCount, growParameters.ResolutionFeatureName, growParameters.MaxItemCountInCategory, growParameters.ItemSubsetCountRatio); if (growParameters.ExportToJson) { ExportToJsonTPL(growParameters.ExportDirectoryPath); } return(qty); }
public async Task <int> GrowAsync(ForestGrowParameters growParameters) { return(await Task <int> .Factory.StartNew(() => { return Grow(growParameters); })); }