Changeset 16313


Ignore:
Timestamp:
11/21/18 10:27:55 (17 months ago)
Author:
chaider
Message:

#2956:

  • Updated value visualization of simplifier tooltip
  • Added VariableRanges field to dataset
  • Added overloads for GetSymbolicExressionTreeIntervals
Location:
branches/2956_apriori_knowledge
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2956_apriori_knowledge/HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntegration/3.4/Interpreter/SymbolicDataAnalysisIntervalArithmeticInterpreter.cs

    r16303 r16313  
    4242    private readonly object syncRoot = new object();
    4343
    44     private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows, Dictionary<string, Interval> customIntervals = null) {
     44    private static InterpreterState PrepareInterpreterState(ISymbolicExpressionTree tree,
     45      IEnumerable<int> rows, IDataset dataset = null, Dictionary<string, Interval> customIntervals = null) {
    4546      Instruction[] code = SymbolicExpressionTreeCompiler.Compile(tree, OpCodes.MapSymbolToOpCode);
    4647      int necessaryArgStackSize = 0;
     
    5152          IList<double> values = new List<double>();
    5253
    53           if (customIntervals != null && customIntervals.ContainsKey(variableTreeNode.VariableName)) {
    54             instr.data = customIntervals[variableTreeNode.VariableName];
     54          if (dataset != null && customIntervals != null) {
     55            if (customIntervals.ContainsKey(variableTreeNode.VariableName)) {
     56              instr.data = customIntervals[variableTreeNode.VariableName];
     57            } else {
     58              foreach (var rowEnum in rows) {
     59                values.Add(dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName)[rowEnum]);
     60              }
     61              instr.data = new Interval(values.Min(), values.Max());
     62            }
     63          } else if (dataset != null) {
     64             foreach (var rowEnum in rows) {
     65              values.Add(dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName)[rowEnum]);
     66            }
     67            instr.data = new Interval(values.Min(), values.Max());
     68          } else if (customIntervals != null) {
     69            if (customIntervals.ContainsKey(variableTreeNode.VariableName)) {
     70              instr.data = customIntervals[variableTreeNode.VariableName];
     71            }
    5572          } else {
    56             foreach (var rowEnum in rows) {
    57               values.Add(dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName)[rowEnum]);
    58             }
    59             instr.data = new Interval(values.Min(), values.Max());
     73            throw new Exception("No valid input for variables!");
    6074          }
    6175        }
     
    204218    //  var x = Evaluate(dataset, state);
    205219    //  state.Reset();
    206      
     220
    207221    //  return state;
    208222    //}
    209223
    210    // public Interval GetSymbolicExressionTreeInterval(tree,variableIntervals)
     224    // public Interval GetSymbolicExressionTreeInterval(tree,variableIntervals)
    211225    //public Interval GetSymbolicExressionTreeInterval(tree,Dataset,intervals = null)
     226
     227    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IEnumerable<int> rows, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {
     228      intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
     229      var state = PrepareInterpreterState(tree, rows);
     230      var x = Evaluate(state, intervals);
     231
     232      return x;
     233    }
     234
     235    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows,
     236      Dictionary<string, Interval> customIntervals, out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {
     237      intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
     238      var state = PrepareInterpreterState(tree, rows, dataset, customIntervals);
     239      var x = Evaluate(state, intervals);
     240
     241      return x;
     242    }
     243
    212244    public Interval GetSymbolicExressionTreeIntervals(ISymbolicExpressionTree tree, IDataset dataset, IEnumerable<int> rows,
    213245      out Dictionary<ISymbolicExpressionTreeNode, Interval> intervals) {
    214246      intervals = new Dictionary<ISymbolicExpressionTreeNode, Interval>();
    215       var state = PrepareInterpreterState(tree, dataset, rows);
     247      var state = PrepareInterpreterState(tree, rows, dataset);
    216248      var x = Evaluate(state, intervals);
    217249     
  • branches/2956_apriori_knowledge/HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntegration/3.4/Plugin.cs

    r16303 r16313  
    2929namespace HeuristicLab.Algorithms.DataAnalysis.IntervalArithmetic
    3030{
    31     [Plugin("HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntergration", "3.4.0.0")]
     31    [Plugin("HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntergration", "3.4.0.16303")]
    3232    [PluginFile("HeuristicLab.Algorithms.DataAnalysis.KnowledgeIntegration-3.4.dll", PluginFileType.Assembly)]
    3333    public class Plugin : PluginBase{
  • branches/2956_apriori_knowledge/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r16303 r16313  
    3434using HeuristicLab.MainForm;
    3535using HeuristicLab.MainForm.WindowsForms;
     36using System.Globalization;
    3637
    3738namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
     
    193194      var interpreter = new SymbolicDataAnalysisIntervalArithmeticInterpreter();
    194195
    195       //var intervalParam = ((IRegressionProblemData)Content.ProblemData).IntervalVariable;
     196      //Get the Variable Ranges and add it to the dictionary
     197      var intervalParameters = ((IRegressionProblemData)Content.ProblemData).VariableRanges;
    196198      var customIntervals = new Dictionary<String, Interval>();
    197       var parser = new FormulationParser();
    198       //foreach (var ci in intervalParam) {
    199       //var inter = parser.Parse(ci.Formulation.GetValue());
    200       //customIntervals.Add(ci.Variable.GetValue(), new Interval(0, 1));
    201       //}
    202       var resultInterval = interpreter.GetSymbolicExressionTreeIntervals(tree, Content.ProblemData.Dataset, Content.ProblemData.TrainingIndices, out intervals);
     199      for (int x = 0; x < intervalParameters.Rows; ++x) {
     200        customIntervals.Add(intervalParameters.RowNames.ElementAt(x),
     201                            new Interval(intervalParameters.GetRow(x).ElementAt(0),
     202                                         intervalParameters.GetRow(x).ElementAt(1)));
     203      }
     204
     205      var resultInterval = interpreter.GetSymbolicExressionTreeIntervals(tree, Content.ProblemData.Dataset, Content.ProblemData.TrainingIndices, customIntervals, out intervals);
    203206      await Task.Delay(500); // wait for progressbar to finish animation
    204207      var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
     
    206209        foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
    207210      }
    208       //Instruction currentInstr = instructions.NextInstruction();
    209       //while (instructions.HasNextInstruction()) {
    210       //  //intervals[currentInstr.dynamicNode] = (Interval)currentInstr.data;
    211       //  intervals.Add(Tuple.Create(currentInstr.dynamicNode, (Interval)currentInstr.data));
    212       //  currentInstr = instructions.NextInstruction();
    213       //}
    214      
    215      
    216 
    217       //intervals.Add(Tuple.Create(currentInstr.dynamicNode, (Interval)currentInstr.data));
     211
    218212      nodeImpacts = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item1);
    219213      progress.Finish();
    220214      PaintIntervals();
    221       //PaintNodeImpacts();
    222215    }
    223216
     
    291284        if (visualTree != null) {
    292285          visualTree.ToolTip = visualTree.Content.ToString();
    293           //visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{intervals[node].Item2.LowerBound:E4} ... {intervals[node].Item2.UpperBound:E4}]{Environment.NewLine}");
    294           visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{intervals[treeNode].LowerBound:E4} ... {intervals[treeNode].UpperBound:E4}]{Environment.NewLine}]");
     286          visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{intervals[treeNode].LowerBound:G5} ... {intervals[treeNode].UpperBound:G5}]{Environment.NewLine}");
    295287          node++;
    296288         
     
    309301              visualTree.FillColor = Color.FromArgb((int)(impact / max * 255), Color.Green);
    310302            }
    311             visualTree.ToolTip += String.Format($"{Environment.NewLine} Node impact: {impact:E4}");
     303            visualTree.ToolTip += String.Format($"Node impact: {impact:G5}");
    312304            var constantReplacementNode = foldedNodes[treeNode] as ConstantTreeNode;
    313305            if (constantReplacementNode != null) {
    314               visualTree.ToolTip += String.Format($"{Environment.NewLine} Replacement value: {constantReplacementNode.Value:E4}");
     306              visualTree.ToolTip += String.Format($"{Environment.NewLine}Replacement value: {constantReplacementNode.Value:G5}");
    315307            }
    316308          }
Note: See TracChangeset for help on using the changeset viewer.