Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6011 for branches/histogram


Ignore:
Timestamp:
04/15/11 14:54:43 (14 years ago)
Author:
abeham
Message:

#1465

  • updated branch with changes from trunk
  • fixed some bugs
  • introduced secondary x-axis option
Location:
branches/histogram
Files:
60 edited
4 copied

Legend:

Unmodified
Added
Removed
  • branches/histogram

  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/HeuristicLab.Algorithms.DataAnalysis.Views-3.4.csproj

    r5829 r6011  
    114114  </ItemGroup>
    115115  <ItemGroup>
     116    <Compile Include="KMeansClusteringModelView.cs">
     117      <SubType>UserControl</SubType>
     118    </Compile>
     119    <Compile Include="KMeansClusteringModelView.Designer.cs">
     120      <DependentUpon>KMeansClusteringModelView.cs</DependentUpon>
     121    </Compile>
    116122    <Compile Include="SupportVectorMachineModelSupportVectorsView.cs">
    117123      <SubType>UserControl</SubType>
  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/SupportVectorMachineModelSupportVectorsView.cs

    r5834 r6011  
    2525
    2626namespace HeuristicLab.Algorithms.DataAnalysis.Views {
    27   [View("SupportVectorMachineModel SupportVectorsView")]
     27  [View("SVM Support Vectors")]
    2828  [Content(typeof(SupportVectorMachineModel), false)]
    2929  public partial class SupportVectorMachineModelSupportVectorsView : AsynchronousContentView {
  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/SupportVectorMachineModelView.cs

    r5834 r6011  
    2626
    2727namespace HeuristicLab.Algorithms.DataAnalysis.Views {
    28   [View("SupportVectorMachineModel view")]
     28  [View("SVM Model")]
    2929  [Content(typeof(SupportVectorMachineModel), true)]
    3030  public partial class SupportVectorMachineModelView : AsynchronousContentView {
  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/AlglibUtil.cs

    r5809 r6011  
    2727  public static class AlglibUtil {
    2828    public static double[,] PrepareInputMatrix(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) {
    29       List<int> allowedRows = CalculateAllowedRows(dataset, variables, rows).ToList();
     29      List<string> variablesList = variables.ToList();
     30      List<int> rowsList = rows.ToList();
    3031
    31       double[,] matrix = new double[allowedRows.Count, variables.Count()];
    32       for (int row = 0; row < allowedRows.Count; row++) {
     32      double[,] matrix = new double[rowsList.Count, variablesList.Count];
     33      for (int row = 0; row < rowsList.Count; row++) {
    3334        int col = 0;
    3435        foreach (string column in variables) {
    35           matrix[row, col] = dataset[column, row];
     36          matrix[row, col] = dataset[column, rowsList[row]];
    3637          col++;
    3738        }
     
    3940      return matrix;
    4041    }
    41 
    42     private static IEnumerable<int> CalculateAllowedRows(Dataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) {
    43       // return only rows that contain no infinity or NaN values
    44       return from row in rows
    45              where (from variable in variables
    46                     let x = dataset[variable, row]
    47                     where double.IsInfinity(x) || double.IsNaN(x)
    48                     select 1)
    49                     .Any() == false
    50              select row;
    51     }
    5242  }
    5343}
  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs

    r5809 r6011  
    7373      int nClasses = problemData.ClassNames.Count();
    7474      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     75      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     76        throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset.");
    7577
    7678      // change class values into class index
  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs

    r5809 r6011  
    7676      IEnumerable<int> rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
    7777      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows);
     78      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     79        throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset.");
    7880
    7981      alglib.linearmodel lm = new alglib.linearmodel();
  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineUtil.cs

    r5809 r6011  
    4141      int maxNodeIndex = 0;
    4242      int svmProblemRowIndex = 0;
     43      List<string> inputVariablesList = inputVariables.ToList();
    4344      foreach (int row in rowIndices) {
    4445        tempRow = new List<SVM.Node>();
    45         foreach (var inputVariable in inputVariables) {
    46           int col = dataset.GetVariableIndex(inputVariable);
    47           double value = dataset[row, col];
     46        int colIndex = 1; // make sure the smallest node index for SVM = 1
     47        foreach (var inputVariable in inputVariablesList) {
     48          double value = dataset[row, dataset.GetVariableIndex(inputVariable)];
     49          // SVM also works with missing values
     50          // => don't add NaN values in the dataset to the sparse SVM matrix representation
    4851          if (!double.IsNaN(value)) {
    49             int nodeIndex = col + 1; // make sure the smallest nodeIndex is 1 (libSVM convention)
    50             tempRow.Add(new SVM.Node(nodeIndex, value));
    51             if (nodeIndex > maxNodeIndex) maxNodeIndex = nodeIndex;
     52            tempRow.Add(new SVM.Node(colIndex, value)); // nodes must be sorted in ascending ordered by column index
     53            if (colIndex > maxNodeIndex) maxNodeIndex = colIndex;
    5254          }
     55          colIndex++;
    5356        }
    54         nodes[svmProblemRowIndex++] = tempRow.OrderBy(x => x.Index).ToArray(); // make sure the values are sorted by node index
     57        nodes[svmProblemRowIndex++] = tempRow.ToArray();
    5558      }
    5659
  • branches/histogram/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClustering.cs

    r5914 r6011  
    9292      int[] xyc;
    9393      double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows);
     94      if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x)))
     95        throw new NotSupportedException("k-Means clustering does not support NaN or infinity values in the input dataset.");
     96
    9497      alglib.kmeansgenerate(inputMatrix, inputMatrix.GetLength(0), inputMatrix.GetLength(1), k, restarts + 1, out info, out centers, out xyc);
    9598      if (info != 1) throw new ArgumentException("Error in calculation of k-Means clustering solution");
  • branches/histogram/HeuristicLab.Analysis

  • branches/histogram/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.Designer.cs

    r6010 r6011  
    5757      this.commonGroupBox = new System.Windows.Forms.GroupBox();
    5858      this.histoGramGroupBox = new System.Windows.Forms.GroupBox();
     59      this.secondXAxisCheckBox = new System.Windows.Forms.CheckBox();
    5960      ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).BeginInit();
    6061      this.commonGroupBox.SuspendLayout();
     
    104105      this.startIndexZeroCheckBox.AutoSize = true;
    105106      this.startIndexZeroCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
    106       this.startIndexZeroCheckBox.Location = new System.Drawing.Point(17, 98);
     107      this.startIndexZeroCheckBox.Location = new System.Drawing.Point(17, 121);
    107108      this.startIndexZeroCheckBox.Name = "startIndexZeroCheckBox";
    108109      this.startIndexZeroCheckBox.Size = new System.Drawing.Size(89, 17);
     
    164165                  | System.Windows.Forms.AnchorStyles.Right)));
    165166      this.commonGroupBox.Controls.Add(this.colorButton);
     167      this.commonGroupBox.Controls.Add(this.secondXAxisCheckBox);
    166168      this.commonGroupBox.Controls.Add(this.secondYAxisCheckBox);
    167169      this.commonGroupBox.Controls.Add(this.label1);
     
    171173      this.commonGroupBox.Location = new System.Drawing.Point(3, 3);
    172174      this.commonGroupBox.Name = "commonGroupBox";
    173       this.commonGroupBox.Size = new System.Drawing.Size(473, 122);
     175      this.commonGroupBox.Size = new System.Drawing.Size(473, 142);
    174176      this.commonGroupBox.TabIndex = 7;
    175177      this.commonGroupBox.TabStop = false;
     
    183185      this.histoGramGroupBox.Controls.Add(this.exactBinsCheckBox);
    184186      this.histoGramGroupBox.Controls.Add(this.label3);
    185       this.histoGramGroupBox.Location = new System.Drawing.Point(3, 131);
     187      this.histoGramGroupBox.Location = new System.Drawing.Point(3, 151);
    186188      this.histoGramGroupBox.Name = "histoGramGroupBox";
    187189      this.histoGramGroupBox.Size = new System.Drawing.Size(473, 49);
     
    190192      this.histoGramGroupBox.Text = "Histogram";
    191193      //
     194      // secondXAxisCheckBox
     195      //
     196      this.secondXAxisCheckBox.AutoSize = true;
     197      this.secondXAxisCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight;
     198      this.secondXAxisCheckBox.Location = new System.Drawing.Point(8, 98);
     199      this.secondXAxisCheckBox.Name = "secondXAxisCheckBox";
     200      this.secondXAxisCheckBox.Size = new System.Drawing.Size(98, 17);
     201      this.secondXAxisCheckBox.TabIndex = 1;
     202      this.secondXAxisCheckBox.Text = "Second X Axis:";
     203      this.secondXAxisCheckBox.UseVisualStyleBackColor = true;
     204      this.secondXAxisCheckBox.CheckedChanged += new System.EventHandler(this.secondXAxisCheckBox_CheckedChanged);
     205      //
    192206      // DataRowVisualPropertiesControl
    193207      //
     
    197211      this.Controls.Add(this.commonGroupBox);
    198212      this.Name = "DataRowVisualPropertiesControl";
    199       this.Size = new System.Drawing.Size(479, 185);
     213      this.Size = new System.Drawing.Size(479, 205);
    200214      ((System.ComponentModel.ISupportInitialize)(this.binsNumericUpDown)).EndInit();
    201215      this.commonGroupBox.ResumeLayout(false);
     
    221235    private System.Windows.Forms.GroupBox commonGroupBox;
    222236    private System.Windows.Forms.GroupBox histoGramGroupBox;
     237    private System.Windows.Forms.CheckBox secondXAxisCheckBox;
    223238  }
    224239}
  • branches/histogram/HeuristicLab.Analysis.Views/3.3/DataRowVisualPropertiesControl.cs

    r6010 r6011  
    5353          colorButton.BackColor = SystemColors.Control;
    5454          secondYAxisCheckBox.Checked = false;
     55          secondXAxisCheckBox.Checked = false;
    5556          startIndexZeroCheckBox.Checked = false;
    5657          binsNumericUpDown.Value = 1;
     
    5859        } else {
    5960          chartTypeComboBox.SelectedItem = Content.ChartType;
    60           colorButton.BackColor = Content.Color;
     61          if (Content.Color.IsEmpty) {
     62            colorButton.BackColor = SystemColors.Control;
     63            colorButton.Text = "?";
     64          } else colorButton.BackColor = Content.Color;
    6165          secondYAxisCheckBox.Checked = Content.SecondYAxis;
     66          secondXAxisCheckBox.Checked = Content.SecondXAxis;
    6267          startIndexZeroCheckBox.Checked = Content.StartIndexZero;
    6368          binsNumericUpDown.Value = Content.Bins;
     
    8590        Content.Color = colorDialog.Color;
    8691        colorButton.BackColor = Content.Color;
     92        colorButton.Text = String.Empty;
    8793      }
    8894    }
     
    9197      if (!SuppressEvents && Content != null) {
    9298        Content.SecondYAxis = secondYAxisCheckBox.Checked;
     99      }
     100    }
     101
     102    private void secondXAxisCheckBox_CheckedChanged(object sender, EventArgs e) {
     103      if (!SuppressEvents && Content != null) {
     104        Content.SecondXAxis = secondXAxisCheckBox.Checked;
    93105      }
    94106    }
  • branches/histogram/HeuristicLab.Analysis.Views/3.3/DataTableView.cs

    r6010 r6011  
    142142      }
    143143      series.YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
     144      series.XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : AxisType.Primary;
    144145      if (row.VisualProperties.Color != Color.Empty) series.Color = row.VisualProperties.Color;
    145146      series.ToolTip = row.Name + " X = #INDEX, Y = #VAL";
     
    305306            chart.Series[row.Name].ChartType = SeriesChartType.Column;
    306307            chart.Series[row.Name]["PointWidth"] = "1";
     308            CalculateHistogram(chart.Series[row.Name], row);
    307309            break;
    308310          default:
     
    311313        }
    312314        chart.Series[row.Name].YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
     315        chart.Series[row.Name].XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : AxisType.Primary;
    313316        if (row.VisualProperties.Color != Color.Empty) chart.Series[row.Name].Color = row.VisualProperties.Color;
    314317        chart.ChartAreas[0].RecalculateAxesScale();
     
    444447
    445448    private void FillSeriesWithRowValues(Series series, DataRow row) {
    446       if (row.VisualProperties.ChartType == DataRowVisualProperties.DataRowChartType.Histogram) {
    447         series.Points.Clear();
    448         if (!row.Values.Any()) return;
    449         int bins = row.VisualProperties.Bins;
    450 
    451         double minValue = row.Values.Min();
    452         double maxValue = row.Values.Max();
    453         double intervalWidth = (maxValue - minValue) / bins;
    454         if (intervalWidth <= 0) return;
    455 
    456         if (!row.VisualProperties.ExactBins) {
    457           intervalWidth = HumanRoundRange(intervalWidth);
    458           minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
    459           maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
    460         }
    461 
    462         double current = minValue, intervalCenter = intervalWidth / 2.0;
    463         int frequency = 0;
    464         foreach (double v in row.Values.Where(x => !IsInvalidValue(x)).OrderBy(x => x)) {
    465           while (v > current + intervalWidth) {
    466             series.Points.AddXY(current + intervalCenter, frequency);
    467             current += intervalWidth;
    468             frequency = 0;
    469           }
    470           frequency++;
    471         }
    472         series.Points.AddXY(current + intervalCenter, frequency);
    473       } else {
    474         for (int i = 0; i < row.Values.Count; i++) {
    475           var value = row.Values[i];
    476           DataPoint point = new DataPoint();
    477           point.XValue = row.VisualProperties.StartIndexZero ? i : i + 1;
    478           if (IsInvalidValue(value))
    479             point.IsEmpty = true;
    480           else
    481             point.YValues = new double[] { value };
    482           series.Points.Add(point);
    483         }
    484       }
     449      switch (row.VisualProperties.ChartType) {
     450        case DataRowVisualProperties.DataRowChartType.Histogram:
     451          CalculateHistogram(series, row);
     452          break;
     453        default: {
     454            for (int i = 0; i < row.Values.Count; i++) {
     455              var value = row.Values[i];
     456              DataPoint point = new DataPoint();
     457              point.XValue = row.VisualProperties.StartIndexZero ? i : i + 1;
     458              if (IsInvalidValue(value))
     459                point.IsEmpty = true;
     460              else
     461                point.YValues = new double[] { value };
     462              series.Points.Add(point);
     463            }
     464          }
     465          break;
     466      }
     467    }
     468
     469    private void CalculateHistogram(Series series, DataRow row) {
     470      series.Points.Clear();
     471      if (!row.Values.Any()) return;
     472      int bins = row.VisualProperties.Bins;
     473
     474      double minValue = row.Values.Min();
     475      double maxValue = row.Values.Max();
     476      double intervalWidth = (maxValue - minValue) / bins;
     477      if (intervalWidth <= 0) return;
     478
     479      if (!row.VisualProperties.ExactBins) {
     480        intervalWidth = HumanRoundRange(intervalWidth);
     481        minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
     482        maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
     483      }
     484
     485      double current = minValue, intervalCenter = intervalWidth / 2.0;
     486      int frequency = 0;
     487      foreach (double v in row.Values.Where(x => !IsInvalidValue(x)).OrderBy(x => x)) {
     488        while (v > current + intervalWidth) {
     489          series.Points.AddXY(current + intervalCenter, frequency);
     490          current += intervalWidth;
     491          frequency = 0;
     492        }
     493        frequency++;
     494      }
     495      series.Points.AddXY(current + intervalCenter, frequency);
    485496    }
    486497
  • branches/histogram/HeuristicLab.Analysis.Views/3.3/DataTableVisualPropertiesDialog.cs

    r6010 r6011  
    6464    private void cancelButton_Click(object sender, System.EventArgs e) {
    6565      DialogResult = DialogResult.Cancel;
    66       Content.VisualProperties = originalDataTableVPs;
    6766      foreach (DataRow row in Content.Rows) {
    6867        row.VisualProperties = originalDataRowVPs[row.Name];
    6968      }
     69      Content.VisualProperties = originalDataTableVPs;
    7070      Close();
    7171    }
  • branches/histogram/HeuristicLab.Analysis/3.3/DataVisualization/DataRowVisualProperties.cs

    r6010 r6011  
    6161      }
    6262    }
     63    private bool secondXAxis;
     64    public bool SecondXAxis {
     65      get { return secondXAxis; }
     66      set {
     67        if (secondXAxis != value) {
     68          secondXAxis = value;
     69          OnPropertyChanged("SecondXAxis");
     70        }
     71      }
     72    }
    6373    private Color color;
    6474    public Color Color {
     
    113123      set { secondYAxis = value; }
    114124    }
     125    [Storable(Name = "SecondXAxis")]
     126    private bool StorableSecondXAxis {
     127      get { return secondXAxis; }
     128      set { secondXAxis = value; }
     129    }
    115130    [Storable(Name = "Color")]
    116131    private Color StorableColor {
     
    141156      this.chartType = original.chartType;
    142157      this.secondYAxis = original.secondYAxis;
     158      this.secondXAxis = original.secondXAxis;
    143159      this.color = original.color;
    144160      this.startIndexZero = original.startIndexZero;
     161      this.bins = original.bins;
     162      this.exactBins = original.exactBins;
    145163    }
    146164    public DataRowVisualProperties() {
    147165      chartType = DataRowChartType.Line;
    148166      secondYAxis = false;
     167      secondXAxis = false;
    149168      color = Color.Empty;
    150169      startIndexZero = false;
     170      bins = 10;
     171      exactBins = false;
    151172    }
    152173
  • branches/histogram/HeuristicLab.Analysis/3.3/Tests

    • Property svn:ignore
      •  

        old new  
        11bin
        22obj
         3*.vs10x
  • branches/histogram/HeuristicLab.Data.Views/3.3/StringConvertibleValueView.Designer.cs

    r5908 r6011  
    5959      // valueTextBox
    6060      //
    61       this.valueTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
     61      this.valueTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    6262            | System.Windows.Forms.AnchorStyles.Right)));
    6363      this.valueTextBox.Location = new System.Drawing.Point(17, 0);
    6464      this.valueTextBox.Name = "valueTextBox";
    6565      this.valueTextBox.Size = new System.Drawing.Size(135, 20);
    66       this.valueTextBox.TabIndex = 1;
     66      this.valueTextBox.TabIndex = 2;
    6767      this.valueTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.valueTextBox_KeyDown);
    6868      this.valueTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.valueTextBox_Validating);
     
    8080      this.valueLabel.Name = "valueLabel";
    8181      this.valueLabel.Size = new System.Drawing.Size(37, 13);
    82       this.valueLabel.TabIndex = 0;
     82      this.valueLabel.TabIndex = 1;
    8383      this.valueLabel.Text = "&Value:";
    8484      //
     
    101101      this.splitContainer.SplitterDistance = 41;
    102102      this.splitContainer.SplitterWidth = 1;
    103       this.splitContainer.TabIndex = 2;
     103      this.splitContainer.TabIndex = 0;
     104      this.splitContainer.TabStop = false;
    104105      //
    105106      // StringConvertibleValueView
  • branches/histogram/HeuristicLab.Data.Views/3.3/StringConvertibleValueView.cs

    r5908 r6011  
    9191      if (e.KeyCode == Keys.Escape) {
    9292        valueTextBox.Text = Content.GetValue();
    93         valueLabel.Focus();  // select label to validate data
     93        valueLabel.Select();  // select label to validate data
    9494      }
    9595    }
  • branches/histogram/HeuristicLab.Encodings.PermutationEncoding

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/histogram/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Analyzers/SymbolicExpressionSymbolFrequencyAnalyzer.cs

    r5809 r6011  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2728using HeuristicLab.Operators;
    2829using HeuristicLab.Optimization;
     
    4041    private const string ResultsParameterName = "Results";
    4142    private const string SymbolFrequenciesParameterName = "SymbolFrequencies";
     43    private const string AggregateSymbolsWithDifferentSubtreeCountParameterName = "AggregateSymbolsWithDifferentSubtreeCount";
    4244
    4345    #region parameter properties
     
    5153      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
    5254    }
     55    public IValueParameter<BoolValue> AggregateSymbolsWithDifferentSubtreeCountParameter {
     56      get { return (IValueParameter<BoolValue>)Parameters[AggregateSymbolsWithDifferentSubtreeCountParameterName]; }
     57    }
    5358    #endregion
    5459    #region properties
    55     public DataTable SymbolFrequencies {
    56       get { return SymbolFrequenciesParameter.ActualValue; }
    57       set { SymbolFrequenciesParameter.ActualValue = value; }
     60    public BoolValue AggregrateSymbolsWithDifferentSubtreeCount {
     61      get { return AggregateSymbolsWithDifferentSubtreeCountParameter.Value; }
     62      set { AggregateSymbolsWithDifferentSubtreeCountParameter.Value = value; }
    5863    }
    5964    #endregion
     
    6570      : base() {
    6671      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees to analyze."));
    67       Parameters.Add(new ValueLookupParameter<DataTable>(SymbolFrequenciesParameterName, "The data table to store the symbol frequencies."));
     72      Parameters.Add(new LookupParameter<DataTable>(SymbolFrequenciesParameterName, "The data table to store the symbol frequencies."));
    6873      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The result collection where the symbol frequencies should be stored."));
     74      Parameters.Add(new ValueParameter<BoolValue>(AggregateSymbolsWithDifferentSubtreeCountParameterName, "Flag that indicates if the frequencies of symbols with the same name but different number of sub-trees should be aggregated.", new BoolValue(true)));
    6975    }
    7076    public override IDeepCloneable Clone(Cloner cloner) {
     
    7278    }
    7379
     80    [StorableHook(HookType.AfterDeserialization)]
     81    private void AfterDeserialization() {
     82      #region remove with HL 3.4
     83      if (!Parameters.ContainsKey(AggregateSymbolsWithDifferentSubtreeCountParameterName))
     84        Parameters.Add(new ValueParameter<BoolValue>(AggregateSymbolsWithDifferentSubtreeCountParameterName, "Flag that indicates if the frequencies of symbols with the same name but different number of sub-trees should be aggregated.", new BoolValue(true)));
     85      #endregion
     86    }
     87
    7488    public override IOperation Apply() {
    7589      ItemArray<ISymbolicExpressionTree> expressions = SymbolicExpressionTreeParameter.ActualValue;
    7690      ResultCollection results = ResultsParameter.ActualValue;
     91      DataTable symbolFrequencies = SymbolFrequenciesParameter.ActualValue;
     92      if (symbolFrequencies == null) {
     93        symbolFrequencies = new DataTable("Symbol frequencies", "Relative frequency of symbols aggregated over the whole population.");
     94        symbolFrequencies.VisualProperties.YAxisTitle = "Relative Symbol Frequency";
    7795
    78       if (SymbolFrequencies == null) {
    79         SymbolFrequencies = new DataTable("Symbol frequencies", "Relative frequency of symbols aggregated over the whole population.");
    80         SymbolFrequencies.VisualProperties.YAxisTitle = "Relative Symbol Frequency";
    81         results.Add(new Result("Symbol frequencies", SymbolFrequencies));
     96        SymbolFrequenciesParameter.ActualValue = symbolFrequencies;
     97        results.Add(new Result("Symbol frequencies", symbolFrequencies));
    8298      }
    8399
    84100      // all rows must have the same number of values so we can just take the first
    85       int numberOfValues = SymbolFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();
     101      int numberOfValues = symbolFrequencies.Rows.Select(r => r.Values.Count).DefaultIfEmpty().First();
    86102
    87       foreach (var pair in SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(expressions)) {
    88         if (!SymbolFrequencies.Rows.ContainsKey(pair.Key)) {
     103      foreach (var pair in SymbolicExpressionSymbolFrequencyAnalyzer.CalculateSymbolFrequencies(expressions, AggregrateSymbolsWithDifferentSubtreeCount.Value)) {
     104        if (!symbolFrequencies.Rows.ContainsKey(pair.Key)) {
    89105          // initialize a new row for the symbol and pad with zeros
    90106          DataRow row = new DataRow(pair.Key, "", Enumerable.Repeat(0.0, numberOfValues));
    91107          row.VisualProperties.StartIndexZero = true;
    92           SymbolFrequencies.Rows.Add(row);
     108          symbolFrequencies.Rows.Add(row);
    93109        }
    94         SymbolFrequencies.Rows[pair.Key].Values.Add(pair.Value);
     110        symbolFrequencies.Rows[pair.Key].Values.Add(pair.Value);
    95111      }
    96112
    97113      // add a zero for each data row that was not modified in the previous loop
    98       foreach (var row in SymbolFrequencies.Rows.Where(r => r.Values.Count != numberOfValues + 1))
     114      foreach (var row in symbolFrequencies.Rows.Where(r => r.Values.Count != numberOfValues + 1))
    99115        row.Values.Add(0.0);
    100116
     
    102118    }
    103119
    104     public static IEnumerable<KeyValuePair<string, double>> CalculateSymbolFrequencies(IEnumerable<ISymbolicExpressionTree> trees) {
     120    public static IEnumerable<KeyValuePair<string, double>> CalculateSymbolFrequencies(IEnumerable<ISymbolicExpressionTree> trees, bool aggregateDifferentNumberOfSubtrees = true) {
    105121      Dictionary<string, double> symbolFrequencies = new Dictionary<string, double>();
    106122      int totalNumberOfSymbols = 0;
     
    108124      foreach (var tree in trees) {
    109125        foreach (var node in tree.IterateNodesPrefix()) {
    110           if (symbolFrequencies.ContainsKey(node.Symbol.Name)) symbolFrequencies[node.Symbol.Name] += 1;
    111           else symbolFrequencies.Add(node.Symbol.Name, 1);
     126          string symbolName;
     127          if (aggregateDifferentNumberOfSubtrees) symbolName = node.Symbol.Name;
     128          else symbolName = node.Symbol.Name + "-" + node.SubtreesCount;
     129          if (symbolFrequencies.ContainsKey(symbolName)) symbolFrequencies[symbolName] += 1;
     130          else symbolFrequencies.Add(symbolName, 1);
    112131          totalNumberOfSymbols++;
    113132        }
  • branches/histogram/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs

    r5925 r6011  
    103103    public static void PTC2(IRandom random, ISymbolicExpressionTreeNode seedNode,
    104104      int maxLength, int maxDepth) {
     105      // make sure it is possible to create a trees smaller than maxLength and maxDepth
     106      if (seedNode.Grammar.GetMinimumExpressionLength(seedNode.Symbol) > maxLength)
     107        throw new ArgumentException("Cannot create trees of length " + maxLength + " or shorter because of grammar constraints.", "maxLength");
     108      if (seedNode.Grammar.GetMinimumExpressionDepth(seedNode.Symbol) > maxDepth)
     109        throw new ArgumentException("Cannot create trees of depth " + maxDepth + " or smaller because of grammar constraints.", "maxDepth");
     110
    105111      // tree length is limited by the grammar and by the explicit size constraints
    106112      int allowedMinLength = seedNode.Grammar.GetMinimumExpressionLength(seedNode.Symbol);
     
    149155        int argumentIndex = nextExtension.ChildIndex;
    150156        int extensionDepth = nextExtension.ExtensionPointDepth;
    151         if (extensionDepth + parent.Grammar.GetMinimumExpressionDepth(parent.Symbol) >= maxDepth) {
     157        if (parent.Grammar.GetMinimumExpressionDepth(parent.Symbol) >= maxDepth - extensionDepth) {
    152158          ReplaceWithMinimalTree(random, root, parent, argumentIndex);
    153159        } else {
     
    155161                                where s.InitialFrequency > 0.0
    156162                                where parent.Grammar.IsAllowedChildSymbol(parent.Symbol, s, argumentIndex)
    157                                 where parent.Grammar.GetMinimumExpressionDepth(s) + extensionDepth - 1 < maxDepth
     163                                where parent.Grammar.GetMinimumExpressionDepth(s) < maxDepth - extensionDepth + 1
    158164                                where parent.Grammar.GetMaximumExpressionLength(s) > targetLength - totalListMinLength - currentLength
    159165                                select s)
  • branches/histogram/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionGrammarBase.cs

    r5809 r6011  
    229229
    230230    public virtual IEnumerable<ISymbol> GetAllowedChildSymbols(ISymbol parent) {
    231       return from s in Symbols where IsAllowedChildSymbol(parent, s) select s;
     231      return from s in AllowedSymbols where IsAllowedChildSymbol(parent, s) select s;
    232232    }
    233233
     
    265265        cachedMinExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion
    266266        long sumOfMinExpressionLengths = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol))
    267                                               let minForSlot = (long)(from s in Symbols
     267                                              let minForSlot = (long)(from s in AllowedSymbols
    268268                                                                      where IsAllowedChildSymbol(symbol, s, argIndex)
    269269                                                                      select GetMinimumExpressionLength(s)).DefaultIfEmpty(0).Min()
     
    282282        cachedMaxExpressionLength[symbol.Name] = int.MaxValue; // prevent infinite recursion
    283283        long sumOfMaxTrees = 1 + (from argIndex in Enumerable.Range(0, GetMaximumSubtreeCount(symbol))
    284                                   let maxForSlot = (long)(from s in Symbols
     284                                  let maxForSlot = (long)(from s in AllowedSymbols
    285285                                                          where IsAllowedChildSymbol(symbol, s, argIndex)
    286286                                                          select GetMaximumExpressionLength(s)).DefaultIfEmpty(0).Max()
    287287                                  select maxForSlot).DefaultIfEmpty(0).Sum();
    288         long limit = int.MaxValue;
    289         cachedMaxExpressionLength[symbol.Name] = (int)Math.Min(sumOfMaxTrees, limit);
     288        cachedMaxExpressionLength[symbol.Name] = (int)Math.Min(sumOfMaxTrees, int.MaxValue);
    290289        return cachedMaxExpressionLength[symbol.Name];
    291290      }
     
    298297      if (!cachedMinExpressionDepth.TryGetValue(symbol.Name, out temp)) {
    299298        cachedMinExpressionDepth[symbol.Name] = int.MaxValue; // prevent infinite recursion
    300         cachedMinExpressionDepth[symbol.Name] = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol))
    301                                                      let minForSlot = (from s in Symbols
    302                                                                        where IsAllowedChildSymbol(symbol, s, argIndex)
    303                                                                        select GetMinimumExpressionDepth(s)).DefaultIfEmpty(0).Min()
    304                                                      select minForSlot).DefaultIfEmpty(0).Max();
     299        long minDepth = 1 + (from argIndex in Enumerable.Range(0, GetMinimumSubtreeCount(symbol))
     300                             let minForSlot = (long)(from s in AllowedSymbols
     301                                                     where IsAllowedChildSymbol(symbol, s, argIndex)
     302                                                     select GetMinimumExpressionDepth(s)).DefaultIfEmpty(0).Min()
     303                             select minForSlot).DefaultIfEmpty(0).Max();
     304        cachedMinExpressionDepth[symbol.Name] = (int)Math.Min(minDepth, int.MaxValue);
    305305        return cachedMinExpressionDepth[symbol.Name];
    306306      }
  • branches/histogram/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.Designer.cs

    r5824 r6011  
    204204      this.chart.Text = "chart";
    205205      this.chart.AxisViewChanged += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.ViewEventArgs>(this.chart_AxisViewChanged);
    206       this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown);
     206      this.chart.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.chart_DoubleClick);
    207207      this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove);
    208208      this.chart.MouseUp += new System.Windows.Forms.MouseEventHandler(this.chart_MouseUp);
  • branches/histogram/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r5837 r6011  
    432432
    433433    #region Drag & drop and tooltip
    434     private IRun draggedRun;
    435     private void chart_MouseDown(object sender, MouseEventArgs e) {
     434    private void chart_DoubleClick(object sender, MouseEventArgs e) {
    436435      HitTestResult h = this.chart.HitTest(e.X, e.Y);
    437436      if (h.ChartElementType == ChartElementType.DataPoint) {
    438437        IRun run = (IRun)((DataPoint)h.Object).Tag;
    439         if (e.Clicks >= 2) {
    440           IContentView view = MainFormManager.MainForm.ShowContent(run);
    441           if (view != null) {
    442             view.ReadOnly = this.ReadOnly;
    443             view.Locked = this.Locked;
    444           }
    445         } else
    446           this.draggedRun = run;
     438        IContentView view = MainFormManager.MainForm.ShowContent(run);
     439        if (view != null) {
     440          view.ReadOnly = this.ReadOnly;
     441          view.Locked = this.Locked;
     442        }
    447443        this.chart.ChartAreas[0].CursorX.SetSelectionPosition(double.NaN, double.NaN);
    448444        this.chart.ChartAreas[0].CursorY.SetSelectionPosition(double.NaN, double.NaN);
     
    452448    private void chart_MouseUp(object sender, MouseEventArgs e) {
    453449      if (isSelecting) {
    454         Content.UpdateOfRunsInProgress = true;
    455450        System.Windows.Forms.DataVisualization.Charting.Cursor xCursor = chart.ChartAreas[0].CursorX;
    456451        System.Windows.Forms.DataVisualization.Charting.Cursor yCursor = chart.ChartAreas[0].CursorY;
     
    484479        this.chart.ChartAreas[0].CursorX.SelectionStart = this.chart.ChartAreas[0].CursorX.SelectionEnd;
    485480        this.chart.ChartAreas[0].CursorY.SelectionStart = this.chart.ChartAreas[0].CursorY.SelectionEnd;
    486         Content.UpdateOfRunsInProgress = false;
    487481      }
    488482    }
     
    490484    private void chart_MouseMove(object sender, MouseEventArgs e) {
    491485      HitTestResult h = this.chart.HitTest(e.X, e.Y);
    492       if (!Locked) {
    493         if (this.draggedRun != null && h.ChartElementType != ChartElementType.DataPoint) {
    494           DataObject data = new DataObject();
    495           data.SetData(HeuristicLab.Common.Constants.DragDropDataFormat, draggedRun);
    496           if (ReadOnly)
    497             DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link);
    498           else {
    499             DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move);
    500             if ((result & DragDropEffects.Move) == DragDropEffects.Move)
    501               Content.Remove(draggedRun);
    502           }
    503           this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !isSelecting;
    504           this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !isSelecting;
    505           this.draggedRun = null;
    506         }
    507       }
    508 
    509486      string newTooltipText = string.Empty;
    510487      string oldTooltipText;
     
    670647
    671648    private void ColorRuns(string axisValue) {
    672       Content.UpdateOfRunsInProgress = true;
    673649      var runs = Content.Select(r => new { Run = r, Value = GetValue(r, axisValue) }).Where(r => r.Value.HasValue);
    674650      double minValue = runs.Min(r => r.Value.Value);
     
    678654      foreach (var r in runs) {
    679655        int colorIndex = 0;
    680         if (!range.IsAlmost(0)) colorIndex = (int)((ColorGradient.Colors.Count - 1) * (r.Value.Value - minValue) / (maxValue - minValue));
     656        if (!range.IsAlmost(0)) colorIndex = (int)((ColorGradient.Colors.Count - 1) * (r.Value.Value - minValue) / (range));
    681657        r.Run.Color = ColorGradient.Colors[colorIndex];
    682658      }
    683       Content.UpdateOfRunsInProgress = false;
    684659    }
    685660    #endregion
  • branches/histogram/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/histogram/HeuristicLab.Persistence

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/histogram/HeuristicLab.PluginInfrastructure/3.3/ErrorHandling/ErrorHandling.cs

    r5445 r6011  
    2525namespace HeuristicLab.PluginInfrastructure {
    2626  public static class ErrorHandling {
    27     public static readonly string NewLine = Environment.NewLine;
    28 
    2927    public static string BuildErrorMessage(Exception exception) {
    3028      if (exception == null) {
    3129        return string.Empty;
    3230      } else {
    33         string message = exception.GetType().Name + ": " + exception.Message + NewLine +
     31        string message = exception.GetType().Name + ": " + exception.Message + Environment.NewLine +
    3432                         exception.StackTrace;
    3533
    3634        while (exception.InnerException != null) {
    3735          exception = exception.InnerException;
    38           message += NewLine +
    39                      "-----" + NewLine +
    40                      exception.GetType().Name + ": " + exception.Message + NewLine +
     36          message += Environment.NewLine +
     37                     "-----" + Environment.NewLine +
     38                     exception.GetType().Name + ": " + exception.Message + Environment.NewLine +
    4139                     exception.StackTrace;
    4240        }
     
    5351    public static void ShowErrorDialog(string message, Exception exception) {
    5452      using (ErrorDialog dialog = new ErrorDialog(message, exception)) {
     53        dialog.StartPosition = FormStartPosition.CenterScreen;
    5554        dialog.ShowDialog();
    5655      }
  • branches/histogram/HeuristicLab.PluginInfrastructure/3.3/HeuristicLab.PluginInfrastructure-3.3.csproj

    r5741 r6011  
    229229    <Compile Include="ErrorHandling\ErrorHandling.cs">
    230230    </Compile>
     231    <Compile Include="ErrorHandling\FrameworkVersionErrorDialog.cs">
     232      <SubType>Form</SubType>
     233    </Compile>
     234    <Compile Include="ErrorHandling\FrameworkVersionErrorDialog.Designer.cs">
     235      <DependentUpon>FrameworkVersionErrorDialog.cs</DependentUpon>
     236    </Compile>
    231237    <Compile Include="LightweightApplicationManager.cs" />
    232238    <Compile Include="Interfaces\IPluginFile.cs" />
  • branches/histogram/HeuristicLab.PluginInfrastructure/3.3/Main.cs

    r5445 r6011  
    3434    /// <param name="args">Command line arguments</param>
    3535    public static void Run(string[] args) {
    36       try {
     36      if (!FrameworkVersionErrorDialog.NET4FullProfileInstalled) {
    3737        Application.EnableVisualStyles();
    3838        Application.SetCompatibleTextRenderingDefault(false);
    39         Application.Run(new StarterForm());
    40       }
    41       catch (Exception ex) {
    42         ErrorHandling.ShowErrorDialog(ex);
     39        Application.Run(new FrameworkVersionErrorDialog());
     40      } else {
     41        try {
     42          Application.EnableVisualStyles();
     43          Application.SetCompatibleTextRenderingDefault(false);
     44          Application.Run(new StarterForm());
     45        }
     46        catch (Exception ex) {
     47          ErrorHandling.ShowErrorDialog(ex);
     48        }
    4349      }
    4450    }
  • branches/histogram/HeuristicLab.PluginInfrastructure/3.3/Starter/SplashScreen.Designer.cs

    r5445 r6011  
    113113      this.Controls.Add(this.infoLabel);
    114114      this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
     115      this.Icon = HeuristicLab.PluginInfrastructure.Resources.HeuristicLab;
    115116      this.MaximizeBox = false;
    116117      this.MinimizeBox = false;
    117118      this.Name = "SplashScreen";
    118       this.Opacity = 0.99;
     119      this.Opacity = 0.99D;
    119120      this.ShowInTaskbar = false;
    120121      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  • branches/histogram/HeuristicLab.Problems.DataAnalysis

  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/InteractiveSymbolicDiscriminantFunctionClassificationSolutionSimplifierView.cs

    r5942 r6011  
    5959    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    6060      Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    61       foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) {
    62         if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) {
    63           replacementValues[node] = CalculateReplacementValue(node);
    64         }
     61      foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     62        replacementValues[node] = CalculateReplacementValue(node, tree);
    6563      }
    6664      return replacementValues;
     
    9088      foreach (ISymbolicExpressionTreeNode node in nodes) {
    9189        var parent = node.Parent;
    92         constantNode.Value = CalculateReplacementValue(node);
     90        constantNode.Value = CalculateReplacementValue(node, tree);
    9391        ISymbolicExpressionTreeNode replacementNode = constantNode;
    9492        SwitchNode(parent, node, replacementNode);
     
    111109    }
    112110
    113     private double CalculateReplacementValue(ISymbolicExpressionTreeNode node) {
     111    private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {
     112      // remove old ADFs
     113      while (tempTree.Root.SubtreesCount > 1) tempTree.Root.RemoveSubtree(1);
     114      // clone ADFs of source tree
     115      for (int i = 1; i < sourceTree.Root.SubtreesCount; i++) {
     116        tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
     117      }
    114118      var start = tempTree.Root.GetSubtree(0);
    115119      while (start.SubtreesCount > 0) start.RemoveSubtree(0);
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views/3.4/SymbolicDiscriminantFunctionClassificationSolutionView.cs

    r5834 r6011  
    2727namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification.Views {
    2828  [Content(typeof(SymbolicDiscriminantFunctionClassificationSolution), true)]
    29   [View("SymbolicDiscriminan FunctionClassificationSolution View")]
     29  [View("SymbolicDiscriminantFunctionClassificationSolution View")]
    3030  public partial class SymbolicDiscriminantFunctionClassificationSolutionView : DiscriminantFunctionClassificationSolutionView {
    3131    public SymbolicDiscriminantFunctionClassificationSolutionView() {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicDiscriminantFunctionClassificationSolution.cs

    r5818 r6011  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    23 using System.Linq;
     22using System;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
    2625using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Operators;
    29 using HeuristicLab.Parameters;
     26using HeuristicLab.Optimization;
    3027using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    31 using HeuristicLab.Optimization;
    32 using System;
    3328
    3429namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    3934  [Item(Name = "SymbolicDiscriminantFunctionClassificationSolution", Description = "Represents a symbolic classification solution (model + data) and attributes of the solution like accuracy and complexity.")]
    4035  public sealed class SymbolicDiscriminantFunctionClassificationSolution : DiscriminantFunctionClassificationSolution, ISymbolicClassificationSolution {
    41     private const string ModelLengthResultName = "ModelLength";
    42     private const string ModelDepthResultName = "ModelDepth";
     36    private const string ModelLengthResultName = "Model Length";
     37    private const string ModelDepthResultName = "Model Depth";
    4338
    4439    public new ISymbolicDiscriminantFunctionClassificationModel Model {
     
    8782      ModelLength = Model.SymbolicExpressionTree.Length;
    8883      ModelDepth = Model.SymbolicExpressionTree.Depth;
    89     }   
     84    }
    9085  }
    9186}
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/InteractiveSymbolicRegressionSolutionSimplifierView.cs

    r5942 r6011  
    6060    protected override Dictionary<ISymbolicExpressionTreeNode, double> CalculateReplacementValues(ISymbolicExpressionTree tree) {
    6161      Dictionary<ISymbolicExpressionTreeNode, double> replacementValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    62       foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) {
    63         if (!(node.Symbol is ProgramRootSymbol || node.Symbol is StartSymbol)) {
    64           replacementValues[node] = CalculateReplacementValue(node);
    65         }
     62      foreach (ISymbolicExpressionTreeNode node in tree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix()) {
     63        replacementValues[node] = CalculateReplacementValue(node, tree);
    6664      }
    6765      return replacementValues;
     
    8482      foreach (ISymbolicExpressionTreeNode node in nodes) {
    8583        var parent = node.Parent;
    86         constantNode.Value = CalculateReplacementValue(node);
     84        constantNode.Value = CalculateReplacementValue(node, tree);
    8785        ISymbolicExpressionTreeNode replacementNode = constantNode;
    8886        SwitchNode(parent, node, replacementNode);
     
    10098    }
    10199
    102     private double CalculateReplacementValue(ISymbolicExpressionTreeNode node) {
     100    private double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree) {
     101      // remove old ADFs
     102      while (tempTree.Root.SubtreesCount > 1) tempTree.Root.RemoveSubtree(1);
     103      // clone ADFs of source tree
     104      for (int i = 1; i < sourceTree.Root.SubtreesCount; i++) {
     105        tempTree.Root.AddSubtree((ISymbolicExpressionTreeNode)sourceTree.Root.GetSubtree(i).Clone());
     106      }
    103107      var start = tempTree.Root.GetSubtree(0);
    104108      while (start.SubtreesCount > 0) start.RemoveSubtree(0);
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolution.cs

    r5914 r6011  
    3434  [Item(Name = "SymbolicRegressionSolution", Description = "Represents a symbolic regression solution (model + data) and attributes of the solution like accuracy and complexity.")]
    3535  public sealed class SymbolicRegressionSolution : RegressionSolution, ISymbolicRegressionSolution {
    36     private const string ModelLengthResultName = "ModelLength";
    37     private const string ModelDepthResultName = "ModelDepth";
     36    private const string ModelLengthResultName = "Model Length";
     37    private const string ModelDepthResultName = "Model Depth";
    3838
    3939    public new ISymbolicRegressionModel Model {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/GraphicalSymbolicDataAnalysisModelView.cs

    r5834 r6011  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    27   [View("SymbolicDataAnalysisModel GraphicalRepresentation")]
     27  [View("Graphical Representation")]
    2828  [Content(typeof(ISymbolicDataAnalysisModel), true)]
    2929  public partial class GraphicalSymbolicDataAnalysisModelView : AsynchronousContentView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r5809 r6011  
    9696          for (int subTreeIndex = 0; subTreeIndex < parent.SubtreesCount; subTreeIndex++) {
    9797            var child = parent.GetSubtree(subTreeIndex);
    98             if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(1.0)) {
     98            if (!(child.Symbol is Constant) && nodeImpacts[child].IsAlmost(0.0)) {
    9999              SwitchNodeWithReplacementNode(parent, subTreeIndex);
    100100            }
    101101          }
    102102        }
    103         // show only interesting part of solution
    104         this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
     103        // show only interesting part of solution
     104        if (tree.Root.SubtreesCount > 1)
     105          this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs
     106        else
     107          this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB
    105108        this.PaintNodeImpacts();
    106109      }
     
    126129        for (int i = 0; i < treeNode.SubtreesCount; i++) {
    127130          ISymbolicExpressionTreeNode subTree = treeNode.GetSubtree(i);
    128           if (subTree == visualTreeNode.SymbolicExpressionTreeNode) {
     131          // only allow to replace nodes for which a replacement value is known (replacement value for ADF nodes are not available)
     132          if (subTree == visualTreeNode.SymbolicExpressionTreeNode && replacementNodes.ContainsKey(subTree)) {
     133            double replacementImpact = nodeImpacts.ContainsKey(replacementNodes[subTree]) ? nodeImpacts[replacementNodes[subTree]] : 0.0;
     134            double originalImpact = nodeImpacts.ContainsKey(subTree) ? nodeImpacts[subTree] : 0.0;
    129135            SwitchNodeWithReplacementNode(treeNode, i);
    130           }
    131         }
    132       }
    133 
    134       // show only interesting part of solution
    135       this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0));
    136 
    137       UpdateModel(tree);
     136
     137            // show only interesting part of solution
     138            if (tree.Root.SubtreesCount > 1)
     139              this.treeChart.Tree = new SymbolicExpressionTree(tree.Root); // RPB + ADFs
     140            else
     141              this.treeChart.Tree = new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); // 1st child of RPB
     142            if (!(originalImpact.IsAlmost(0.0) && replacementImpact.IsAlmost(0.0))) {
     143              // update everything after the change if necessary (impact != 0)           
     144              UpdateModel(tree);
     145            } else {
     146              // both impacts are zero, so we only need to repaint the nodes
     147              PaintNodeImpacts();
     148            }
     149            return; // break all loops
     150          }
     151        }
     152      }
    138153    }
    139154
     
    176191            visualTree.ToolTip += Environment.NewLine + "Replacement value: " + constantReplacementNode.Value;
    177192          }
    178         }
     193        } 
    179194      }
    180195      this.PaintCollapsedNodes();
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/RunCollectionVariableImpactView.cs

    r5834 r6011  
    3232namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    3333  [Content(typeof(RunCollection), false)]
    34   [View("RunCollection VariableImpacts")]
     34  [View("Variable Impacts")]
    3535  public sealed partial class RunCollectionVariableImpactView : AsynchronousContentView {
    3636    private const string variableImpactResultName = "Variable impacts";
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TextualSymbolicDataAnalysisModelView.cs

    r5834 r6011  
    2525
    2626namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    27   [View("SymbolicDataAnalysisModel TextualRepresentation")]
     27  [View("Textual Representation")]
    2828  [Content(typeof(ISymbolicDataAnalysisModel), false)]
    2929  public partial class TextualSymbolicDataAnalysisModelView : AsynchronousContentView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionTreeInterpreter.cs

    r5925 r6011  
    3636    #region private classes
    3737    private class InterpreterState {
    38       private const int ARGUMENT_STACK_SIZE = 1024;
    3938      private double[] argumentStack;
    4039      private int argumentStackPointer;
     
    4544        set { pc = value; }
    4645      }
    47       internal InterpreterState(Instruction[] code) {
     46      internal InterpreterState(Instruction[] code, int argumentStackSize) {
    4847        this.code = code;
    4948        this.pc = 0;
    50         this.argumentStack = new double[ARGUMENT_STACK_SIZE];
     49        if (argumentStackSize > 0) {
     50          this.argumentStack = new double[argumentStackSize];
     51        }
    5152        this.argumentStackPointer = 0;
    5253      }
     
    202203      var compiler = new SymbolicExpressionTreeCompiler();
    203204      Instruction[] code = compiler.Compile(tree, MapSymbolToOpCode);
    204 
     205      int necessaryArgStackSize = 0;
    205206      for (int i = 0; i < code.Length; i++) {
    206207        Instruction instr = code[i];
     
    216217          var variableConditionTreeNode = instr.dynamicNode as VariableConditionTreeNode;
    217218          instr.iArg0 = (ushort)dataset.GetVariableIndex(variableConditionTreeNode.VariableName);
     219        } else if (instr.opCode == OpCodes.Call) {
     220          necessaryArgStackSize += instr.nArguments + 1;
    218221        }
    219222      }
    220       var state = new InterpreterState(code);
     223      var state = new InterpreterState(code, necessaryArgStackSize);
    221224
    222225      foreach (var rowEnum in rows) {
     
    370373            double f_3 = Evaluate(dataset, ref row, state); row--;
    371374            state.ProgramCounter = savedPc;
    372             double f_4 = Evaluate(dataset, ref row, state); 
     375            double f_4 = Evaluate(dataset, ref row, state);
    373376            row += 4;
    374377
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionConfusionMatrixView.cs

    r5834 r6011  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
    31   [View("ClassificationSolution ConfusionMatrix")]
     31  [View("Confusion Matrix")]
    3232  [Content(typeof(IClassificationSolution))]
    3333  public partial class ClassificationSolutionConfusionMatrixView : ItemView, IClassificationSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/ClassificationSolutionEstimatedClassValuesView.cs

    r5834 r6011  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
    31   [View("ClassificationSolution EstimatedClassValues")]
     31  [View("Estimated Class Values")]
    3232  [Content(typeof(IClassificationSolution))]
    3333  public partial class ClassificationSolutionEstimatedClassValuesView : ItemView, IClassificationSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationRocCurvesView.cs

    r5834 r6011  
    3232using HeuristicLab.MainForm.WindowsForms;
    3333namespace HeuristicLab.Problems.DataAnalysis.Views {
    34   [View("DiscriminantFunctionClassificationSolution ROC Curves")]
     34  [View("ROC Curves")]
    3535  [Content(typeof(IDiscriminantFunctionClassificationSolution))]
    3636  public partial class DiscriminantFunctionClassificationRocCurvesView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionEstimatedClassValuesView.cs

    r5834 r6011  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
    31   [View("DiscriminantFunctionClassificationSolution EstimatedClassValues")]
     31  [View("Estimated Class Values")]
    3232  [Content(typeof(IDiscriminantFunctionClassificationSolution))]
    3333  public partial class DiscriminantFunctionClassificationSolutionEstimatedClassValuesView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Classification/DiscriminantFunctionClassificationSolutionThresholdView.cs

    r5834 r6011  
    3232
    3333namespace HeuristicLab.Problems.DataAnalysis.Views {
    34   [View("DsicriminantFunctionClassificationSolution ThresholdView")]
     34  [View("Classification Threshold")]
    3535  [Content(typeof(IDiscriminantFunctionClassificationSolution), true)]
    3636  public sealed partial class DiscriminantFunctionClassificationSolutionThresholdView : ItemView, IDiscriminantFunctionClassificationSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Clustering/ClusteringSolutionEstimatedClusterView.cs

    r5853 r6011  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
    31   [View("ClusteringSolution EstimatedCluster")]
     31  [View("Estimated Clusters")]
    3232  [Content(typeof(IClusteringSolution))]
    3333  public partial class ClusteringSolutionEstimatedClusterView : ItemView, IClusteringSolutionEvaluationView {
     
    101101
    102102          matrix = new DoubleMatrix(values);
    103           var columnNames = dataset.VariableNames.ToList();
     103          var columnNames = Content.ProblemData.AllowedInputVariables.ToList();
    104104          columnNames.Insert(0, CLUSTER_NAMES);
    105105          matrix.ColumnNames = columnNames;
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/ClusteringSolutionView.cs

    r5853 r6011  
    2626
    2727namespace HeuristicLab.Problems.DataAnalysis.Views {
    28   [View("RegressionSolution View")]
     28  [View("ClusteringSolution View")]
    2929  [Content(typeof(ClusteringSolution), true)]
    3030  public partial class ClusteringSolutionView : DataAnalysisSolutionView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionEstimatedValuesView.cs

    r5834 r6011  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
    31   [View("RegressionSolution EstimatedValues")]
     31  [View("Estimated Values")]
    3232  [Content(typeof(IRegressionSolution))]
    3333  public partial class RegressionSolutionEstimatedValuesView : ItemView, IRegressionSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartView.cs

    r5834 r6011  
    2929
    3030namespace HeuristicLab.Problems.DataAnalysis.Views {
    31   [View("RegressionSolution LineChart")]
     31  [View("Line Chart")]
    3232  [Content(typeof(IRegressionSolution))]
    3333  public partial class RegressionSolutionLineChartView : ItemView, IRegressionSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionScatterPlotView.cs

    r5834 r6011  
    3030
    3131namespace HeuristicLab.Problems.DataAnalysis.Views {
    32   [View("RegressionSolution ScatterPlot")]
     32  [View("Scatter Plot")]
    3333  [Content(typeof(IRegressionSolution))]
    3434  public partial class RegressionSolutionScatterPlotView : ItemView, IRegressionSolutionEvaluationView {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs

    r5942 r6011  
    107107      Add(new Result(TrainingRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the training partition", new PercentValue()));
    108108      Add(new Result(TestRelativeErrorResultName, "Average of the relative errors of the model output and the actual values on the test partition", new PercentValue()));
    109       Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "", new DoubleValue()));
    110       Add(new Result(TestNormalizedMeanSquaredErrorResultName, "", new DoubleValue()));
     109      Add(new Result(TrainingNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the training partition", new DoubleValue()));
     110      Add(new Result(TestNormalizedMeanSquaredErrorResultName, "Normalized mean of squared errors of the model on the test partition", new DoubleValue()));
    111111
    112112      RecalculateResults();
  • branches/histogram/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineNormalizedMeanSquaredErrorCalculator.cs

    r5945 r6011  
    6868      OnlineNormalizedMeanSquaredErrorCalculator normalizedMSECalculator = new OnlineNormalizedMeanSquaredErrorCalculator();
    6969
     70      //needed because otherwise the normalizedMSECalculator is in ErrorState.InsufficientValuesAdded
     71      if (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
     72        double estimated = secondEnumerator.Current;
     73        double original = firstEnumerator.Current;
     74        normalizedMSECalculator.Add(original, estimated);
     75      }
     76
    7077      // always move forward both enumerators (do not use short-circuit evaluation!)
    7178      while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) {
  • branches/histogram/HeuristicLab.Problems.DataAnalysis/3.4/Tests/OnlineCalculatorPerformanceTest.cs

    r5952 r6011  
    7575      var twister = new MersenneTwister(31415);
    7676      var dataset = CreateRandomDataset(twister, Rows, Columns);
    77       var errorState = new OnlineCalculatorError();
     77      OnlineCalculatorError errorState = OnlineCalculatorError.None; ;
    7878
    7979      Stopwatch watch = new Stopwatch();
     
    8181      for (int i = 0; i < Repetitions; i++) {
    8282        double value = calculateFunc(dataset.GetEnumeratedVariableValues(0), dataset.GetEnumeratedVariableValues(1), out errorState);
    83 
    8483      }
     84      Assert.AreEqual(errorState, OnlineCalculatorError.None);
    8585      watch.Stop();
    8686
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment.Views/3.3

    • Property svn:ignore
      •  

        old new  
        22obj
        33Plugin.cs
         4*.vs10x
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3

    • Property svn:ignore
      •  

        old new  
        33Plugin.cs
        44*.user
         5*.vs10x
  • branches/histogram/HeuristicLab.Problems.QuadraticAssignment/3.3/Tests

    • Property svn:ignore
      •  

        old new  
        11bin
        22obj
         3*.vs10x
  • branches/histogram/HeuristicLab.Problems.VehicleRouting

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

    • Property svn:mergeinfo changed (with no actual effect on merging)
  • branches/histogram/HeuristicLab.Selection/3.3/NoSameMatesSelector.cs

    r5957 r6011  
    11using System;
     2using System.Collections.Generic;
    23using System.Linq;
    3 using System.Collections.Generic;
    44using System.Threading;
    55using HeuristicLab.Common;
     
    5555    [StorableConstructor]
    5656    protected NoSameMatesSelector(bool deserializing) : base(deserializing) { }
    57     protected NoSameMatesSelector(NoSameMatesSelector original, Cloner cloner) : base(original, cloner) {
     57    protected NoSameMatesSelector(NoSameMatesSelector original, Cloner cloner)
     58      : base(original, cloner) {
    5859      RegisterParameterEventHandlers();
    5960    }
     
    6263    }
    6364
    64     public NoSameMatesSelector() : base() {
     65    public NoSameMatesSelector()
     66      : base() {
    6567      #region Create parameters
    6668      Parameters.Add(new ValueParameter<ISingleObjectiveSelector>(SelectorParameterName, "The inner selection operator to select the parents.", new TournamentSelector()));
     
    8587          Parameters.Add(new ValueParameter<ISingleObjectiveSelector>(SelectorParameterName, "The inner selection operator to select the parents.", selector));
    8688        }
    87       }   
     89      }
    8890      // FixedValueParameter for quality difference percentage, max attempts, use range
    8991      if (Parameters.ContainsKey(QualityDifferencePercentageParameterName)) {
     
    153155        ScopeList parents = CurrentScope.SubScopes[1].SubScopes;
    154156
    155         for (int indexParent1 = 0, indexParent2 = 1; 
    156              indexParent1 < parents.Count - 1 && selectedParents < parentsToSelect - 1; 
     157        for (int indexParent1 = 0, indexParent2 = 1;
     158             indexParent1 < parents.Count - 1 && selectedParents < parentsToSelect - 1;
    157159             indexParent1 += 2, indexParent2 += 2) {
    158160          double qualityParent1 = ((DoubleValue)parents[indexParent1].Variables[qualityName].Value).Value;
     
    168170          }
    169171
    170           if (parentsDifferent) { 
     172          if (parentsDifferent) {
    171173            // inner selector already copied scopes, no cloning necessary here
    172174            selected[selectedParents++] = parents[indexParent1];
     
    204206      if (CopySelected.Value != true) {
    205207        CopySelected.Value = true;
    206         throw new ArgumentException(Name + ": CopySelected must always be true.");
    207       }
    208     }
    209     #endregion
    210 
    211     #region Helpers 
     208      }
     209    }
     210    #endregion
     211
     212    #region Helpers
    212213    private void ParameterizeSelector(ISingleObjectiveSelector selector) {
    213214      selector.CopySelected = new BoolValue(true); // must always be true
Note: See TracChangeset for help on using the changeset viewer.