Changeset 18132 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/3140_NumberSymbol (added) merged: 18091,18093,18100,18112-18121,18123-18131
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Views
- Property svn:mergeinfo changed
/branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views (added) merged: 18100,18114-18115,18125
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r17579 r18132 109 109 110 110 // the optimizer always assumes 2 children for multiplication and addition nodes 111 // thus, we enforce that the tree stays valid so that the constantoptimization won't throw an exception111 // thus, we enforce that the tree stays valid so that the parameter optimization won't throw an exception 112 112 // by returning 2 as the minimum allowed arity for addition and multiplication symbols 113 113 private readonly Func<ISymbol, int> GetMinArity = symbol => { … … 130 130 131 131 if (valid) { 132 btnOptimize Constants.Enabled = true;132 btnOptimizeParameters.Enabled = true; 133 133 btnSimplify.Enabled = true; 134 134 treeStatusValue.Visible = false; 135 135 } else { 136 btnOptimize Constants.Enabled = false;136 btnOptimizeParameters.Enabled = false; 137 137 btnSimplify.Enabled = false; 138 138 treeStatusValue.Visible = true; … … 193 193 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 194 194 195 progress.Start("Calculate Impact and Replacement Values ...");195 progress.Start("Calculate impact and replacement values ..."); 196 196 cancellationTokenSource = new CancellationTokenSource(); 197 197 progress.CanBeStopped = true; … … 203 203 204 204 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] = Make ConstantTreeNode(pair.Value);205 foreach (var pair in replacementValues.Where(pair => !(pair.Key is INumericTreeNode))) { 206 foldedNodes[pair.Key] = MakeNumberTreeNode(pair.Value); 207 207 } 208 208 … … 235 235 foreach (var node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) { 236 236 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 _); 239 239 double newProgressValue = progress.ProgressValue + 1.0 / (tree.Length - 2); 240 240 progress.ProgressValue = Math.Min(newProgressValue, 1); … … 246 246 protected abstract void UpdateModel(ISymbolicExpressionTree tree); 247 247 248 protected virtual ISymbolicExpressionTree Optimize Constants(ISymbolicExpressionTree tree, IProgress progress) {248 protected virtual ISymbolicExpressionTree OptimizeParameters(ISymbolicExpressionTree tree, IProgress progress) { 249 249 return tree; 250 250 } 251 251 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; 257 257 } 258 258 … … 297 297 VisualTreeNode<ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); 298 298 299 if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) {299 if (!(treeNode is INumericTreeNode) && nodeImpacts.ContainsKey(treeNode)) { 300 300 visualTree.ToolTip = visualTree.Content.ToString(); 301 301 double impact = nodeImpacts[treeNode]; … … 314 314 } 315 315 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; 319 318 } 320 319 } 321 320 if (visualTree != null) { 322 321 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}]"); 324 323 if (changedNodes.ContainsKey(treeNode)) { 325 324 visualTree.LineColor = Color.DodgerBlue; 326 } else if (treeNode is ConstantTreeNode && foldedNodes.ContainsKey(treeNode)) {325 } else if (treeNode is INumericTreeNode && foldedNodes.ContainsKey(treeNode)) { 327 326 visualTree.LineColor = Color.DarkOrange; 328 327 } … … 337 336 } 338 337 339 private async void btnOptimize Constants_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 ..."); 341 340 cancellationTokenSource = new CancellationTokenSource(); 342 341 progress.CanBeStopped = true; … … 344 343 var tree = (ISymbolicExpressionTree)Content.Model.SymbolicExpressionTree.Clone(); 345 344 346 var newTree = await Task.Run(() => Optimize Constants(tree, progress));345 var newTree = await Task.Run(() => OptimizeParameters(tree, progress)); 347 346 try { 348 347 await Task.Delay(300, cancellationTokenSource.Token); // wait for progressbar to finish animation
Note: See TracChangeset
for help on using the changeset viewer.