Changeset 14878


Ignore:
Timestamp:
04/19/17 16:53:09 (3 months ago)
Author:
bburlacu
Message:

#1772: Merge trunk changes.

Location:
branches/HeuristicLab.EvolutionTracking
Files:
3 deleted
45 edited
13 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r14312 r14878  
    111111      } else {
    112112        var selectedBranch = SelectRandomBranch(random, allowedBranches, internalCrossoverPointProbability);
    113         if (selectedBranch != null)
    114           selectedBranch = (ISymbolicExpressionTreeNode)selectedBranch.Clone();
    115113
    116114        if (crossoverPoint0.Child != null) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views

  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r14576 r14878  
    183183    }
    184184
    185     protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree);
    186     protected abstract Dictionary<ISymbolicExpressionTreeNode, double> CalculateImpactValues(ISymbolicExpressionTree tree);
    187185    protected abstract Dictionary<ISymbolicExpressionTreeNode, Tuple<double, double>> CalculateImpactAndReplacementValues(ISymbolicExpressionTree tree);
    188186    protected abstract void UpdateModel(ISymbolicExpressionTree tree);
     
    268266
    269267    private void btnSimplify_Click(object sender, EventArgs e) {
    270       var simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
     268      var simplifier = new TreeSimplifier();
    271269      var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
    272270      UpdateModel(simplifiedExpressionTree);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/LaggedVariableView.Designer.cs

    r14312 r14878  
    6363      // weightInitializationMuTextBox
    6464      //
     65      this.weightInitializationMuTextBox.Size = new System.Drawing.Size(293, 20);
    6566      this.toolTip.SetToolTip(this.weightInitializationMuTextBox, "The mu (mean) parameter of the normal distribution from which to sample the initi" +
    6667        "al weights.");
     
    6970      //
    7071      this.initializationGroupBox.Location = new System.Drawing.Point(6, 7);
    71       this.initializationGroupBox.Size = new System.Drawing.Size(379, 73);
     72      this.initializationGroupBox.Size = new System.Drawing.Size(391, 73);
    7273      //
    7374      // weightSigmaLabel
     
    7778      // weightInitializationSigmaTextBox
    7879      //
     80      this.weightInitializationSigmaTextBox.Size = new System.Drawing.Size(293, 20);
    7981      this.toolTip.SetToolTip(this.weightInitializationSigmaTextBox, "The sigma parameter for the normal distribution from which to sample the initial " +
    8082        "weights.");
     
    8385      //
    8486      this.mutationGroupBox.Location = new System.Drawing.Point(6, 86);
    85       this.mutationGroupBox.Size = new System.Drawing.Size(379, 73);
     87      this.mutationGroupBox.Size = new System.Drawing.Size(391, 95);
    8688      //
    8789      // multiplicativeWeightChangeLabel
    8890      //
     91      this.multiplicativeWeightChangeLabel.TabIndex = 4;
    8992      this.toolTip.SetToolTip(this.multiplicativeWeightChangeLabel, "The sigma parameter for the normal distribution to use to sample a multiplicative" +
    9093        " change in weight.");
     
    9295      // multiplicativeWeightChangeSigmaTextBox
    9396      //
     97      this.multiplicativeWeightChangeSigmaTextBox.TabIndex = 5;
    9498      this.toolTip.SetToolTip(this.multiplicativeWeightChangeSigmaTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample a multiplica" +
    9599        "tive change in weight.");
     
    97101      // additiveWeightChangeLabel
    98102      //
     103      this.additiveWeightChangeLabel.TabIndex = 2;
    99104      this.toolTip.SetToolTip(this.additiveWeightChangeLabel, "The sigma (std.dev.) parameter for the normal distribution to sample an additive " +
    100105        "change in weight.");
     
    102107      // additiveWeightChangeSigmaTextBox
    103108      //
     109      this.additiveWeightChangeSigmaTextBox.TabIndex = 3;
    104110      this.toolTip.SetToolTip(this.additiveWeightChangeSigmaTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample an additive " +
    105111        "change in weight.");
     
    111117      // parametersTabPage
    112118      //
    113       this.parametersTabPage.Size = new System.Drawing.Size(400, 149);
     119      this.parametersTabPage.Size = new System.Drawing.Size(412, 208);
    114120      //
    115121      // tabControl
    116122      //
    117123      this.tabControl.Location = new System.Drawing.Point(0, 179);
    118       this.tabControl.Size = new System.Drawing.Size(408, 175);
    119       this.tabControl.TabIndex = 9;
     124      this.tabControl.Size = new System.Drawing.Size(420, 234);
     125      this.tabControl.TabIndex = 13;
     126      //
     127      // varChangeProbTextBox
     128      //
     129      this.varChangeProbTextBox.TabIndex = 1;
     130      this.toolTip.SetToolTip(this.varChangeProbTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample an additive " +
     131        "change in weight.");
     132      //
     133      // varChangeProbLabel
     134      //
     135      this.varChangeProbLabel.TabIndex = 0;
     136      this.toolTip.SetToolTip(this.varChangeProbLabel, "The probability of changing the referenced variable in [0..1]. Variable reference" +
     137        "s are sampled uniformly.");
    120138      //
    121139      // initialFrequencyLabel
    122140      //
     141      this.initialFrequencyLabel.TabIndex = 2;
    123142      this.toolTip.SetToolTip(this.initialFrequencyLabel, "Relative frequency of the symbol in randomly created trees");
    124143      //
     
    126145      //
    127146      this.errorProvider.SetIconAlignment(this.initialFrequencyTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
     147      this.initialFrequencyTextBox.Size = new System.Drawing.Size(323, 20);
     148      this.initialFrequencyTextBox.TabIndex = 3;
     149      //
     150      // enabledCheckBox
     151      //
     152      this.enabledCheckBox.TabIndex = 8;
     153      //
     154      // minimumArityLabel
     155      //
     156      this.minimumArityLabel.TabIndex = 4;
     157      this.toolTip.SetToolTip(this.minimumArityLabel, "The minimum arity of the symbol");
     158      //
     159      // maximumArityLabel
     160      //
     161      this.toolTip.SetToolTip(this.maximumArityLabel, "The maximum arity of the symbol");
    128162      //
    129163      // minimumArityTextBox
    130164      //
    131165      this.errorProvider.SetIconAlignment(this.minimumArityTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    132       this.minimumArityTextBox.Size = new System.Drawing.Size(315, 20);
     166      this.minimumArityTextBox.Size = new System.Drawing.Size(327, 20);
     167      this.minimumArityTextBox.TabIndex = 5;
    133168      //
    134169      // maximumArityTextBox
    135170      //
    136171      this.errorProvider.SetIconAlignment(this.maximumArityTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    137       this.maximumArityTextBox.Size = new System.Drawing.Size(315, 20);
     172      this.maximumArityTextBox.Size = new System.Drawing.Size(327, 20);
    138173      //
    139174      // nameTextBox
     
    141176      this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    142177      this.errorProvider.SetIconPadding(this.nameTextBox, 2);
     178      this.nameTextBox.Size = new System.Drawing.Size(302, 20);
     179      //
     180      // infoLabel
     181      //
     182      this.infoLabel.Location = new System.Drawing.Point(401, 3);
    143183      //
    144184      // minTimeOffsetLabel
     
    148188      this.minTimeOffsetLabel.Name = "minTimeOffsetLabel";
    149189      this.minTimeOffsetLabel.Size = new System.Drawing.Size(81, 13);
    150       this.minTimeOffsetLabel.TabIndex = 5;
     190      this.minTimeOffsetLabel.TabIndex = 9;
    151191      this.minTimeOffsetLabel.Text = "Min. time offset:";
    152192      //
     
    157197      this.maxTimeOffsetLabel.Name = "maxTimeOffsetLabel";
    158198      this.maxTimeOffsetLabel.Size = new System.Drawing.Size(84, 13);
    159       this.maxTimeOffsetLabel.TabIndex = 7;
     199      this.maxTimeOffsetLabel.TabIndex = 11;
    160200      this.maxTimeOffsetLabel.Text = "Max. time offset:";
    161201      //
    162202      // minTimeOffsetTextBox
    163203      //
    164       this.minTimeOffsetTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     204      this.minTimeOffsetTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    165205            | System.Windows.Forms.AnchorStyles.Right)));
    166206      this.minTimeOffsetTextBox.Location = new System.Drawing.Point(93, 127);
    167207      this.minTimeOffsetTextBox.Name = "minTimeOffsetTextBox";
    168       this.minTimeOffsetTextBox.Size = new System.Drawing.Size(315, 20);
    169       this.minTimeOffsetTextBox.TabIndex = 6;
     208      this.minTimeOffsetTextBox.Size = new System.Drawing.Size(327, 20);
     209      this.minTimeOffsetTextBox.TabIndex = 10;
    170210      this.minTimeOffsetTextBox.TextChanged += new System.EventHandler(this.minTimeOffsetTextBox_TextChanged);
    171211      //
    172212      // maxTimeOffsetTextBox
    173213      //
    174       this.maxTimeOffsetTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     214      this.maxTimeOffsetTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
    175215            | System.Windows.Forms.AnchorStyles.Right)));
    176216      this.maxTimeOffsetTextBox.Location = new System.Drawing.Point(93, 153);
    177217      this.maxTimeOffsetTextBox.Name = "maxTimeOffsetTextBox";
    178       this.maxTimeOffsetTextBox.Size = new System.Drawing.Size(315, 20);
    179       this.maxTimeOffsetTextBox.TabIndex = 8;
     218      this.maxTimeOffsetTextBox.Size = new System.Drawing.Size(327, 20);
     219      this.maxTimeOffsetTextBox.TabIndex = 12;
    180220      this.maxTimeOffsetTextBox.TextChanged += new System.EventHandler(this.maxTimeOffsetTextBox_TextChanged);
    181221      //
    182222      // LaggedVariableView
    183223      //
    184       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    185224      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    186225      this.Controls.Add(this.minTimeOffsetTextBox);
     
    189228      this.Controls.Add(this.maxTimeOffsetTextBox);
    190229      this.Name = "LaggedVariableView";
    191       this.Size = new System.Drawing.Size(408, 352);
     230      this.Size = new System.Drawing.Size(420, 411);
     231      this.Controls.SetChildIndex(this.enabledCheckBox, 0);
    192232      this.Controls.SetChildIndex(this.maxTimeOffsetTextBox, 0);
    193233      this.Controls.SetChildIndex(this.minTimeOffsetLabel, 0);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.Designer.cs

    r14312 r14878  
    5151      this.weightInitializationSigmaTextBox = new System.Windows.Forms.TextBox();
    5252      this.mutationGroupBox = new System.Windows.Forms.GroupBox();
     53      this.varChangeProbTextBox = new System.Windows.Forms.TextBox();
     54      this.varChangeProbLabel = new System.Windows.Forms.Label();
    5355      this.multiplicativeWeightChangeLabel = new System.Windows.Forms.Label();
    5456      this.multiplicativeWeightChangeSigmaTextBox = new System.Windows.Forms.TextBox();
     
    6769      // initialFrequencyLabel
    6870      //
     71      this.initialFrequencyLabel.TabIndex = 2;
    6972      this.toolTip.SetToolTip(this.initialFrequencyLabel, "Relative frequency of the symbol in randomly created trees");
    7073      //
     
    7376      this.errorProvider.SetIconAlignment(this.initialFrequencyTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    7477      this.initialFrequencyTextBox.Size = new System.Drawing.Size(311, 20);
     78      this.initialFrequencyTextBox.TabIndex = 3;
     79      //
     80      // enabledCheckBox
     81      //
     82      this.enabledCheckBox.TabIndex = 8;
    7583      //
    7684      // minimumArityLabel
    7785      //
     86      this.minimumArityLabel.TabIndex = 4;
    7887      this.toolTip.SetToolTip(this.minimumArityLabel, "The minimum arity of the symbol");
    7988      //
     
    8695      this.errorProvider.SetIconAlignment(this.minimumArityTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft);
    8796      this.minimumArityTextBox.Size = new System.Drawing.Size(311, 20);
     97      this.minimumArityTextBox.TabIndex = 5;
    8898      //
    8999      // maximumArityTextBox
     
    165175      this.mutationGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    166176            | System.Windows.Forms.AnchorStyles.Right)));
     177      this.mutationGroupBox.Controls.Add(this.varChangeProbTextBox);
     178      this.mutationGroupBox.Controls.Add(this.varChangeProbLabel);
    167179      this.mutationGroupBox.Controls.Add(this.multiplicativeWeightChangeLabel);
    168180      this.mutationGroupBox.Controls.Add(this.multiplicativeWeightChangeSigmaTextBox);
     
    171183      this.mutationGroupBox.Location = new System.Drawing.Point(6, 85);
    172184      this.mutationGroupBox.Name = "mutationGroupBox";
    173       this.mutationGroupBox.Size = new System.Drawing.Size(391, 73);
     185      this.mutationGroupBox.Size = new System.Drawing.Size(391, 97);
    174186      this.mutationGroupBox.TabIndex = 1;
    175187      this.mutationGroupBox.TabStop = false;
    176188      this.mutationGroupBox.Text = "Mutation";
    177189      //
     190      // varChangeProbTextBox
     191      //
     192      this.varChangeProbTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
     193            | System.Windows.Forms.AnchorStyles.Right)));
     194      this.varChangeProbTextBox.Location = new System.Drawing.Point(201, 13);
     195      this.varChangeProbTextBox.Name = "varChangeProbTextBox";
     196      this.varChangeProbTextBox.Size = new System.Drawing.Size(184, 20);
     197      this.varChangeProbTextBox.TabIndex = 1;
     198      this.toolTip.SetToolTip(this.varChangeProbTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample an additive " +
     199        "change in weight.");
     200      this.varChangeProbTextBox.TextChanged += new System.EventHandler(this.VarProbTextBox_TextChanged);
     201      //
     202      // varChangeProbLabel
     203      //
     204      this.varChangeProbLabel.AutoSize = true;
     205      this.varChangeProbLabel.Location = new System.Drawing.Point(6, 16);
     206      this.varChangeProbLabel.Name = "varChangeProbLabel";
     207      this.varChangeProbLabel.Size = new System.Drawing.Size(134, 13);
     208      this.varChangeProbLabel.TabIndex = 0;
     209      this.varChangeProbLabel.Text = "Variable change probability";
     210      this.toolTip.SetToolTip(this.varChangeProbLabel, "The probability of changing the referenced variable in [0..1]. Variable reference" +
     211        "s are sampled uniformly.");
     212      //
    178213      // multiplicativeWeightChangeLabel
    179214      //
    180215      this.multiplicativeWeightChangeLabel.AutoSize = true;
    181       this.multiplicativeWeightChangeLabel.Location = new System.Drawing.Point(6, 48);
     216      this.multiplicativeWeightChangeLabel.Location = new System.Drawing.Point(6, 68);
    182217      this.multiplicativeWeightChangeLabel.Name = "multiplicativeWeightChangeLabel";
    183218      this.multiplicativeWeightChangeLabel.Size = new System.Drawing.Size(180, 13);
    184       this.multiplicativeWeightChangeLabel.TabIndex = 2;
     219      this.multiplicativeWeightChangeLabel.TabIndex = 4;
    185220      this.multiplicativeWeightChangeLabel.Text = "Multiplicative weight change (sigma):";
    186221      this.toolTip.SetToolTip(this.multiplicativeWeightChangeLabel, "The sigma parameter for the normal distribution to use to sample a multiplicative" +
     
    191226      this.multiplicativeWeightChangeSigmaTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    192227            | System.Windows.Forms.AnchorStyles.Right)));
    193       this.multiplicativeWeightChangeSigmaTextBox.Location = new System.Drawing.Point(201, 45);
     228      this.multiplicativeWeightChangeSigmaTextBox.Location = new System.Drawing.Point(201, 65);
    194229      this.multiplicativeWeightChangeSigmaTextBox.Name = "multiplicativeWeightChangeSigmaTextBox";
    195230      this.multiplicativeWeightChangeSigmaTextBox.Size = new System.Drawing.Size(184, 20);
    196       this.multiplicativeWeightChangeSigmaTextBox.TabIndex = 3;
     231      this.multiplicativeWeightChangeSigmaTextBox.TabIndex = 5;
    197232      this.toolTip.SetToolTip(this.multiplicativeWeightChangeSigmaTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample a multiplica" +
    198233        "tive change in weight.");
     
    202237      //
    203238      this.additiveWeightChangeLabel.AutoSize = true;
    204       this.additiveWeightChangeLabel.Location = new System.Drawing.Point(6, 22);
     239      this.additiveWeightChangeLabel.Location = new System.Drawing.Point(6, 42);
    205240      this.additiveWeightChangeLabel.Name = "additiveWeightChangeLabel";
    206241      this.additiveWeightChangeLabel.Size = new System.Drawing.Size(157, 13);
    207       this.additiveWeightChangeLabel.TabIndex = 0;
     242      this.additiveWeightChangeLabel.TabIndex = 2;
    208243      this.additiveWeightChangeLabel.Text = "Additive weight change (sigma):";
    209244      this.toolTip.SetToolTip(this.additiveWeightChangeLabel, "The sigma (std.dev.) parameter for the normal distribution to sample an additive " +
     
    214249      this.additiveWeightChangeSigmaTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    215250            | System.Windows.Forms.AnchorStyles.Right)));
    216       this.additiveWeightChangeSigmaTextBox.Location = new System.Drawing.Point(201, 19);
     251      this.additiveWeightChangeSigmaTextBox.Location = new System.Drawing.Point(201, 39);
    217252      this.additiveWeightChangeSigmaTextBox.Name = "additiveWeightChangeSigmaTextBox";
    218253      this.additiveWeightChangeSigmaTextBox.Size = new System.Drawing.Size(184, 20);
    219       this.additiveWeightChangeSigmaTextBox.TabIndex = 1;
     254      this.additiveWeightChangeSigmaTextBox.TabIndex = 3;
    220255      this.toolTip.SetToolTip(this.additiveWeightChangeSigmaTextBox, "The sigma (std.dev.) parameter for the normal distribution to sample an additive " +
    221256        "change in weight.");
     
    232267      this.tabControl.Name = "tabControl";
    233268      this.tabControl.SelectedIndex = 0;
    234       this.tabControl.Size = new System.Drawing.Size(408, 190);
    235       this.tabControl.TabIndex = 5;
     269      this.tabControl.Size = new System.Drawing.Size(408, 216);
     270      this.tabControl.TabIndex = 9;
    236271      //
    237272      // variableNamesTabPage
     
    240275      this.variableNamesTabPage.Name = "variableNamesTabPage";
    241276      this.variableNamesTabPage.Padding = new System.Windows.Forms.Padding(3);
    242       this.variableNamesTabPage.Size = new System.Drawing.Size(400, 164);
     277      this.variableNamesTabPage.Size = new System.Drawing.Size(400, 190);
    243278      this.variableNamesTabPage.TabIndex = 0;
    244279      this.variableNamesTabPage.Text = "Variable Names";
     
    252287      this.parametersTabPage.Name = "parametersTabPage";
    253288      this.parametersTabPage.Padding = new System.Windows.Forms.Padding(3);
    254       this.parametersTabPage.Size = new System.Drawing.Size(400, 164);
     289      this.parametersTabPage.Size = new System.Drawing.Size(400, 190);
    255290      this.parametersTabPage.TabIndex = 1;
    256291      this.parametersTabPage.Text = "Parameters";
     
    259294      // VariableView
    260295      //
    261       this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    262296      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    263297      this.Controls.Add(this.tabControl);
    264298      this.Name = "VariableView";
    265       this.Size = new System.Drawing.Size(408, 317);
     299      this.Size = new System.Drawing.Size(408, 346);
     300      this.Controls.SetChildIndex(this.enabledCheckBox, 0);
    266301      this.Controls.SetChildIndex(this.maximumArityLabel, 0);
    267302      this.Controls.SetChildIndex(this.maximumArityTextBox, 0);
     
    301336    protected System.Windows.Forms.TabPage parametersTabPage;
    302337    protected System.Windows.Forms.TabControl tabControl;
     338    protected System.Windows.Forms.TextBox varChangeProbTextBox;
     339    protected System.Windows.Forms.Label varChangeProbLabel;
    303340  }
    304341}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/Symbols/VariableView.cs

    r14312 r14878  
    2929using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    3030using HeuristicLab.MainForm;
    31 using HeuristicLab.MainForm.WindowsForms;
    3231
    3332
    3433namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3534  [View("Variable View")]
    36   [Content(typeof(Variable), true)]
     35  [Content(typeof(VariableBase), true)]
    3736  public partial class VariableView : SymbolView {
    3837    private CheckedItemCollectionView<StringValue> variableNamesView;
    3938
    40     public new Variable Content {
    41       get { return (Variable)base.Content; }
     39    public new VariableBase Content {
     40      get { return (VariableBase)base.Content; }
    4241      set { base.Content = value; }
    4342    }
     
    101100      multiplicativeWeightChangeSigmaTextBox.Enabled = Content != null;
    102101      multiplicativeWeightChangeSigmaTextBox.ReadOnly = ReadOnly;
     102      varChangeProbTextBox.Enabled = Content != null;
     103      varChangeProbTextBox.ReadOnly = ReadOnly;
    103104    }
    104105
     
    175176      }
    176177    }
     178
     179    private void VarProbTextBox_TextChanged(object sender, EventArgs e) {
     180      double prob;
     181      if (double.TryParse(varChangeProbTextBox.Text, out prob) && prob >= 0.0 && prob <= 1.0) {
     182        Content.VariableChangeProbability = prob;
     183        errorProvider.SetError(varChangeProbTextBox, string.Empty);
     184      } else {
     185        errorProvider.SetError(varChangeProbTextBox, "Invalid value");
     186      }
     187    }
    177188    #endregion
    178189
     
    184195        additiveWeightChangeSigmaTextBox.Text = string.Empty;
    185196        multiplicativeWeightChangeSigmaTextBox.Text = string.Empty;
     197        varChangeProbTextBox.Text = string.Empty;
    186198        // temporarily deregister to prevent circular calling of events
    187199        DeregisterVariableNamesViewContentEvents();
     
    201213        additiveWeightChangeSigmaTextBox.Text = Content.WeightManipulatorSigma.ToString();
    202214        multiplicativeWeightChangeSigmaTextBox.Text = Content.MultiplicativeWeightManipulatorSigma.ToString();
     215        varChangeProbTextBox.Text = Content.VariableChangeProbability.ToString();
    203216      }
    204217      SetEnabledStateOfControls();
    205218    }
    206219    #endregion
     220
    207221  }
    208222}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeNodeInsertDialog.cs

    r14576 r14878  
    6565        constantValueLabel.Visible = true;
    6666        constantValueTextBox.Visible = true;
    67       } else if (symbol is Variable) {
    68         var variableSymbol = (Variable)symbol;
     67      } else if (symbol is VariableBase) {
     68        var variableSymbol = (VariableBase)symbol;
    6969        if (variableSymbol.VariableNames.Any()) {
    7070          foreach (var name in variableSymbol.VariableNames)
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.cs

    r14576 r14878  
    3434      get { return variableTreeNode; }
    3535      set {
    36         if (InvokeRequired)
    37           Invoke(new Action<SymbolicExpressionTreeNode>(x => variableTreeNode = (VariableTreeNode)x), value);
    38         else
     36        if (InvokeRequired) {
     37          Invoke(new Action<SymbolicExpressionTreeNode>(x =>
     38          {
     39            variableTreeNode = (VariableTreeNode) x;
     40            variableNameTextBox.Text = variableTreeNode.VariableName;
     41          }), value);
     42        } else {
    3943          variableTreeNode = value;
     44          variableNameTextBox.Text = variableTreeNode.VariableName;
     45        }
    4046      }
    4147    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs

    r14312 r14878  
    8989      var varTreeNode = tree as VariableTreeNode;
    9090      var constTreeNode = tree as ConstantTreeNode;
     91      var factorVarTreeNode = tree as FactorVariableTreeNode;
     92      var binFactorVarTreeNode = tree as BinaryFactorVariableTreeNode;
    9193      if (varTreeNode != null) {
    9294        builder.Append("(var " + varTreeNode.VariableName);
     95      } else if (factorVarTreeNode != null) {
     96        builder.Append("(factor " + factorVarTreeNode.VariableName);
     97      } else if (binFactorVarTreeNode != null) {
     98        builder.Append("(factor " + binFactorVarTreeNode.VariableName + "=" + binFactorVarTreeNode.VariableValue);
    9399      } else if (constTreeNode != null) {
    94100        builder.Append("(const");
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer.cs

    r14312 r14878  
    3535  [Item("SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic data analysis solution for single objective symbolic data analysis problems.")]
    3636  [StorableClass]
    37   public abstract class SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<T> : SymbolicDataAnalysisSingleObjectiveAnalyzer, IIterationBasedOperator
    38 
    39     where T : class, ISymbolicDataAnalysisSolution {
     37  public abstract class SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<T> : SymbolicDataAnalysisSingleObjectiveAnalyzer, IIterationBasedOperator where T : class, ISymbolicDataAnalysisSolution {
    4038    private const string TrainingBestSolutionParameterName = "Best training solution";
    4139    private const string TrainingBestSolutionQualityParameterName = "Best training solution quality";
    4240    private const string TrainingBestSolutionGenerationParameterName = "Best training solution generation";
     41    private const string TrainingBestSolutionsHistoryParameterName = "Best training solutions history";
    4342    private const string UpdateAlwaysParameterName = "Always update best solution";
    4443    private const string IterationsParameterName = "Iterations";
    4544    private const string MaximumIterationsParameterName = "Maximum Iterations";
     45    private const string StoreHistoryParameterName = "Store History";
    4646
    4747    #region parameter properties
     
    5555      get { return (ILookupParameter<IntValue>)Parameters[TrainingBestSolutionGenerationParameterName]; }
    5656    }
     57    public ILookupParameter<ItemList<T>> TrainingBestSolutionsHistoryParameter {
     58      get { return (ILookupParameter<ItemList<T>>)Parameters[TrainingBestSolutionsHistoryParameterName]; }
     59    }
    5760    public IFixedValueParameter<BoolValue> UpdateAlwaysParameter {
    5861      get { return (IFixedValueParameter<BoolValue>)Parameters[UpdateAlwaysParameterName]; }
     
    6366    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
    6467      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsParameterName]; }
     68    }
     69
     70    public IFixedValueParameter<BoolValue> StoreHistoryParameter {
     71      get { return (IFixedValueParameter<BoolValue>)Parameters[StoreHistoryParameterName]; }
    6572    }
    6673    #endregion
     
    7481      set { TrainingBestSolutionQualityParameter.ActualValue = value; }
    7582    }
    76     public BoolValue UpdateAlways {
    77       get { return UpdateAlwaysParameter.Value; }
     83    public bool UpdateAlways {
     84      get { return UpdateAlwaysParameter.Value.Value; }
     85      set { UpdateAlwaysParameter.Value.Value = value; }
     86    }
     87
     88    public bool StoreHistory {
     89      get { return StoreHistoryParameter.Value.Value; }
     90      set { StoreHistoryParameter.Value.Value = value; }
    7891    }
    7992    #endregion
     93
    8094
    8195    [StorableConstructor]
     
    8498    public SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer()
    8599      : base() {
    86       Parameters.Add(new LookupParameter<T>(TrainingBestSolutionParameterName, "The training best symbolic data analyis solution."));
     100      Parameters.Add(new LookupParameter<T>(TrainingBestSolutionParameterName, "The best training symbolic data analyis solution."));
    87101      Parameters.Add(new LookupParameter<DoubleValue>(TrainingBestSolutionQualityParameterName, "The quality of the training best symbolic data analysis solution."));
    88102      Parameters.Add(new LookupParameter<IntValue>(TrainingBestSolutionGenerationParameterName, "The generation in which the best training solution was found."));
     
    90104      Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, "The number of performed iterations."));
    91105      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true });
     106      Parameters.Add(new FixedValueParameter<BoolValue>(StoreHistoryParameterName, "Flag that determines whether all encountered best solutions should be stored as results.", new BoolValue(false)));
     107      Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsHistoryParameterName, "The history of the best training symbolic data analysis solutions."));
    92108      UpdateAlwaysParameter.Hidden = true;
    93109    }
     
    105121      if (!Parameters.ContainsKey(MaximumIterationsParameterName))
    106122        Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, "The maximum number of performed iterations.") { Hidden = true });
     123      if (!Parameters.ContainsKey(StoreHistoryParameterName))
     124        Parameters.Add(new FixedValueParameter<BoolValue>(StoreHistoryParameterName, "Flag that determines whether all encountered best solutions should be stored as results.", new BoolValue(false)));
     125      if (!Parameters.ContainsKey(TrainingBestSolutionsHistoryParameterName))
     126        Parameters.Add(new LookupParameter<ItemList<T>>(TrainingBestSolutionsHistoryParameterName, "The history of the best training symbolic data analysis solutions."));
    107127    }
    108128
    109129    public override IOperation Apply() {
     130      var results = ResultCollection;
     131      #region create results
     132      if (!results.ContainsKey(TrainingBestSolutionParameter.Name))
     133        results.Add(new Result(TrainingBestSolutionParameter.Name, TrainingBestSolutionParameter.Description, typeof(T)));
     134      if (!results.ContainsKey(TrainingBestSolutionQualityParameter.Name))
     135        results.Add(new Result(TrainingBestSolutionQualityParameter.Name, TrainingBestSolutionQualityParameter.Description, typeof(DoubleValue)));
     136      if (!results.ContainsKey(TrainingBestSolutionGenerationParameter.Name) && IterationsParameter.ActualValue != null)
     137        results.Add(new Result(TrainingBestSolutionGenerationParameter.Name, TrainingBestSolutionGenerationParameter.Description, typeof(IntValue)));
     138      if (StoreHistory && !results.ContainsKey(TrainingBestSolutionsHistoryParameter.Name)) {
     139
     140        results.Add(new Result(TrainingBestSolutionsHistoryParameter.Name, TrainingBestSolutionsHistoryParameter.Description, typeof(ItemList<T>)));
     141        TrainingBestSolutionsHistoryParameter.ActualValue = new ItemList<T>();
     142        results[TrainingBestSolutionsHistoryParameter.Name].Value = TrainingBestSolutionsHistoryParameter.ActualValue;
     143      }
     144      #endregion
     145
    110146      #region find best tree
    111147      double bestQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity;
     
    121157      #endregion
    122158
    123       var results = ResultCollection;
    124       if (bestTree != null && (UpdateAlways.Value || TrainingBestSolutionQuality == null ||
     159      if (bestTree != null && (UpdateAlways || TrainingBestSolutionQuality == null ||
    125160        IsBetter(bestQuality, TrainingBestSolutionQuality.Value, Maximization.Value))) {
    126161        TrainingBestSolution = CreateSolution(bestTree, bestQuality);
     
    129164          TrainingBestSolutionGenerationParameter.ActualValue = new IntValue(IterationsParameter.ActualValue.Value);
    130165
    131         if (!results.ContainsKey(TrainingBestSolutionParameter.Name)) {
    132           results.Add(new Result(TrainingBestSolutionParameter.Name, TrainingBestSolutionParameter.Description, TrainingBestSolution));
    133           results.Add(new Result(TrainingBestSolutionQualityParameter.Name, TrainingBestSolutionQualityParameter.Description, TrainingBestSolutionQuality));
    134           if (TrainingBestSolutionGenerationParameter.ActualValue != null)
    135             results.Add(new Result(TrainingBestSolutionGenerationParameter.Name, TrainingBestSolutionGenerationParameter.Description, TrainingBestSolutionGenerationParameter.ActualValue));
    136         } else {
    137           results[TrainingBestSolutionParameter.Name].Value = TrainingBestSolution;
    138           results[TrainingBestSolutionQualityParameter.Name].Value = TrainingBestSolutionQuality;
    139           if (TrainingBestSolutionGenerationParameter.ActualValue != null)
    140             results[TrainingBestSolutionGenerationParameter.Name].Value = TrainingBestSolutionGenerationParameter.ActualValue;
     166        results[TrainingBestSolutionParameter.Name].Value = TrainingBestSolution;
     167        results[TrainingBestSolutionQualityParameter.Name].Value = TrainingBestSolutionQuality;
     168        if (TrainingBestSolutionGenerationParameter.ActualValue != null)
     169          results[TrainingBestSolutionGenerationParameter.Name].Value = TrainingBestSolutionGenerationParameter.ActualValue;
    141170
     171        if (StoreHistory) {
     172          TrainingBestSolutionsHistoryParameter.ActualValue.Add(TrainingBestSolution);
    142173        }
    143174      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisVariableFrequencyAnalyzer.cs

    r14312 r14878  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Globalization;
    2425using System.Linq;
    2526using HeuristicLab.Analysis;
     
    4142    private const string VariableFrequenciesParameterName = "VariableFrequencies";
    4243    private const string AggregateLaggedVariablesParameterName = "AggregateLaggedVariables";
     44    private const string AggregateFactorVariablesParameterName = "AggregateFactorVariables";
    4345    private const string VariableImpactsParameterName = "VariableImpacts";
    4446
     
    5254    public IValueLookupParameter<BoolValue> AggregateLaggedVariablesParameter {
    5355      get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateLaggedVariablesParameterName]; }
     56    }
     57    public IValueLookupParameter<BoolValue> AggregateFactorVariablesParameter {
     58      get { return (IValueLookupParameter<BoolValue>)Parameters[AggregateFactorVariablesParameterName]; }
    5459    }
    5560    #endregion
     
    5964      set { AggregateLaggedVariablesParameter.Value = value; }
    6065    }
     66    public BoolValue AggregateFactorVariables {
     67      get { return AggregateFactorVariablesParameter.ActualValue; }
     68      set { AggregateFactorVariablesParameter.Value = value; }
     69    }
    6170    #endregion
    6271    [StorableConstructor]
     
    7079      Parameters.Add(new LookupParameter<DoubleMatrix>(VariableImpactsParameterName, "The relative variable relevance calculated as the average relative variable frequency over the whole run."));
    7180      Parameters.Add(new ValueLookupParameter<BoolValue>(AggregateLaggedVariablesParameterName, "Switch that determines whether all references to a variable should be aggregated regardless of time-offsets. Turn off to analyze all variable references with different time offsets separately.", new BoolValue(true)));
     81      Parameters.Add(new ValueLookupParameter<BoolValue>(AggregateFactorVariablesParameterName, "Switch that determines whether all references to factor variables should be aggregated regardless of the value. Turn off to analyze all factor variable references with different values separately.", new BoolValue(true)));
     82    }
     83
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      // BackwardsCompatibility3.3
     87      #region Backwards compatible code, remove with 3.4
     88      if (!Parameters.ContainsKey(AggregateFactorVariablesParameterName)) {
     89        Parameters.Add(new ValueLookupParameter<BoolValue>(AggregateFactorVariablesParameterName, "Switch that determines whether all references to factor variables should be aggregated regardless of the value. Turn off to analyze all factor variable references with different values separately.", new BoolValue(true)));
     90      }
     91      #endregion
    7292    }
    7393
     
    93113      int numberOfValues = datatable.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();
    94114
    95       foreach (var pair in SymbolicDataAnalysisVariableFrequencyAnalyzer.CalculateVariableFrequencies(expressions, AggregateLaggedVariables.Value)) {
     115      foreach (var pair in CalculateVariableFrequencies(expressions, AggregateLaggedVariables.Value, AggregateFactorVariables.Value)) {
    96116        if (!datatable.Rows.ContainsKey(pair.Key)) {
    97117          // initialize a new row for the variable and pad with zeros
     
    128148    }
    129149
    130     public static IEnumerable<KeyValuePair<string, double>> CalculateVariableFrequencies(IEnumerable<ISymbolicExpressionTree> trees, bool aggregateLaggedVariables = true) {
     150    public static IEnumerable<KeyValuePair<string, double>> CalculateVariableFrequencies(IEnumerable<ISymbolicExpressionTree> trees,
     151      bool aggregateLaggedVariables = true, bool aggregateFactorVariables = true) {
    131152
    132153      var variableFrequencies = trees
    133         .SelectMany(t => GetVariableReferences(t, aggregateLaggedVariables))
     154        .SelectMany(t => GetVariableReferences(t, aggregateLaggedVariables, aggregateFactorVariables))
    134155        .GroupBy(pair => pair.Key, pair => pair.Value)
    135156        .ToDictionary(g => g.Key, g => (double)g.Sum());
     
    141162    }
    142163
    143     private static IEnumerable<KeyValuePair<string, int>> GetVariableReferences(ISymbolicExpressionTree tree, bool aggregateLaggedVariables = true) {
     164    private static IEnumerable<KeyValuePair<string, int>> GetVariableReferences(ISymbolicExpressionTree tree,
     165      bool aggregateLaggedVariables = true, bool aggregateFactorVariables = true) {
    144166      Dictionary<string, int> references = new Dictionary<string, int>();
    145167      if (aggregateLaggedVariables) {
    146168        tree.Root.ForEachNodePrefix(node => {
    147           if (node.Symbol is Variable) {
    148             var varNode = node as VariableTreeNode;
    149             IncReferenceCount(references, varNode.VariableName);
    150           } else if (node.Symbol is VariableCondition) {
    151             var varCondNode = node as VariableConditionTreeNode;
    152             IncReferenceCount(references, varCondNode.VariableName);
     169          if (node is IVariableTreeNode) {
     170            var factorNode = node as BinaryFactorVariableTreeNode;
     171            if (factorNode != null && !aggregateFactorVariables) {
     172              IncReferenceCount(references, factorNode.VariableName + "=" + factorNode.VariableValue);
     173            } else {
     174              var varNode = node as IVariableTreeNode;
     175              IncReferenceCount(references, varNode.VariableName);
     176            }
    153177          }
    154178        });
    155179      } else {
    156         GetVariableReferences(references, tree.Root, 0);
     180        GetVariableReferences(references, tree.Root, 0, aggregateFactorVariables);
    157181      }
    158182      return references;
    159183    }
    160184
    161     private static void GetVariableReferences(Dictionary<string, int> references, ISymbolicExpressionTreeNode node, int currentLag) {
    162       if (node.Symbol is LaggedVariable) {
    163         var laggedVarNode = node as LaggedVariableTreeNode;
    164         IncReferenceCount(references, laggedVarNode.VariableName, currentLag + laggedVarNode.Lag);
    165       } else if (node.Symbol is Variable) {
    166         var varNode = node as VariableTreeNode;
    167         IncReferenceCount(references, varNode.VariableName, currentLag);
    168       } else if (node.Symbol is VariableCondition) {
    169         var varCondNode = node as VariableConditionTreeNode;
    170         IncReferenceCount(references, varCondNode.VariableName, currentLag);
    171         GetVariableReferences(references, node.GetSubtree(0), currentLag);
    172         GetVariableReferences(references, node.GetSubtree(1), currentLag);
     185    private static void GetVariableReferences(Dictionary<string, int> references, ISymbolicExpressionTreeNode node, int currentLag, bool aggregateFactorVariables) {
     186      if (node is IVariableTreeNode) {
     187        var laggedVarTreeNode = node as LaggedVariableTreeNode;
     188        var binFactorVariableTreeNode = node as BinaryFactorVariableTreeNode;
     189        var varConditionTreeNode = node as VariableConditionTreeNode;
     190        if (laggedVarTreeNode != null) {
     191          IncReferenceCount(references, laggedVarTreeNode.VariableName, currentLag + laggedVarTreeNode.Lag);
     192        } else if (binFactorVariableTreeNode != null) {
     193          if (aggregateFactorVariables) {
     194            IncReferenceCount(references, binFactorVariableTreeNode.VariableName, currentLag);
     195          } else {
     196            IncReferenceCount(references, binFactorVariableTreeNode.VariableName + "=" + binFactorVariableTreeNode.VariableValue, currentLag);
     197          }
     198        } else if (varConditionTreeNode != null) {
     199          IncReferenceCount(references, varConditionTreeNode.VariableName, currentLag);
     200          GetVariableReferences(references, node.GetSubtree(0), currentLag, aggregateFactorVariables);
     201          GetVariableReferences(references, node.GetSubtree(1), currentLag, aggregateFactorVariables);
     202        } else {
     203          var varNode = node as IVariableTreeNode;
     204          IncReferenceCount(references, varNode.VariableName, currentLag);
     205        }
    173206      } else if (node.Symbol is Integral) {
    174207        var laggedNode = node as LaggedTreeNode;
    175208        for (int l = laggedNode.Lag; l <= 0; l++) {
    176           GetVariableReferences(references, node.GetSubtree(0), currentLag + l);
     209          GetVariableReferences(references, node.GetSubtree(0), currentLag + l, aggregateFactorVariables);
    177210        }
    178211      } else if (node.Symbol is Derivative) {
    179212        for (int l = -4; l <= 0; l++) {
    180           GetVariableReferences(references, node.GetSubtree(0), currentLag + l);
     213          GetVariableReferences(references, node.GetSubtree(0), currentLag + l, aggregateFactorVariables);
    181214        }
    182215      } else if (node.Symbol is TimeLag) {
    183216        var laggedNode = node as LaggedTreeNode;
    184         GetVariableReferences(references, node.GetSubtree(0), currentLag + laggedNode.Lag);
     217        GetVariableReferences(references, node.GetSubtree(0), currentLag + laggedNode.Lag, aggregateFactorVariables);
    185218      } else {
    186219        foreach (var subtree in node.Subtrees) {
    187           GetVariableReferences(references, subtree, currentLag);
     220          GetVariableReferences(references, subtree, currentLag, aggregateFactorVariables);
    188221        }
    189222      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/InfixExpressionFormatter.cs

    r14576 r14878  
    141141            strBuilder.Append(")");
    142142          }
     143        } else if (node.Symbol is FactorVariable) {
     144          var factorNode = node as FactorVariableTreeNode;
     145          if (factorNode.VariableName.Contains("'")) {
     146            strBuilder.AppendFormat("\"{0}\"", factorNode.VariableName);
     147          } else {
     148            strBuilder.AppendFormat("'{0}'", factorNode.VariableName);
     149          }
     150          strBuilder.AppendFormat("[{0}]",
     151            string.Join(", ", factorNode.Weights.Select(w => w.ToString(CultureInfo.InvariantCulture))));
     152        } else if (node.Symbol is BinaryFactorVariable) {
     153          var factorNode = node as BinaryFactorVariableTreeNode;
     154          if (!factorNode.Weight.IsAlmost(1.0)) {
     155            strBuilder.Append("(");
     156            strBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0}", factorNode.Weight);
     157            strBuilder.Append("*");
     158          }
     159          if (factorNode.VariableName.Contains("'")) {
     160            strBuilder.AppendFormat("\"{0}\"", factorNode.VariableName);
     161          } else {
     162            strBuilder.AppendFormat("'{0}'", factorNode.VariableName);
     163          }
     164          strBuilder.Append(" = ");
     165          if (factorNode.VariableValue.Contains("'")) {
     166            strBuilder.AppendFormat("\"{0}\"", factorNode.VariableValue);
     167          } else {
     168            strBuilder.AppendFormat("'{0}'", factorNode.VariableValue);
     169          }
     170
     171          if (!factorNode.Weight.IsAlmost(1.0)) {
     172            strBuilder.Append(")");
     173          }
     174
    143175        } else if (node.Symbol is Constant) {
    144176          var constNode = node as ConstantTreeNode;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionCSharpFormatter.cs

    r14312 r14878  
    2525using System.Linq;
    2626using System.Text;
     27using System.Text.RegularExpressions;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Core;
     
    5354      GenerateFooter(strBuilder);
    5455      return strBuilder.ToString();
     56    }
     57
     58    private string VariableName2Identifier(string name) {     
     59      /*
     60       * identifier-start-character:
     61       *    letter-character
     62       *    _ (the underscore character U+005F)
     63       *  identifier-part-characters:
     64       *    identifier-part-character
     65       *    identifier-part-characters   identifier-part-character
     66       *  identifier-part-character:
     67       *    letter-character
     68       *    decimal-digit-character
     69       *    connecting-character
     70       *    combining-character
     71       *    formatting-character
     72       *  letter-character:
     73       *    A Unicode character of classes Lu, Ll, Lt, Lm, Lo, or Nl
     74       *    A unicode-escape-sequence representing a character of classes Lu, Ll, Lt, Lm, Lo, or Nl
     75       *  combining-character:
     76       *    A Unicode character of classes Mn or Mc
     77       *    A unicode-escape-sequence representing a character of classes Mn or Mc
     78       *  decimal-digit-character:
     79       *    A Unicode character of the class Nd
     80       *    A unicode-escape-sequence representing a character of the class Nd
     81       *  connecting-character:
     82       *    A Unicode character of the class Pc
     83       *    A unicode-escape-sequence representing a character of the class Pc
     84       *  formatting-character:
     85       *    A Unicode character of the class Cf
     86       *    A unicode-escape-sequence representing a character of the class Cf
     87       */
     88
     89      var invalidIdentifierStarts = new Regex(@"[^_\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}]");
     90      var invalidIdentifierParts = new Regex(@"[^\p{Lu}\p{Ll}\p{Lt}\p{Lm}\p{Lo}\p{Nl}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\p{Cf}]");
     91      return "@" +
     92        (invalidIdentifierStarts.IsMatch(name.Substring(0, 1)) ? "_" : "") + // prepend '_' if necessary
     93        invalidIdentifierParts.Replace(name, "_");
    5594    }
    5695
     
    106145        if (node is VariableTreeNode) {
    107146          var varNode = node as VariableTreeNode;
    108           strBuilder.AppendFormat("{0} * {1}", varNode.VariableName, varNode.Weight.ToString("g17", CultureInfo.InvariantCulture));
     147          strBuilder.AppendFormat("{0} * {1}", VariableName2Identifier(varNode.VariableName), varNode.Weight.ToString("g17", CultureInfo.InvariantCulture));
    109148        } else if (node is ConstantTreeNode) {
    110149          var constNode = node as ConstantTreeNode;
    111150          strBuilder.Append(constNode.Value.ToString("g17", CultureInfo.InvariantCulture));
     151        } else if (node.Symbol is FactorVariable) {
     152          var factorNode = node as FactorVariableTreeNode;
     153          FormatFactor(factorNode, strBuilder);
     154        } else if (node.Symbol is BinaryFactorVariable) {
     155          var binFactorNode = node as BinaryFactorVariableTreeNode;
     156          FormatBinaryFactor(binFactorNode, strBuilder);
    112157        } else {
    113158          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for C# symbolic expression tree formatter.");
    114159        }
    115160      }
     161    }
     162
     163    private void FormatFactor(FactorVariableTreeNode node, StringBuilder strBuilder) {
     164      strBuilder.AppendFormat("EvaluateFactor({0}, new [] {{ {1} }}, new [] {{ {2} }})", VariableName2Identifier(node.VariableName),
     165        string.Join(",", node.Symbol.GetVariableValues(node.VariableName).Select(name => "\"" + name + "\"")), string.Join(",", node.Weights.Select(v => v.ToString(CultureInfo.InvariantCulture))));
     166    }
     167
     168    private void FormatBinaryFactor(BinaryFactorVariableTreeNode node, StringBuilder strBuilder) {
     169      strBuilder.AppendFormat(CultureInfo.InvariantCulture, "EvaluateBinaryFactor({0}, \"{1}\", {2})", VariableName2Identifier(node.VariableName), node.VariableValue, node.Weight);
    116170    }
    117171
     
    182236      GenerateAverageSource(strBuilder);
    183237      GenerateIfThenElseSource(strBuilder);
     238      GenerateFactorSource(strBuilder);
     239      GenerateBinaryFactorSource(strBuilder);
    184240      strBuilder.Append(Environment.NewLine + "public static double Evaluate (");
    185241
    186       HashSet<string> varNames = new HashSet<string>();
    187       foreach (var node in symbolicExpressionTree.IterateNodesPostfix().Where(x => x is VariableTreeNode)) {
    188         varNames.Add(((VariableTreeNode)node).VariableName);
    189       }
    190 
    191       var orderedNames = varNames.OrderBy(n => n, new NaturalStringComparer()).Select(n => "double " + n);
     242      // here we don't have access to problemData to determine the type for each variable (double/string) therefore we must distinguish based on the symbol type
     243      HashSet<string> doubleVarNames = new HashSet<string>();
     244      foreach (var node in symbolicExpressionTree.IterateNodesPostfix().Where(x => x is VariableTreeNode || x is VariableConditionTreeNode)) {
     245        doubleVarNames.Add(((IVariableTreeNode)node).VariableName);
     246      }
     247
     248      HashSet<string> stringVarNames = new HashSet<string>();
     249      foreach (var node in symbolicExpressionTree.IterateNodesPostfix().Where(x => x is BinaryFactorVariableTreeNode || x is FactorVariableTreeNode)) {
     250        stringVarNames.Add(((IVariableTreeNode)node).VariableName);
     251      }
     252
     253      var orderedNames = stringVarNames.OrderBy(n => n, new NaturalStringComparer()).Select(n => "string " + VariableName2Identifier(n) + " /* " + n + " */");
    192254      strBuilder.Append(string.Join(", ", orderedNames));
     255
     256      if (stringVarNames.Any() && doubleVarNames.Any())
     257        strBuilder.AppendLine(",");
     258      orderedNames = doubleVarNames.OrderBy(n => n, new NaturalStringComparer()).Select(n => "double " + VariableName2Identifier(n) + " /* " + n + " */");
     259      strBuilder.Append(string.Join(", ", orderedNames));
     260
    193261
    194262      strBuilder.AppendLine(") {");
     
    198266    private void GenerateFooter(StringBuilder strBuilder) {
    199267      strBuilder.AppendLine(";");
     268
    200269      strBuilder.AppendLine("return result;");
    201270      strBuilder.AppendLine("}");
     
    215284      strBuilder.AppendLine("}");
    216285    }
     286
     287    private void GenerateFactorSource(StringBuilder strBuilder) {
     288      strBuilder.AppendLine("private static double EvaluateFactor(string factorValue, string[] factorValues, double[] constants) {");
     289      strBuilder.AppendLine("   for(int i=0;i<factorValues.Length;i++) " +
     290                            "      if(factorValues[i] == factorValue) return constants[i];" +
     291                            "   throw new ArgumentException();");
     292      strBuilder.AppendLine("}");
     293    }
     294
     295    private void GenerateBinaryFactorSource(StringBuilder strBuilder) {
     296      strBuilder.AppendLine("private static double EvaluateBinaryFactor(string factorValue, string targetValue, double weight) {");
     297      strBuilder.AppendLine("  return factorValue == targetValue ? weight : 0.0;");
     298      strBuilder.AppendLine("}");
     299    }
     300
    217301  }
    218302}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionExcelFormatter.cs

    r14312 r14878  
    5151      while (dividend > 0) {
    5252        int modulo = (dividend - 1) % 26;
    53         columnName = Convert.ToChar(65 + modulo).ToString() + columnName;
     53        columnName = System.Convert.ToChar(65 + modulo) + columnName;
    5454        dividend = (int)((dividend - modulo) / 26);
    5555      }
     
    6060    private readonly Dictionary<string, string> variableNameMapping = new Dictionary<string, string>();
    6161    private int currentVariableIndex = 0;
    62     private string GetColumnToVariableName(string variabelName) {
    63       if (!variableNameMapping.ContainsKey(variabelName)) {
     62    private string GetColumnToVariableName(string varName) {
     63      if (!variableNameMapping.ContainsKey(varName)) {
    6464        currentVariableIndex++;
    65         variableNameMapping.Add(variabelName, GetExcelColumnName(currentVariableIndex));
    66       }
    67       return string.Format("${0}1", variableNameMapping[variabelName]);
     65        variableNameMapping.Add(varName, GetExcelColumnName(currentVariableIndex));
     66      }
     67      return string.Format("${0}1", variableNameMapping[varName]);
    6868    }
    6969    public string Format(ISymbolicExpressionTree symbolicExpressionTree) {
     
    7171    }
    7272
     73
    7374    public string Format(ISymbolicExpressionTree symbolicExpressionTree, IDataset dataset) {
     75      if (dataset != null)
     76        return FormatWithMapping(symbolicExpressionTree, CalculateVariableMapping(symbolicExpressionTree, dataset));
     77      else return FormatWithMapping(symbolicExpressionTree, new Dictionary<string, string>());
     78    }
     79
     80    public string FormatWithMapping(ISymbolicExpressionTree symbolicExpressionTree, Dictionary<string,string> variableNameMapping)
     81    {
     82      foreach(var kvp in variableNameMapping) this.variableNameMapping.Add(kvp.Key,kvp.Value);
    7483      var stringBuilder = new StringBuilder();
    75       if (dataset != null) CalculateVariableMapping(symbolicExpressionTree, dataset);
    76 
     84     
    7785      stringBuilder.Append("=");
    7886      stringBuilder.Append(FormatRecursively(symbolicExpressionTree.Root));
    7987
    80       foreach (var variable in variableNameMapping) {
     88      foreach (var variable in this.variableNameMapping) {
    8189        stringBuilder.AppendLine();
    8290        stringBuilder.Append(variable.Key + " = " + variable.Value);
     
    8593    }
    8694
    87     private void CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
    88       int columnIndex = 0;
     95    private Dictionary<string,string> CalculateVariableMapping(ISymbolicExpressionTree tree, IDataset dataset) {
     96      var mapping = new Dictionary<string,string>();
    8997      int inputIndex = 0;
    90       var usedVariables = tree.IterateNodesPrefix().OfType<VariableTreeNode>().Select(v => v.VariableName).Distinct();
     98      var usedVariables = tree.IterateNodesPrefix().OfType<IVariableTreeNode>().Select(v => v.VariableName).Distinct().ToArray();
    9199      foreach (var variable in dataset.VariableNames) {
    92         columnIndex++;
    93100        if (!usedVariables.Contains(variable)) continue;
    94101        inputIndex++;
    95         variableNameMapping[variable] = GetExcelColumnName(inputIndex);
    96       }
     102        mapping[variable] = GetExcelColumnName(inputIndex);
     103      }
     104      return mapping;
    97105    }
    98106
     
    190198        stringBuilder.Append(variableTreeNode.Weight.ToString(CultureInfo.InvariantCulture));
    191199        stringBuilder.Append("*");
    192         stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName));// + LagToString(currentLag));
     200        stringBuilder.Append(GetColumnToVariableName(variableTreeNode.VariableName));
     201      } else if (symbol is BinaryFactorVariable) {
     202        var binFactorNode = node as BinaryFactorVariableTreeNode;
     203        stringBuilder.AppendFormat("IF({0}=\"{1}\", {2}, 0)",
     204          GetColumnToVariableName(binFactorNode.VariableName),
     205          binFactorNode.VariableValue,
     206          binFactorNode.Weight.ToString(CultureInfo.InvariantCulture)
     207          );
     208      } else if (symbol is FactorVariable) {
     209        var factorNode = node as FactorVariableTreeNode;
     210        var values = factorNode.Symbol.GetVariableValues(factorNode.VariableName).ToArray();
     211        var w = factorNode.Weights;
     212        // create nested if
     213        for (int i = 0; i < values.Length; i++) {
     214          stringBuilder.AppendFormat("IF({0}=\"{1}\", {2}, ",
     215            GetColumnToVariableName(factorNode.VariableName),
     216            values[i],
     217            w[i].ToString(CultureInfo.InvariantCulture));
     218        }
     219        stringBuilder.Append("\"\""); // return empty string on unknown value
     220        stringBuilder.Append(')', values.Length); // add closing parenthesis
    193221      } else if (symbol is Power) {
    194222        stringBuilder.Append("POWER(");
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionLatexFormatter.cs

    r14576 r14878  
    3333  [StorableClass]
    3434  public sealed class SymbolicDataAnalysisExpressionLatexFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {
    35     private readonly List<double> constants;
     35    private readonly List<KeyValuePair<string, double>> constants;
     36    private int constIndex;
    3637    private int targetCount;
    3738    private int currentLag;
     
    4344    private SymbolicDataAnalysisExpressionLatexFormatter(SymbolicDataAnalysisExpressionLatexFormatter original, Cloner cloner)
    4445      : base(original, cloner) {
    45       constants = new List<double>(original.constants);
     46      constants = new List<KeyValuePair<string, double>>(original.constants);
     47      constIndex = original.constIndex;
     48      currentLag = original.currentLag;
     49      targetCount = original.targetCount;
    4650    }
    4751    public SymbolicDataAnalysisExpressionLatexFormatter()
     
    4953      Name = ItemName;
    5054      Description = ItemDescription;
    51       constants = new List<double>();
     55      constants = new List<KeyValuePair<string, double>>();
    5256    }
    5357
     
    6367        StringBuilder strBuilder = new StringBuilder();
    6468        constants.Clear();
     69        constIndex = 0;
    6570        this.targetVariable = targetVariable;
    6671        containsTimeSeriesSymbol = symbolicExpressionTree.IterateNodesBreadth().Any(n => IsTimeSeriesSymbol(n.Symbol));
     
    8489      }
    8590      int i = 1;
    86       foreach (SymbolicExpressionTreeNode subTree in node.Subtrees.Skip(1)) {
     91      foreach (var subTree in node.Subtrees.Skip(1)) {
    8792        FormatSep(node, strBuilder, i);
    8893        // format the whole subtree
     
    175180        strBuilder.Append(@" \operatorname{if}  \left( ");
    176181      } else if (node.Symbol is Constant) {
     182        var constName = "c_{" + constIndex + "}";
     183        constIndex++;
    177184        var constNode = node as ConstantTreeNode;
    178185        if (constNode.Value.IsAlmost(1.0)) {
    179186          strBuilder.Append("1 ");
    180187        } else {
    181           strBuilder.Append("c_{" + constants.Count + "} ");
    182           constants.Add(constNode.Value);
    183         }
     188          strBuilder.Append(constName);
     189          constants.Add(new KeyValuePair<string, double>(constName, constNode.Value));
     190        }
     191
     192      } else if (node.Symbol is FactorVariable) {
     193        var factorNode = node as FactorVariableTreeNode;
     194        var constName = "c_{" + constIndex + "}";
     195        strBuilder.Append(constName + " ");
     196        foreach (var e in factorNode.Symbol.GetVariableValues(factorNode.VariableName)
     197          .Zip(factorNode.Weights, Tuple.Create)) {
     198          constants.Add(new KeyValuePair<string, double>("c_{" + constIndex + ", " + EscapeLatexString(factorNode.VariableName) + "=" + EscapeLatexString(e.Item1) + "}", e.Item2));
     199        }
     200        constIndex++;
     201      } else if (node.Symbol is BinaryFactorVariable) {
     202        var binFactorNode = node as BinaryFactorVariableTreeNode;
     203        if (!binFactorNode.Weight.IsAlmost((1.0))) {
     204          var constName = "c_{" + constIndex + "}";
     205          strBuilder.Append(constName + "  \\cdot");
     206          constants.Add(new KeyValuePair<string, double>(constName, binFactorNode.Weight));
     207          constIndex++;
     208        }
     209        strBuilder.Append("(" + EscapeLatexString(binFactorNode.VariableName));
     210        strBuilder.Append(LagToString(currentLag));
     211        strBuilder.Append(" = " + EscapeLatexString(binFactorNode.VariableValue) + " )");
    184212      } else if (node.Symbol is LaggedVariable) {
    185213        var laggedVarNode = node as LaggedVariableTreeNode;
    186214        if (!laggedVarNode.Weight.IsAlmost(1.0)) {
    187           strBuilder.Append("c_{" + constants.Count + "} \\cdot ");
    188           constants.Add(laggedVarNode.Weight);
     215          var constName = "c_{" + constIndex + "}";
     216          strBuilder.Append(constName + "  \\cdot");
     217          constants.Add(new KeyValuePair<string, double>(constName, laggedVarNode.Weight));
     218          constIndex++;
    189219        }
    190220        strBuilder.Append(EscapeLatexString(laggedVarNode.VariableName));
     
    194224        var varNode = node as VariableTreeNode;
    195225        if (!varNode.Weight.IsAlmost((1.0))) {
    196           strBuilder.Append("c_{" + constants.Count + "} \\cdot ");
    197           constants.Add(varNode.Weight);
     226          var constName = "c_{" + constIndex + "}";
     227          strBuilder.Append(constName + "  \\cdot");
     228          constants.Add(new KeyValuePair<string, double>(constName, varNode.Weight));
     229          constIndex++;
    198230        }
    199231        strBuilder.Append(EscapeLatexString(varNode.VariableName));
     
    229261      } else if (node.Symbol is VariableCondition) {
    230262        var conditionTreeNode = node as VariableConditionTreeNode;
    231         string p = @"1 /  1 + \exp  - c_{" + constants.Count + "} ";
    232         constants.Add(conditionTreeNode.Slope);
    233         p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"}   ";
    234         constants.Add(conditionTreeNode.Threshold);
     263        var constName = "c_{" + constants.Count + "}";
     264        string p = @"1 /  1 + \exp  - " + constName + " ";
     265        constants.Add(new KeyValuePair<string, double>(constName, conditionTreeNode.Slope));
     266        constIndex++;
     267        var const2Name = "c_{" + constants.Count + @"}";
     268        p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - " + const2Name + "   ";
     269        constants.Add(new KeyValuePair<string, double>(const2Name, conditionTreeNode.Threshold));
     270        constIndex++;
    235271        strBuilder.Append(@" \left( " + p + @"\cdot ");
    236272      } else {
     
    323359      } else if (node.Symbol is VariableCondition) {
    324360        var conditionTreeNode = node as VariableConditionTreeNode;
    325         string p = @"1 / \left( 1 + \exp \left( - c_{" + constants.Count + "} ";
    326         constants.Add(conditionTreeNode.Slope);
    327         p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - c_{" + constants.Count + @"} \right) \right) \right)   ";
    328         constants.Add(conditionTreeNode.Threshold);
     361        var const1Name = "c_{" + constants.Count + "}";
     362        string p = @"1 / \left( 1 + \exp \left( - " + const1Name + " ";
     363        constants.Add(new KeyValuePair<string, double>(const1Name, conditionTreeNode.Slope));
     364        constIndex++;
     365        var const2Name = "c_{" + constants.Count + "}";
     366        p += @" \cdot " + EscapeLatexString(conditionTreeNode.VariableName) + LagToString(currentLag) + " - " + const2Name + " \right) \right) \right)   ";
     367        constants.Add(new KeyValuePair<string, double>(const2Name, conditionTreeNode.Threshold));
     368        constIndex++;
    329369        strBuilder.Append(@" +  \left( 1 - " + p + @" \right) \cdot ");
    330370      } else {
     
    404444      } else if (node.Symbol is LaggedVariable) {
    405445      } else if (node.Symbol is Variable) {
     446      } else if (node.Symbol is FactorVariable) {
     447      } else if (node.Symbol is BinaryFactorVariable) {
    406448      } else if (node.Symbol is ProgramRootSymbol) {
    407449        strBuilder
     
    411453        // output all constant values
    412454        if (constants.Count > 0) {
    413           int i = 0;
    414455          foreach (var constant in constants) {
    415456            // replace "." with ".&" to align decimal points
    416             var constStr = string.Format(System.Globalization.NumberFormatInfo.InvariantInfo, "{0:G5}", constant);
     457            var constStr = string.Format(System.Globalization.NumberFormatInfo.InvariantInfo, "{0:G5}", constant.Value);
    417458            if (!constStr.Contains(".")) constStr = constStr + ".0";
    418459            constStr = constStr.Replace(".", "&.");  // fix problem in rendering of aligned expressions
    419             strBuilder.Append("c_{" + i + "}& = & " + constStr);
     460            strBuilder.Append(constant.Key + "& = & " + constStr);
    420461            strBuilder.Append(@"\\");
    421             i++;
    422462          }
    423463        }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMATLABFormatter.cs

    r14312 r14878  
    2121
    2222using System.Globalization;
     23using System.Linq;
    2324using System.Text;
    2425using HeuristicLab.Common;
     
    7778      stringBuilder.AppendLine("  y = (f0 + 2*f1 - 2*f3 - f4) / 8;");
    7879      stringBuilder.AppendLine("end");
     80
     81      var factorVariableNames =
     82        symbolicExpressionTree.IterateNodesPostfix()
     83          .OfType<FactorVariableTreeNode>()
     84          .Select(n => n.VariableName)
     85          .Distinct();
     86
     87      foreach (var factorVarName in factorVariableNames) {
     88        var factorSymb = symbolicExpressionTree.IterateNodesPostfix()
     89          .OfType<FactorVariableTreeNode>()
     90          .First(n => n.VariableName == factorVarName)
     91          .Symbol;
     92        stringBuilder.AppendFormat("function y = switch_{0}(val, v)", factorVarName).AppendLine();
     93        var values = factorSymb.GetVariableValues(factorVarName).ToArray();
     94        stringBuilder.AppendLine("switch val");
     95        for (int i = 0; i < values.Length; i++) {
     96          stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "  case \"{0}\" y = v({1})", values[i], i).AppendLine();
     97        }
     98        stringBuilder.AppendLine("end");
     99        stringBuilder.AppendLine();
     100      }
     101
    79102      return stringBuilder.ToString();
    80103    }
     
    296319        stringBuilder.Append("*");
    297320        stringBuilder.Append(variableTreeNode.VariableName + LagToString(currentLag));
     321      } else if (symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.FactorVariable) {
     322        var factorNode = node as FactorVariableTreeNode;
     323        var weights = string.Join(" ", factorNode.Weights.Select(w => w.ToString("G17", CultureInfo.InvariantCulture)));
     324        stringBuilder.AppendFormat("switch_{0}(\"{1}\",[{2}])",
     325          factorNode.VariableName, factorNode.VariableName, weights)
     326          .AppendLine();
     327      } else if (symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.BinaryFactorVariable) {
     328        var factorNode = node as BinaryFactorVariableTreeNode;
     329        stringBuilder.AppendFormat(CultureInfo.InvariantCulture,
     330          "((strcmp({0},\"{1}\")==1) * {2:G17})", factorNode.VariableName, factorNode.VariableValue, factorNode.Weight);
    298331      } else if (symbol is Power) {
    299332        stringBuilder.Append("(");
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionMathematicaFormatter.cs

    r14312 r14878  
    110110        }
    111111      } else {
    112         if (node is VariableTreeNode) {
     112        // terminals
     113        if (node.Symbol is Variable) {
    113114          var varNode = node as VariableTreeNode;
    114115          strBuilder.AppendFormat("Times[{0}, {1}]", varNode.VariableName, varNode.Weight.ToString("G17", CultureInfo.InvariantCulture));
    115         } else if (node is ConstantTreeNode) {
     116        } else if (node.Symbol is Constant) {
    116117          var constNode = node as ConstantTreeNode;
    117118          strBuilder.Append(constNode.Value.ToString("G17", CultureInfo.InvariantCulture));
     119        } else if (node.Symbol is FactorVariable) {
     120          var factorNode = node as FactorVariableTreeNode;
     121          strBuilder.AppendFormat("Switch[{0},", factorNode.VariableName);
     122          var varValues = factorNode.Symbol.GetVariableValues(factorNode.VariableName).ToArray();
     123          var weights = varValues.Select(factorNode.GetValue).ToArray();
     124
     125          var weightStr = string.Join(", ",
     126            varValues.Zip(weights, (s, d) => string.Format(CultureInfo.InvariantCulture, "\"{0}\", {1:G17}", s, d)));
     127          strBuilder.Append(weightStr);
     128          strBuilder.Append("]");
     129        } else if (node.Symbol is BinaryFactorVariable) {
     130          var factorNode = node as BinaryFactorVariableTreeNode;
     131          strBuilder.AppendFormat(CultureInfo.InvariantCulture, "If[{0}==\"{1}\",{2:G17},0.0]",
     132            factorNode.VariableName, factorNode.VariableValue, factorNode.Weight);
    118133        } else {
    119134          throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " is not supported.");
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Formatters/SymbolicDataAnalysisExpressionSmalltalkFormatter.cs

    r14312 r14878  
    115115        stringBuilder.Append("]");
    116116      } else if (symbol is LaggedVariable) {
    117         stringBuilder.Append("lagged variable not implemented");
     117        stringBuilder.Append("lagged variables are not supported");
    118118      } else if (symbol is LessThan) {
    119119        stringBuilder.Append("(");
     
    165165        stringBuilder.Append("*");
    166166        stringBuilder.Append(variableTreeNode.VariableName);
     167      } else if (symbol is BinaryFactorVariable || symbol is FactorVariable) {
     168        stringBuilder.Append("factor variables are not supported");
    167169      } else {
    168170        stringBuilder.Append("(");
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/ArithmeticExpressionGrammar.cs

    r14312 r14878  
    5353      constant.MaxValue = 20;
    5454      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     55      var binFactorVariableSymbol = new BinaryFactorVariable();
     56      var factorVariableSymbol = new FactorVariable();
    5557
    56       var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol };
     58      var allSymbols = new List<Symbol>() { add, sub, mul, div, constant, variableSymbol, binFactorVariableSymbol, factorVariableSymbol};
    5759      var functionSymbols = new List<Symbol>() { add, sub, mul, div };
    5860
     
    6567      SetSubtreeCount(constant, 0, 0);
    6668      SetSubtreeCount(variableSymbol, 0, 0);
     69      SetSubtreeCount(binFactorVariableSymbol, 0, 0);
     70      SetSubtreeCount(factorVariableSymbol, 0, 0);
    6771
    6872      // allow each symbol as child of the start symbol
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r14312 r14878  
    115115      constant.MaxValue = 20;
    116116      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
     117      var binFactorVariable = new BinaryFactorVariable();
     118      var factorVariable = new FactorVariable();
    117119      var laggedVariable = new LaggedVariable();
    118120      laggedVariable.InitialFrequency = 0.0;
     
    123125      var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, square, pow, sqrt, root, exp,
    124126        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral,
    125         @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, laggedVariable,autoregressiveVariable, variableCondition };
     127        @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition };
    126128      var unaryFunctionSymbols = new List<Symbol>() { square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
    127129        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
     
    130132      var binaryFunctionSymbols = new List<Symbol>() { pow, root, gt, lt, variableCondition };
    131133      var ternarySymbols = new List<Symbol>() { add, sub, mul, div, mean, and, or, xor };
    132       var terminalSymbols = new List<Symbol>() { variableSymbol, constant, laggedVariable, autoregressiveVariable };
     134      var terminalSymbols = new List<Symbol>() { variableSymbol, binFactorVariable, factorVariable, constant, laggedVariable, autoregressiveVariable };
    133135
    134136      foreach (var symb in allSymbols)
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentExpressionGrammar.cs

    r14312 r14878  
    2626using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2727using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
    2928
    3029namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    8887      var psi = new Psi();
    8988      var sineIntegral = new SineIntegral();
    90       var passthrough = new Passthrough();
    9189
    9290      var @if = new IfThenElse();
     
    107105      constant.MaxValue = 20;
    108106      var variableSymbol = new Variable();
     107      var binFactorVariable = new BinaryFactorVariable();
     108      var factorVariable = new FactorVariable();
    109109      var laggedVariable = new LaggedVariable();
    110110      var autoregressiveVariable = new AutoregressiveTargetVariable();
     
    115115      var trigonometricSymbols = new GroupSymbol(TrigonometricFunctionsName, new List<ISymbol>() { sin, cos, tan });
    116116      var exponentialAndLogarithmicSymbols = new GroupSymbol(ExponentialFunctionsName, new List<ISymbol> { exp, log });
    117       var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, 
    118         fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral, passthrough});
    119       var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol });
     117      var specialFunctions = new GroupSymbol(SpecialFunctionsName, new List<ISymbol> { airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi,
     118        fresnelCosineIntegral,fresnelSineIntegral,gamma,hypCosineIntegral,hypSineIntegral,norm, psi, sineIntegral});
     119      var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variableSymbol, binFactorVariable, factorVariable });
    120120      var realValuedSymbols = new GroupSymbol(RealValuedSymbolsName, new List<ISymbol>() { arithmeticSymbols, trigonometricSymbols, exponentialAndLogarithmicSymbols, specialFunctions, terminalSymbols });
    121121
     
    159159      SetSubtreeCount(laggedVariable, 0, 0);
    160160      SetSubtreeCount(autoregressiveVariable, 0, 0);
    161       SetSubtreeCount(passthrough, 1, 1);
    162161      #endregion
    163162
     
    228227      AddAllowedChildSymbol(derivative, powerSymbols);
    229228      AddAllowedChildSymbol(derivative, conditionSymbols);
    230 
    231       AddAllowedChildSymbol(passthrough, realValuedSymbols);
    232       AddAllowedChildSymbol(passthrough, powerSymbols);
    233       AddAllowedChildSymbol(passthrough, conditionSymbols);
    234       AddAllowedChildSymbol(passthrough, timeSeriesSymbols);
    235       AddAllowedChildSymbol(passthrough, specialFunctions);
    236229      #endregion
    237230    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r14427 r14878  
    4747    <CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
    4848    <Prefer32Bit>false</Prefer32Bit>
    49     <UseVSHostingProcess>false</UseVSHostingProcess>
    5049  </PropertyGroup>
    5150  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     
    102101    <Reference Include="ALGLIB-3.7.0">
    103102      <HintPath>..\..\..\..\trunk\sources\bin\ALGLIB-3.7.0.dll</HintPath>
    104       <Private>False</Private>
     103    </Reference>
     104    <Reference Include="AutoDiff-1.0">
     105      <HintPath>..\..\..\..\trunk\sources\bin\AutoDiff-1.0.dll</HintPath>
    105106    </Reference>
    106107    <Reference Include="HeuristicLab.Analysis-3.3">
    107108      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
    108       <Private>False</Private>
    109109    </Reference>
    110110    <Reference Include="HeuristicLab.Collections-3.3">
    111111      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
    112       <Private>False</Private>
    113     </Reference>
    114     <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    115       <SpecificVersion>False</SpecificVersion>
     112    </Reference>
     113    <Reference Include="HeuristicLab.Common-3.3">
    116114      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common-3.3.dll</HintPath>
    117       <Private>False</Private>
    118115    </Reference>
    119116    <Reference Include="HeuristicLab.Common.Resources-3.3">
    120117      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Common.Resources-3.3.dll</HintPath>
    121       <Private>False</Private>
    122     </Reference>
    123     <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    124       <SpecificVersion>False</SpecificVersion>
     118    </Reference>
     119    <Reference Include="HeuristicLab.Core-3.3">
    125120      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
    126       <Private>False</Private>
    127121    </Reference>
    128122    <Reference Include="HeuristicLab.Data-3.3">
    129123      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
    130       <Private>False</Private>
    131124    </Reference>
    132125    <Reference Include="HeuristicLab.Operators-3.3">
    133126      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
    134       <Private>False</Private>
    135127    </Reference>
    136128    <Reference Include="HeuristicLab.Optimization-3.3">
    137129      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
    138       <Private>False</Private>
    139130    </Reference>
    140131    <Reference Include="HeuristicLab.Optimization.Operators-3.3">
    141132      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath>
    142       <Private>False</Private>
    143133    </Reference>
    144134    <Reference Include="HeuristicLab.Parameters-3.3">
    145135      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
    146       <Private>False</Private>
    147136    </Reference>
    148137    <Reference Include="HeuristicLab.Persistence-3.3">
    149138      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
    150       <Private>False</Private>
    151139    </Reference>
    152140    <Reference Include="HeuristicLab.PluginInfrastructure-3.3">
    153141      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
    154       <Private>False</Private>
    155142    </Reference>
    156143    <Reference Include="HeuristicLab.Problems.DataAnalysis-3.4">
    157144      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.DataAnalysis-3.4.dll</HintPath>
    158       <Private>False</Private>
    159145    </Reference>
    160146    <Reference Include="HeuristicLab.Problems.Instances-3.3">
    161147      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Problems.Instances-3.3.dll</HintPath>
    162       <Private>False</Private>
    163148    </Reference>
    164149    <Reference Include="HeuristicLab.Random-3.3">
    165150      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath>
    166       <Private>False</Private>
    167151    </Reference>
    168152    <Reference Include="System" />
     
    181165  </ItemGroup>
    182166  <ItemGroup>
    183     <Compile Include="Analyzers\BuildingBlockAnalyzers\SymbolicDataAnalysisPoly10Analyzer.cs" />
    184167    <Compile Include="Analyzers\SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs" />
     168    <Compile Include="Analyzers\SymbolicDataAnalysisGenealogyAnalyzer.cs" />
    185169    <Compile Include="Analyzers\SymbolicDataAnalysisGeneticOperatorImprovementAnalyzer.cs" />
    186     <Compile Include="Importer\InfixExpressionParser.cs" />
    187     <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" />
    188     <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" />
    189     <Compile Include="Symbols\Wildcards\AnyNode.cs" />
    190     <Compile Include="Symbols\Wildcards\AnySubtreeSymbol.cs" />
    191     <Compile Include="Symbols\Wildcards\AnySubtree.cs" />
    192     <Compile Include="Symbols\Wildcards\AnyNodeSymbol.cs" />
    193170    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" />
    194     <Compile Include="Analyzers\SymbolicDataAnalysisGenealogyAnalyzer.cs" />
    195171    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" />
    196172    <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" />
     
    206182      <SubType>Code</SubType>
    207183    </Compile>
     184    <Compile Include="Converters\Convert.cs" />
     185    <Compile Include="Converters\LinearModelToTreeConverter.cs" />
     186    <Compile Include="Converters\TreeSimplifier.cs" />
     187    <Compile Include="Converters\TreeToAutoDiffTermConverter.cs" />
    208188    <Compile Include="Formatters\InfixExpressionFormatter.cs" />
     189    <Compile Include="Formatters\SymbolicDataAnalysisExpressionMathematicaFormatter.cs" />
     190    <Compile Include="Formatters\SymbolicDataAnalysisExpressionCSharpFormatter.cs" />
     191    <Compile Include="Importer\InfixExpressionParser.cs" />
    209192    <Compile Include="Importer\SymbolicExpressionImporter.cs" />
    210193    <Compile Include="Importer\Token.cs" />
    211194    <Compile Include="Interfaces\IModelBacktransformator.cs" />
    212     <Compile Include="Interfaces\ISymbolicDataAnalysisExpressionSimilarityCalculator.cs" />
    213     <Compile Include="SymbolicExpressionTreeBacktransformator.cs" />
     195    <Compile Include="Interfaces\IVariableTreeNode.cs" />
     196    <Compile Include="Interfaces\IVariableSymbol.cs" />
     197    <Compile Include="Interpreter\SymbolicDataAnalysisExpressionCompiledTreeInterpreter.cs" />
     198    <Compile Include="SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs" />
     199    <Compile Include="SymbolicDataAnalysisModelComplexityCalculator.cs" />
    214200    <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" />
    215     <Compile Include="SymbolicDataAnalysisSolutionPruningOptimizer.cs" />
    216201    <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" />
    217202    <Compile Include="Analyzers\SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs" />
     
    255240    <Compile Include="Interfaces\ISymbolicDataAnalysisAnalyzer.cs" />
    256241    <Compile Include="SymbolicDataAnalysisSingleObjectiveProblem.cs" />
    257     <Compile Include="SymbolicDataAnalysisExpressionTreeSimplifier.cs" />
    258242    <Compile Include="SymbolicDataAnalysisProblem.cs" />
    259243    <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" />
     
    267251    <Compile Include="Symbols\AiryB.cs" />
    268252    <Compile Include="Symbols\Bessel.cs" />
    269     <Compile Include="Symbols\Passthrough.cs" />
     253    <Compile Include="Symbols\BinaryFactorVariable.cs" />
     254    <Compile Include="Symbols\BinaryFactorVariableTreeNode.cs" />
     255    <Compile Include="Symbols\FactorVariableTreeNode.cs" />
     256    <Compile Include="Symbols\FactorVariable.cs" />
     257    <Compile Include="Symbols\VariableBase.cs" />
     258    <Compile Include="Symbols\VariableTreeNodeBase.cs" />
     259    <Compile Include="Symbols\Wildcards\AnyNode.cs" />
     260    <Compile Include="Symbols\Wildcards\AnyNodeSymbol.cs" />
     261    <Compile Include="Symbols\Wildcards\AnySubtree.cs" />
     262    <Compile Include="Symbols\Wildcards\AnySubtreeSymbol.cs" />
    270263    <Compile Include="Symbols\Xor.cs" />
    271264    <Compile Include="Symbols\Erf.cs" />
     
    315308    <Compile Include="Tracking\Analyzers\SymbolicDataAnalysisTraceOverlapAnalyzer.cs" />
    316309    <Compile Include="Tracking\SchemaDiversification\DiversificationStatisticsOperator.cs" />
     310    <Compile Include="Tracking\SchemaDiversification\SchemaCreator.cs" />
    317311    <Compile Include="Tracking\SchemaDiversification\SchemaEvaluator.cs" />
    318     <Compile Include="Tracking\SchemaDiversification\SchemaCreator.cs" />
    319312    <Compile Include="Tracking\SchemaDiversification\SchemaUtil.cs" />
    320313    <Compile Include="Tracking\SchemaDiversification\UpdateQualityOperator.cs" />
     
    324317    <Compile Include="Tracking\SymbolicDataAnalysisExpressionBeforeManipulatorOperator.cs" />
    325318    <Compile Include="Tracking\TraceCalculator.cs" />
    326     <Compile Include="TransformationToSymbolicTreeMapper.cs" />
     319    <Compile Include="Transformations\SymbolicExpressionTreeBacktransformator.cs" />
     320    <Compile Include="Transformations\TransformationToSymbolicTreeMapper.cs" />
    327321    <Compile Include="TreeMatching\QueryMatch.cs" />
    328322    <Compile Include="TreeMatching\SymbolicExpressionTreeBottomUpSimilarityCalculator.cs" />
     
    368362  </ItemGroup>
    369363  <ItemGroup>
    370     <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj">
    371       <Project>{423bd94f-963a-438e-ba45-3bb3d61cd03b}</Project>
    372       <Name>HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4</Name>
    373       <Private>False</Private>
    374     </ProjectReference>
    375364    <ProjectReference Include="..\..\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding\3.4\HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj">
    376365      <Project>{06D4A186-9319-48A0-BADE-A2058D462EEA}</Project>
     
    381370      <Project>{1f75cea3-464f-4a6f-b2f0-04b9841ebc16}</Project>
    382371      <Name>HeuristicLab.EvolutionTracking-3.4</Name>
    383       <Private>False</Private>
    384372    </ProjectReference>
    385373  </ItemGroup>
    386   <ItemGroup />
    387374  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    388375  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs

    r14576 r14878  
    3333  /// Parses mathematical expressions in infix form. E.g. x1 * (3.0 * x2 + x3)
    3434  /// Identifier format (functions or variables): '_' | letter { '_' | letter | digit }
    35   /// Variables names can be set under quotes "" or '' because variable names might contain spaces.
     35  /// Variables names and variable values can be set under quotes "" or '' because variable names might contain spaces.
     36  ///   Variable = ident | " ident " | ' ident '
    3637  /// It is also possible to use functions e.g. log("x1") or real-valued constants e.g. 3.1415 .
    3738  /// Variable names are case sensitive. Function names are not case sensitive.
     39  ///
     40  ///
     41  /// S             = Expr EOF
     42  /// Expr          = ['-' | '+'] Term { '+' Term | '-' Term }
     43  /// Term          = Fact { '*' Fact | '/' Fact }
     44  /// Fact          = '(' Expr ')'
     45  ///                 | 'LAG' '(' varId ',' ['+' | '-' ] number ')'
     46  ///                 | funcId '(' ArgList ')'
     47  ///                 | VarExpr | number
     48  /// ArgList       = Expr { ',' Expr }
     49  /// VarExpr       = varId OptFactorPart
     50  /// OptFactorPart = [ ('=' varVal | '[' ['+' | '-' ] number {',' ['+' | '-' ] number } ']' ) ]
     51  /// varId         =  ident | ' ident ' | " ident "
     52  /// varVal        =  ident | ' ident ' | " ident "
     53  /// ident         =  '_' | letter { '_' | letter | digit }
    3854  /// </summary>
    3955  public sealed class InfixExpressionParser {
    40     private enum TokenType { Operator, Identifier, Number, LeftPar, RightPar, Comma, End, NA };
     56    private enum TokenType { Operator, Identifier, Number, LeftPar, RightPar, LeftBracket, RightBracket, Comma, Eq, End, NA };
    4157    private class Token {
    4258      internal double doubleVal;
     
    6581    private Constant constant = new Constant();
    6682    private Variable variable = new Variable();
     83    private BinaryFactorVariable binaryFactorVar = new BinaryFactorVariable();
     84    private FactorVariable factorVar = new FactorVariable();
    6785
    6886    private ProgramRootSymbol programRootSymbol = new ProgramRootSymbol();
     
    150168            && str[pos] != '/'
    151169            && str[pos] != ')'
     170            && str[pos] != ']'
    152171            && str[pos] != ',') {
    153172            sb.Append(str[pos]);
     
    214233          pos++;
    215234          yield return new Token { TokenType = TokenType.RightPar, strVal = ")" };
     235        } else if (str[pos] == '[') {
     236          pos++;
     237          yield return new Token { TokenType = TokenType.LeftBracket, strVal = "[" };
     238        } else if (str[pos] == ']') {
     239          pos++;
     240          yield return new Token { TokenType = TokenType.RightBracket, strVal = "]" };
     241        } else if (str[pos] == '=') {
     242          pos++;
     243          yield return new Token { TokenType = TokenType.Eq, strVal = "=" };
    216244        } else if (str[pos] == ',') {
    217245          pos++;
     
    222250      }
    223251    }
    224 
    225     // S       = Expr EOF
    226     // Expr    = ['-' | '+'] Term { '+' Term | '-' Term }
    227     // Term    = Fact { '*' Fact | '/' Fact }
    228     // Fact    = '(' Expr ')' | funcId '(' ArgList ')' | varId | number
    229     // ArgList = Expr { ',' Expr }
     252    /// S             = Expr EOF
    230253    private ISymbolicExpressionTreeNode ParseS(Queue<Token> tokens) {
    231254      var expr = ParseExpr(tokens);
     
    237260      return expr;
    238261    }
     262
     263    /// Expr          = ['-' | '+'] Term { '+' Term | '-' Term }
    239264    private ISymbolicExpressionTreeNode ParseExpr(Queue<Token> tokens) {
    240265      var next = tokens.Peek();
     
    300325    }
    301326
    302     // Term = Fact { '*' Fact | '/' Fact }
     327    /// Term          = Fact { '*' Fact | '/' Fact }
    303328    private ISymbolicExpressionTreeNode ParseTerm(Queue<Token> tokens) {
    304329      var factors = new List<ISymbolicExpressionTreeNode>();
     
    335360    }
    336361
    337     // Fact = '(' Expr ')' | 'LAG' '(' varId ',' ['+' | '-'] number ')' | funcId '(' ArgList ')' | varId | number
     362    /// Fact          = '(' Expr ')'
     363    ///                 | 'LAG' '(' varId ',' ['+' | '-' ] number ')'
     364    ///                 | funcId '(' ArgList ')'
     365    ///                 | VarExpr | number
     366    /// ArgList       = Expr { ',' Expr }
     367    /// VarExpr       = varId OptFactorPart
     368    /// OptFactorPart = [ ('=' varVal | '[' ['+' | '-' ] number {',' ['+' | '-' ] number } ']' ) ]
     369    /// varId         =  ident | ' ident ' | " ident "
     370    /// varVal        =  ident | ' ident ' | " ident "
     371    /// ident         =  '_' | letter { '_' | letter | digit }
    338372    private ISymbolicExpressionTreeNode ParseFact(Queue<Token> tokens) {
    339373      var next = tokens.Peek();
     
    348382        var idTok = tokens.Dequeue();
    349383        if (tokens.Peek().TokenType == TokenType.LeftPar) {
    350           // function identifier
     384          // function identifier or LAG
    351385          var funcId = idTok.strVal.ToUpperInvariant();
    352386
     
    394428        } else {
    395429          // variable
    396           var varNode = (VariableTreeNode)variable.CreateTreeNode();
    397           varNode.Weight = 1.0;
    398           varNode.VariableName = idTok.strVal;
    399           return varNode;
     430          if (tokens.Peek().TokenType == TokenType.Eq) {
     431            // binary factor
     432            tokens.Dequeue(); // skip Eq
     433            var valTok = tokens.Dequeue();
     434            if (valTok.TokenType != TokenType.Identifier) throw new ArgumentException("expected identifier");
     435            var binFactorNode = (BinaryFactorVariableTreeNode)binaryFactorVar.CreateTreeNode();
     436            binFactorNode.Weight = 1.0;
     437            binFactorNode.VariableName = idTok.strVal;
     438            binFactorNode.VariableValue = valTok.strVal;
     439            return binFactorNode;
     440          } else if (tokens.Peek().TokenType == TokenType.LeftBracket) {
     441            // factor variable
     442            var factorVariableNode = (FactorVariableTreeNode)factorVar.CreateTreeNode();
     443            factorVariableNode.VariableName = idTok.strVal;
     444
     445            tokens.Dequeue(); // skip [
     446            var weights = new List<double>();
     447            // at least one weight is necessary
     448            var sign = 1.0;
     449            if (tokens.Peek().TokenType == TokenType.Operator) {
     450              var opToken = tokens.Dequeue();
     451              if (opToken.strVal == "+") sign = 1.0;
     452              else if (opToken.strVal == "-") sign = -1.0;
     453              else throw new ArgumentException();
     454            }
     455            if (tokens.Peek().TokenType != TokenType.Number) throw new ArgumentException("number expected");
     456            var weightTok = tokens.Dequeue();
     457            weights.Add(sign * weightTok.doubleVal);
     458            while (tokens.Peek().TokenType == TokenType.Comma) {
     459              // skip comma
     460              tokens.Dequeue();
     461              if (tokens.Peek().TokenType == TokenType.Operator) {
     462                var opToken = tokens.Dequeue();
     463                if (opToken.strVal == "+") sign = 1.0;
     464                else if (opToken.strVal == "-") sign = -1.0;
     465                else throw new ArgumentException();
     466              }
     467              weightTok = tokens.Dequeue();
     468              if (weightTok.TokenType != TokenType.Number) throw new ArgumentException("number expected");
     469              weights.Add(sign * weightTok.doubleVal);
     470            }
     471            var rightBracketToken = tokens.Dequeue();
     472            if (rightBracketToken.TokenType != TokenType.RightBracket) throw new ArgumentException("closing bracket ] expected");
     473            factorVariableNode.Weights = weights.ToArray();
     474            return factorVariableNode;
     475          } else {
     476            // variable
     477            var varNode = (VariableTreeNode)variable.CreateTreeNode();
     478            varNode.Weight = 1.0;
     479            varNode.VariableName = idTok.strVal;
     480            return varNode;
     481          }
    400482        }
    401483      } else if (next.TokenType == TokenType.Number) {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/SymbolicExpressionImporter.cs

    r14576 r14878  
    4545        {"POW", new Power()},
    4646        {"ROOT", new Root()},
     47        {"SQR", new Square()},
     48        {"SQRT", new SquareRoot()},
    4749        {"SIN",new Sine()},
    4850        {"COS", new Cosine()},
     
    7476        {"PROG", new ProgramRootSymbol()},
    7577        {"MAIN", new StartSymbol()},
     78        {"FACTOR", new FactorVariable() },
     79        {"BINFACTOR", new BinaryFactorVariable()}
    7680      };
    7781
     
    8286    TimeLag timeLag = new TimeLag();
    8387    Integral integral = new Integral();
     88    FactorVariable factorVar = new FactorVariable();
     89    BinaryFactorVariable binFactorVar = new BinaryFactorVariable();
    8490
    8591    ProgramRootSymbol programRootSymbol = new ProgramRootSymbol();
     
    136142            tree.AddSubtree(ParseSexp(tokens));
    137143          }
     144        } else if (tokens.Peek().StringValue.StartsWith("FACTOR")) {
     145          tree = ParseFactor(tokens);
     146        } else if (tokens.Peek().StringValue.StartsWith("BINFACTOR")) {
     147          tree = ParseBinaryFactor(tokens);
    138148        } else {
    139149          Token curToken = tokens.Dequeue();
     
    201211    }
    202212
     213    private ISymbolicExpressionTreeNode ParseFactor(Queue<Token> tokens) {
     214      Token tok = tokens.Dequeue();
     215      Debug.Assert(tok.StringValue == "FACTOR");
     216      FactorVariableTreeNode t = (FactorVariableTreeNode)(new FactorVariable()).CreateTreeNode(); // create a new symbol each time on purpose
     217      var varNameTok = tokens.Dequeue();
     218      Debug.Assert(tok.Symbol == TokenSymbol.SYMB);
     219      t.VariableName = varNameTok.StringValue;
     220
     221      var weights = new List<double>();
     222      while (tokens.Peek().Symbol == TokenSymbol.NUMBER) {
     223        weights.Add(tokens.Dequeue().DoubleValue);
     224      }
     225
     226      t.Weights = weights.ToArray();
     227
     228      // create a set of (virtual) values to match the number of weights
     229      t.Symbol.VariableNames = new string[] { t.VariableName };
     230      t.Symbol.VariableValues = new[]
     231      { new KeyValuePair<string, Dictionary<string,int>>(
     232        t.VariableName,
     233        weights.Select((_, i) => Tuple.Create(_,i)).ToDictionary(tup=>"X" + tup.Item2, tup=>tup.Item2)) };
     234      return t;
     235    }
     236
     237    private ISymbolicExpressionTreeNode ParseBinaryFactor(Queue<Token> tokens) {
     238      Token tok = tokens.Dequeue();
     239      Debug.Assert(tok.StringValue == "BINFACTOR");
     240      var t = (BinaryFactorVariableTreeNode)binFactorVar.CreateTreeNode();
     241      var varNameTok = tokens.Dequeue();
     242      Debug.Assert(varNameTok.Symbol == TokenSymbol.SYMB);
     243      t.VariableName = varNameTok.StringValue;
     244
     245      var varValTok = tokens.Dequeue();
     246      Debug.Assert(varValTok.Symbol == TokenSymbol.SYMB);
     247      t.VariableValue = varValTok.StringValue;
     248
     249      var weightTok = tokens.Dequeue();
     250      Debug.Assert(weightTok.Symbol == TokenSymbol.NUMBER);
     251      t.Weight = weightTok.DoubleValue;
     252
     253      return t;
     254    }
     255
     256
    203257    private ISymbolicExpressionTreeNode ParseLaggedVariable(Queue<Token> tokens) {
    204258      Token varTok = tokens.Dequeue();
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisImpactValuesCalculator.cs

    r12891 r14878  
    55namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    66  public interface ISymbolicDataAnalysisSolutionImpactValuesCalculator : IItem {
    7     double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows);
    8     double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN);
    97    void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData,
    108      IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r14312 r14878  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    25 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
    2625
    2726namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    8483    public const byte Erf = 43;
    8584    public const byte Bessel = 44;
    86     public const byte Passthrough = 45;
     85    public const byte FactorVariable = 46;
     86    public const byte BinaryFactorVariable = 47;
     87
    8788
    8889    private static Dictionary<Type, byte> symbolToOpcode = new Dictionary<Type, byte>() {
     
    133134      { typeof(Erf), OpCodes.Erf},
    134135      { typeof(Bessel), OpCodes.Bessel},
    135       { typeof(Passthrough), OpCodes.Passthrough}
     136      { typeof(FactorVariable), OpCodes.FactorVariable },
     137      { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable }
    136138    };
    137139
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeILEmittingInterpreter.cs

    r14312 r14878  
    6666    private static MethodInfo erf = thisType.GetMethod("Erf", new Type[] { typeof(double) });
    6767    private static MethodInfo bessel = thisType.GetMethod("Bessel", new Type[] { typeof(double) });
     68    private static MethodInfo string_eq = typeof(string).GetMethod("Equals", new Type[] { typeof(string) });
    6869    #endregion
    6970
     
    259260              il.Emit(System.Reflection.Emit.OpCodes.Add);
    260261            }
    261             il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4, nArgs);
     262            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, (double)nArgs);
    262263            il.Emit(System.Reflection.Emit.OpCodes.Div);
    263264            return;
     
    457458            il.Emit(System.Reflection.Emit.OpCodes.Ldc_I4_0); // > 0
    458459            il.Emit(System.Reflection.Emit.OpCodes.Cgt);
     460            il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
    459461            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
    460462            il.Emit(System.Reflection.Emit.OpCodes.Mul);
     
    475477              il.Emit(System.Reflection.Emit.OpCodes.Xor);
    476478            }
     479            il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
     480
    477481            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
    478482            il.Emit(System.Reflection.Emit.OpCodes.Mul);
     
    486490
    487491            il.Emit(System.Reflection.Emit.OpCodes.Cgt); // 1 (>) / 0 (otherwise)
     492            il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
    488493            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
    489494            il.Emit(System.Reflection.Emit.OpCodes.Mul);
     
    496501            CompileInstructions(il, state, ds);
    497502            il.Emit(System.Reflection.Emit.OpCodes.Clt);
     503            il.Emit(System.Reflection.Emit.OpCodes.Conv_R8); // convert to float64
    498504            il.Emit(System.Reflection.Emit.OpCodes.Ldc_R8, 2.0); // * 2
    499505            il.Emit(System.Reflection.Emit.OpCodes.Mul);
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r14576 r14878  
    2222using System;
    2323using System.Collections.Generic;
     24using System.Linq;
    2425using HeuristicLab.Common;
    2526using HeuristicLab.Core;
     
    143144          var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    144145          instr.data = dataset.GetReadOnlyDoubleValues(variableTreeNode.VariableName);
     146        } else if (instr.opCode == OpCodes.FactorVariable) {
     147          var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode;
     148          instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName);
     149        } else if (instr.opCode == OpCodes.BinaryFactorVariable) {
     150          var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;
     151          instr.data = dataset.GetReadOnlyStringValues(factorTreeNode.VariableName);
    145152        } else if (instr.opCode == OpCodes.LagVariable) {
    146153          var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
     
    455462            return ((IList<double>)currentInstr.data)[row] * variableTreeNode.Weight;
    456463          }
     464        case OpCodes.BinaryFactorVariable: {
     465            if (row < 0 || row >= dataset.Rows) return double.NaN;
     466            var factorVarTreeNode = currentInstr.dynamicNode as BinaryFactorVariableTreeNode;
     467            return ((IList<string>)currentInstr.data)[row] == factorVarTreeNode.VariableValue ? factorVarTreeNode.Weight : 0;
     468          }
     469        case OpCodes.FactorVariable: {
     470            if (row < 0 || row >= dataset.Rows) return double.NaN;
     471            var factorVarTreeNode = currentInstr.dynamicNode as FactorVariableTreeNode;
     472            return factorVarTreeNode.GetValue(((IList<string>)currentInstr.data)[row]);
     473          }
    457474        case OpCodes.LagVariable: {
    458475            var laggedVariableTreeNode = (LaggedVariableTreeNode)currentInstr.dynamicNode;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r14576 r14878  
    156156            var variableTreeNode = (VariableTreeNode)instr.dynamicNode;
    157157            instr.value = ((IList<double>)instr.data)[row] * variableTreeNode.Weight;
     158          }
     159        } else if (instr.opCode == OpCodes.BinaryFactorVariable) {
     160          if (row < 0 || row >= dataset.Rows) instr.value = double.NaN;
     161          else {
     162            var factorTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;
     163            instr.value = ((IList<string>)instr.data)[row] == factorTreeNode.VariableValue ? factorTreeNode.Weight : 0;
     164          }
     165        } else if (instr.opCode == OpCodes.FactorVariable) {
     166          if (row < 0 || row >= dataset.Rows) instr.value = double.NaN;
     167          else {
     168            var factorTreeNode = instr.dynamicNode as FactorVariableTreeNode;
     169            instr.value = factorTreeNode.GetValue(((IList<string>)instr.data)[row]);
    158170          }
    159171        } else if (instr.opCode == OpCodes.LagVariable) {
     
    371383          state.Reset();
    372384          instr.value = interpreter.Evaluate(dataset, ref row, state);
    373         } else if (instr.opCode == OpCodes.Passthrough) {
    374           instr.value = code[instr.childIndex].value;
    375385        } else {
    376386          var errorText = string.Format("The {0} symbol is not supported by the linear interpreter. To support this symbol, please use the SymbolicDataAnalysisExpressionTreeInterpreter.", instr.dynamicNode.Symbol.Name);
     
    412422            }
    413423            break;
     424          case OpCodes.BinaryFactorVariable: {
     425              var factorVariableTreeNode = instr.dynamicNode as BinaryFactorVariableTreeNode;
     426              instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName);
     427            }
     428            break;
     429          case OpCodes.FactorVariable: {
     430              var factorVariableTreeNode = instr.dynamicNode as FactorVariableTreeNode;
     431              instr.data = dataset.GetReadOnlyStringValues(factorVariableTreeNode.VariableName);
     432            }
     433            break;
    414434          case OpCodes.LagVariable: {
    415435              var laggedVariableTreeNode = (LaggedVariableTreeNode)instr.dynamicNode;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame

    r14312 r14878  
    2929  [PluginFile("HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.dll", PluginFileType.Assembly)]
    3030  [PluginDependency("HeuristicLab.ALGLIB", "3.7.0")]
     31  [PluginDependency("HeuristicLab.AutoDiff", "1.0")]
    3132  [PluginDependency("HeuristicLab.Analysis", "3.3")]
    3233  [PluginDependency("HeuristicLab.Collections", "3.3")]
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeSimplificationOperator.cs

    r14312 r14878  
    3737    }
    3838
    39     private readonly SymbolicDataAnalysisExpressionTreeSimplifier simplifier = new SymbolicDataAnalysisExpressionTreeSimplifier();
     39    private readonly TreeSimplifier simplifier = new TreeSimplifier();
    4040
    4141    [StorableConstructor]
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModel.cs

    r14312 r14878  
    6363        var variables =
    6464          SymbolicExpressionTree.IterateNodesPrefix()
    65             .OfType<VariableTreeNode>()
     65            .OfType<IVariableTreeNode>()
    6666            .Select(x => x.VariableName)
    6767            .Distinct();
    68         var variableConditions = SymbolicExpressionTree.IterateNodesPrefix()
    69           .OfType<VariableConditionTreeNode>().Select(x => x.VariableName).Distinct();
    7068
    71         return variables.Union(variableConditions).OrderBy(x => x);
     69        return variables.OrderBy(x => x);
    7270      }
    7371    }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisModelComplexityCalculator.cs

    r14312 r14878  
    3939            return 1;
    4040          }
    41         case OpCodes.Variable: {
     41        case OpCodes.Variable:
     42        case OpCodes.BinaryFactorVariable:
     43        case OpCodes.FactorVariable: {
    4244            return 2;
    4345          }
    44         case OpCodes.Add: 
     46        case OpCodes.Add:
    4547        case OpCodes.Sub: {
    4648            double complexity = 0;
     
    5052            return complexity;
    5153          }
    52         case OpCodes.Mul: 
     54        case OpCodes.Mul:
    5355        case OpCodes.Div: {
    5456            double complexity = 1;
     
    6062          }
    6163        case OpCodes.Sin:
    62         case OpCodes.Cos: 
     64        case OpCodes.Cos:
    6365        case OpCodes.Tan:
    64         case OpCodes.Exp: 
     66        case OpCodes.Exp:
    6567        case OpCodes.Log: {
    6668            double complexity = CalculateComplexity(node.GetSubtree(0));
     
    7577            return complexity * complexity * complexity;
    7678          }
    77         case OpCodes.Power:         
     79        case OpCodes.Power:
    7880        case OpCodes.Root: {
    7981            double complexity = CalculateComplexity(node.GetSubtree(0));
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs

    r14312 r14878  
    208208
    209209    protected virtual void UpdateGrammar() {
    210       SymbolicExpressionTreeGrammar.MaximumFunctionArguments = MaximumFunctionArguments.Value;
    211       SymbolicExpressionTreeGrammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
    212       foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>()) {
     210      var problemData = ProblemData;
     211      var ds = problemData.Dataset;
     212      var grammar = SymbolicExpressionTreeGrammar;
     213      grammar.MaximumFunctionArguments = MaximumFunctionArguments.Value;
     214      grammar.MaximumFunctionDefinitions = MaximumFunctionDefinitions.Value;
     215      foreach (var varSymbol in grammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableBase>()) {
    213216        if (!varSymbol.Fixed) {
    214           varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value);
    215           varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     217          varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<double>(x));
     218          varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<double>(x));
    216219        }
    217220      }
    218       foreach (var varSymbol in SymbolicExpressionTreeGrammar.Symbols.OfType<HeuristicLab.Problems.DataAnalysis.Symbolic.VariableCondition>()) {
    219         if (!varSymbol.Fixed) {
    220           varSymbol.AllVariableNames = ProblemData.InputVariables.Select(x => x.Value);
    221           varSymbol.VariableNames = ProblemData.AllowedInputVariables;
     221      foreach (var factorSymbol in grammar.Symbols.OfType<BinaryFactorVariable>()) {
     222        if (!factorSymbol.Fixed) {
     223          factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
     224          factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
     225          factorSymbol.VariableValues = factorSymbol.VariableNames
     226            .ToDictionary(varName => varName, varName => ds.GetStringValues(varName).Distinct().ToList());
     227        }
     228      }
     229      foreach (var factorSymbol in grammar.Symbols.OfType<FactorVariable>()) {
     230        if (!factorSymbol.Fixed) {
     231          factorSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => ds.VariableHasType<string>(x));
     232          factorSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => ds.VariableHasType<string>(x));
     233          factorSymbol.VariableValues = factorSymbol.VariableNames
     234            .ToDictionary(varName => varName,
     235            varName => ds.GetStringValues(varName).Distinct()
     236            .Select((n, i) => Tuple.Create(n, i))
     237            .ToDictionary(tup => tup.Item1, tup => tup.Item2));
    222238        }
    223239      }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSingleObjectiveProblem.cs

    r14312 r14878  
    7373    }
    7474
    75     public SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
     75    protected SymbolicDataAnalysisSingleObjectiveProblem(T problemData, U evaluator, V solutionCreator)
    7676      : base(problemData, evaluator, solutionCreator) {
    7777      Parameters.Add(new FixedValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized."));
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs

    r14312 r14878  
    2121
    2222using System.Collections.Generic;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    3637    [StorableConstructor]
    3738    protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { }
    38     public abstract double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows);
    39     public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double qualityForImpactsCalculation = double.NaN);
    4039    public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, out double newQualityForImpactsCalculation, double qualityForImpactsCalculation = double.NaN);
    4140
    42     protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
     41    protected IEnumerable<double> CalculateReplacementValues(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
    4342      IDataset dataset, IEnumerable<int> rows) {
    4443      //optimization: constant nodes return always the same value
    4544      ConstantTreeNode constantNode = node as ConstantTreeNode;
    46       if (constantNode != null) return constantNode.Value;
     45      BinaryFactorVariableTreeNode binaryFactorNode = node as BinaryFactorVariableTreeNode;
     46      FactorVariableTreeNode factorNode = node as FactorVariableTreeNode;
     47      if (constantNode != null) {
     48        yield return constantNode.Value;
     49      } else if (binaryFactorNode != null) {
     50        // valid replacements are either all off or all on
     51        yield return 0;
     52        yield return 1;
     53      } else if (factorNode != null) {
     54        foreach (var w in factorNode.Weights) yield return w;
     55        yield return 0.0;
     56      } else {
     57        var rootSymbol = new ProgramRootSymbol().CreateTreeNode();
     58        var startSymbol = new StartSymbol().CreateTreeNode();
     59        rootSymbol.AddSubtree(startSymbol);
     60        startSymbol.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());
    4761
    48       var rootSymbol = new ProgramRootSymbol().CreateTreeNode();
    49       var startSymbol = new StartSymbol().CreateTreeNode();
    50       rootSymbol.AddSubtree(startSymbol);
    51       startSymbol.AddSubtree((ISymbolicExpressionTreeNode)node.Clone());
    52 
    53       var tempTree = new SymbolicExpressionTree(rootSymbol);
    54       // clone ADFs of source tree
    55       for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) {
    56         tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
     62        var tempTree = new SymbolicExpressionTree(rootSymbol);
     63        // clone ADFs of source tree
     64        for (int i = 1; i < sourceTree.Root.SubtreeCount; i++) {
     65          tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
     66        }
     67        yield return interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Median();
     68        yield return interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Average(); // TODO perf
    5769      }
    58       return interpreter.GetSymbolicExpressionTreeValues(tempTree, dataset, rows).Median();
    5970    }
    6071
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariable.cs

    r14312 r14878  
    2727  [StorableClass]
    2828  [Item("LaggedVariable", "Represents a variable value with a time offset.")]
    29   public class LaggedVariable : Variable {
     29  public class LaggedVariable : VariableBase {
    3030    [Storable]
    3131    private int minLag;
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/LaggedVariableTreeNode.cs

    r14312 r14878  
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2727  [StorableClass]
    28   public sealed class LaggedVariableTreeNode : VariableTreeNode, ILaggedTreeNode {
     28  public sealed class LaggedVariableTreeNode : VariableTreeNodeBase, ILaggedTreeNode {
    2929    public new LaggedVariable Symbol {
    3030      get { return (LaggedVariable)base.Symbol; }
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/Variable.cs

    r14312 r14878  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
     
    2927  [StorableClass]
    3028  [Item("Variable", "Represents a variable value.")]
    31   public class Variable : Symbol {
    32     #region Properties
    33     [Storable]
    34     private double weightMu;
    35     public double WeightMu {
    36       get { return weightMu; }
    37       set {
    38         if (value != weightMu) {
    39           weightMu = value;
    40           OnChanged(EventArgs.Empty);
    41         }
    42       }
    43     }
    44     [Storable]
    45     private double weightSigma;
    46     public double WeightSigma {
    47       get { return weightSigma; }
    48       set {
    49         if (weightSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    50         if (value != weightSigma) {
    51           weightSigma = value;
    52           OnChanged(EventArgs.Empty);
    53         }
    54       }
    55     }
    56     [Storable]
    57     private double weightManipulatorMu;
    58     public double WeightManipulatorMu {
    59       get { return weightManipulatorMu; }
    60       set {
    61         if (value != weightManipulatorMu) {
    62           weightManipulatorMu = value;
    63           OnChanged(EventArgs.Empty);
    64         }
    65       }
    66     }
    67     [Storable]
    68     private double weightManipulatorSigma;
    69     public double WeightManipulatorSigma {
    70       get { return weightManipulatorSigma; }
    71       set {
    72         if (weightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    73         if (value != weightManipulatorSigma) {
    74           weightManipulatorSigma = value;
    75           OnChanged(EventArgs.Empty);
    76         }
    77       }
    78     }
    79     [Storable(DefaultValue = 0.0)]
    80     private double multiplicativeWeightManipulatorSigma;
    81     public double MultiplicativeWeightManipulatorSigma {
    82       get { return multiplicativeWeightManipulatorSigma; }
    83       set {
    84         if (multiplicativeWeightManipulatorSigma < 0.0) throw new ArgumentException("Negative sigma is not allowed.");
    85         if (value != multiplicativeWeightManipulatorSigma) {
    86           multiplicativeWeightManipulatorSigma = value;
    87           OnChanged(EventArgs.Empty);
    88         }
    89       }
    90     }
    91     private List<string> variableNames;
    92     [Storable]
    93     public IEnumerable<string> VariableNames {
    94       get { return variableNames; }
    95       set {
    96         if (value == null) throw new ArgumentNullException();
    97         variableNames.Clear();
    98         variableNames.AddRange(value);
    99         OnChanged(EventArgs.Empty);
    100       }
    101     }
    102 
    103     private List<string> allVariableNames;
    104     [Storable]
    105     public IEnumerable<string> AllVariableNames {
    106       get { return allVariableNames; }
    107       set {
    108         if (value == null) throw new ArgumentNullException();
    109         allVariableNames.Clear();
    110         allVariableNames.AddRange(value);
    111       }
    112     }
    113 
    114     public override bool Enabled {
    115       get {
    116         if (variableNames.Count == 0) return false;
    117         return base.Enabled;
    118       }
    119       set {
    120         if (variableNames.Count == 0) base.Enabled = false;
    121         else base.Enabled = value;
    122       }
    123     }
    124 
    125     private const int minimumArity = 0;
    126     private const int maximumArity = 0;
    127 
    128     public override int MinimumArity {
    129       get { return minimumArity; }
    130     }
    131     public override int MaximumArity {
    132       get { return maximumArity; }
    133     }
    134     #endregion
    135 
    136     [StorableHook(HookType.AfterDeserialization)]
    137     private void AfterDeserialization() {
    138       if (allVariableNames == null || (allVariableNames.Count == 0 && variableNames.Count > 0)) {
    139         allVariableNames = variableNames;
    140       }
    141     }
     29  public sealed class Variable : VariableBase {
    14230
    14331    [StorableConstructor]
    144     protected Variable(bool deserializing)
     32    private Variable(bool deserializing)
    14533      : base(deserializing) {
    146       variableNames = new List<string>();
    147       allVariableNames = new List<string>();
    14834    }
    149     protected Variable(Variable original, Cloner cloner)
     35    private Variable(Variable original, Cloner cloner)
    15036      : base(original, cloner) {
    151       weightMu = original.weightMu;
    152       weightSigma = original.weightSigma;
    153       variableNames = new List<string>(original.variableNames);
    154       allVariableNames = new List<string>(original.allVariableNames);
    155       weightManipulatorMu = original.weightManipulatorMu;
    156       weightManipulatorSigma = original.weightManipulatorSigma;
    157       multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma;
    15837    }
    159     public Variable() : this("Variable", "Represents a variable value.") { }
    160     public Variable(string name, string description)
    161       : base(name, description) {
    162       weightMu = 1.0;
    163       weightSigma = 1.0;
    164       weightManipulatorMu = 0.0;
    165       weightManipulatorSigma = 0.05;
    166       multiplicativeWeightManipulatorSigma = 0.03;
    167       variableNames = new List<string>();
    168       allVariableNames = new List<string>();
    169     }
     38    public Variable() : base("Variable", "Represents a variable value.") { }
     39    public Variable(string name, string description) : base(name, description) { }
    17040
    17141    public override ISymbolicExpressionTreeNode CreateTreeNode() {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableCondition.cs

    r14576 r14878  
    3030  [StorableClass]
    3131  [Item("Variable Condition", "Represents a condition that tests a given variable against a specified threshold.")]
    32   public sealed class VariableCondition : Symbol {
     32  public sealed class VariableCondition : Symbol, IVariableSymbol {
    3333    #region properties
    3434    [Storable]
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableConditionTreeNode.cs

    r14576 r14878  
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3030  [StorableClass]
    31   public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode {
     31  public sealed class VariableConditionTreeNode : SymbolicExpressionTreeNode, IVariableTreeNode {
    3232    #region properties
    3333    public new VariableCondition Symbol {
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNode.cs

    r14312 r14878  
    2121
    2222using HeuristicLab.Common;
    23 using HeuristicLab.Core;
    24 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    2523using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    26 using HeuristicLab.Random;
    2724namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    2825  [StorableClass]
    29   public class VariableTreeNode : SymbolicExpressionTreeTerminalNode {
     26  public sealed class VariableTreeNode : VariableTreeNodeBase {
    3027    public new Variable Symbol {
    3128      get { return (Variable)base.Symbol; }
    3229    }
    33     [Storable]
    34     private double weight;
    35     public double Weight {
    36       get { return weight; }
    37       set { weight = value; }
     30    [StorableConstructor]
     31    private VariableTreeNode(bool deserializing) : base(deserializing) { }
     32    private VariableTreeNode(VariableTreeNode original, Cloner cloner)
     33      : base(original, cloner) {
    3834    }
    39     [Storable]
    40     private string variableName;
    41     public string VariableName {
    42       get { return variableName; }
    43       set { variableName = value; }
    44     }
    45 
    46     [StorableConstructor]
    47     protected VariableTreeNode(bool deserializing) : base(deserializing) { }
    48     protected VariableTreeNode(VariableTreeNode original, Cloner cloner)
    49       : base(original, cloner) {
    50       weight = original.weight;
    51       variableName = original.variableName;
    52     }
    53     protected VariableTreeNode() { }
     35    private VariableTreeNode() { }
    5436    public VariableTreeNode(Variable variableSymbol) : base(variableSymbol) { }
    55 
    56     public override bool HasLocalParameters {
    57       get { return true; }
    58     }
    59 
    60     public override void ResetLocalParameters(IRandom random) {
    61       base.ResetLocalParameters(random);
    62       weight = NormalDistributedRandom.NextDouble(random, Symbol.WeightMu, Symbol.WeightSigma);
    63 
    64 #pragma warning disable 612, 618
    65       variableName = Symbol.VariableNames.SelectRandom(random);
    66 #pragma warning restore 612, 618
    67     }
    68 
    69     public override void ShakeLocalParameters(IRandom random, double shakingFactor) {
    70       base.ShakeLocalParameters(random, shakingFactor);
    71       // 50% additive & 50% multiplicative
    72       if (random.NextDouble() < 0) {
    73         double x = NormalDistributedRandom.NextDouble(random, Symbol.WeightManipulatorMu, Symbol.WeightManipulatorSigma);
    74         weight = weight + x * shakingFactor;
    75       } else {
    76         double x = NormalDistributedRandom.NextDouble(random, 1.0, Symbol.MultiplicativeWeightManipulatorSigma);
    77         weight = weight * x;
    78       }
    79 #pragma warning disable 612, 618
    80       variableName = Symbol.VariableNames.SelectRandom(random);
    81 #pragma warning restore 612, 618
    82     }
    8337
    8438    public override IDeepCloneable Clone(Cloner cloner) {
    8539      return new VariableTreeNode(this, cloner);
    8640    }
    87 
    88     public override string ToString() {
    89       if (weight.IsAlmost(1.0)) return variableName;
    90       else return weight.ToString("E4") + " " + variableName;
    91     }
    9241  }
    9342}
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.TravelingSalesman

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/HeuristicLab.EvolutionTracking/HeuristicLab.Problems.TravelingSalesman.Views

Note: See TracChangeset for help on using the changeset viewer.