Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18115


Ignore:
Timestamp:
12/13/21 17:49:34 (2 years ago)
Author:
gkronber
Message:

#3140: made several more changes for the constant -> number branch

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  
    101101      for (int i = 0; i < nodes.Count; ++i) {
    102102        var node = nodes[i];
    103         if (node is NumberTreeNode) continue;
     103        if (node is INumericTreeNode) continue;
    104104
    105105        impactValuesCalculator.CalculateImpactAndReplacementValues(model, node, problemData, rows,
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/Interfaces/IMultiObjectiveConstraintsEvaluator.cs

    r17959 r18115  
    2727  [StorableType("F96C5253-5A78-491C-95AE-78F64BD1F3B1")]
    2828  public interface IMultiObjectiveConstraintsEvaluator : ISymbolicRegressionMultiObjectiveEvaluator {
    29 
    3029    IFixedValueParameter<IntValue> NumConstraintsParameter { get; }
    3130  }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/NMSEMultiObjectiveConstraintsEvaluator.cs

    r18113 r18115  
    105105          var scaling = offset.GetSubtree(0);
    106106
    107           //Check if tree contains offset and scaling nodes
     107          // Check if tree contains offset and scaling nodes
    108108          if (!(offset.Symbol is Addition) || !(scaling.Symbol is Multiplication))
    109109            throw new ArgumentException($"{ItemName} can only be used with LinearScalingGrammar.");
     
    115115          var newTree = new SymbolicExpressionTree(rootNode);
    116116
    117           //calculate alpha and beta for scaling
     117          // calculate alpha and beta for scaling
    118118          var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(newTree, problemData.Dataset, rows);
    119119
     
    122122            out var errorState);
    123123          if (errorState == OnlineCalculatorError.None) {
    124             //Set alpha and beta to the scaling nodes from ia grammar
     124            // Set alpha and beta to the scaling nodes from linear scaling grammar
    125125            var offsetParameter = offset.GetSubtree(1) as NumberTreeNode;
    126126            offsetParameter.Value = alpha;
     
    162162      double upperEstimationLimit,
    163163      IRegressionProblemData problemData, IEnumerable<int> rows, IBoundsEstimator estimator, int decimalPlaces) {
    164       OnlineCalculatorError errorState;
    165164      var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, problemData.Dataset, rows);
    166165      var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, rows);
     
    174173
    175174      var boundedEstimatedValues = estimatedValues.LimitToRange(lowerEstimationLimit, upperEstimationLimit);
    176       nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out errorState);
     175      nmse = OnlineNormalizedMeanSquaredErrorCalculator.Calculate(targetValues, boundedEstimatedValues, out OnlineCalculatorError errorState);
    177176
    178177      if (errorState != OnlineCalculatorError.None) nmse = 1.0;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/Evaluators/NMSESingleObjectiveConstraintsEvaluator.cs

    r18113 r18115  
    9797    public NMSESingleObjectiveConstraintsEvaluator() {
    9898      Parameters.Add(new FixedValueParameter<BoolValue>(OptimizeParametersParameterName,
    99         "Define whether optimization of numeric parameters is active or not (default: false).", new BoolValue(false)));
     99        "Define whether optimization of parameters is active or not (default: false).", new BoolValue(false)));
    100100      Parameters.Add(new FixedValueParameter<IntValue>(ParameterOptimizationIterationsParameterName,
    101101        "Define how many parameter optimization steps should be performed (default: 10).", new IntValue(10)));
     
    109109
    110110    [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() { }
    122112
    123113    public override IDeepCloneable Clone(Cloner cloner) {
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs

    r18114 r18115  
    9191      for (int i = 0; i < nodes.Count; ++i) {
    9292        var node = nodes[i];
    93         if (node is NumberTreeNode) continue;
     93        if (node is INumericTreeNode) continue; // skip constants and numbers
    9494
    9595        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  
    129129    </Compile>
    130130    <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>
    131143    <Compile Include="TextualSymbolicDataAnalysisModelView.cs">
    132144      <SubType>UserControl</SubType>
     
    146158    <Compile Include="GraphicalSymbolicDataAnalysisModelView.designer.cs">
    147159      <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>
    154160    </Compile>
    155161    <Compile Include="Symbols\LaggedVariableView.cs">
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r18114 r18115  
    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;
     
    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);
     
    297297        VisualTreeNode<ISymbolicExpressionTreeNode> visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);
    298298
    299         if (!(treeNode is NumberTreeNode) && 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           if (foldedNodes[treeNode] is NumberTreeNode numReplacementNode) {
     316          if (foldedNodes[treeNode] is INumericTreeNode numReplacementNode) {
    317317            visualTree.ToolTip += Environment.NewLine + "Replacement value: " + numReplacementNode.Value;
    318318          }
     
    320320        if (visualTree != null) {
    321321          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}]");
    323323          if (changedNodes.ContainsKey(treeNode)) {
    324324            visualTree.LineColor = Color.DodgerBlue;
    325           } else if (treeNode is NumberTreeNode && foldedNodes.ContainsKey(treeNode)) {
     325          } else if (treeNode is INumericTreeNode && foldedNodes.ContainsKey(treeNode)) {
    326326            visualTree.LineColor = Color.DarkOrange;
    327327          }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.Designer.cs

    r17180 r18115  
    6464      this.insertNodeToolStripMenuItem.Name = "insertNodeToolStripMenuItem";
    6565      this.insertNodeToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
    66       this.insertNodeToolStripMenuItem.Text = "Insert Node";
     66      this.insertNodeToolStripMenuItem.Text = "Insert node";
    6767      this.insertNodeToolStripMenuItem.Click += new System.EventHandler(this.insertNodeToolStripMenuItem_Click);
    6868      //
     
    7171      this.changeNodeToolStripMenuItem.Name = "changeNodeToolStripMenuItem";
    7272      this.changeNodeToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
    73       this.changeNodeToolStripMenuItem.Text = "Change Node";
     73      this.changeNodeToolStripMenuItem.Text = "Change node";
    7474      this.changeNodeToolStripMenuItem.Click += new System.EventHandler(this.changeNodeToolStripMenuItem_Click);
    7575      //
     
    7878      this.cutToolStripMenuItem.Name = "cutToolStripMenuItem";
    7979      this.cutToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
    80       this.cutToolStripMenuItem.Text = "Cut Subtree";
     80      this.cutToolStripMenuItem.Text = "Cut subtree";
    8181      this.cutToolStripMenuItem.Click += new System.EventHandler(this.cutToolStripMenuItem_Click);
    8282      //
     
    109109      this.pasteToolStripMenuItem.Name = "pasteToolStripMenuItem";
    110110      this.pasteToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
    111       this.pasteToolStripMenuItem.Text = "Paste Subtree";
     111      this.pasteToolStripMenuItem.Text = "Paste subtree";
    112112      this.pasteToolStripMenuItem.Click += new System.EventHandler(this.pasteToolStripMenuItem_Clicked);
    113113      //
     
    121121      this.copyToolStripMenuItem.Name = "copyToolStripMenuItem";
    122122      this.copyToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
    123       this.copyToolStripMenuItem.Text = "Copy Subtree";
     123      this.copyToolStripMenuItem.Text = "Copy subtree";
    124124      this.copyToolStripMenuItem.Click += new System.EventHandler(this.copyToolStripMenuItem_Click);
    125125      //
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicExpressionTreeChart.cs

    r18100 r18115  
    2828
    2929namespace 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);
    3232
    3333  internal sealed partial class InteractiveSymbolicExpressionTreeChart : SymbolicExpressionTreeChart {
     
    8282
    8383    protected override void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
    84       currSelected = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender; ;
     84      currSelected = (VisualTreeNode<ISymbolicExpressionTreeNode>)sender;
    8585      base.OnSymbolicExpressionTreeNodeClicked(sender, e);
    8686    }
     
    104104        var symbol = dialog.SelectedSymbol;
    105105        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);
    109108        } else if (node is VariableTreeNode) {
    110109          var variable = node as VariableTreeNode;
     
    133132      ISymbolicExpressionTreeNode newNode = null;
    134133      var result = DialogResult.Cancel;
    135       if (node is NumberTreeNode) {
     134      if (node is INumericTreeNode) {
    136135        using (var dialog = new NumberNodeEditDialog(node)) {
    137136          dialog.ShowDialog(this);
     
    200199      // check if the copied/cut node (stored in the tempNode) can be inserted as a child of the current selected node
    201200      var node = currSelected.Content;
    202       if (node is NumberTreeNode || node is VariableTreeNode) return;
     201      if (node is INumericTreeNode || node is VariableTreeNode) return;
    203202      // check if the currently selected node can accept the copied node as a child
    204203      // 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  
    4545    /// </summary>
    4646    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();
    5749      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    58       this.initializationGroupBox.SuspendLayout();
    59       this.mutationGroupBox.SuspendLayout();
    6050      this.SuspendLayout();
    6151      //
     
    6858      this.errorProvider.SetIconAlignment(this.initialFrequencyTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    6959      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");
    7068      //
    7169      // minimumArityTextBox
     
    8987      this.infoLabel.Location = new System.Drawing.Point(379, 3);
    9088      //
    91       // weightNuLabel
     89      // valueLabel
    9290      //
    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.");
    10098      //
    101       // minValueTextBox
     99      // valueTextBox
    102100      //
    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)
    104102            | 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);
    212110      //
    213111      // ConstantView
    214112      //
    215       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    216113      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);
    219116      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);
    221123      this.Controls.SetChildIndex(this.maximumArityLabel, 0);
    222124      this.Controls.SetChildIndex(this.maximumArityTextBox, 0);
     
    224126      this.Controls.SetChildIndex(this.minimumArityTextBox, 0);
    225127      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);
    229128      this.Controls.SetChildIndex(this.nameLabel, 0);
    230129      this.Controls.SetChildIndex(this.nameTextBox, 0);
    231       this.Controls.SetChildIndex(this.mutationGroupBox, 0);
    232130      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    233       this.initializationGroupBox.ResumeLayout(false);
    234       this.initializationGroupBox.PerformLayout();
    235       this.mutationGroupBox.ResumeLayout(false);
    236       this.mutationGroupBox.PerformLayout();
    237131      this.ResumeLayout(false);
    238132      this.PerformLayout();
     
    242136    #endregion
    243137
    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;
    255140  }
    256141}
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/ConstantView.cs

    r18100 r18115  
    2727
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    29   [View("Number View")]
    30   [Content(typeof(Number), true)]
     29  [View("Constant View")]
     30  [Content(typeof(Constant), true)]
    3131  public partial class ConstantView : SymbolView {
    32     public new Number Content {
    33       get { return (Number)base.Content; }
     32    public new Constant Content {
     33      get { return (Constant)base.Content; }
    3434      set { base.Content = value; }
    3535    }
     
    4343      Content.Changed += new EventHandler(Content_Changed);
    4444    }
    45 
     45   
    4646    protected override void DeregisterContentEvents() {
    4747      base.DeregisterContentEvents();
     
    5656    protected override void SetEnabledStateOfControls() {
    5757      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;
    6660    }
    6761
     
    7367
    7468    #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);
    8074      } 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");
    11176      }
    11277    }
     
    11681    private void UpdateControl() {
    11782      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;
    12384      } 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");
    12886      }
    12987      SetEnabledStateOfControls();
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/NumberView.Designer.cs

    r18114 r18115  
    2121
    2222namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    23   partial class ConstantView {
     23  partial class NumberView {
    2424    /// <summary>
    2525    /// Required designer variable.
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/NumberView.cs

    r18113 r18115  
    2929  [View("Number View")]
    3030  [Content(typeof(Number), true)]
    31   public partial class ConstantView : SymbolView {
     31  public partial class NumberView : SymbolView {
    3232    public new Number Content {
    3333      get { return (Number)base.Content; }
     
    3535    }
    3636
    37     public ConstantView() {
     37    public NumberView() {
    3838      InitializeComponent();
    3939    }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeConstantNodeEditDialog.cs

    r18114 r18115  
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3030  public partial class NumberNodeEditDialog : Form {
    31     private NumberTreeNode numberTreeNode;
    32     public NumberTreeNode NewNode {
     31    private INumericTreeNode numberTreeNode;
     32    public INumericTreeNode NewNode {
    3333      get { return numberTreeNode; }
    3434      set {
    3535        if (InvokeRequired)
    36           Invoke(new Action<SymbolicExpressionTreeNode>(x => numberTreeNode = (NumberTreeNode)x), value);
     36          Invoke(new Action<SymbolicExpressionTreeNode>(x => numberTreeNode = (INumericTreeNode)x), value);
    3737        else
    3838          numberTreeNode = value;
     
    4343      InitializeComponent();
    4444      oldValueTextBox.TabStop = false; // cannot receive focus using tab key
    45       NewNode = (NumberTreeNode)node;
     45      NewNode = (INumericTreeNode)node;
    4646      InitializeFields();
    4747    }
     
    7171
    7272    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 _);
    7574      errorMessage = string.Empty;
    7675      if (!valid) {
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeSimplifier.cs

    r18114 r18115  
    2525using System.Collections.Generic;
    2626using System.Linq;
     27using HeuristicLab.Common;
    2728using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2829
     
    8081    private static ISymbolicExpressionTreeNode MacroExpand(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode node,
    8182      IList<ISymbolicExpressionTreeNode> argumentTrees) {
    82       List<ISymbolicExpressionTreeNode> subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);
     83      var subtrees = new List<ISymbolicExpressionTreeNode>(node.Subtrees);
    8384      while (node.SubtreeCount > 0) node.RemoveSubtree(0);
    8485      if (node.Symbol is InvokeFunction) {
     
    239240    }
    240241
     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    }
    241248    private static bool IsConstantOrNumber(ISymbolicExpressionTreeNode node) {
    242249      return node is INumericTreeNode;
    243250    }
    244251
    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     // dynamic
    253252    private static bool IsTimeLag(ISymbolicExpressionTreeNode node) {
    254253      return node.Symbol is TimeLag;
     
    330329    private static ISymbolicExpressionTreeNode SimplifyAny(ISymbolicExpressionTreeNode original) {
    331330      // 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);
    333332      while (original.Subtrees.Count() > 0) original.RemoveSubtree(0);
    334333      var clone = (SymbolicExpressionTreeNode)original.Clone();
    335       List<ISymbolicExpressionTreeNode> simplifiedSubtrees = new List<ISymbolicExpressionTreeNode>();
     334      var simplifiedSubtrees = new List<ISymbolicExpressionTreeNode>();
    336335      foreach (var subtree in subtrees) {
    337336        simplifiedSubtrees.Add(GetSimplifiedTree(subtree));
     
    341340        clone.AddSubtree(simplifiedSubtree);
    342341      }
    343       if (simplifiedSubtrees.TrueForAll(IsConstantOrNumber)) {
     342      if (simplifiedSubtrees.TrueForAll(IsNumber)) {
    344343        FoldNumbers(clone);
    345344      }
     
    348347
    349348    private static ISymbolicExpressionTreeNode FoldNumbers(ISymbolicExpressionTreeNode original) {
    350       // TODO not yet implemented
     349      // TODO not implemented
    351350      return original;
    352351    }
     
    500499        return AddLagToDynamicNodes(simplifiedSubtree, laggedTreeNode.Lag);
    501500      } else {
    502         return TimeLag(simplifiedSubtree, laggedTreeNode.Lag);
     501        return Lag(simplifiedSubtree, laggedTreeNode.Lag);
    503502      }
    504503    }
     
    518517    #region low level tree restructuring
    519518
    520     private static ISymbolicExpressionTreeNode TimeLag(ISymbolicExpressionTreeNode subtree, int lag) {
     519    private static ISymbolicExpressionTreeNode Lag(ISymbolicExpressionTreeNode subtree, int lag) {
    521520      if (lag == 0) return subtree;
    522       if (IsNumber(subtree)) return subtree;
     521      if (IsConstantOrNumber(subtree)) return subtree;
    523522      var lagNode = (LaggedTreeNode)timeLagSymbol.CreateTreeNode();
    524523      lagNode.Lag = lag;
     
    541540    private static ISymbolicExpressionTreeNode Not(ISymbolicExpressionTreeNode t) {
    542541      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);
    545544        else return Number(1.0);
    546545      } else if (IsNot(t)) {
     
    562561    private static ISymbolicExpressionTreeNode Or(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    563562      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) {
    567566          return Number(1.0);
    568567        } else {
     
    572571        return Or(b, a);
    573572      } 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) {
    576575          // boolean expression is necessarily true
    577576          return Number(1.0);
    578577        } else {
    579           // the constant value has no effect on the result of the boolean condition so we can drop the constant term
     578          // the value has no effect on the result of the boolean condition so we can drop the number
    580579          var orNode = orSymbol.CreateTreeNode();
    581580          orNode.AddSubtree(a);
     
    592591    private static ISymbolicExpressionTreeNode And(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    593592      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) {
    597596          return Number(1.0);
    598597        } else {
     
    602601        return And(b, a);
    603602      } 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 term
     603        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
    607606          var andNode = andSymbol.CreateTreeNode();
    608607          andNode.AddSubtree(a);
     
    623622      ISymbolicExpressionTreeNode rightSide) {
    624623      if (IsNumber(leftSide) && IsNumber(rightSide)) {
    625         var lsConst = leftSide as NumberTreeNode;
    626         var rsConst = rightSide as NumberTreeNode;
    627         if (lsConst.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);
    628627        else return Number(-1.0);
    629628      } else {
     
    638637      ISymbolicExpressionTreeNode rightSide) {
    639638      if (IsNumber(leftSide) && IsNumber(rightSide)) {
    640         var lsConst = leftSide as NumberTreeNode;
    641         var rsConst = rightSide as NumberTreeNode;
    642         if (lsConst.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);
    643642        else return Number(-1.0);
    644643      } else {
     
    652651    private static ISymbolicExpressionTreeNode IfThenElse(ISymbolicExpressionTreeNode condition,
    653652      ISymbolicExpressionTreeNode trueBranch, ISymbolicExpressionTreeNode falseBranch) {
    654       if (IsNumber(condition)) {
    655         var constT = condition as NumberTreeNode;
    656         if (constT.Value > 0.0) return trueBranch;
     653      if (IsConstantOrNumber(condition)) {
     654        var condNode = condition as INumericTreeNode;
     655        if (condNode.Value > 0.0) return trueBranch;
    657656        else return falseBranch;
    658657      } else {
     
    674673    private static ISymbolicExpressionTreeNode Sine(ISymbolicExpressionTreeNode node) {
    675674      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));
    678677      } else if (IsFactor(node)) {
    679678        var factor = node as FactorVariableTreeNode;
     
    691690    private static ISymbolicExpressionTreeNode Tangent(ISymbolicExpressionTreeNode node) {
    692691      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));
    695694      } else if (IsFactor(node)) {
    696695        var factor = node as FactorVariableTreeNode;
     
    708707    private static ISymbolicExpressionTreeNode Cosine(ISymbolicExpressionTreeNode node) {
    709708      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));
    712711      } else if (IsFactor(node)) {
    713712        var factor = node as FactorVariableTreeNode;
     
    727726    private static ISymbolicExpressionTreeNode Exp(ISymbolicExpressionTreeNode node) {
    728727      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));
    731730      } else if (IsFactor(node)) {
    732731        var factNode = node as FactorVariableTreeNode;
     
    751750    private static ISymbolicExpressionTreeNode Log(ISymbolicExpressionTreeNode node) {
    752751      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));
    755754      } else if (IsFactor(node)) {
    756755        var factNode = node as FactorVariableTreeNode;
     
    769768    private static ISymbolicExpressionTreeNode Square(ISymbolicExpressionTreeNode node) {
    770769      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);
    773772      } else if (IsFactor(node)) {
    774773        var factNode = node as FactorVariableTreeNode;
     
    803802    private static ISymbolicExpressionTreeNode Cube(ISymbolicExpressionTreeNode node) {
    804803      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);
    807806      } else if (IsFactor(node)) {
    808807        var factNode = node as FactorVariableTreeNode;
     
    828827    private static ISymbolicExpressionTreeNode Abs(ISymbolicExpressionTreeNode node) {
    829828      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));
    832831      } else if (IsFactor(node)) {
    833832        var factNode = node as FactorVariableTreeNode;
     
    860859    private static ISymbolicExpressionTreeNode AQ(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    861860      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)));
    864863      } else if (IsFactor(b)) {
    865864        var factNode = b as FactorVariableTreeNode;
     
    878877    private static ISymbolicExpressionTreeNode SquareRoot(ISymbolicExpressionTreeNode node) {
    879878      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));
    882881      } else if (IsFactor(node)) {
    883882        var factNode = node as FactorVariableTreeNode;
     
    897896    private static ISymbolicExpressionTreeNode CubeRoot(ISymbolicExpressionTreeNode node) {
    898897      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));
    901900      } else if (IsFactor(node)) {
    902901        var factNode = node as FactorVariableTreeNode;
     
    916915    private static ISymbolicExpressionTreeNode Root(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    917916      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)));
    921920      } else if (IsFactor(a) && IsNumber(b)) {
    922921        var factNode = a as FactorVariableTreeNode;
    923         var constNode = b as NumberTreeNode;
     922        var bNode = b as NumberTreeNode;
    924923        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))));
    926925      } else if (IsBinFactor(a) && IsNumber(b)) {
    927926        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)));
    930929      } else if (IsNumber(a) && IsFactor(b)) {
    931         var constNode = a as NumberTreeNode;
     930        var aNode = a as NumberTreeNode;
    932931        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))));
    934933      } else if (IsNumber(a) && IsBinFactor(b)) {
    935         var constNode = a as NumberTreeNode;
     934        var aNode = a as NumberTreeNode;
    936935        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)));
    938937      } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) {
    939938        var node0 = a as FactorVariableTreeNode;
     
    941940        return Factor(node0.Symbol, node0.VariableName, node0.Weights.Zip(node1.Weights, (u, v) => Math.Pow(u, 1.0 / Math.Round(v))));
    942941      } 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) {
    946945          // root(a, 1) => a
    947946          return a;
    948         } else if (constBValue == 0.0) {
     947        } else if (bVal == 0.0) {
    949948          // root(a, 0) is not defined
    950           //return MakeConstant(1.0);
    951949          return Number(double.NaN);
    952         } else if (constBValue == -1.0) {
     950        } else if (bVal == -1.0) {
    953951          // root(a, -1) => a^(-1/1) => 1/a
    954952          return Fraction(Number(1.0), a);
    955         } else if (constBValue < 0) {
     953        } else if (bVal < 0) {
    956954          // root(a, -b) => a^(-1/b) => (1/a)^(1/b) => root(1, b) / root(a, b) => 1 / root(a, b)
    957955          var rootNode = rootSymbol.CreateTreeNode();
    958956          rootNode.AddSubtree(a);
    959           rootNode.AddSubtree(Number(-1.0 * constBValue));
     957          rootNode.AddSubtree(Number(-1.0 * bVal));
    960958          return Fraction(Number(1.0), rootNode);
    961959        } else {
    962960          var rootNode = rootSymbol.CreateTreeNode();
    963961          rootNode.AddSubtree(a);
    964           rootNode.AddSubtree(Number(constBValue));
     962          rootNode.AddSubtree(Number(bVal));
    965963          return rootNode;
    966964        }
     
    976974    private static ISymbolicExpressionTreeNode Power(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    977975      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)));
    981979      } else if (IsFactor(a) && IsNumber(b)) {
    982980        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))));
    985983      } else if (IsBinFactor(a) && IsNumber(b)) {
    986984        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)));
    989987      } else if (IsNumber(a) && IsFactor(b)) {
    990         var constNode = a as NumberTreeNode;
     988        var aNode = a as NumberTreeNode;
    991989        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))));
    993991      } else if (IsNumber(a) && IsBinFactor(b)) {
    994         var constNode = a as NumberTreeNode;
     992        var aNode = a as NumberTreeNode;
    995993        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)));
    997995      } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) {
    998996        var node0 = a as FactorVariableTreeNode;
     
    1000998        return Factor(node0.Symbol, node0.VariableName, node0.Weights.Zip(node1.Weights, (u, v) => Math.Pow(u, Math.Round(v))));
    1001999      } 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);
    10041002        if (exponent == 0.0) {
    10051003          // a^0 => 1
     
    10321030
    10331031
    1034     // MakeFraction, MakeProduct and MakeSum take two already simplified trees and create a new simplified tree
     1032    // Fraction, Product and Sum take two already simplified trees and create a new simplified tree
    10351033    private static ISymbolicExpressionTreeNode Fraction(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {
    10361034      if (IsNumber(a) && IsNumber(b)) {
    10371035        // fold constants
    10381036        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) {
    10401038        // a / x => (a * 1/a) / (x * 1/a) => 1 / (x * 1/a)
    10411039        return Fraction(Number(1.0), Product(b, Invert(a)));
    10421040      } else if (IsVariableBase(a) && IsNumber(b)) {
    10431041        // 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;
    10461044        return a;
    10471045      } else if (IsFactor(a) && IsNumber(b)) {
    10481046        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));
    10511049      } else if (IsBinFactor(a) && IsNumber(b)) {
    10521050        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);
    10551053      } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) {
    10561054        var node0 = a as FactorVariableTreeNode;
     
    11191117      } else if (IsFactor(a) && IsNumber(b)) {
    11201118        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));
    11231121      } else if (IsFactor(a) && IsFactor(b) && AreSameTypeAndVariable(a, b)) {
    11241122        var node0 = a as FactorVariableTreeNode;
     
    12071205                            group node by GroupId(node) into g
    12081206                            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();
    12111209      var unchangedSubtrees = subtrees.Where(t => t.SubtreeCount > 0 || !(t is IVariableTreeNode) && !(t is NumberTreeNode));
    12121210
     
    12301228      foreach (var unchangedSubtree in unchangedSubtrees)
    12311229        sum.AddSubtree(unchangedSubtree);
    1232       if (constant != 0.0) {
    1233         sum.AddSubtree(Number(constant));
     1230      if (sumNumbers != 0.0) {
     1231        sum.AddSubtree(Number(sumNumbers));
    12341232      }
    12351233    }
     
    12371235    // nodes referencing variables can be grouped if they have
    12381236    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) {
    12441238        return "var " + variableNode.VariableName;
    1245       } else if (binaryFactorNode != null) {
     1239      } else if (node is BinaryFactorVariableTreeNode binaryFactorNode) {
    12461240        return "binfactor " + binaryFactorNode.VariableName + " " + binaryFactorNode.VariableValue;
    1247       } else if (factorNode != null) {
     1241      } else if (node is FactorVariableTreeNode factorNode) {
    12481242        return "factor " + factorNode.VariableName;
    1249       } else if (laggedVarNode != null) {
     1243      } else if (node is LaggedVariableTreeNode laggedVarNode) {
    12501244        return "lagged " + laggedVarNode.VariableName + " " + laggedVarNode.Lag;
    12511245      } else {
     
    13001294          IsFactor(b) && IsAddition(a) ||
    13011295          IsBinFactor(b) && IsAddition(a)) {
    1302         // multiply constants into additions
     1296        // multiply numbers into additions
    13031297        return a.Subtrees.Select(x => Product(GetSimplifiedTree(x), GetSimplifiedTree(b))).Aggregate((c, d) => Sum(c, d));
    13041298      } else if (IsDivision(a) && IsDivision(b)) {
     
    13281322        return Abs(Product(a.GetSubtree(0), b.GetSubtree(0)));
    13291323      } 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) {
    13331327          return Abs(Product(a.GetSubtree(0), Number(posF)));
    13341328        } else {
     
    13611355
    13621356    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)
    13671358        laggedTreeNode.Lag += lag;
    1368       else if (variableNode != null) {
     1359      else if (node is VariableTreeNode variableNode) {
    13691360        var laggedVariableNode = (LaggedVariableTreeNode)laggedVariableSymbol.CreateTreeNode();
    13701361        laggedVariableNode.Lag = lag;
    13711362        laggedVariableNode.VariableName = variableNode.VariableName;
    13721363        return laggedVariableNode;
    1373       } else if (variableConditionNode != null) {
     1364      } else if (node is VariableConditionTreeNode) {
    13741365        throw new NotSupportedException("Removal of time lags around variable condition symbols is not allowed.");
    13751366      }
     
    13951386                            orderby g.Count()
    13961387                            select g;
    1397       var constantProduct = (from node in subtrees.OfType<VariableTreeNodeBase>()
    1398                              select node.Weight)
    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);
    14031394
    14041395      var unchangedSubtrees = from tree in subtrees
     
    14281419          }
    14291420          for (int j = 0; j < representative.Weights.Length; j++) {
    1430             representative.Weights[j] *= constantProduct;
     1421            representative.Weights[j] *= numberProduct;
    14311422          }
    1432           constantProduct = 1.0;
     1423          numberProduct = 1.0;
    14331424          // if the product already contains a factor it is not necessary to multiply a constant below
    14341425          prod.AddSubtree(representative);
     
    14391430        prod.AddSubtree(unchangedSubtree);
    14401431
    1441       if (constantProduct != 1.0) {
    1442         prod.AddSubtree(Number(constantProduct));
     1432      if (numberProduct != 1.0) {
     1433        prod.AddSubtree(Number(numberProduct));
    14431434      }
    14441435    }
     
    15031494
    15041495    private static ISymbolicExpressionTreeNode Number(double value) {
    1505       NumberTreeNode numberTreeNode = (NumberTreeNode)(numberSymbol.CreateTreeNode());
     1496      var numberTreeNode = (NumberTreeNode)numberSymbol.CreateTreeNode();
    15061497      numberTreeNode.Value = value;
    15071498      return numberTreeNode;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs

    r18114 r18115  
    129129
    130130    // state for recursive transformation of trees
    131     private readonly
    132     List<double> initialParamValues;
     131    private readonly List<double> initialParamValues;
    133132    private readonly Dictionary<DataForVariable, AutoDiff.Variable> parameters;
    134133    private readonly List<AutoDiff.Variable> variables;
     
    151150        return var;
    152151      }
    153 
    154152      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;
    159155      }
    160156      if (node.Symbol is Variable || node.Symbol is BinaryFactorVariable) {
     
    267263      }
    268264      if (node.Symbol is Power) {
    269         var powerNode = node.GetSubtree(1) as NumberTreeNode;
     265        var powerNode = node.GetSubtree(1) as INumericTreeNode;
    270266        if (powerNode == null)
    271           throw new NotSupportedException("Only integer powers 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.");
    272268        var intPower = Math.Truncate(powerNode.Value);
    273269        if (intPower != powerNode.Value)
     
    320316      var data = new DataForVariable(varName, varValue, lag);
    321317
    322       AutoDiff.Variable par = null;
    323       if (!parameters.TryGetValue(data, out par)) {
     318      if (!parameters.TryGetValue(data, out AutoDiff.Variable par)) {
    324319        // not found -> create new parameter and entries in names and values lists
    325320        par = new AutoDiff.Variable();
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs

    r18114 r18115  
    5454
    5555          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));
    5858          } else {
    5959            strBuilder.Append(" ").Append(token).Append(" ");
     
    141141
    142142          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) {
    145144          if (parameters == null && numNode.Value < 0) {
     145            // negative value
    146146            strBuilder.Append("(").Append(numNode.Value.ToString(formatString, numberFormat))
    147                       .Append(")"); // (-1
     147                      .Append(")");
    148148          } else {
    149149            AppendNumber(strBuilder, parameters, numNode.Value, formatString, numberFormat);
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r18100 r18115  
    4747    private string GetExcelColumnName(int columnNumber) {
    4848      int dividend = columnNumber;
    49       string columnName = String.Empty;
     49      string columnName = string.Empty;
    5050
    5151      while (dividend > 0) {
    5252        int modulo = (dividend - 1) % 26;
    5353        columnName = System.Convert.ToChar(65 + modulo) + columnName;
    54         dividend = (int)((dividend - modulo) / 26);
     54        dividend = (dividend - modulo) / 26;
    5555      }
    5656
     
    134134        }
    135135        stringBuilder.Append("))");
    136       } else if (symbol is INumericSymbol numNode) {
     136      } else if (symbol is INumericSymbol numSy) {
    137137        var numTreeNode = node as INumericTreeNode;
    138138        stringBuilder.Append(numTreeNode.Value.ToString(CultureInfo.InvariantCulture));
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r18114 r18115  
    189189      } else if (node.Symbol is IfThenElse) {
    190190        strBuilder.Append(@" \operatorname{if}  \left( ");
    191       } else if (node.Symbol is INumericSymbol numNode) {
     191      } else if (node.Symbol is INumericSymbol numSy) {
    192192        var numName = "c_{" + paramIdx + "}";
    193193        paramIdx++;
     
    472472      } else if (node.Symbol is Number) {
    473473      } else if (node.Symbol is Constant) {
    474       }else if (node.Symbol is LaggedVariable) {
     474      } else if (node.Symbol is LaggedVariable) {
    475475      } else if (node.Symbol is Variable) {
    476476      } else if (node.Symbol is FactorVariable) {
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs

    r18100 r18115  
    153153      } else if (symbol is INumericSymbol) {
    154154        var numberTreeNode = node as INumericTreeNode;
    155         stringBuilder.Append(numberTreeNode?.Value.ToString(CultureInfo.InvariantCulture));
     155        stringBuilder.Append(numberTreeNode.Value.ToString(CultureInfo.InvariantCulture));
    156156      } else if (symbol is Cosine) {
    157157        stringBuilder.Append("cos(");
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs

    r18100 r18115  
    132132        } else if (node.Symbol is INumericSymbol) {
    133133          var numNode = node as INumericTreeNode;
    134           strBuilder.Append(numNode?.Value.ToString("G17", CultureInfo.InvariantCulture));
     134          strBuilder.Append(numNode.Value.ToString("G17", CultureInfo.InvariantCulture));
    135135        } else if (node.Symbol is FactorVariable) {
    136136          var factorNode = node as FactorVariableTreeNode;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionPythonFormatter.cs

    r18100 r18115  
    229229    private static void FormatNumericTreeNode(ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    230230      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));
    235233      } else {
    236234        throw new NotSupportedException("Formatting of symbol: " + symbol + " not supported for Python symbolic expression tree formatter.");
    237235      }
    238        
    239 
    240       strBuilder.Append(value.ToString("g17", CultureInfo.InvariantCulture));
    241236    }
    242237
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs

    r18100 r18115  
    8585      } else if (symbol is INumericSymbol) {
    8686        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) {
    8989        stringBuilder.Append(FormatRecursively(node.GetSubtree(0)));
    9090        stringBuilder.Append(" cos");
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/TSQLExpressionFormatter.cs

    r18100 r18115  
    9393      //Generate function header
    9494      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))));
    9696      if (varcharVarNames.Any() && floatVarNames.Any())
    9797        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))));
    9999      strBuilder.AppendLine(")");
    100100
     
    166166        } else if (node is INumericTreeNode numNode) {
    167167          strBuilder.Append(numNode.Value.ToString("g17", CultureInfo.InvariantCulture));
    168         }else if (node.Symbol is FactorVariable) {
     168        } else if (node.Symbol is FactorVariable) {
    169169          var factorNode = node as FactorVariableTreeNode;
    170170          FormatFactor(level, factorNode, strBuilder);
     
    180180    private void FormatIfThenElse(int level, ISymbolicExpressionTreeNode node, StringBuilder strBuilder) {
    181181      strBuilder.Append("CASE ISNULL((SELECT 1 WHERE");
    182       FormatRecursively(level,node.GetSubtree(0), strBuilder);
     182      FormatRecursively(level, node.GetSubtree(0), strBuilder);
    183183      strBuilder.AppendLine("),0)");
    184       strBuilder.AppendIndented(level,"WHEN 1 THEN ");
     184      strBuilder.AppendIndented(level, "WHEN 1 THEN ");
    185185      FormatRecursively(level, node.GetSubtree(1), strBuilder);
    186186      strBuilder.AppendLine();
     
    202202
    203203    private string VariableName2Identifier(string variableName) {
    204       return "@"+variableName.Replace(' ', '_');
     204      return "@" + variableName.Replace(' ', '_');
    205205    }
    206206
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs

    r18114 r18115  
    5252      number.MinValue = -20;
    5353      number.MaxValue = 20;
    54       var variableSymbol = new Variable();
     54      var constant = new Constant();
     55      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    5556      var binFactorVariableSymbol = new BinaryFactorVariable();
    5657      var factorVariableSymbol = new FactorVariable();
    5758
    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 };
    5960      var functionSymbols = new List<Symbol>() { add, sub, mul, div };
    6061
     
    6667      }
    6768      SetSubtreeCount(number, 0, 0);
     69      SetSubtreeCount(constant, 0, 0);
    6870      SetSubtreeCount(variableSymbol, 0, 0);
    6971      SetSubtreeCount(binFactorVariableSymbol, 0, 0);
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r18114 r18115  
    121121      number.MinValue = -20;
    122122      number.MaxValue = 20;
    123       var variableSymbol = new Variable();
     123      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    124124      var binFactorVariable = new BinaryFactorVariable();
    125125      var factorVariable = new FactorVariable();
     
    130130      autoregressiveVariable.Enabled = false;
    131131
     132      var constant = new Constant();
     133
    132134      var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, abs, sin, cos, tan, log, square, cube, pow, sqrt, cubeRoot, root, exp, tanh,
    133135        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 };
    135137      var unaryFunctionSymbols = new List<Symbol>() { abs, square, sqrt, cube, cubeRoot, sin, cos, tan, log, exp, tanh, not, timeLag, integral, derivative,
    136138        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
     
    139141      var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, aq, variableCondition };
    140142      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 };
    142144
    143145      foreach (var symb in allSymbols)
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/LinearScalingGrammar.cs

    r18114 r18115  
    6969      number.MinValue = -20;
    7070      number.MaxValue = 20;
     71      var constant = new Constant();
    7172      var variableSymbol = new Variable();
    7273
     
    7879      //all other symbols
    7980      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,
    8182        tanh, aq, abs
    8283      };
     
    8687      var realValueSymbols = new List<Symbol> {
    8788         add, sub, mul, div, sin, cos, tan, tanh, exp, log, aq, abs, square, cube, sqrt, cbrt,
    88          variableSymbol, number
     89         variableSymbol, number, constant
    8990        };
    9091
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r18114 r18115  
    108108      number.MinValue = -20;
    109109      number.MaxValue = 20;
     110      var constant = new Constant();
    110111      var variableSymbol = new Variable();
    111112      var binFactorVariable = new BinaryFactorVariable();
     
    121122      var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { abs, airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi,
    122123        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 });
    124125      var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols });
    125126
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r18114 r18115  
    2828namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2929  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();
    3830    private static readonly Number number = new Number();
    3931
     
    6658      var symbol = node.Symbol;
    6759      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";
    7062      } else if (node is VariableTreeNode variableNode) {
    7163        name = strict ? variableNode.Weight.ToString() + variableNode.VariableName : variableNode.VariableName;
     
    222214            variableTreeNode.VariableName = variable.VariableName;
    223215            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];
    226218            newNumNode.Value = existingNumNode.Value;
    227219          }
     
    285277
    286278        var symbol = child.Data.Symbol;
    287         if (child.Data is NumberTreeNode firstNum) {
     279        if (child.Data is INumericTreeNode firstNum) {
    288280          // fold sibling number nodes into the first number
    289281          for (int k = j + 1; k < children.Length; ++k) {
    290282            var sibling = nodes[children[k]];
    291             if (sibling.Data is NumberTreeNode otherNum) {
     283            if (sibling.Data is INumericTreeNode otherNum) {
    292284              sibling.Enabled = false;
    293285              node.Arity--;
     
    301293          for (int k = j + 1; k < children.Length; ++k) {
    302294            var sibling = nodes[children[k]];
    303             if (sibling.Data is NumberTreeNode numNode) {
     295            if (sibling.Data is INumericTreeNode numNode) {
    304296              sibling.Enabled = false;
    305297              node.Arity--;
     
    344336      var tmp = nodes;
    345337
    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;
    348340        if (node.Arity == 1) {
    349341          v = 1 / v;
    350342        } else if (node.Arity > 1) {
    351343          foreach (var j in children.Skip(1)) {
    352             v /= ((NumberTreeNode)nodes[j].Data).Value;
     344            v /= ((INumericTreeNode)nodes[j].Data).Value;
    353345          }
    354346        }
     
    383375      var childSymbol = child.Data.Symbol;
    384376
    385       if (childSymbol is Number) {
     377      if (childSymbol is INumericSymbol) {
    386378        nodes[i].Enabled = false;
    387379      } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) {
     
    393385      var children = nodes.IterateChildren(i);
    394386      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)) {
    396388        foreach (var j in children) {
    397389          nodes[j].Enabled = false;
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/INumericSymbol.cs

    r18100 r18115  
    2525namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2626  [StorableType("3CD759AF-A45E-4B70-BDCF-66AF1A03BAD8")]
    27   public interface INumericSymbol : ISymbol {
    28 
    29   }
     27  public interface INumericSymbol : ISymbol { }
    3028
    3129}
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/IntervalInterpreter.cs

    r18114 r18115  
    326326          !(n.Symbol is Variable) &&
    327327          !(n.Symbol is Number) &&
     328          !(n.Symbol is Constant) &&
    328329          !(n.Symbol is StartSymbol) &&
    329330          !(n.Symbol is Addition) &&
     
    347348        else if (n.Symbol is Power) {
    348349          // 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;
    351352        }
    352353      }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r18113 r18115  
    146146        var addition = new Addition();
    147147        var node = addition.CreateTreeNode();
    148         var alphaConst = MakeNumber(alpha);
     148        var alphaNode = MakeNumber(alpha);
    149149        node.AddSubtree(treeNode);
    150         node.AddSubtree(alphaConst);
     150        node.AddSubtree(alphaNode);
    151151        return node;
    152152      }
     
    159159        var multiplication = new Multiplication();
    160160        var node = multiplication.CreateTreeNode();
    161         var betaConst = MakeNumber(beta);
     161        var betaNode = MakeNumber(beta);
    162162        node.AddSubtree(treeNode);
    163         node.AddSubtree(betaConst);
     163        node.AddSubtree(betaNode);
    164164        return node;
    165165      }
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Constant.cs

    r18114 r18115  
    3535    public override int MaximumArity => maximumArity;
    3636
     37    public double Value { get; set; }
     38
    3739    [StorableConstructor]
    3840    private Constant(StorableConstructorFlag _) : base(_) { }
    3941
    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    }
    4145    public override IDeepCloneable Clone(Cloner cloner) {
    4246      return new Constant(this, cloner);
    4347    }
    4448
    45     public Constant() : base("Constant", "Represents a real-valued constant.") {}
     49    public Constant() : base("Constant", "Represents a real-valued constant.") { }
    4650
    4751    public override ISymbolicExpressionTreeNode CreateTreeNode() {
  • branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ConstantTreeNode.cs

    r18114 r18115  
    3030    public new Constant Symbol => (Constant) base.Symbol;
    3131
    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    }
    3336
    3437    [StorableConstructor]
     
    3740    private ConstantTreeNode(ConstantTreeNode original, Cloner cloner)
    3841      : base(original, cloner) {
    39       Value = original.Value;
    4042    }
    4143
  • branches/3140_NumberSymbol/HeuristicLab.Problems.ExternalEvaluation.GP/3.5/ExternalEvaluationExpressionGrammar.cs

    r18114 r18115  
    6565      number.MinValue = -20;
    6666      number.MaxValue = 20;
     67      var constant = new Constant();
    6768      variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
    6869
    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 };
    7071      var unaryFunctionSymbols = new List<Symbol>() { sin, cos, tan, log, exp, not };
    7172      var binaryFunctionSymbols = new List<Symbol>() { gt, lt };
     
    8788      SetSubtreeCount(@if, 3, 3);
    8889      SetSubtreeCount(number, 0, 0);
     90      SetSubtreeCount(constant,0, 0);
    8991      SetSubtreeCount(variableSymbol, 0, 0);
    9092
Note: See TracChangeset for help on using the changeset viewer.