Changeset 9124 for branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Problems.Instances.DataAnalysis.GaussianProcessRegression
- Timestamp:
- 01/08/13 11:01:56 (12 years ago)
- Location:
- branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Problems.Instances.DataAnalysis.GaussianProcessRegression
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Problems.Instances.DataAnalysis.GaussianProcessRegression/GaussianProcessRegressionInstance.cs
r9112 r9124 30 30 31 31 public override string Name { 32 get { return "Gaussian Process " + covarianceFunction.ItemName; }32 get { return "Gaussian Process " + name; } 33 33 } 34 34 public override string Description { … … 36 36 } 37 37 protected override string TargetVariable { get { return "Y"; } } 38 protected override string[] VariableNames { get { return new string[] { "X1", " X2", "Y" }; } }39 protected override string[] AllowedInputVariables { get { return new string[] { "X1" , "X2"}; } }38 protected override string[] VariableNames { get { return new string[] { "X1", "Y" }; } } 39 protected override string[] AllowedInputVariables { get { return new string[] { "X1" }; } } 40 40 protected override int TrainingPartitionStart { get { return 0; } } 41 protected override int TrainingPartitionEnd { get { return 100; } }42 protected override int TestPartitionStart { get { return 100; } }43 protected override int TestPartitionEnd { get { return 200; } }41 protected override int TrainingPartitionEnd { get { return 200; } } 42 protected override int TestPartitionStart { get { return 200; } } 43 protected override int TestPartitionEnd { get { return 400; } } 44 44 45 private ICovarianceFunction covarianceFunction; 45 private ParameterizedCovarianceFunction cov; 46 private string name; 46 47 47 public GaussianProcessRegressionInstance(ICovarianceFunction covarianceFunction) { 48 this.covarianceFunction = covarianceFunction; 48 public GaussianProcessRegressionInstance(string name, ICovarianceFunction covarianceFunction, double[] hyp) { 49 this.name = name; 50 cov = covarianceFunction.GetParameterizedCovarianceFunction(hyp, null); 49 51 } 50 52 … … 53 55 List<List<double>> data = new List<List<double>>(); 54 56 for (int i = 0; i < AllowedInputVariables.Count(); i++) { 55 data.Add(ValueGenerator.GenerateSteps(0, 0.99, 0.01).ToList());56 data[i].AddRange(ValueGenerator.GenerateSteps( 0.005, 1, 0.01).ToList());57 data.Add(ValueGenerator.GenerateSteps(0, 0.99, 1.0 / TrainingPartitionEnd).ToList()); 58 data[i].AddRange(ValueGenerator.GenerateSteps(-0.5, 1.5, 2.0 / (TestPartitionEnd - TestPartitionStart)).ToList()); 57 59 } 58 60 var mt = new MersenneTwister(); 59 61 60 var noise = new CovarianceNoise();61 noise.SetParameter(new double[] { Math.Log(Math.Sqrt(0.01)) });62 var t = new CovarianceSum();63 t.Terms.Add(covarianceFunction);64 t.Terms.Add(noise);65 66 var p = Enumerable.Range(0, t.GetNumberOfParameters(data.Count)).Select(i => mt.NextDouble() - 1).ToArray();67 68 var cov = t.GetParameterizedCovarianceFunction(p, null);69 62 70 63 var target = Util.SampleGaussianProcess(mt, cov, data); -
branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Problems.Instances.DataAnalysis.GaussianProcessRegression/Instances.DataAnalysis.GaussianProcessRegression-3.3.csproj
r9112 r9124 178 178 </ItemGroup> 179 179 <ItemGroup> 180 <Compile Include="GaussianProcessSumOfRQIso.cs" /> 181 <Compile Include="GaussianProcessSumOfSEIso.cs" /> 180 182 <Compile Include="GaussianProcessRegressionInstance.cs" /> 181 183 <Compile Include="GaussianProcessSEIso6.cs" /> -
branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Problems.Instances.DataAnalysis.GaussianProcessRegression/Util.cs
r9099 r9124 31 31 32 32 33 public static List<double> SampleGaussianProcess(IRandom random, ParameterizedCovarianceFunction covFunction, List<List<double>> data) { 34 int n = data[0].Count; 33 35 34 public static List<double> SampleGaussianProcess(IRandom random, ParameterizedCovarianceFunction covFunction, List<List<double>> data) { 36 var normalRand = new NormalDistributedRandom(random, 0, 1); 37 var alpha = (from i in Enumerable.Range(0, n) 38 select normalRand.NextDouble()).ToArray(); 39 return SampleGaussianProcess(random, covFunction, data, alpha); 40 } 41 42 public static List<double> SampleGaussianProcess(IRandom random, ParameterizedCovarianceFunction covFunction, List<List<double>> data, double[] alpha) { 43 if (alpha.Length != data[0].Count) throw new ArgumentException(); 35 44 36 45 double[,] x = new double[data[0].Count, data.Count]; … … 43 52 K[i, j] = covFunction.Covariance(x, i, j); 44 53 45 var normalRand = new NormalDistributedRandom(random, 0, 1);46 47 54 if (!alglib.spdmatrixcholesky(ref K, K.GetLength(0), true)) throw new ArgumentException(); 48 var r = (from i in Enumerable.Range(0, K.GetLength(0))49 select normalRand.NextDouble()).ToArray();50 55 51 56 List<double> target = new List<double>(K.GetLength(0)); … … 54 59 for (int j = K.GetLength(0) - 1; j >= 0; j--) { 55 60 56 s += K[j, i] * r[j];61 s += K[j, i] * alpha[j]; 57 62 } 58 63 -
branches/HeuristicLab.Problems.GaussianProcessTuning/HeuristicLab.Problems.Instances.DataAnalysis.GaussianProcessRegression/VariousInstanceProvider.cs
r9112 r9124 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 24 25 using HeuristicLab.Algorithms.DataAnalysis; 25 26 … … 51 52 descriptorList.Add(new GaussianProcessSEIsoDependentNoise()); 52 53 53 var covs = new ICovarianceFunction[] { 54 new CovarianceSquaredExponentialIso(), 55 new CovarianceSquaredExponentialArd(), 56 new CovarianceLinear(), 57 new CovarianceLinearArd(), 58 new CovarianceMaternIso(), 59 new CovariancePeriodic(), 60 new CovarianceRationalQuadraticArd(), 61 new CovarianceRationalQuadraticIso() 62 }; 63 foreach (var cov in covs) { 64 descriptorList.Add(new GaussianProcessRegressionInstance(cov)); 54 { 55 var cov = new CovarianceSum(); 56 cov.Terms.Add(new CovarianceSquaredExponentialIso()); 57 cov.Terms.Add(new CovarianceSquaredExponentialIso()); 58 cov.Terms.Add(new CovarianceNoise()); 59 var hyp = new double[] { -2.8, -0.1, 0.5, 0.3, -1.5 }; 60 descriptorList.Add(new GaussianProcessRegressionInstance("SE+SE", cov, hyp)); 65 61 } 62 { 63 var cov = new CovarianceSum(); 64 cov.Terms.Add(new CovarianceRationalQuadraticIso()); 65 cov.Terms.Add(new CovarianceRationalQuadraticIso()); 66 cov.Terms.Add(new CovarianceNoise()); 67 var hyp = new double[] { -3, 0, 0, -1.5, 0, 2.5, -1.5 }; 68 descriptorList.Add(new GaussianProcessRegressionInstance("RQ+RQ", cov, hyp)); 69 } 70 { 71 var cov = new CovarianceSum(); 72 cov.Terms.Add(new CovariancePeriodic()); 73 cov.Terms.Add(new CovariancePeriodic()); 74 cov.Terms.Add(new CovarianceNoise()); 75 var hyp = new double[] { 0, -1.8, -1.5, 0, -0.5, -1, -2.1 }; 76 descriptorList.Add(new GaussianProcessRegressionInstance("Periodic+Periodic", cov, hyp)); 77 } 78 { 79 var cov = new CovarianceSum(); 80 cov.Terms.Add(new CovarianceMaternIso()); 81 cov.Terms.Add(new CovarianceMaternIso()); 82 cov.Terms.Add(new CovarianceNoise()); 83 var hyp = new double[] { 0, 0, -1, 1, -4 }; 84 descriptorList.Add(new GaussianProcessRegressionInstance("Matern1+Matern1", cov, hyp)); 85 } 86 { 87 var cov = new CovarianceSum(); 88 var m1 = new CovarianceMaternIso(); 89 m1.DParameter.Value = m1.DParameter.ValidValues.First(v => v.Value == 3); 90 var m2 = new CovarianceMaternIso(); 91 m2.DParameter.Value = m2.DParameter.ValidValues.First(v => v.Value == 3); 92 cov.Terms.Add(m1); 93 cov.Terms.Add(m2); 94 cov.Terms.Add(new CovarianceNoise()); 95 var hyp = new double[] { -2.7, 0, -1, 1, -1.5 }; 96 descriptorList.Add(new GaussianProcessRegressionInstance("Matern3+Matern3", cov, hyp)); 97 } 98 { 99 var cov = new CovarianceSum(); 100 cov.Terms.Add(new CovarianceRationalQuadraticIso()); 101 cov.Terms.Add(new CovarianceSquaredExponentialIso()); 102 cov.Terms.Add(new CovarianceNoise()); 103 var hyp = new double[] { -1.5, -0.5, -3, -1, -1, -3 }; 104 descriptorList.Add(new GaussianProcessRegressionInstance("RQ+SE", cov, hyp)); 105 } 106 { 107 var cov = new CovarianceSum(); 108 cov.Terms.Add(new CovarianceSquaredExponentialIso()); 109 var prod = new CovarianceProduct(); 110 prod.Factors.Add(new CovarianceLinear()); 111 prod.Factors.Add(new CovarianceNoise()); 112 cov.Terms.Add(prod); 113 cov.Terms.Add(new CovarianceNoise()); 114 var hyp = new double[] { -3, 0, 0, -1.5 }; 115 descriptorList.Add(new GaussianProcessRegressionInstance("SE+Linear*Noise", cov, hyp)); 116 } 117 { 118 var cov = new CovarianceSum(); 119 cov.Terms.Add(new CovarianceSquaredExponentialIso()); 120 cov.Terms.Add(new CovariancePeriodic()); 121 cov.Terms.Add(new CovarianceNoise()); 122 var hyp = new double[] { -1, 0, 0, -1.5, 0, -2 }; 123 descriptorList.Add(new GaussianProcessRegressionInstance("SE+Periodic", cov, hyp)); 124 } 125 66 126 67 127 return descriptorList;
Note: See TracChangeset
for help on using the changeset viewer.