- Timestamp:
- 03/31/13 13:17:49 (12 years ago)
- Location:
- branches/HeuristicLab.Problems.GaussianProcessTuning
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GaussianProcessTuning
- Property svn:ignore
-
old new 4 4 *.testsettings 5 5 *.user 6 bin
-
- Property svn:ignore
-
branches/HeuristicLab.Problems.GaussianProcessTuning/GaussianProcessDemo/Form1.Designer.cs
r9124 r9338 32 32 this.splitContainer1 = new System.Windows.Forms.SplitContainer(); 33 33 this.flowLayoutPanel1 = new System.Windows.Forms.FlowLayoutPanel(); 34 this.dataButton = new System.Windows.Forms.Button(); 34 35 ((System.ComponentModel.ISupportInitialize)(this.chart1)).BeginInit(); 35 36 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); … … 37 38 this.splitContainer1.Panel2.SuspendLayout(); 38 39 this.splitContainer1.SuspendLayout(); 40 this.flowLayoutPanel1.SuspendLayout(); 39 41 this.SuspendLayout(); 40 42 // … … 57 59 series2.Name = "GP (mean)"; 58 60 series3.ChartArea = "ChartArea1"; 59 series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Fast Line;61 series3.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint; 60 62 series3.Legend = "Legend1"; 61 63 series3.Name = "GP SEiso (mean)"; … … 87 89 // flowLayoutPanel1 88 90 // 91 this.flowLayoutPanel1.Controls.Add(this.dataButton); 89 92 this.flowLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; 90 93 this.flowLayoutPanel1.Location = new System.Drawing.Point(0, 0); … … 92 95 this.flowLayoutPanel1.Size = new System.Drawing.Size(735, 126); 93 96 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); 94 107 // 95 108 // Form1 … … 106 119 ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit(); 107 120 this.splitContainer1.ResumeLayout(false); 121 this.flowLayoutPanel1.ResumeLayout(false); 108 122 this.ResumeLayout(false); 109 123 … … 115 129 private System.Windows.Forms.SplitContainer splitContainer1; 116 130 private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel1; 131 private System.Windows.Forms.Button dataButton; 117 132 } 118 133 } -
branches/HeuristicLab.Problems.GaussianProcessTuning/GaussianProcessDemo/Form1.cs
r9212 r9338 10 10 using HeuristicLab.Algorithms.DataAnalysis; 11 11 using HeuristicLab.Core; 12 using HeuristicLab.Data; 12 13 using HeuristicLab.Problems.DataAnalysis; 13 14 using HeuristicLab.Problems.Instances.DataAnalysis; … … 27 28 28 29 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); 30 33 sum.Terms.Add(new CovarianceNoise()); 31 34 this.covFunction = sum; … … 38 41 private void UpdateSliders() { 39 42 flowLayoutPanel1.Controls.Clear(); 43 flowLayoutPanel1.Controls.Add(dataButton); 40 44 for (int i = 0; i < covFunction.GetNumberOfParameters(1); i++) { 41 45 var sliderControl = new TrackBar(); … … 49 53 50 54 private void InitData() { 51 int n = 20 ;55 int n = 200; 52 56 data = new List<List<double>>(); 53 57 data.Add(ValueGenerator.GenerateSteps(0, 1, 1.0 / n).ToList()); … … 69 73 } 70 74 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 71 87 var allData = new List<List<double>>(); 72 88 allData.Add(y); 73 89 allData.Add(data[0]); 74 90 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(), 78 96 (ICovarianceFunction)covFunction.Clone()); 79 var yPred = correctModel.GetEstimatedValues( ds, rows);97 var yPred = correctModel.GetEstimatedValues(fullDataSet, fullRows); 80 98 chart1.Series[1].Points.Clear(); 81 99 foreach (var p in yPred.Zip(data[0], (t, x) => new { t, x })) { … … 86 104 private double[] GetSliderValues() { 87 105 var hyp = new List<double>(); 88 foreach (var slider in flowLayoutPanel1.Controls. Cast<TrackBar>()) {106 foreach (var slider in flowLayoutPanel1.Controls.OfType<TrackBar>()) { 89 107 Console.Write(slider.Value / 10.0 + " "); 90 108 hyp.Add(slider.Value / 10.0); … … 94 112 return hyp.ToArray(); 95 113 } 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 } 96 132 } 97 133 }
Note: See TracChangeset
for help on using the changeset viewer.