Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/21 11:50:57 (3 years ago)
Author:
gkronber
Message:

#3140: merged r18091:18131 from branch to trunk

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r17579 r18132  
    109109
    110110    // the optimizer always assumes 2 children for multiplication and addition nodes
    111     // thus, we enforce that the tree stays valid so that the constant optimization won't throw an exception
     111    // thus, we enforce that the tree stays valid so that the parameter optimization won't throw an exception
    112112    // by returning 2 as the minimum allowed arity for addition and multiplication symbols
    113113    private readonly Func<ISymbol, int> GetMinArity = symbol => {
     
    130130
    131131      if (valid) {
    132         btnOptimizeConstants.Enabled = true;
     132        btnOptimizeParameters.Enabled = true;
    133133        btnSimplify.Enabled = true;
    134134        treeStatusValue.Visible = false;
    135135      } else {
    136         btnOptimizeConstants.Enabled = false;
     136        btnOptimizeParameters.Enabled = false;
    137137        btnSimplify.Enabled = false;
    138138        treeStatusValue.Visible = true;
     
    193193      treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    194194
    195       progress.Start("Calculate Impact and Replacement Values ...");
     195      progress.Start("Calculate impact and replacement values ...");
    196196      cancellationTokenSource = new CancellationTokenSource();
    197197      progress.CanBeStopped = true;
     
    203203
    204204        var replacementValues = impactAndReplacementValues.ToDictionary(x => x.Key, x => x.Value.Item2);
    205         foreach (var pair in replacementValues.Where(pair => !(pair.Key is ConstantTreeNode))) {
    206           foldedNodes[pair.Key] = MakeConstantTreeNode(pair.Value);
     205        foreach (var pair in replacementValues.Where(pair => !(pair.Key is INumericTreeNode))) {
     206          foldedNodes[pair.Key] = MakeNumberTreeNode(pair.Value);
    207207        }
    208208       
     
    235235      foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
    236236        if (progress.ProgressState == ProgressState.StopRequested) continue;
    237         double impactValue, replacementValue, newQualityForImpactsCalculation;
    238         impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices, out impactValue, out replacementValue, out newQualityForImpactsCalculation);
     237        impactCalculator.CalculateImpactAndReplacementValues(Content.Model, node, Content.ProblemData, Content.ProblemData.TrainingIndices,
     238          out double impactValue, out double replacementValue, out _);
    239239        double newProgressValue = progress.ProgressValue + 1.0 / (tree.Length - 2);
    240240        progress.ProgressValue = Math.Min(newProgressValue, 1);
     
    246246    protected abstract void UpdateModel(ISymbolicExpressionTree tree);
    247247
    248     protected virtual ISymbolicExpressionTree OptimizeConstants(ISymbolicExpressionTree tree, IProgress progress) {
     248    protected virtual ISymbolicExpressionTree OptimizeParameters(ISymbolicExpressionTree tree, IProgress progress) {
    249249      return tree;
    250250    }
    251251
    252     private static ConstantTreeNode MakeConstantTreeNode(double value) {
    253       var constant = new Constant { MinValue = value - 1, MaxValue = value + 1 };
    254       var constantTreeNode = (ConstantTreeNode)constant.CreateTreeNode();
    255       constantTreeNode.Value = value;
    256       return constantTreeNode;
     252    private static NumberTreeNode MakeNumberTreeNode(double value) {
     253      var num = new Number { MinValue = value - 1, MaxValue = value + 1 };
     254      var numTreeNode = (NumberTreeNode)num.CreateTreeNode();
     255      numTreeNode.Value = value;
     256      return numTreeNode;
    257257    }
    258258
     
    297297        VisualTreeNode<ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
    298298
    299         if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) {
     299        if (!(treeNode is INumericTreeNode) && nodeImpacts.ContainsKey(treeNode)) {
    300300          visualTree.ToolTip = visualTree.Content.ToString();
    301301          double impact = nodeImpacts[treeNode];
     
    314314          }
    315315          visualTree.ToolTip += Environment.NewLine + "Node impact: " + impact;
    316           var constantReplacementNode = foldedNodes[treeNode] as ConstantTreeNode;
    317           if (constantReplacementNode != null) {
    318             visualTree.ToolTip += Environment.NewLine + "Replacement value: " + constantReplacementNode.Value;
     316          if (foldedNodes[treeNode] is INumericTreeNode numReplacementNode) {
     317            visualTree.ToolTip += Environment.NewLine + "Replacement value: " + numReplacementNode.Value;
    319318          }
    320319        }
    321320        if (visualTree != null) {
    322321          if (nodeIntervals.ContainsKey(treeNode))
    323             visualTree.ToolTip += String.Format($"{Environment.NewLine}Intervals: [{nodeIntervals[treeNode].LowerBound:G5} ... {nodeIntervals[treeNode].UpperBound:G5}]");
     322            visualTree.ToolTip += string.Format($"{Environment.NewLine}Intervals: [{nodeIntervals[treeNode].LowerBound:G5} ... {nodeIntervals[treeNode].UpperBound:G5}]");
    324323          if (changedNodes.ContainsKey(treeNode)) {
    325324            visualTree.LineColor = Color.DodgerBlue;
    326           } else if (treeNode is ConstantTreeNode && foldedNodes.ContainsKey(treeNode)) {
     325          } else if (treeNode is INumericTreeNode && foldedNodes.ContainsKey(treeNode)) {
    327326            visualTree.LineColor = Color.DarkOrange;
    328327          }
     
    337336    }
    338337
    339     private async void btnOptimizeConstants_Click(object sender, EventArgs e) {
    340       progress.Start("Optimizing Constants ...");
     338    private async void btnOptimizeParameters_Click(object sender, EventArgs e) {
     339      progress.Start("Optimizing parameters ...");
    341340      cancellationTokenSource = new CancellationTokenSource();
    342341      progress.CanBeStopped = true;
     
    344343        var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone();
    345344
    346         var newTree = await Task.Run(() => OptimizeConstants(tree, progress));
     345        var newTree = await Task.Run(() => OptimizeParameters(tree, progress));
    347346        try {
    348347          await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation
Note: See TracChangeset for help on using the changeset viewer.