Changeset 18115
- Timestamp:
- 12/13/21 17:49:34 (3 years ago)
- Location:
- branches/3140_NumberSymbol
- Files:
-
- 33 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
r18114 r18115 101 101 for (int i = 0; i < nodes.Count; ++i) { 102 102 var node = nodes[i]; 103 if (node is NumberTreeNode) continue;103 if (node is INumericTreeNode) continue; 104 104 105 105 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/IMultiObjectiveConstraintsEvaluator.cs
r17959 r18115 27 27 [StorableType("F96C5253-5A78-491C-95AE-78F64BD1F3B1")] 28 28 public interface IMultiObjectiveConstraintsEvaluator : ISymbolicRegressionMultiObjectiveEvaluator { 29 30 29 IFixedValueParameter<IntValue> NumConstraintsParameter { get; } 31 30 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/NMSEMultiObjectiveConstraintsEvaluator.cs
r18113 r18115 105 105 var scaling = offset.GetSubtree(0); 106 106 107 // Check if tree contains offset and scaling nodes107 // Check if tree contains offset and scaling nodes 108 108 if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication)) 109 109 throw new ArgumentException($"{ItemName} can only be used with LinearScalingGrammar."); … … 115 115 var newTree = new SymbolicExpressionTree(rootNode); 116 116 117 // calculate alpha and beta for scaling117 // calculate alpha and beta for scaling 118 118 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows); 119 119 … … 122 122 out var errorState); 123 123 if (errorState == OnlineCalculatorError.None) { 124 // Set alpha and beta to the scaling nodes from iagrammar124 // Set alpha and beta to the scaling nodes from linear scaling grammar 125 125 var offsetParameter = offset.GetSubtree(1) as NumberTreeNode; 126 126 offsetParameter.Value = alpha; … … 162 162 double upperEstimationLimit, 163 163 IRegressionProblemData problemData, IEnumerable<int> rows, IBoundsEstimator estimator, int decimalPlaces) { 164 OnlineCalculatorError errorState;165 164 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows); 166 165 var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows); … … 174 173 175 174 var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit); 176 nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);175 nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out OnlineCalculatorError errorState); 177 176 178 177 if (errorState != OnlineCalculatorError.None) nmse = 1.0; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSESingleObjectiveConstraintsEvaluator.cs
r18113 r18115 97 97 public NMSESingleObjectiveConstraintsEvaluator() { 98 98 Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeParametersParameterName, 99 "Define whether optimization of numericparameters is active or not (default: false).", new BoolValue(false)));99 "Define whether optimization of parameters is active or not (default: false).", new BoolValue(false))); 100 100 Parameters.Add(new FixedValueParameter<IntValue>(ParameterOptimizationIterationsParameterName, 101 101 "Define how many parameter optimization steps should be performed (default: 10).", new IntValue(10))); … … 109 109 110 110 [StorableHook(HookType.AfterDeserialization)] 111 private void AfterDeserialization() { 112 if (!Parameters.ContainsKey(ParameterOptimizationIterationsParameterName)) { 113 if (Parameters.ContainsKey("ParameterOptimizationIterations")) { 114 Parameters.Add(new FixedValueParameter<IntValue>(ParameterOptimizationIterationsParameterName, "Define how many parameter optimization steps should be performed (default: 10).", (IntValue)Parameters["ParameterOptimizationIterations"].ActualValue)); 115 Parameters.Remove("ParameterOptimizationIterations"); 116 } else { 117 Parameters.Add(new FixedValueParameter<IntValue>(ParameterOptimizationIterationsParameterName, "Define how many parameter optimization steps should be performed (default: 10).", new IntValue(10))); 118 } 119 } 120 121 } 111 private void AfterDeserialization() { } 122 112 123 113 public override IDeepCloneable Clone(Cloner cloner) { -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r18114 r18115 91 91 for (int i = 0; i < nodes.Count; ++i) { 92 92 var node = nodes[i]; 93 if (node is NumberTreeNode) continue;93 if (node is INumericTreeNode) continue; // skip constants and numbers 94 94 95 95 impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows, -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r18052 r18115 129 129 </Compile> 130 130 <Compile Include="Plugin.cs" /> 131 <Compile Include="Symbols\ConstantView.cs"> 132 <SubType>UserControl</SubType> 133 </Compile> 134 <Compile Include="Symbols\ConstantView.Designer.cs"> 135 <DependentUpon>ConstantView.cs</DependentUpon> 136 </Compile> 137 <Compile Include="Symbols\NumberView.cs"> 138 <SubType>UserControl</SubType> 139 </Compile> 140 <Compile Include="Symbols\NumberView.Designer.cs"> 141 <DependentUpon>NumberView.cs</DependentUpon> 142 </Compile> 131 143 <Compile Include="TextualSymbolicDataAnalysisModelView.cs"> 132 144 <SubType>UserControl</SubType> … … 146 158 <Compile Include="GraphicalSymbolicDataAnalysisModelView.designer.cs"> 147 159 <DependentUpon>GraphicalSymbolicDataAnalysisModelView.cs</DependentUpon> 148 </Compile>149 <Compile Include="Symbols\ConstantView.cs">150 <SubType>UserControl</SubType>151 </Compile>152 <Compile Include="Symbols\ConstantView.Designer.cs">153 <DependentUpon>ConstantView.cs</DependentUpon>154 160 </Compile> 155 161 <Compile Include="Symbols\LaggedVariableView.cs"> -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r18114 r18115 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; … … 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); … … 297 297 VisualTreeNode<ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); 298 298 299 if (!(treeNode is NumberTreeNode) && 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 if (foldedNodes[treeNode] is NumberTreeNode numReplacementNode) {316 if (foldedNodes[treeNode] is INumericTreeNode numReplacementNode) { 317 317 visualTree.ToolTip += Environment.NewLine + "Replacement value: " + numReplacementNode.Value; 318 318 } … … 320 320 if (visualTree != null) { 321 321 if (nodeIntervals.ContainsKey(treeNode)) 322 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}]"); 323 323 if (changedNodes.ContainsKey(treeNode)) { 324 324 visualTree.LineColor = Color.DodgerBlue; 325 } else if (treeNode is NumberTreeNode && foldedNodes.ContainsKey(treeNode)) {325 } else if (treeNode is INumericTreeNode && foldedNodes.ContainsKey(treeNode)) { 326 326 visualTree.LineColor = Color.DarkOrange; 327 327 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.Designer.cs
r17180 r18115 64 64 this.insertNodeToolStripMenuItem.Name = "insertNodeToolStripMenuItem"; 65 65 this.insertNodeToolStripMenuItem.Size = new System.Drawing.Size(165, 22); 66 this.insertNodeToolStripMenuItem.Text = "Insert Node";66 this.insertNodeToolStripMenuItem.Text = "Insert node"; 67 67 this.insertNodeToolStripMenuItem.Click += new System.EventHandler(this.insertNodeToolStripMenuItem_Click); 68 68 // … … 71 71 this.changeNodeToolStripMenuItem.Name = "changeNodeToolStripMenuItem"; 72 72 this.changeNodeToolStripMenuItem.Size = new System.Drawing.Size(165, 22); 73 this.changeNodeToolStripMenuItem.Text = "Change Node";73 this.changeNodeToolStripMenuItem.Text = "Change node"; 74 74 this.changeNodeToolStripMenuItem.Click += new System.EventHandler(this.changeNodeToolStripMenuItem_Click); 75 75 // … … 78 78 this.cutToolStripMenuItem.Name = "cutToolStripMenuItem"; 79 79 this.cutToolStripMenuItem.Size = new System.Drawing.Size(165, 22); 80 this.cutToolStripMenuItem.Text = "Cut Subtree";80 this.cutToolStripMenuItem.Text = "Cut subtree"; 81 81 this.cutToolStripMenuItem.Click += new System.EventHandler(this.cutToolStripMenuItem_Click); 82 82 // … … 109 109 this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem"; 110 110 this.pasteToolStripMenuItem.Size = new System.Drawing.Size(165, 22); 111 this.pasteToolStripMenuItem.Text = "Paste Subtree";111 this.pasteToolStripMenuItem.Text = "Paste subtree"; 112 112 this.pasteToolStripMenuItem.Click += new System.EventHandler(this.pasteToolStripMenuItem_Clicked); 113 113 // … … 121 121 this.copyToolStripMenuItem.Name = "copyToolStripMenuItem"; 122 122 this.copyToolStripMenuItem.Size = new System.Drawing.Size(165, 22); 123 this.copyToolStripMenuItem.Text = "Copy Subtree";123 this.copyToolStripMenuItem.Text = "Copy subtree"; 124 124 this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click); 125 125 // -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs
r18100 r18115 28 28 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 30 internal delegate void 31 ModifyTree(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode node, ISymbolicExpressionTreeNode oldChild, ISymbolicExpressionTreeNode newChild,bool removeSubtree = true);30 internal delegate void ModifyTree(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode node, ISymbolicExpressionTreeNode oldChild, ISymbolicExpressionTreeNode newChild, 31 bool removeSubtree = true); 32 32 33 33 internal sealed partial class InteractiveSymbolicExpressionTreeChart : SymbolicExpressionTreeChart { … … 82 82 83 83 protected override void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) { 84 currSelected = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender; ;84 currSelected = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender; 85 85 base.OnSymbolicExpressionTreeNodeClicked(sender, e); 86 86 } … … 104 104 var symbol = dialog.SelectedSymbol; 105 105 var node = symbol.CreateTreeNode(); 106 if (node is NumberTreeNode) { 107 var number = node as NumberTreeNode; 108 number.Value = double.Parse(dialog.numberValueTextBox.Text); 106 if (node is INumericTreeNode numTreeNode) { 107 numTreeNode.Value = double.Parse(dialog.numberValueTextBox.Text); 109 108 } else if (node is VariableTreeNode) { 110 109 var variable = node as VariableTreeNode; … … 133 132 ISymbolicExpressionTreeNode newNode = null; 134 133 var result = DialogResult.Cancel; 135 if (node is NumberTreeNode) {134 if (node is INumericTreeNode) { 136 135 using (var dialog = new NumberNodeEditDialog(node)) { 137 136 dialog.ShowDialog(this); … … 200 199 // check if the copied/cut node (stored in the tempNode) can be inserted as a child of the current selected node 201 200 var node = currSelected.Content; 202 if (node is NumberTreeNode || node is VariableTreeNode) return;201 if (node is INumericTreeNode || node is VariableTreeNode) return; 203 202 // check if the currently selected node can accept the copied node as a child 204 203 // no need to check the grammar, an arity check will do just fine here -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/ConstantView.Designer.cs
r18114 r18115 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 this.weightNuLabel = new System.Windows.Forms.Label(); 48 this.minValueTextBox = new System.Windows.Forms.TextBox(); 49 this.initializationGroupBox = new System.Windows.Forms.GroupBox(); 50 this.weightSigmaLabel = new System.Windows.Forms.Label(); 51 this.maxValueTextBox = new System.Windows.Forms.TextBox(); 52 this.mutationGroupBox = new System.Windows.Forms.GroupBox(); 53 this.multiplicativeChangeLabel = new System.Windows.Forms.Label(); 54 this.multiplicativeChangeSigmaTextBox = new System.Windows.Forms.TextBox(); 55 this.additiveChangeLabel = new System.Windows.Forms.Label(); 56 this.additiveChangeSigmaTextBox = new System.Windows.Forms.TextBox(); 47 this.valueLabel = new System.Windows.Forms.Label(); 48 this.valueTextBox = new System.Windows.Forms.TextBox(); 57 49 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit(); 58 this.initializationGroupBox.SuspendLayout();59 this.mutationGroupBox.SuspendLayout();60 50 this.SuspendLayout(); 61 51 // … … 68 58 this.errorProvider.SetIconAlignment(this.initialFrequencyTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 69 59 this.initialFrequencyTextBox.Size = new System.Drawing.Size(280, 20); 60 // 61 // minimumArityLabel 62 // 63 this.toolTip.SetToolTip(this.minimumArityLabel, "The minimum arity of the symbol"); 64 // 65 // maximumArityLabel 66 // 67 this.toolTip.SetToolTip(this.maximumArityLabel, "The maximum arity of the symbol"); 70 68 // 71 69 // minimumArityTextBox … … 89 87 this.infoLabel.Location = new System.Drawing.Point(379, 3); 90 88 // 91 // weightNuLabel89 // valueLabel 92 90 // 93 this. weightNuLabel.AutoSize = true;94 this. weightNuLabel.Location = new System.Drawing.Point(6, 22);95 this. weightNuLabel.Name = "weightNuLabel";96 this. weightNuLabel.Size = new System.Drawing.Size(56, 13);97 this. weightNuLabel.TabIndex = 0;98 this. weightNuLabel.Text = "Min value:";99 this.toolTip.SetToolTip(this. weightNuLabel, "The minimal value to use for random initialization of numbers.");91 this.valueLabel.AutoSize = true; 92 this.valueLabel.Location = new System.Drawing.Point(3, 130); 93 this.valueLabel.Name = "valueLabel"; 94 this.valueLabel.Size = new System.Drawing.Size(37, 13); 95 this.valueLabel.TabIndex = 0; 96 this.valueLabel.Text = "Value:"; 97 this.toolTip.SetToolTip(this.valueLabel, "The value of the constant."); 100 98 // 101 // minValueTextBox99 // valueTextBox 102 100 // 103 this. minValueTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)101 this.valueTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 104 102 | System.Windows.Forms.AnchorStyles.Right))); 105 this.errorProvider.SetIconAlignment(this.minValueTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 106 this.minValueTextBox.Location = new System.Drawing.Point(92, 19); 107 this.minValueTextBox.Name = "minValueTextBox"; 108 this.minValueTextBox.Size = new System.Drawing.Size(300, 20); 109 this.minValueTextBox.TabIndex = 1; 110 this.toolTip.SetToolTip(this.minValueTextBox, "The minimal value to use for random initialization of numbers."); 111 this.minValueTextBox.TextChanged += new System.EventHandler(this.minValueTextBox_TextChanged); 112 // 113 // initializationGroupBox 114 // 115 this.initializationGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 116 | System.Windows.Forms.AnchorStyles.Right))); 117 this.initializationGroupBox.Controls.Add(this.weightSigmaLabel); 118 this.initializationGroupBox.Controls.Add(this.maxValueTextBox); 119 this.initializationGroupBox.Controls.Add(this.weightNuLabel); 120 this.initializationGroupBox.Controls.Add(this.minValueTextBox); 121 this.initializationGroupBox.Location = new System.Drawing.Point(0, 127); 122 this.initializationGroupBox.Name = "initializationGroupBox"; 123 this.initializationGroupBox.Size = new System.Drawing.Size(398, 73); 124 this.initializationGroupBox.TabIndex = 5; 125 this.initializationGroupBox.TabStop = false; 126 this.initializationGroupBox.Text = "Initialization"; 127 // 128 // weightSigmaLabel 129 // 130 this.weightSigmaLabel.AutoSize = true; 131 this.weightSigmaLabel.Location = new System.Drawing.Point(6, 48); 132 this.weightSigmaLabel.Name = "weightSigmaLabel"; 133 this.weightSigmaLabel.Size = new System.Drawing.Size(59, 13); 134 this.weightSigmaLabel.TabIndex = 2; 135 this.weightSigmaLabel.Text = "Max value:"; 136 this.toolTip.SetToolTip(this.weightSigmaLabel, "The maximal value to use for random initialization of numbers."); 137 // 138 // maxValueTextBox 139 // 140 this.maxValueTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 141 | System.Windows.Forms.AnchorStyles.Right))); 142 this.errorProvider.SetIconAlignment(this.maxValueTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 143 this.maxValueTextBox.Location = new System.Drawing.Point(92, 45); 144 this.maxValueTextBox.Name = "maxValueTextBox"; 145 this.maxValueTextBox.Size = new System.Drawing.Size(300, 20); 146 this.maxValueTextBox.TabIndex = 3; 147 this.toolTip.SetToolTip(this.maxValueTextBox, "The maximal value to use for random initialization of numbers."); 148 this.maxValueTextBox.TextChanged += new System.EventHandler(this.maxValueTextBox_TextChanged); 149 // 150 // mutationGroupBox 151 // 152 this.mutationGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 153 | System.Windows.Forms.AnchorStyles.Right))); 154 this.mutationGroupBox.Controls.Add(this.multiplicativeChangeLabel); 155 this.mutationGroupBox.Controls.Add(this.multiplicativeChangeSigmaTextBox); 156 this.mutationGroupBox.Controls.Add(this.additiveChangeLabel); 157 this.mutationGroupBox.Controls.Add(this.additiveChangeSigmaTextBox); 158 this.mutationGroupBox.Location = new System.Drawing.Point(0, 206); 159 this.mutationGroupBox.Name = "mutationGroupBox"; 160 this.mutationGroupBox.Size = new System.Drawing.Size(398, 73); 161 this.mutationGroupBox.TabIndex = 6; 162 this.mutationGroupBox.TabStop = false; 163 this.mutationGroupBox.Text = "Mutation"; 164 // 165 // multiplicativeChangeLabel 166 // 167 this.multiplicativeChangeLabel.AutoSize = true; 168 this.multiplicativeChangeLabel.Location = new System.Drawing.Point(6, 48); 169 this.multiplicativeChangeLabel.Name = "multiplicativeChangeLabel"; 170 this.multiplicativeChangeLabel.Size = new System.Drawing.Size(146, 13); 171 this.multiplicativeChangeLabel.TabIndex = 2; 172 this.multiplicativeChangeLabel.Text = "Multiplicative change (sigma):"; 173 this.toolTip.SetToolTip(this.multiplicativeChangeLabel, "The sigma (std. dev.) parameter for the normal distribution to use to sample the " + 174 "multiplicative change."); 175 // 176 // multiplicativeChangeSigmaTextBox 177 // 178 this.multiplicativeChangeSigmaTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 179 | System.Windows.Forms.AnchorStyles.Right))); 180 this.errorProvider.SetIconAlignment(this.multiplicativeChangeSigmaTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 181 this.multiplicativeChangeSigmaTextBox.Location = new System.Drawing.Point(168, 45); 182 this.multiplicativeChangeSigmaTextBox.Name = "multiplicativeChangeSigmaTextBox"; 183 this.multiplicativeChangeSigmaTextBox.Size = new System.Drawing.Size(224, 20); 184 this.multiplicativeChangeSigmaTextBox.TabIndex = 3; 185 this.toolTip.SetToolTip(this.multiplicativeChangeSigmaTextBox, "The sigma (std. dev.) parameter for the normal distribution to use to sample a mu" + 186 "ltiplicative change."); 187 this.multiplicativeChangeSigmaTextBox.TextChanged += new System.EventHandler(this.multiplicativeChangeSigmaTextBox_TextChanged); 188 // 189 // additiveChangeLabel 190 // 191 this.additiveChangeLabel.AutoSize = true; 192 this.additiveChangeLabel.Location = new System.Drawing.Point(6, 22); 193 this.additiveChangeLabel.Name = "additiveChangeLabel"; 194 this.additiveChangeLabel.Size = new System.Drawing.Size(123, 13); 195 this.additiveChangeLabel.TabIndex = 0; 196 this.additiveChangeLabel.Text = "Additive change (sigma):"; 197 this.toolTip.SetToolTip(this.additiveChangeLabel, "The sigma (std. dev.) parameter for the normal distribution to sample the additiv" + 198 "e change."); 199 // 200 // additiveChangeSigmaTextBox 201 // 202 this.additiveChangeSigmaTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 203 | System.Windows.Forms.AnchorStyles.Right))); 204 this.errorProvider.SetIconAlignment(this.additiveChangeSigmaTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 205 this.additiveChangeSigmaTextBox.Location = new System.Drawing.Point(168, 19); 206 this.additiveChangeSigmaTextBox.Name = "additiveChangeSigmaTextBox"; 207 this.additiveChangeSigmaTextBox.Size = new System.Drawing.Size(224, 20); 208 this.additiveChangeSigmaTextBox.TabIndex = 1; 209 this.toolTip.SetToolTip(this.additiveChangeSigmaTextBox, "The sigma (std. dev.) parameter for the normal distribution to use to sample an a" + 210 "dditive change."); 211 this.additiveChangeSigmaTextBox.TextChanged += new System.EventHandler(this.additiveChangeSigmaTextBox_TextChanged); 103 this.errorProvider.SetIconAlignment(this.valueTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 104 this.valueTextBox.Location = new System.Drawing.Point(93, 127); 105 this.valueTextBox.Name = "valueTextBox"; 106 this.valueTextBox.Size = new System.Drawing.Size(280, 20); 107 this.valueTextBox.TabIndex = 1; 108 this.toolTip.SetToolTip(this.valueTextBox, "The value of the constant."); 109 this.valueTextBox.TextChanged += new System.EventHandler(this.valueTextBox_TextChanged); 212 110 // 213 111 // ConstantView 214 112 // 215 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);216 113 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 217 this.Controls.Add(this. mutationGroupBox);218 this.Controls.Add(this. initializationGroupBox);114 this.Controls.Add(this.valueLabel); 115 this.Controls.Add(this.valueTextBox); 219 116 this.Name = "ConstantView"; 220 this.Size = new System.Drawing.Size(398, 284); 117 this.Size = new System.Drawing.Size(398, 168); 118 this.Controls.SetChildIndex(this.valueTextBox, 0); 119 this.Controls.SetChildIndex(this.valueLabel, 0); 120 this.Controls.SetChildIndex(this.enabledCheckBox, 0); 121 this.Controls.SetChildIndex(this.initialFrequencyLabel, 0); 122 this.Controls.SetChildIndex(this.initialFrequencyTextBox, 0); 221 123 this.Controls.SetChildIndex(this.maximumArityLabel, 0); 222 124 this.Controls.SetChildIndex(this.maximumArityTextBox, 0); … … 224 126 this.Controls.SetChildIndex(this.minimumArityTextBox, 0); 225 127 this.Controls.SetChildIndex(this.infoLabel, 0); 226 this.Controls.SetChildIndex(this.initializationGroupBox, 0);227 this.Controls.SetChildIndex(this.initialFrequencyTextBox, 0);228 this.Controls.SetChildIndex(this.initialFrequencyLabel, 0);229 128 this.Controls.SetChildIndex(this.nameLabel, 0); 230 129 this.Controls.SetChildIndex(this.nameTextBox, 0); 231 this.Controls.SetChildIndex(this.mutationGroupBox, 0);232 130 ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit(); 233 this.initializationGroupBox.ResumeLayout(false);234 this.initializationGroupBox.PerformLayout();235 this.mutationGroupBox.ResumeLayout(false);236 this.mutationGroupBox.PerformLayout();237 131 this.ResumeLayout(false); 238 132 this.PerformLayout(); … … 242 136 #endregion 243 137 244 private System.Windows.Forms.Label weightNuLabel; 245 private System.Windows.Forms.TextBox minValueTextBox; 246 protected System.Windows.Forms.GroupBox initializationGroupBox; 247 private System.Windows.Forms.Label weightSigmaLabel; 248 private System.Windows.Forms.TextBox maxValueTextBox; 249 protected System.Windows.Forms.GroupBox mutationGroupBox; 250 private System.Windows.Forms.Label multiplicativeChangeLabel; 251 private System.Windows.Forms.TextBox multiplicativeChangeSigmaTextBox; 252 private System.Windows.Forms.Label additiveChangeLabel; 253 private System.Windows.Forms.TextBox additiveChangeSigmaTextBox; 254 138 private System.Windows.Forms.Label valueLabel; 139 private System.Windows.Forms.TextBox valueTextBox; 255 140 } 256 141 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/ConstantView.cs
r18100 r18115 27 27 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 29 [View(" NumberView")]30 [Content(typeof( Number), true)]29 [View("Constant View")] 30 [Content(typeof(Constant), true)] 31 31 public partial class ConstantView : SymbolView { 32 public new NumberContent {33 get { return ( Number)base.Content; }32 public new Constant Content { 33 get { return (Constant)base.Content; } 34 34 set { base.Content = value; } 35 35 } … … 43 43 Content.Changed += new EventHandler(Content_Changed); 44 44 } 45 45 46 46 protected override void DeregisterContentEvents() { 47 47 base.DeregisterContentEvents(); … … 56 56 protected override void SetEnabledStateOfControls() { 57 57 base.SetEnabledStateOfControls(); 58 minValueTextBox.Enabled = Content != null; 59 minValueTextBox.ReadOnly = ReadOnly; 60 maxValueTextBox.Enabled = Content != null; 61 maxValueTextBox.ReadOnly = ReadOnly; 62 additiveChangeSigmaTextBox.Enabled = Content != null; 63 additiveChangeSigmaTextBox.ReadOnly = ReadOnly; 64 multiplicativeChangeSigmaTextBox.Enabled = Content != null; 65 multiplicativeChangeSigmaTextBox.ReadOnly = ReadOnly; 58 valueTextBox.Enabled = Content != null; 59 valueTextBox.ReadOnly = ReadOnly; 66 60 } 67 61 … … 73 67 74 68 #region control event handlers 75 private void minValueTextBox_TextChanged(object sender, EventArgs e) {76 double min;77 if (double.TryParse( minValueTextBox.Text, out min)) {78 Content. MinValue = min;79 errorProvider.SetError( minValueTextBox, string.Empty);69 private void valueTextBox_TextChanged(object sender, EventArgs e) { 70 double val; 71 if (double.TryParse(valueTextBox.Text, out val)) { 72 Content.Value = val; 73 errorProvider.SetError(valueTextBox, string.Empty); 80 74 } else { 81 errorProvider.SetError(minValueTextBox, "Invalid value"); 82 } 83 } 84 private void maxValueTextBox_TextChanged(object sender, EventArgs e) { 85 double max; 86 if (double.TryParse(maxValueTextBox.Text, out max)) { 87 Content.MaxValue = max; 88 errorProvider.SetError(maxValueTextBox, string.Empty); 89 } else { 90 errorProvider.SetError(maxValueTextBox, "Invalid value"); 91 } 92 } 93 94 private void additiveChangeSigmaTextBox_TextChanged(object sender, EventArgs e) { 95 double sigma; 96 if (double.TryParse(additiveChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) { 97 Content.ManipulatorSigma = sigma; 98 errorProvider.SetError(additiveChangeSigmaTextBox, string.Empty); 99 } else { 100 errorProvider.SetError(additiveChangeSigmaTextBox, "Invalid value"); 101 } 102 } 103 104 private void multiplicativeChangeSigmaTextBox_TextChanged(object sender, EventArgs e) { 105 double sigma; 106 if (double.TryParse(multiplicativeChangeSigmaTextBox.Text, out sigma) && sigma >= 0.0) { 107 Content.MultiplicativeManipulatorSigma = sigma; 108 errorProvider.SetError(multiplicativeChangeSigmaTextBox, string.Empty); 109 } else { 110 errorProvider.SetError(multiplicativeChangeSigmaTextBox, "Invalid value"); 75 errorProvider.SetError(valueTextBox, "Invalid value"); 111 76 } 112 77 } … … 116 81 private void UpdateControl() { 117 82 if (Content == null) { 118 minValueTextBox.Text = string.Empty; 119 maxValueTextBox.Text = string.Empty; 120 minValueTextBox.Text = string.Empty; 121 multiplicativeChangeSigmaTextBox.Text = string.Empty; 122 additiveChangeSigmaTextBox.Text = string.Empty; 83 valueTextBox.Text = string.Empty; 123 84 } else { 124 minValueTextBox.Text = Content.MinValue.ToString(); 125 maxValueTextBox.Text = Content.MaxValue.ToString(); 126 additiveChangeSigmaTextBox.Text = Content.ManipulatorSigma.ToString(); 127 multiplicativeChangeSigmaTextBox.Text = Content.MultiplicativeManipulatorSigma.ToString(); 85 valueTextBox.Text = Content.Value.ToString("g17"); 128 86 } 129 87 SetEnabledStateOfControls(); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/NumberView.Designer.cs
r18114 r18115 21 21 22 22 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 23 partial class ConstantView {23 partial class NumberView { 24 24 /// <summary> 25 25 /// Required designer variable. -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/NumberView.cs
r18113 r18115 29 29 [View("Number View")] 30 30 [Content(typeof(Number), true)] 31 public partial class ConstantView : SymbolView {31 public partial class NumberView : SymbolView { 32 32 public new Number Content { 33 33 get { return (Number)base.Content; } … … 35 35 } 36 36 37 public ConstantView() {37 public NumberView() { 38 38 InitializeComponent(); 39 39 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeConstantNodeEditDialog.cs
r18114 r18115 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views { 30 30 public partial class NumberNodeEditDialog : Form { 31 private NumberTreeNode numberTreeNode;32 public NumberTreeNode NewNode {31 private INumericTreeNode numberTreeNode; 32 public INumericTreeNode NewNode { 33 33 get { return numberTreeNode; } 34 34 set { 35 35 if (InvokeRequired) 36 Invoke(new Action<SymbolicExpressionTreeNode>(x => numberTreeNode = ( NumberTreeNode)x), value);36 Invoke(new Action<SymbolicExpressionTreeNode>(x => numberTreeNode = (INumericTreeNode)x), value); 37 37 else 38 38 numberTreeNode = value; … … 43 43 InitializeComponent(); 44 44 oldValueTextBox.TabStop = false; // cannot receive focus using tab key 45 NewNode = ( NumberTreeNode)node;45 NewNode = (INumericTreeNode)node; 46 46 InitializeFields(); 47 47 } … … 71 71 72 72 private static bool ValidateNewValue(string value, out string errorMessage) { 73 double val; 74 bool valid = double.TryParse(value, out val); 73 bool valid = double.TryParse(value, out _); 75 74 errorMessage = string.Empty; 76 75 if (!valid) { -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs
r18114 r18115 25 25 using System.Collections.Generic; 26 26 using System.Linq; 27 using HeuristicLab.Common; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 29 … … 80 81 private static ISymbolicExpressionTreeNode MacroExpand(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode node, 81 82 IList<ISymbolicExpressionTreeNode> argumentTrees) { 82 List<ISymbolicExpressionTreeNode>subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);83 var subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees); 83 84 while (node.SubtreeCount > 0) node.RemoveSubtree(0); 84 85 if (node.Symbol is InvokeFunction) { … … 239 240 } 240 241 242 private static bool IsNumber(ISymbolicExpressionTreeNode node) { 243 return node.Symbol is Number; 244 } 245 private static bool IsConstant(ISymbolicExpressionTreeNode node) { 246 return node.Symbol is Constant; 247 } 241 248 private static bool IsConstantOrNumber(ISymbolicExpressionTreeNode node) { 242 249 return node is INumericTreeNode; 243 250 } 244 251 245 private static bool IsNumber(ISymbolicExpressionTreeNode node) {246 return node.Symbol is Number;247 }248 249 private static bool IsConstant(ISymbolicExpressionTreeNode node) {250 return node.Symbol is Constant;251 }252 // dynamic253 252 private static bool IsTimeLag(ISymbolicExpressionTreeNode node) { 254 253 return node.Symbol is TimeLag; … … 330 329 private static ISymbolicExpressionTreeNode SimplifyAny(ISymbolicExpressionTreeNode original) { 331 330 // can't simplify this function but simplify all subtrees 332 List<ISymbolicExpressionTreeNode>subtrees = new List<ISymbolicExpressionTreeNode>(original.Subtrees);331 var subtrees = new List<ISymbolicExpressionTreeNode>(original.Subtrees); 333 332 while (original.Subtrees.Count() > 0) original.RemoveSubtree(0); 334 333 var clone = (SymbolicExpressionTreeNode)original.Clone(); 335 List<ISymbolicExpressionTreeNode>simplifiedSubtrees = new List<ISymbolicExpressionTreeNode>();334 var simplifiedSubtrees = new List<ISymbolicExpressionTreeNode>(); 336 335 foreach (var subtree in subtrees) { 337 336 simplifiedSubtrees.Add(GetSimplifiedTree(subtree)); … … 341 340 clone.AddSubtree(simplifiedSubtree); 342 341 } 343 if (simplifiedSubtrees.TrueForAll(Is ConstantOrNumber)) {342 if (simplifiedSubtrees.TrueForAll(IsNumber)) { 344 343 FoldNumbers(clone); 345 344 } … … 348 347 349 348 private static ISymbolicExpressionTreeNode FoldNumbers(ISymbolicExpressionTreeNode original) { 350 // TODO not yetimplemented349 // TODO not implemented 351 350 return original; 352 351 } … … 500 499 return AddLagToDynamicNodes(simplifiedSubtree, laggedTreeNode.Lag); 501 500 } else { 502 return TimeLag(simplifiedSubtree, laggedTreeNode.Lag);501 return Lag(simplifiedSubtree, laggedTreeNode.Lag); 503 502 } 504 503 } … … 518 517 #region low level tree restructuring 519 518 520 private static ISymbolicExpressionTreeNode TimeLag(ISymbolicExpressionTreeNode subtree, int lag) {519 private static ISymbolicExpressionTreeNode Lag(ISymbolicExpressionTreeNode subtree, int lag) { 521 520 if (lag == 0) return subtree; 522 if (Is Number(subtree)) return subtree;521 if (IsConstantOrNumber(subtree)) return subtree; 523 522 var lagNode = (LaggedTreeNode)timeLagSymbol.CreateTreeNode(); 524 523 lagNode.Lag = lag; … … 541 540 private static ISymbolicExpressionTreeNode Not(ISymbolicExpressionTreeNode t) { 542 541 if (IsNumber(t)) { 543 var constNode = t as NumberTreeNode;544 if ( constNode.Value > 0) return Number(-1.0);542 var numNode = t as NumberTreeNode; 543 if (numNode.Value > 0) return Number(-1.0); 545 544 else return Number(1.0); 546 545 } else if (IsNot(t)) { … … 562 561 private static ISymbolicExpressionTreeNode Or(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 563 562 if (IsNumber(a) && IsNumber(b)) { 564 var constA= a as NumberTreeNode;565 var constB= b as NumberTreeNode;566 if ( constA.Value > 0.0 || constB.Value > 0.0) {563 var aNode = a as NumberTreeNode; 564 var bNode = b as NumberTreeNode; 565 if (aNode.Value > 0.0 || bNode.Value > 0.0) { 567 566 return Number(1.0); 568 567 } else { … … 572 571 return Or(b, a); 573 572 } else if (IsNumber(b)) { 574 var constT= b as NumberTreeNode;575 if ( constT.Value > 0.0) {573 var bNode = b as NumberTreeNode; 574 if (bNode.Value > 0.0) { 576 575 // boolean expression is necessarily true 577 576 return Number(1.0); 578 577 } else { 579 // the constant value has no effect on the result of the boolean condition so we can drop the constant term578 // the value has no effect on the result of the boolean condition so we can drop the number 580 579 var orNode = orSymbol.CreateTreeNode(); 581 580 orNode.AddSubtree(a); … … 592 591 private static ISymbolicExpressionTreeNode And(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 593 592 if (IsNumber(a) && IsNumber(b)) { 594 var constA= a as NumberTreeNode;595 var constB= b as NumberTreeNode;596 if ( constA.Value > 0.0 && constB.Value > 0.0) {593 var aNode = a as NumberTreeNode; 594 var bNode = b as NumberTreeNode; 595 if (aNode.Value > 0.0 && bNode.Value > 0.0) { 597 596 return Number(1.0); 598 597 } else { … … 602 601 return And(b, a); 603 602 } else if (IsNumber(b)) { 604 var constB= b as NumberTreeNode;605 if ( constB.Value > 0.0) {606 // the constant value has no effect on the result of the boolean condition so we can drop the constant term603 var bNode = b as NumberTreeNode; 604 if (bNode.Value > 0.0) { 605 // the value has no effect on the result of the boolean condition so we can drop the number 607 606 var andNode = andSymbol.CreateTreeNode(); 608 607 andNode.AddSubtree(a); … … 623 622 ISymbolicExpressionTreeNode rightSide) { 624 623 if (IsNumber(leftSide) && IsNumber(rightSide)) { 625 var ls Const= leftSide as NumberTreeNode;626 var rs Const= rightSide as NumberTreeNode;627 if (ls Const.Value < rsConst.Value) return Number(1.0);624 var lsNode = leftSide as NumberTreeNode; 625 var rsNode = rightSide as NumberTreeNode; 626 if (lsNode.Value < rsNode.Value) return Number(1.0); 628 627 else return Number(-1.0); 629 628 } else { … … 638 637 ISymbolicExpressionTreeNode rightSide) { 639 638 if (IsNumber(leftSide) && IsNumber(rightSide)) { 640 var ls Const= leftSide as NumberTreeNode;641 var rs Const= rightSide as NumberTreeNode;642 if (ls Const.Value > rsConst.Value) return Number(1.0);639 var lsNode = leftSide as NumberTreeNode; 640 var rsNode = rightSide as NumberTreeNode; 641 if (lsNode.Value > rsNode.Value) return Number(1.0); 643 642 else return Number(-1.0); 644 643 } else { … … 652 651 private static ISymbolicExpressionTreeNode IfThenElse(ISymbolicExpressionTreeNode condition, 653 652 ISymbolicExpressionTreeNode trueBranch, ISymbolicExpressionTreeNode falseBranch) { 654 if (Is Number(condition)) {655 var con stT = condition as NumberTreeNode;656 if (con stT.Value > 0.0) return trueBranch;653 if (IsConstantOrNumber(condition)) { 654 var condNode = condition as INumericTreeNode; 655 if (condNode.Value > 0.0) return trueBranch; 657 656 else return falseBranch; 658 657 } else { … … 674 673 private static ISymbolicExpressionTreeNode Sine(ISymbolicExpressionTreeNode node) { 675 674 if (IsNumber(node)) { 676 var constT= node as NumberTreeNode;677 return Number(Math.Sin( constT.Value));675 var numNode = node as NumberTreeNode; 676 return Number(Math.Sin(numNode.Value)); 678 677 } else if (IsFactor(node)) { 679 678 var factor = node as FactorVariableTreeNode; … … 691 690 private static ISymbolicExpressionTreeNode Tangent(ISymbolicExpressionTreeNode node) { 692 691 if (IsNumber(node)) { 693 var constT= node as NumberTreeNode;694 return Number(Math.Tan( constT.Value));692 var numNode = node as NumberTreeNode; 693 return Number(Math.Tan(numNode.Value)); 695 694 } else if (IsFactor(node)) { 696 695 var factor = node as FactorVariableTreeNode; … … 708 707 private static ISymbolicExpressionTreeNode Cosine(ISymbolicExpressionTreeNode node) { 709 708 if (IsNumber(node)) { 710 var constT= node as NumberTreeNode;711 return Number(Math.Cos( constT.Value));709 var numNode = node as NumberTreeNode; 710 return Number(Math.Cos(numNode.Value)); 712 711 } else if (IsFactor(node)) { 713 712 var factor = node as FactorVariableTreeNode; … … 727 726 private static ISymbolicExpressionTreeNode Exp(ISymbolicExpressionTreeNode node) { 728 727 if (IsNumber(node)) { 729 var constT= node as NumberTreeNode;730 return Number(Math.Exp( constT.Value));728 var numNode = node as NumberTreeNode; 729 return Number(Math.Exp(numNode.Value)); 731 730 } else if (IsFactor(node)) { 732 731 var factNode = node as FactorVariableTreeNode; … … 751 750 private static ISymbolicExpressionTreeNode Log(ISymbolicExpressionTreeNode node) { 752 751 if (IsNumber(node)) { 753 var constT= node as NumberTreeNode;754 return Number(Math.Log( constT.Value));752 var numNode = node as NumberTreeNode; 753 return Number(Math.Log(numNode.Value)); 755 754 } else if (IsFactor(node)) { 756 755 var factNode = node as FactorVariableTreeNode; … … 769 768 private static ISymbolicExpressionTreeNode Square(ISymbolicExpressionTreeNode node) { 770 769 if (IsNumber(node)) { 771 var constT= node as NumberTreeNode;772 return Number( constT.Value * constT.Value);770 var numNode = node as NumberTreeNode; 771 return Number(numNode.Value * numNode.Value); 773 772 } else if (IsFactor(node)) { 774 773 var factNode = node as FactorVariableTreeNode; … … 803 802 private static ISymbolicExpressionTreeNode Cube(ISymbolicExpressionTreeNode node) { 804 803 if (IsNumber(node)) { 805 var constT= node as NumberTreeNode;806 return Number( constT.Value * constT.Value * constT.Value);804 var numNode = node as NumberTreeNode; 805 return Number(numNode.Value * numNode.Value * numNode.Value); 807 806 } else if (IsFactor(node)) { 808 807 var factNode = node as FactorVariableTreeNode; … … 828 827 private static ISymbolicExpressionTreeNode Abs(ISymbolicExpressionTreeNode node) { 829 828 if (IsNumber(node)) { 830 var constT= node as NumberTreeNode;831 return Number(Math.Abs( constT.Value));829 var numNode = node as NumberTreeNode; 830 return Number(Math.Abs(numNode.Value)); 832 831 } else if (IsFactor(node)) { 833 832 var factNode = node as FactorVariableTreeNode; … … 860 859 private static ISymbolicExpressionTreeNode AQ(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 861 860 if (IsNumber(b)) { 862 var c= b as NumberTreeNode;863 return Fraction(a, Number(Math.Sqrt(1.0 + c.Value * c.Value)));861 var nNode = b as NumberTreeNode; 862 return Fraction(a, Number(Math.Sqrt(1.0 + nNode.Value * nNode.Value))); 864 863 } else if (IsFactor(b)) { 865 864 var factNode = b as FactorVariableTreeNode; … … 878 877 private static ISymbolicExpressionTreeNode SquareRoot(ISymbolicExpressionTreeNode node) { 879 878 if (IsNumber(node)) { 880 var constT= node as NumberTreeNode;881 return Number(Math.Sqrt( constT.Value));879 var numNode = node as NumberTreeNode; 880 return Number(Math.Sqrt(numNode.Value)); 882 881 } else if (IsFactor(node)) { 883 882 var factNode = node as FactorVariableTreeNode; … … 897 896 private static ISymbolicExpressionTreeNode CubeRoot(ISymbolicExpressionTreeNode node) { 898 897 if (IsNumber(node)) { 899 var constT= node as NumberTreeNode;900 return Number(Math.Pow( constT.Value, 1.0 / 3.0));898 var numNode = node as NumberTreeNode; 899 return Number(Math.Pow(numNode.Value, 1.0 / 3.0)); 901 900 } else if (IsFactor(node)) { 902 901 var factNode = node as FactorVariableTreeNode; … … 916 915 private static ISymbolicExpressionTreeNode Root(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 917 916 if (IsNumber(a) && IsNumber(b)) { 918 var constA= a as NumberTreeNode;919 var constB= b as NumberTreeNode;920 return Number(Math.Pow( constA.Value, 1.0 / Math.Round(constB.Value)));917 var aNode = a as NumberTreeNode; 918 var bNode = b as NumberTreeNode; 919 return Number(Math.Pow(aNode.Value, 1.0 / Math.Round(bNode.Value))); 921 920 } else if (IsFactor(a) && IsNumber(b)) { 922 921 var factNode = a as FactorVariableTreeNode; 923 var constNode = b as NumberTreeNode;922 var bNode = b as NumberTreeNode; 924 923 return Factor(factNode.Symbol, factNode.VariableName, 925 factNode.Weights.Select(w => Math.Pow(w, 1.0 / Math.Round( constNode.Value))));924 factNode.Weights.Select(w => Math.Pow(w, 1.0 / Math.Round(bNode.Value)))); 926 925 } else if (IsBinFactor(a) && IsNumber(b)) { 927 926 var binFactor = a as BinaryFactorVariableTreeNode; 928 var constNode = b as NumberTreeNode;929 return BinFactor(binFactor.Symbol, binFactor.VariableName, binFactor.VariableValue, Math.Pow(binFactor.Weight, 1.0 / Math.Round( constNode.Value)));927 var bNode = b as NumberTreeNode; 928 return BinFactor(binFactor.Symbol, binFactor.VariableName, binFactor.VariableValue, Math.Pow(binFactor.Weight, 1.0 / Math.Round(bNode.Value))); 930 929 } else if (IsNumber(a) && IsFactor(b)) { 931 var constNode = a as NumberTreeNode;930 var aNode = a as NumberTreeNode; 932 931 var factNode = b as FactorVariableTreeNode; 933 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => Math.Pow( constNode.Value, 1.0 / Math.Round(w))));932 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => Math.Pow(aNode.Value, 1.0 / Math.Round(w)))); 934 933 } else if (IsNumber(a) && IsBinFactor(b)) { 935 var constNode = a as NumberTreeNode;934 var aNode = a as NumberTreeNode; 936 935 var factNode = b as BinaryFactorVariableTreeNode; 937 return BinFactor(factNode.Symbol, factNode.VariableName, factNode.VariableValue, Math.Pow( constNode.Value, 1.0 / Math.Round(factNode.Weight)));936 return BinFactor(factNode.Symbol, factNode.VariableName, factNode.VariableValue, Math.Pow(aNode.Value, 1.0 / Math.Round(factNode.Weight))); 938 937 } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) { 939 938 var node0 = a as FactorVariableTreeNode; … … 941 940 return Factor(node0.Symbol, node0.VariableName, node0.Weights.Zip(node1.Weights, (u, v) => Math.Pow(u, 1.0 / Math.Round(v)))); 942 941 } else if (IsNumber(b)) { 943 var constB= b as NumberTreeNode;944 var constBValue = Math.Round(constB.Value);945 if ( constBValue== 1.0) {942 var bNode = b as NumberTreeNode; 943 var bVal = Math.Round(bNode.Value); 944 if (bVal == 1.0) { 946 945 // root(a, 1) => a 947 946 return a; 948 } else if ( constBValue== 0.0) {947 } else if (bVal == 0.0) { 949 948 // root(a, 0) is not defined 950 //return MakeConstant(1.0);951 949 return Number(double.NaN); 952 } else if ( constBValue== -1.0) {950 } else if (bVal == -1.0) { 953 951 // root(a, -1) => a^(-1/1) => 1/a 954 952 return Fraction(Number(1.0), a); 955 } else if ( constBValue< 0) {953 } else if (bVal < 0) { 956 954 // root(a, -b) => a^(-1/b) => (1/a)^(1/b) => root(1, b) / root(a, b) => 1 / root(a, b) 957 955 var rootNode = rootSymbol.CreateTreeNode(); 958 956 rootNode.AddSubtree(a); 959 rootNode.AddSubtree(Number(-1.0 * constBValue));957 rootNode.AddSubtree(Number(-1.0 * bVal)); 960 958 return Fraction(Number(1.0), rootNode); 961 959 } else { 962 960 var rootNode = rootSymbol.CreateTreeNode(); 963 961 rootNode.AddSubtree(a); 964 rootNode.AddSubtree(Number( constBValue));962 rootNode.AddSubtree(Number(bVal)); 965 963 return rootNode; 966 964 } … … 976 974 private static ISymbolicExpressionTreeNode Power(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 977 975 if (IsNumber(a) && IsNumber(b)) { 978 var constA= a as NumberTreeNode;979 var constB= b as NumberTreeNode;980 return Number(Math.Pow( constA.Value, Math.Round(constB.Value)));976 var aNode = a as NumberTreeNode; 977 var bNode = b as NumberTreeNode; 978 return Number(Math.Pow(aNode.Value, Math.Round(bNode.Value))); 981 979 } else if (IsFactor(a) && IsNumber(b)) { 982 980 var factNode = a as FactorVariableTreeNode; 983 var constNode = b as NumberTreeNode;984 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => Math.Pow(w, Math.Round( constNode.Value))));981 var bNode = b as NumberTreeNode; 982 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => Math.Pow(w, Math.Round(bNode.Value)))); 985 983 } else if (IsBinFactor(a) && IsNumber(b)) { 986 984 var binFactor = a as BinaryFactorVariableTreeNode; 987 var constNode = b as NumberTreeNode;988 return BinFactor(binFactor.Symbol, binFactor.VariableName, binFactor.VariableValue, Math.Pow(binFactor.Weight, Math.Round( constNode.Value)));985 var bNode = b as NumberTreeNode; 986 return BinFactor(binFactor.Symbol, binFactor.VariableName, binFactor.VariableValue, Math.Pow(binFactor.Weight, Math.Round(bNode.Value))); 989 987 } else if (IsNumber(a) && IsFactor(b)) { 990 var constNode = a as NumberTreeNode;988 var aNode = a as NumberTreeNode; 991 989 var factNode = b as FactorVariableTreeNode; 992 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => Math.Pow( constNode.Value, Math.Round(w))));990 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => Math.Pow(aNode.Value, Math.Round(w)))); 993 991 } else if (IsNumber(a) && IsBinFactor(b)) { 994 var constNode = a as NumberTreeNode;992 var aNode = a as NumberTreeNode; 995 993 var factNode = b as BinaryFactorVariableTreeNode; 996 return BinFactor(factNode.Symbol, factNode.VariableName, factNode.VariableValue, Math.Pow( constNode.Value, Math.Round(factNode.Weight)));994 return BinFactor(factNode.Symbol, factNode.VariableName, factNode.VariableValue, Math.Pow(aNode.Value, Math.Round(factNode.Weight))); 997 995 } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) { 998 996 var node0 = a as FactorVariableTreeNode; … … 1000 998 return Factor(node0.Symbol, node0.VariableName, node0.Weights.Zip(node1.Weights, (u, v) => Math.Pow(u, Math.Round(v)))); 1001 999 } else if (IsNumber(b)) { 1002 var constB= b as NumberTreeNode;1003 double exponent = Math.Round( constB.Value);1000 var bNode = b as NumberTreeNode; 1001 double exponent = Math.Round(bNode.Value); 1004 1002 if (exponent == 0.0) { 1005 1003 // a^0 => 1 … … 1032 1030 1033 1031 1034 // MakeFraction, MakeProduct and MakeSum take two already simplified trees and create a new simplified tree1032 // Fraction, Product and Sum take two already simplified trees and create a new simplified tree 1035 1033 private static ISymbolicExpressionTreeNode Fraction(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 1036 1034 if (IsNumber(a) && IsNumber(b)) { 1037 1035 // fold constants 1038 1036 return Number(((NumberTreeNode)a).Value / ((NumberTreeNode)b).Value); 1039 } else if ( (IsNumber(a) && ((NumberTreeNode)a).Value != 1.0)) {1037 } else if (IsNumber(a) && ((NumberTreeNode)a).Value != 1.0) { 1040 1038 // a / x => (a * 1/a) / (x * 1/a) => 1 / (x * 1/a) 1041 1039 return Fraction(Number(1.0), Product(b, Invert(a))); 1042 1040 } else if (IsVariableBase(a) && IsNumber(b)) { 1043 1041 // merge constant values into variable weights 1044 var constB= ((NumberTreeNode)b).Value;1045 ((VariableTreeNodeBase)a).Weight /= constB;1042 var bVal = ((NumberTreeNode)b).Value; 1043 ((VariableTreeNodeBase)a).Weight /= bVal; 1046 1044 return a; 1047 1045 } else if (IsFactor(a) && IsNumber(b)) { 1048 1046 var factNode = a as FactorVariableTreeNode; 1049 var constNode = b as NumberTreeNode;1050 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => w / constNode.Value));1047 var bNode = b as NumberTreeNode; 1048 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select(w => w / bNode.Value)); 1051 1049 } else if (IsBinFactor(a) && IsNumber(b)) { 1052 1050 var factNode = a as BinaryFactorVariableTreeNode; 1053 var constNode = b as NumberTreeNode;1054 return BinFactor(factNode.Symbol, factNode.VariableName, factNode.VariableValue, factNode.Weight / constNode.Value);1051 var bNode = b as NumberTreeNode; 1052 return BinFactor(factNode.Symbol, factNode.VariableName, factNode.VariableValue, factNode.Weight / bNode.Value); 1055 1053 } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) { 1056 1054 var node0 = a as FactorVariableTreeNode; … … 1119 1117 } else if (IsFactor(a) && IsNumber(b)) { 1120 1118 var factNode = a as FactorVariableTreeNode; 1121 var constNode = b as NumberTreeNode;1122 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select((w) => w + constNode.Value));1119 var bNode = b as NumberTreeNode; 1120 return Factor(factNode.Symbol, factNode.VariableName, factNode.Weights.Select((w) => w + bNode.Value)); 1123 1121 } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) { 1124 1122 var node0 = a as FactorVariableTreeNode; … … 1207 1205 group node by GroupId(node) into g 1208 1206 select g; 1209 var constant= (from node in subtrees.OfType<NumberTreeNode>()1210 select node.Value).DefaultIfEmpty(0.0).Sum();1207 var sumNumbers = (from node in subtrees.OfType<NumberTreeNode>() 1208 select node.Value).DefaultIfEmpty(0.0).Sum(); 1211 1209 var unchangedSubtrees = subtrees.Where(t => t.SubtreeCount > 0 || !(t is IVariableTreeNode) && !(t is NumberTreeNode)); 1212 1210 … … 1230 1228 foreach (var unchangedSubtree in unchangedSubtrees) 1231 1229 sum.AddSubtree(unchangedSubtree); 1232 if ( constant!= 0.0) {1233 sum.AddSubtree(Number( constant));1230 if (sumNumbers != 0.0) { 1231 sum.AddSubtree(Number(sumNumbers)); 1234 1232 } 1235 1233 } … … 1237 1235 // nodes referencing variables can be grouped if they have 1238 1236 private static string GroupId(IVariableTreeNode node) { 1239 var binaryFactorNode = node as BinaryFactorVariableTreeNode; 1240 var factorNode = node as FactorVariableTreeNode; 1241 var variableNode = node as VariableTreeNode; 1242 var laggedVarNode = node as LaggedVariableTreeNode; 1243 if (variableNode != null) { 1237 if (node is VariableTreeNode variableNode) { 1244 1238 return "var " + variableNode.VariableName; 1245 } else if ( binaryFactorNode != null) {1239 } else if (node is BinaryFactorVariableTreeNode binaryFactorNode) { 1246 1240 return "binfactor " + binaryFactorNode.VariableName + " " + binaryFactorNode.VariableValue; 1247 } else if ( factorNode != null) {1241 } else if (node is FactorVariableTreeNode factorNode) { 1248 1242 return "factor " + factorNode.VariableName; 1249 } else if ( laggedVarNode != null) {1243 } else if (node is LaggedVariableTreeNode laggedVarNode) { 1250 1244 return "lagged " + laggedVarNode.VariableName + " " + laggedVarNode.Lag; 1251 1245 } else { … … 1300 1294 IsFactor(b) && IsAddition(a) || 1301 1295 IsBinFactor(b) && IsAddition(a)) { 1302 // multiply constants into additions1296 // multiply numbers into additions 1303 1297 return a.Subtrees.Select(x => Product(GetSimplifiedTree(x), GetSimplifiedTree(b))).Aggregate((c, d) => Sum(c, d)); 1304 1298 } else if (IsDivision(a) && IsDivision(b)) { … … 1328 1322 return Abs(Product(a.GetSubtree(0), b.GetSubtree(0))); 1329 1323 } else if (IsAbsolute(a) && IsNumber(b)) { 1330 var constNode = b as NumberTreeNode;1331 var posF = Math.Abs( constNode.Value);1332 if ( constNode.Value > 0) {1324 var bNode = b as NumberTreeNode; 1325 var posF = Math.Abs(bNode.Value); 1326 if (bNode.Value > 0) { 1333 1327 return Abs(Product(a.GetSubtree(0), Number(posF))); 1334 1328 } else { … … 1361 1355 1362 1356 private static ISymbolicExpressionTreeNode AddLagToDynamicNodes(ISymbolicExpressionTreeNode node, int lag) { 1363 var laggedTreeNode = node as ILaggedTreeNode; 1364 var variableNode = node as VariableTreeNode; 1365 var variableConditionNode = node as VariableConditionTreeNode; 1366 if (laggedTreeNode != null) 1357 if (node is ILaggedTreeNode laggedTreeNode) 1367 1358 laggedTreeNode.Lag += lag; 1368 else if ( variableNode != null) {1359 else if (node is VariableTreeNode variableNode) { 1369 1360 var laggedVariableNode = (LaggedVariableTreeNode)laggedVariableSymbol.CreateTreeNode(); 1370 1361 laggedVariableNode.Lag = lag; 1371 1362 laggedVariableNode.VariableName = variableNode.VariableName; 1372 1363 return laggedVariableNode; 1373 } else if ( variableConditionNode != null) {1364 } else if (node is VariableConditionTreeNode) { 1374 1365 throw new NotSupportedException("Removal of time lags around variable condition symbols is not allowed."); 1375 1366 } … … 1395 1386 orderby g.Count() 1396 1387 select g; 1397 var constantProduct = (from node in subtrees.OfType<VariableTreeNodeBase>()1398 1399 .Concat(from node in subtrees.OfType<NumberTreeNode>()1400 select node.Value)1401 .DefaultIfEmpty(1.0)1402 .Aggregate((c1, c2) => c1 * c2);1388 var numberProduct = (from node in subtrees.OfType<VariableTreeNodeBase>() 1389 select node.Weight) 1390 .Concat(from node in subtrees.OfType<NumberTreeNode>() 1391 select node.Value) 1392 .DefaultIfEmpty(1.0) 1393 .Aggregate((c1, c2) => c1 * c2); 1403 1394 1404 1395 var unchangedSubtrees = from tree in subtrees … … 1428 1419 } 1429 1420 for (int j = 0; j < representative.Weights.Length; j++) { 1430 representative.Weights[j] *= constantProduct;1421 representative.Weights[j] *= numberProduct; 1431 1422 } 1432 constantProduct = 1.0;1423 numberProduct = 1.0; 1433 1424 // if the product already contains a factor it is not necessary to multiply a constant below 1434 1425 prod.AddSubtree(representative); … … 1439 1430 prod.AddSubtree(unchangedSubtree); 1440 1431 1441 if ( constantProduct != 1.0) {1442 prod.AddSubtree(Number( constantProduct));1432 if (numberProduct != 1.0) { 1433 prod.AddSubtree(Number(numberProduct)); 1443 1434 } 1444 1435 } … … 1503 1494 1504 1495 private static ISymbolicExpressionTreeNode Number(double value) { 1505 NumberTreeNode numberTreeNode = (NumberTreeNode)(numberSymbol.CreateTreeNode());1496 var numberTreeNode = (NumberTreeNode)numberSymbol.CreateTreeNode(); 1506 1497 numberTreeNode.Value = value; 1507 1498 return numberTreeNode; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
r18114 r18115 129 129 130 130 // state for recursive transformation of trees 131 private readonly 132 List<double> initialParamValues; 131 private readonly List<double> initialParamValues; 133 132 private readonly Dictionary<DataForVariable, AutoDiff.Variable> parameters; 134 133 private readonly List<AutoDiff.Variable> variables; … … 151 150 return var; 152 151 } 153 154 152 if (node.Symbol is Constant) { 155 initialParamValues.Add(((ConstantTreeNode)node).Value); 156 var var = new AutoDiff.Variable(); 157 variables.Add(var); 158 return var; 153 // constants are fixed in autodiff 154 return (node as ConstantTreeNode).Value; 159 155 } 160 156 if (node.Symbol is Variable || node.Symbol is BinaryFactorVariable) { … … 267 263 } 268 264 if (node.Symbol is Power) { 269 var powerNode = node.GetSubtree(1) as NumberTreeNode;265 var powerNode = node.GetSubtree(1) as INumericTreeNode; 270 266 if (powerNode == null) 271 throw new NotSupportedException("Only integerpowers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol.");267 throw new NotSupportedException("Only numeric powers are allowed in parameter optimization. Try to use exp() and log() instead of the power symbol."); 272 268 var intPower = Math.Truncate(powerNode.Value); 273 269 if (intPower != powerNode.Value) … … 320 316 var data = new DataForVariable(varName, varValue, lag); 321 317 322 AutoDiff.Variable par = null; 323 if (!parameters.TryGetValue(data, out par)) { 318 if (!parameters.TryGetValue(data, out AutoDiff.Variable par)) { 324 319 // not found -> create new parameter and entries in names and values lists 325 320 par = new AutoDiff.Variable(); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs
r18114 r18115 54 54 55 55 var power = node.GetSubtree(1); 56 if(power is NumberTreeNode constNode && Math.Truncate(constNode.Value) == constNode.Value) {57 strBuilder.Append(" ").Append(token).Append(" ").Append( constNode.Value.ToString(formatString, numberFormat));56 if(power is INumericTreeNode numNode && Math.Truncate(numNode.Value) == numNode.Value) { 57 strBuilder.Append(" ").Append(token).Append(" ").Append(numNode.Value.ToString(formatString, numberFormat)); 58 58 } else { 59 59 strBuilder.Append(" ").Append(token).Append(" "); … … 141 141 142 142 if (!factorNode.Weight.IsAlmost(1.0)) strBuilder.Append(")"); 143 } else if (node.Symbol is Number) { 144 var numNode = node as NumberTreeNode; 143 } else if (node is INumericTreeNode numNode) { 145 144 if (parameters == null && numNode.Value < 0) { 145 // negative value 146 146 strBuilder.Append("(").Append(numNode.Value.ToString(formatString, numberFormat)) 147 .Append(")"); // (-1147 .Append(")"); 148 148 } else { 149 149 AppendNumber(strBuilder, parameters, numNode.Value, formatString, numberFormat); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs
r18100 r18115 47 47 private string GetExcelColumnName(int columnNumber) { 48 48 int dividend = columnNumber; 49 string columnName = String.Empty;49 string columnName = string.Empty; 50 50 51 51 while (dividend > 0) { 52 52 int modulo = (dividend - 1) % 26; 53 53 columnName = System.Convert.ToChar(65 + modulo) + columnName; 54 dividend = ( int)((dividend - modulo) / 26);54 dividend = (dividend - modulo) / 26; 55 55 } 56 56 … … 134 134 } 135 135 stringBuilder.Append("))"); 136 } else if (symbol is INumericSymbol num Node) {136 } else if (symbol is INumericSymbol numSy) { 137 137 var numTreeNode = node as INumericTreeNode; 138 138 stringBuilder.Append(numTreeNode.Value.ToString(CultureInfo.InvariantCulture)); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs
r18114 r18115 189 189 } else if (node.Symbol is IfThenElse) { 190 190 strBuilder.Append(@" \operatorname{if} \left( "); 191 } else if (node.Symbol is INumericSymbol num Node) {191 } else if (node.Symbol is INumericSymbol numSy) { 192 192 var numName = "c_{" + paramIdx + "}"; 193 193 paramIdx++; … … 472 472 } else if (node.Symbol is Number) { 473 473 } else if (node.Symbol is Constant) { 474 } else if (node.Symbol is LaggedVariable) {474 } else if (node.Symbol is LaggedVariable) { 475 475 } else if (node.Symbol is Variable) { 476 476 } else if (node.Symbol is FactorVariable) { -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs
r18100 r18115 153 153 } else if (symbol is INumericSymbol) { 154 154 var numberTreeNode = node as INumericTreeNode; 155 stringBuilder.Append(numberTreeNode ?.Value.ToString(CultureInfo.InvariantCulture));155 stringBuilder.Append(numberTreeNode.Value.ToString(CultureInfo.InvariantCulture)); 156 156 } else if (symbol is Cosine) { 157 157 stringBuilder.Append("cos("); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs
r18100 r18115 132 132 } else if (node.Symbol is INumericSymbol) { 133 133 var numNode = node as INumericTreeNode; 134 strBuilder.Append(numNode ?.Value.ToString("G17", CultureInfo.InvariantCulture));134 strBuilder.Append(numNode.Value.ToString("G17", CultureInfo.InvariantCulture)); 135 135 } else if (node.Symbol is FactorVariable) { 136 136 var factorNode = node as FactorVariableTreeNode; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionPythonFormatter.cs
r18100 r18115 229 229 private static void FormatNumericTreeNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 230 230 var symbol = node.Symbol; 231 double value = 0.0; 232 if (symbol is INumericSymbol) { 233 var numNode = node as INumericTreeNode; 234 value = numNode.Value; 231 if (node is INumericTreeNode numNode) { 232 strBuilder.Append(numNode.Value.ToString("g17", CultureInfo.InvariantCulture)); 235 233 } else { 236 234 throw new NotSupportedException("Formatting of symbol: " + symbol + " not supported for Python symbolic expression tree formatter."); 237 235 } 238 239 240 strBuilder.Append(value.ToString("g17", CultureInfo.InvariantCulture));241 236 } 242 237 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs
r18100 r18115 85 85 } else if (symbol is INumericSymbol) { 86 86 var numberTreeNode = node as INumericTreeNode; 87 stringBuilder.Append(numberTreeNode ?.Value.ToString(CultureInfo.InvariantCulture));88 } else if (symbol is Cosine) {87 stringBuilder.Append(numberTreeNode.Value.ToString(CultureInfo.InvariantCulture)); 88 } else if (symbol is Cosine) { 89 89 stringBuilder.Append(FormatRecursively(node.GetSubtree(0))); 90 90 stringBuilder.Append(" cos"); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/TSQLExpressionFormatter.cs
r18100 r18115 93 93 //Generate function header 94 94 strBuilder.Append("CREATE FUNCTION dbo.REGRESSIONMODEL("); 95 strBuilder.Append(string.Join(", ", sortedVarcharIdentifiers.Select(n => string.Format("{0} NVARCHAR(max)", n))));95 strBuilder.Append(string.Join(", ", sortedVarcharIdentifiers.Select(n => string.Format("{0} NVARCHAR(max)", n)))); 96 96 if (varcharVarNames.Any() && floatVarNames.Any()) 97 97 strBuilder.Append(","); 98 strBuilder.Append(string.Join(", ", sortedFloatIdentifiers.Select(n => string.Format("{0} FLOAT", n))));98 strBuilder.Append(string.Join(", ", sortedFloatIdentifiers.Select(n => string.Format("{0} FLOAT", n)))); 99 99 strBuilder.AppendLine(")"); 100 100 … … 166 166 } else if (node is INumericTreeNode numNode) { 167 167 strBuilder.Append(numNode.Value.ToString("g17", CultureInfo.InvariantCulture)); 168 } else if (node.Symbol is FactorVariable) {168 } else if (node.Symbol is FactorVariable) { 169 169 var factorNode = node as FactorVariableTreeNode; 170 170 FormatFactor(level, factorNode, strBuilder); … … 180 180 private void FormatIfThenElse(int level, ISymbolicExpressionTreeNode node, StringBuilder strBuilder) { 181 181 strBuilder.Append("CASE ISNULL((SELECT 1 WHERE"); 182 FormatRecursively(level, node.GetSubtree(0), strBuilder);182 FormatRecursively(level, node.GetSubtree(0), strBuilder); 183 183 strBuilder.AppendLine("),0)"); 184 strBuilder.AppendIndented(level, "WHEN 1 THEN ");184 strBuilder.AppendIndented(level, "WHEN 1 THEN "); 185 185 FormatRecursively(level, node.GetSubtree(1), strBuilder); 186 186 strBuilder.AppendLine(); … … 202 202 203 203 private string VariableName2Identifier(string variableName) { 204 return "@" +variableName.Replace(' ', '_');204 return "@" + variableName.Replace(' ', '_'); 205 205 } 206 206 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs
r18114 r18115 52 52 number.MinValue = -20; 53 53 number.MaxValue = 20; 54 var variableSymbol = new Variable(); 54 var constant = new Constant(); 55 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 55 56 var binFactorVariableSymbol = new BinaryFactorVariable(); 56 57 var factorVariableSymbol = new FactorVariable(); 57 58 58 var allSymbols = new List<Symbol>() { add, sub, mul, div, number, variableSymbol, binFactorVariableSymbol, factorVariableSymbol };59 var allSymbols = new List<Symbol>() { add, sub, mul, div, number, constant, variableSymbol, binFactorVariableSymbol, factorVariableSymbol }; 59 60 var functionSymbols = new List<Symbol>() { add, sub, mul, div }; 60 61 … … 66 67 } 67 68 SetSubtreeCount(number, 0, 0); 69 SetSubtreeCount(constant, 0, 0); 68 70 SetSubtreeCount(variableSymbol, 0, 0); 69 71 SetSubtreeCount(binFactorVariableSymbol, 0, 0); -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs
r18114 r18115 121 121 number.MinValue = -20; 122 122 number.MaxValue = 20; 123 var variableSymbol = new Variable();123 var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 124 124 var binFactorVariable = new BinaryFactorVariable(); 125 125 var factorVariable = new FactorVariable(); … … 130 130 autoregressiveVariable.Enabled = false; 131 131 132 var constant = new Constant(); 133 132 134 var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp, tanh, 133 135 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral, 134 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, number, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition };136 @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, number, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition }; 135 137 var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, tanh, not, timeLag, integral, derivative, 136 138 airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral … … 139 141 var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, aq, variableCondition }; 140 142 var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or, xor }; 141 var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, number, laggedVariable, autoregressiveVariable };143 var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, number, constant, laggedVariable, autoregressiveVariable }; 142 144 143 145 foreach (var symb in allSymbols) -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/LinearScalingGrammar.cs
r18114 r18115 69 69 number.MinValue = -20; 70 70 number.MaxValue = 20; 71 var constant = new Constant(); 71 72 var variableSymbol = new Variable(); 72 73 … … 78 79 //all other symbols 79 80 var allSymbols = new List<Symbol> { 80 add, sub, mul, div, number, variableSymbol, sin, cos, tan, log, square, sqrt, cube, cbrt, exp,81 add, sub, mul, div, number, constant, variableSymbol, sin, cos, tan, log, square, sqrt, cube, cbrt, exp, 81 82 tanh, aq, abs 82 83 }; … … 86 87 var realValueSymbols = new List<Symbol> { 87 88 add, sub, mul, div, sin, cos, tan, tanh, exp, log, aq, abs, square, cube, sqrt, cbrt, 88 variableSymbol, number 89 variableSymbol, number, constant 89 90 }; 90 91 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs
r18114 r18115 108 108 number.MinValue = -20; 109 109 number.MaxValue = 20; 110 var constant = new Constant(); 110 111 var variableSymbol = new Variable(); 111 112 var binFactorVariable = new BinaryFactorVariable(); … … 121 122 var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { abs, airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, 122 123 fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral, analyticalQuotient}); 123 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { number, variableSymbol, binFactorVariable, factorVariable });124 var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { number, constant, variableSymbol, binFactorVariable, factorVariable }); 124 125 var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols }); 125 126 -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r18114 r18115 28 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 29 29 public static class SymbolicExpressionTreeHash { 30 private static readonly Addition add = new Addition();31 private static readonly Subtraction sub = new Subtraction();32 private static readonly Multiplication mul = new Multiplication();33 private static readonly Division div = new Division();34 private static readonly Logarithm log = new Logarithm();35 private static readonly Exponential exp = new Exponential();36 private static readonly Sine sin = new Sine();37 private static readonly Cosine cos = new Cosine();38 30 private static readonly Number number = new Number(); 39 31 … … 66 58 var symbol = node.Symbol; 67 59 var name = symbol.Name; 68 if (node is NumberTreeNode numNode) {69 name = strict ? numNode.Value.ToString() : symbol.Name;60 if (node is INumericTreeNode numNode) { 61 name = strict ? numNode.Value.ToString() : "Number"; 70 62 } else if (node is VariableTreeNode variableNode) { 71 63 name = strict ? variableNode.Weight.ToString() + variableNode.VariableName : variableNode.VariableName; … … 222 214 variableTreeNode.VariableName = variable.VariableName; 223 215 variableTreeNode.Weight = variable.Weight; 224 } else if (node.Data is NumberTreeNode existingNumNode) {225 var newNumNode = ( NumberTreeNode)treeNodes[i];216 } else if (node.Data is INumericTreeNode existingNumNode) { 217 var newNumNode = (INumericTreeNode)treeNodes[i]; 226 218 newNumNode.Value = existingNumNode.Value; 227 219 } … … 285 277 286 278 var symbol = child.Data.Symbol; 287 if (child.Data is NumberTreeNode firstNum) {279 if (child.Data is INumericTreeNode firstNum) { 288 280 // fold sibling number nodes into the first number 289 281 for (int k = j + 1; k < children.Length; ++k) { 290 282 var sibling = nodes[children[k]]; 291 if (sibling.Data is NumberTreeNode otherNum) {283 if (sibling.Data is INumericTreeNode otherNum) { 292 284 sibling.Enabled = false; 293 285 node.Arity--; … … 301 293 for (int k = j + 1; k < children.Length; ++k) { 302 294 var sibling = nodes[children[k]]; 303 if (sibling.Data is NumberTreeNode numNode) {295 if (sibling.Data is INumericTreeNode numNode) { 304 296 sibling.Enabled = false; 305 297 node.Arity--; … … 344 336 var tmp = nodes; 345 337 346 if (children.All(x => tmp[x].Data.Symbol is Number)) {347 var v = (( NumberTreeNode)nodes[children.First()].Data).Value;338 if (children.All(x => tmp[x].Data.Symbol is INumericSymbol)) { 339 var v = ((INumericTreeNode)nodes[children.First()].Data).Value; 348 340 if (node.Arity == 1) { 349 341 v = 1 / v; 350 342 } else if (node.Arity > 1) { 351 343 foreach (var j in children.Skip(1)) { 352 v /= (( NumberTreeNode)nodes[j].Data).Value;344 v /= ((INumericTreeNode)nodes[j].Data).Value; 353 345 } 354 346 } … … 383 375 var childSymbol = child.Data.Symbol; 384 376 385 if (childSymbol is Number) {377 if (childSymbol is INumericSymbol) { 386 378 nodes[i].Enabled = false; 387 379 } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) { … … 393 385 var children = nodes.IterateChildren(i); 394 386 var tmp = nodes; 395 if (children.All(x => tmp[x].Data.Symbol is Number)) {387 if (children.All(x => tmp[x].Data.Symbol is INumericSymbol)) { 396 388 foreach (var j in children) { 397 389 nodes[j].Enabled = false; -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/INumericSymbol.cs
r18100 r18115 25 25 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 26 26 [StorableType("3CD759AF-A45E-4B70-BDCF-66AF1A03BAD8")] 27 public interface INumericSymbol : ISymbol { 28 29 } 27 public interface INumericSymbol : ISymbol { } 30 28 31 29 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs
r18114 r18115 326 326 !(n.Symbol is Variable) && 327 327 !(n.Symbol is Number) && 328 !(n.Symbol is Constant) && 328 329 !(n.Symbol is StartSymbol) && 329 330 !(n.Symbol is Addition) && … … 347 348 else if (n.Symbol is Power) { 348 349 // only integer exponents are supported 349 var exp = n.GetSubtree(1) as NumberTreeNode;350 if (exp == null || exp.Value != Math.Truncate(exp.Value)) return false;350 var exponent = n.GetSubtree(1) as INumericTreeNode; 351 if (exponent == null || exponent.Value != Math.Truncate(exponent.Value)) return false; 351 352 } 352 353 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs
r18113 r18115 146 146 var addition = new Addition(); 147 147 var node = addition.CreateTreeNode(); 148 var alpha Const= MakeNumber(alpha);148 var alphaNode = MakeNumber(alpha); 149 149 node.AddSubtree(treeNode); 150 node.AddSubtree(alpha Const);150 node.AddSubtree(alphaNode); 151 151 return node; 152 152 } … … 159 159 var multiplication = new Multiplication(); 160 160 var node = multiplication.CreateTreeNode(); 161 var beta Const= MakeNumber(beta);161 var betaNode = MakeNumber(beta); 162 162 node.AddSubtree(treeNode); 163 node.AddSubtree(beta Const);163 node.AddSubtree(betaNode); 164 164 return node; 165 165 } -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Constant.cs
r18114 r18115 35 35 public override int MaximumArity => maximumArity; 36 36 37 public double Value { get; set; } 38 37 39 [StorableConstructor] 38 40 private Constant(StorableConstructorFlag _) : base(_) { } 39 41 40 private Constant(Constant original, Cloner cloner) : base(original, cloner) {} 42 private Constant(Constant original, Cloner cloner) : base(original, cloner) { 43 this.Value = original.Value; 44 } 41 45 public override IDeepCloneable Clone(Cloner cloner) { 42 46 return new Constant(this, cloner); 43 47 } 44 48 45 public Constant() : base("Constant", "Represents a real-valued constant.") { }49 public Constant() : base("Constant", "Represents a real-valued constant.") { } 46 50 47 51 public override ISymbolicExpressionTreeNode CreateTreeNode() { -
branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ConstantTreeNode.cs
r18114 r18115 30 30 public new Constant Symbol => (Constant) base.Symbol; 31 31 32 public double Value { get; set; } 32 public double Value { 33 get => Symbol.Value; 34 set => throw new System.NotSupportedException("Cannot change the value of a constant."); 35 } 33 36 34 37 [StorableConstructor] … … 37 40 private ConstantTreeNode(ConstantTreeNode original, Cloner cloner) 38 41 : base(original, cloner) { 39 Value = original.Value;40 42 } 41 43 -
branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationExpressionGrammar.cs
r18114 r18115 65 65 number.MinValue = -20; 66 66 number.MaxValue = 20; 67 var constant = new Constant(); 67 68 variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 68 69 69 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, number, variableSymbol };70 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, number, constant, variableSymbol }; 70 71 var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not }; 71 72 var binaryFunctionSymbols = new List<Symbol>() { gt, lt }; … … 87 88 SetSubtreeCount(@if, 3, 3); 88 89 SetSubtreeCount(number, 0, 0); 90 SetSubtreeCount(constant,0, 0); 89 91 SetSubtreeCount(variableSymbol, 0, 0); 90 92
Note: See TracChangeset
for help on using the changeset viewer.