Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/31/13 13:17:49 (12 years ago)
Author:
gkronber
Message:

#1967: minor adaptations necessary for the EuroCAST presentation

Location:
branches/HeuristicLab.Problems.GaussianProcessTuning
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Problems.GaussianProcessTuning

    • Property svn:ignore
      •  

        old new  
        44*.testsettings
        55*.user
         6bin
  • branches/HeuristicLab.Problems.GaussianProcessTuning/GaussianProcessDemo/Form1.Designer.cs

    r9124 r9338  
    3232      this.splitContainer1 = new System.Windows.Forms.SplitContainer();
    3333      this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel();
     34      this.dataButton = new System.Windows.Forms.Button();
    3435      ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit();
    3536      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
     
    3738      this.splitContainer1.Panel2.SuspendLayout();
    3839      this.splitContainer1.SuspendLayout();
     40      this.flowLayoutPanel1.SuspendLayout();
    3941      this.SuspendLayout();
    4042      //
     
    5759      series2.Name = "GP (mean)";
    5860      series3.ChartArea = "ChartArea1";
    59       series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
     61      series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint;
    6062      series3.Legend = "Legend1";
    6163      series3.Name = "GP SEiso (mean)";
     
    8789      // flowLayoutPanel1
    8890      //
     91      this.flowLayoutPanel1.Controls.Add(this.dataButton);
    8992      this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill;
    9093      this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0);
     
    9295      this.flowLayoutPanel1.Size = new System.Drawing.Size(735, 126);
    9396      this.flowLayoutPanel1.TabIndex = 0;
     97      //
     98      // dataButton
     99      //
     100      this.dataButton.Location = new System.Drawing.Point(3, 3);
     101      this.dataButton.Name = "dataButton";
     102      this.dataButton.Size = new System.Drawing.Size(75, 23);
     103      this.dataButton.TabIndex = 0;
     104      this.dataButton.Text = "Data...";
     105      this.dataButton.UseVisualStyleBackColor = true;
     106      this.dataButton.Click += new System.EventHandler(this.dataButton_Click);
    94107      //
    95108      // Form1
     
    106119      ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
    107120      this.splitContainer1.ResumeLayout(false);
     121      this.flowLayoutPanel1.ResumeLayout(false);
    108122      this.ResumeLayout(false);
    109123
     
    115129    private System.Windows.Forms.SplitContainer splitContainer1;
    116130    private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1;
     131    private System.Windows.Forms.Button dataButton;
    117132  }
    118133}
  • branches/HeuristicLab.Problems.GaussianProcessTuning/GaussianProcessDemo/Form1.cs

    r9212 r9338  
    1010using HeuristicLab.Algorithms.DataAnalysis;
    1111using HeuristicLab.Core;
     12using HeuristicLab.Data;
    1213using HeuristicLab.Problems.DataAnalysis;
    1314using HeuristicLab.Problems.Instances.DataAnalysis;
     
    2728
    2829      var sum = new CovarianceSum();
    29       sum.Terms.Add(new CovariancePeriodic());
     30      var t = new CovarianceSquaredExponentialIso();
     31      t.InverseLengthParameter.Value = new DoubleValue(1.0 / Math.Exp(-2));
     32      sum.Terms.Add(t);
    3033      sum.Terms.Add(new CovarianceNoise());
    3134      this.covFunction = sum;
     
    3841    private void UpdateSliders() {
    3942      flowLayoutPanel1.Controls.Clear();
     43      flowLayoutPanel1.Controls.Add(dataButton);
    4044      for (int i = 0; i < covFunction.GetNumberOfParameters(1); i++) {
    4145        var sliderControl = new TrackBar();
     
    4953
    5054    private void InitData() {
    51       int n = 20;
     55      int n = 200;
    5256      data = new List<List<double>>();
    5357      data.Add(ValueGenerator.GenerateSteps(0, 1, 1.0 / n).ToList());
     
    6973      }
    7074
     75      var trainingData = new List<List<double>>();
     76      var trainingIndices = RandomEnumerable.SampleRandomWithoutRepetition(Enumerable.Range(0, y.Count), random, 10);
     77      var trainingY = trainingIndices.Select(i => y[i]).ToList();
     78      var trainingX = trainingIndices.Select(i => data[0][i]).ToList();
     79      trainingData.Add(trainingY);
     80      trainingData.Add(trainingX);
     81     
     82      //chart1.Series[2].Points.Clear();
     83      //foreach (var p in trainingY.Zip(trainingX, (t, x) => new { t, x })) {
     84      //  chart1.Series[2].Points.AddXY(p.x, p.t);
     85      //}
     86
    7187      var allData = new List<List<double>>();
    7288      allData.Add(y);
    7389      allData.Add(data[0]);
    7490      var variableNames = new string[] { "y", "x" };
    75       var ds = new Dataset(variableNames, allData);
    76       var rows = Enumerable.Range(0, data[0].Count);
    77       var correctModel = new GaussianProcessModel(ds, variableNames.First(), variableNames.Skip(1), rows, hyp, new MeanZero(),
     91      var fullDataSet = new Dataset(variableNames, allData);
     92      var trainingDataSet = new Dataset(variableNames, trainingData);
     93      var trainingRows = Enumerable.Range(0, trainingIndices.Count());
     94      var fullRows = Enumerable.Range(0, data[0].Count);
     95      var correctModel = new GaussianProcessModel(fullDataSet, variableNames.First(), variableNames.Skip(1), fullRows, hyp, new MeanZero(),
    7896                                                (ICovarianceFunction)covFunction.Clone());
    79       var yPred = correctModel.GetEstimatedValues(ds, rows);
     97      var yPred = correctModel.GetEstimatedValues(fullDataSet, fullRows);
    8098      chart1.Series[1].Points.Clear();
    8199      foreach (var p in yPred.Zip(data[0], (t, x) => new { t, x })) {
     
    86104    private double[] GetSliderValues() {
    87105      var hyp = new List<double>();
    88       foreach (var slider in flowLayoutPanel1.Controls.Cast<TrackBar>()) {
     106      foreach (var slider in flowLayoutPanel1.Controls.OfType<TrackBar>()) {
    89107        Console.Write(slider.Value / 10.0 + " ");
    90108        hyp.Add(slider.Value / 10.0);
     
    94112      return hyp.ToArray();
    95113    }
     114
     115    private void dataButton_Click(object sender, EventArgs e) {
     116      var dataForm = new Form();
     117      var dataTextField = new TextBox();
     118      dataTextField.Multiline = true;
     119      dataTextField.Text = DataToText();
     120      dataTextField.Dock = DockStyle.Fill;
     121      dataForm.Controls.Add(dataTextField);
     122      dataForm.ShowDialog();
     123    }
     124
     125    private string DataToText() {
     126      var str = new StringBuilder();
     127      foreach (var p in chart1.Series[1].Points) {
     128        str.AppendLine(p.XValue + "\t" + p.YValues.First());
     129      }
     130      return str.ToString();
     131    }
    96132  }
    97133}
Note: See TracChangeset for help on using the changeset viewer.