private double EntropyOfCond(ArraySlice <DecisionTest> S) { double p1; int index = Split(S, out p1); double p2 = 1.0 - p1; double result = (Functions.Entropy(p1) + Functions.Entropy(1 - p1)) / platform.BranchCost; return(result); }
private double EntropyOfSwitch(ArraySlice <DecisionTest> S) { double result = 0; foreach (var test in S) { result += Functions.Entropy(test.Probability); } result /= platform.SwitchCost; return(result); }
private void Normalize(ArraySlice <DecisionTest> S) { var tests = S.Array; double sum = 0; foreach (var test in S) { sum += test.Probability; } foreach (var test in S) { test.Probability /= sum; } }
private bool IsSwitchable(ArraySlice <DecisionTest> S) { long elementCount = S.Sum(test => test.Interval.LongSize); if (elementCount > platform.MaxSwitchElementCount) { return(false); } var rangeSize = S[S.Count - 1].Interval.Last - S[0].Interval.First + 1; double density = elementCount / (double)rangeSize; return(density > platform.MinSwitchDensity); }
private Decision GenTree(ArraySlice <DecisionTest> S) { if (S.Count == 1) { return(GetActionDecision(S[0].Action)); } Normalize(S); if (IsSwitchable(S) && EntropyOfSwitch(S) > EntropyOfCond(S)) { return(GenSwitch(S)); } else { return(GenCond(S)); } }
internal JumpTableDecision(ArraySlice <DecisionTest> tests, Func <int, ActionDecision> idToAction) { this.tests = tests; this.startElement = tests.Array[tests.Offset].Interval.First; int elementCount = tests.Array[tests.Offset + tests.Count - 1].Interval.Last - startElement + 1; this.elementToAction = new Decision[elementCount]; foreach (var test in tests) { var action = idToAction(test.Action); if (!leafDecisions.Contains(action)) { leafDecisions.Add(action); } for (int i = test.Interval.First; i <= test.Interval.Last; ++i) { elementToAction[i - startElement] = action; } } }
private Decision GenSwitch(ArraySlice <DecisionTest> S) { var result = new JumpTableDecision(S, GetActionDecision); return(result); }