Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/10/17 12:56:36 (6 years ago)
Author:
bwerth
Message:

#2847 worked on M5Regression

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/M5Utilities/M5Analyzer.cs

    r15430 r15470  
    2929namespace HeuristicLab.Algorithms.DataAnalysis {
    3030  internal static class M5Analyzer {
    31     private const string LeftResultName = "Left";
    32     private const string RightResultName = "Right";
    3331    private const string ConditionResultName = "Condition";
    3432    private const string CoverResultName = "Covered Instances";
    3533    private const string CoverageDiagramResultName = "Coverage";
    36     private const string NodeModelResultName = "NodeModel";
    37     private const string NodeSizeResultName = "NodeSize";
    3834    private const string RuleModelResultName = "RuleModel";
    3935
     
    4137      var res = ruleSetModel.VariablesUsedForPrediction.ToDictionary(x => x, x => 0);
    4238      foreach (var rule in ruleSetModel.Rules)
    43         foreach (var att in rule.SplitAtts)
    44           res[att]++;
     39      foreach (var att in rule.SplitAtts)
     40        res[att]++;
    4541      return res;
    4642    }
     
    5753      var list = new List<int>();
    5854      GetLeafDepths(treeModel.Root, 0, list);
    59       var row = new DataRow("Depths", "", list.Select(x => (double)x)) {
    60         VisualProperties = { ChartType = DataRowVisualProperties.DataRowChartType.Histogram }
     55      var row = new DataRow("Depths", "", list.Select(x => (double) x)) {
     56        VisualProperties = {ChartType = DataRowVisualProperties.DataRowChartType.Histogram}
    6157      };
    6258      var hist = new DataTable("LeafDepths");
     
    6561    }
    6662
    67     public static Result CreateRulesResult(M5RuleSetModel ruleSetModel, IRegressionProblemData pd, string resultName, int maxDepth, bool displayModels) {
     63    public static Result CreateRulesResult(M5RuleSetModel ruleSetModel, IRegressionProblemData pd, string resultName, bool displayModels) {
    6864      var res = new ResultCollection();
    6965      var i = 0;
    7066      foreach (var rule in ruleSetModel.Rules)
    71         res.Add(new Result("Rule" + i++, CreateRulesResult(rule, pd, maxDepth, displayModels, out pd)));
     67        res.Add(new Result("Rule" + i++, CreateRulesResult(rule, pd, displayModels, out pd)));
    7268      return new Result(resultName, res);
    7369    }
     
    10197    }
    10298
    103     private static ResultCollection CreateRulesResult(M5NodeModel nodeModel, IRegressionProblemData pd, IList<int> rows, int maxDepth, bool displayModels) {
    104       var res = new ResultCollection();
    105       if (!nodeModel.IsLeaf) {
    106         res.Add(new Result(ConditionResultName, new StringValue(nodeModel.SplitAttr + " <= " + nodeModel.SplitValue)));
    107         var assignment = pd.Dataset.GetDoubleValues(nodeModel.SplitAttr, rows).Select(x => x <= nodeModel.SplitValue).ToArray();
    108         var leftRows = Enumerable.Range(0, assignment.Length).Where(i => assignment[i]).Select(i => rows[i]).ToList();
    109         var rightRows = Enumerable.Range(0, assignment.Length).Where(i => !assignment[i]).Select(i => rows[i]).ToList();
    110         if (nodeModel.Left != null && maxDepth > 0) res.Add(new Result(LeftResultName, CreateRulesResult(nodeModel.Left, pd, leftRows, maxDepth - 1, displayModels)));
    111         if (nodeModel.Right != null && maxDepth > 0) res.Add(new Result(RightResultName, CreateRulesResult(nodeModel.Right, pd, rightRows, maxDepth - 1, displayModels)));
    112       }
    113       if (nodeModel.NodeModel != null && displayModels) res.Add(new Result(NodeModelResultName, nodeModel.NodeModel.CreateRegressionSolution(pd)));
    114       res.Add(new Result(NodeSizeResultName, new IntValue(rows.Count)));
    115       return res;
    116     }
    117 
    118     private static ResultCollection CreateRulesResult(M5RuleModel m5RuleModel, IRegressionProblemData pd, int maxDepth, bool displayModels, out IRegressionProblemData notCovered) {
    119 
     99    private static ResultCollection CreateRulesResult(M5RuleModel m5RuleModel, IRegressionProblemData pd, bool displayModels, out IRegressionProblemData notCovered) {
    120100      var training = pd.TrainingIndices.Where(x => !m5RuleModel.Covers(pd.Dataset, x)).ToArray();
    121101      var test = pd.TestIndices.Where(x => !m5RuleModel.Covers(pd.Dataset, x)).ToArray();
     
    134114      var res = new ResultCollection {
    135115        new Result(ConditionResultName, new StringValue(m5RuleModel.ToCompactString())),
    136         new Result(CoverResultName, new IntValue(pd.TrainingIndices.Count()-training.Length))
     116        new Result(CoverResultName, new IntValue(pd.TrainingIndices.Count() - training.Length))
    137117      };
    138118      if (displayModels) res.Add(new Result(RuleModelResultName, m5RuleModel.CreateRegressionSolution(covered)));
    139119      return res;
    140     }
    141 
    142     private static IEnumerable<double> Cumulate(this IEnumerable<double> values) {
    143       double sum = 0.0;
    144       foreach (var value in values) {
    145         sum += value;
    146         yield return sum;
    147       }
    148120    }
    149121
     
    161133  }
    162134}
    163 
Note: See TracChangeset for help on using the changeset viewer.