public void TestDecisionTreeEvaluate() { var dt = DecisionTree.Create(exampleDecisionTree); var value = dt.Evaluate(testValues); Assert.Equal(0.077062957, value); }
public void TestDecisionTreeEvaluate() { var dt = DecisionTree.Create(exampleDecisionTree); var actual = dt.Evaluate(testValues); var expected = 0.077062957; Assert.InRange(actual, expected - 1e-06, expected + 1e-06); }
public void TestCompiledFuncVsDT() { var filename2 = @"../../../../datasets/xgboost/xgboost_test_cases_no_feature_names.txt"; var samplesString = File.ReadLines(filename2); var samples = new Dictionary <string, float[]>(); foreach (var line in samplesString.Skip(1)) { var parts = line.Split(','); var sample = parts[0]; var featureIndex = int.Parse(parts[1]); var value = float.Parse(parts[2]); if (!samples.ContainsKey(sample)) { samples.Add(sample, new float[1000]); } samples[sample][featureIndex] = value; } var s = samples.Select(m => m.Value).ToArray(); var dt = DecisionTree.Create(exampleDecisionTree); var results = new float[s.Length]; var timer1 = Stopwatch.StartNew(); for (int _ = 0; _ < 1000; _++) { for (int i = 0; i < s.Length; i++) { results[i] = eval(s[i]); } } timer1.Stop(); var timer2 = Stopwatch.StartNew(); for (int _ = 0; _ < 1000; _++) { for (int i = 0; i < s.Length; i++) { results[i] = dt.Evaluate(s[i]); } } timer2.Stop(); output.WriteLine($"func: {timer1.Elapsed.TotalMilliseconds}"); output.WriteLine($" dt: {timer2.Elapsed.TotalMilliseconds}"); }
public void TestDecisionTreeCreate() { var dt = DecisionTree.Create(exampleDecisionTree); var nodeStrings = dt.ToString().Split('\n'); var exampleStrings = exampleDecisionTree.Split('\n'); foreach (var n in nodeStrings) { bool isCool = false; foreach (var e in exampleStrings) { isCool = isCool || e.StartsWith(n); } if (!isCool) { Assert.True(isCool, "node failed to be found: '" + n + "'"); } } }
public void TestDecisionTreePrecomputeEverything() { var css = new CharSetSolver(); var regex = new Regex("abc[^a-i]"); var sr = css.RegexConverter.ConvertToSymbolicRegex(regex, true); var partition = sr.ComputeMinterms(); Assert.AreEqual <int>(5, partition.Length); var dt = DecisionTree.Create(css, partition, 0xFFFF); for (int i = 0; i < partition.Length; i++) { foreach (var c in css.GenerateAllCharacters(partition[i])) { Assert.AreEqual(i, dt.GetId(c)); } } Assert.IsTrue(dt.Tree == null); }
public void TestDecisionTreePrecomputeExtendedASCII() { var css = new CharSetSolver(); var regex = new Regex("(?i:abc[^a-i])"); var sr = css.RegexConverter.ConvertToSymbolicRegex(regex, true); var partition = sr.ComputeMinterms(); Assert.AreEqual <int>(5, partition.Length); var dt = DecisionTree.Create(css, partition, 0xFF); for (int i = 0; i < partition.Length; i++) { foreach (var c in css.GenerateAllCharacters(partition[i])) { Assert.AreEqual(i, dt.GetId(c)); } } //there is a special unicode 'i' character that is equivalent to i with ignore-case option //that forms a separate character class here Assert.IsFalse(dt.Tree.IsLeaf); }