Changeset 18014
- Timestamp:
- 07/17/21 18:12:59 (3 years ago)
- Location:
- stable
- Files:
-
- 6 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 17812,17815,17839,17867,17888-17889
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis merged: 17812,17815,17839,17867,17888-17889
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 merged: 17812,17815,17839,17867,17888-17889
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/GeneralizedAdditiveModelAlgorithm.cs
r17812 r18014 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * and the BEACON Center for the Study of Evolution in Action. 5 * 3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 6 5 * This file is part of HeuristicLab. 7 6 * … … 40 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 600)] 41 40 public sealed class GeneralizedAdditiveModelAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 41 42 42 #region ParameterNames 43 43 … … 47 47 private const string SetSeedRandomlyParameterName = "SetSeedRandomly"; 48 48 private const string CreateSolutionParameterName = "CreateSolution"; 49 49 50 #endregion 50 51 … … 142 143 var problemData = Problem.ProblemData; 143 144 var ds = problemData.Dataset; 144 var trainRows = problemData.TrainingIndices ;145 var testRows = problemData.TestIndices ;145 var trainRows = problemData.TrainingIndices.ToArray(); 146 var testRows = problemData.TestIndices.ToArray(); 146 147 var avgY = problemData.TargetVariableTrainingValues.Average(); 147 148 var inputVars = problemData.AllowedInputVariables.ToArray(); … … 179 180 double[] resTest = problemData.TargetVariableTestValues.Select(yi => yi - avgY).ToArray(); 180 181 181 curRMSE.Value = res.StandardDeviation();182 curRMSETest.Value = resTest.StandardDeviation();183 rmseRow.Values.Add( res.StandardDeviation());184 rmseRowTest.Values.Add( resTest.StandardDeviation());182 curRMSE.Value = RMSE(res); 183 curRMSETest.Value = RMSE(resTest); 184 rmseRow.Values.Add(curRMSE.Value); 185 rmseRowTest.Values.Add(curRMSETest.Value); 185 186 186 187 … … 198 199 AddInPlace(resTest, f[inputIdx].GetEstimatedValues(ds, testRows)); 199 200 200 rssTable[inputIdx, 0] = res.Variance();201 rssTable[inputIdx, 0] = MSE(res); 201 202 f[inputIdx] = RegressSpline(problemData, inputVar, res, lambda); 202 203 … … 205 206 } 206 207 207 curRMSE.Value = res.StandardDeviation();208 curRMSETest.Value = resTest.StandardDeviation();208 curRMSE.Value = RMSE(res); 209 curRMSETest.Value = RMSE(resTest); 209 210 rmseRow.Values.Add(curRMSE.Value); 210 211 rmseRowTest.Values.Add(curRMSETest.Value); … … 216 217 var model = new RegressionEnsembleModel(f.Concat(new[] { new ConstantModel(avgY, problemData.TargetVariable) })); 217 218 model.AverageModelEstimates = false; 218 var solution = model.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 219 var solution = model.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 219 220 Results.Add(new Result("Ensemble solution", solution)); 220 221 } 222 } 223 224 public static double MSE(IEnumerable<double> residuals) { 225 var mse = residuals.Select(r => r * r).Average(); 226 return mse; 227 } 228 229 public static double RMSE(IEnumerable<double> residuals) { 230 var mse = MSE(residuals); 231 var rmse = Math.Sqrt(mse); 232 return rmse; 221 233 } 222 234 -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/Spline1dModel.cs
r17812 r18014 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * and the BEACON Center for the Study of Evolution in Action. 5 * 3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 * 6 5 * This file is part of HeuristicLab. 7 6 * … … 21 20 #endregion 22 21 23 using System;24 22 using HEAL.Attic; 25 23 using System.Collections.Generic; … … 27 25 using HeuristicLab.Common; 28 26 using HeuristicLab.Core; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;30 27 using HeuristicLab.Problems.DataAnalysis; 28 using System; 31 29 32 30 namespace HeuristicLab.Algorithms.DataAnalysis { … … 38 36 private alglib.spline1d.spline1dinterpolant interpolant; 39 37 40 [Storable ]41 private readonly string[] variablesUsedForPrediction;42 public override IEnumerable<string> VariablesUsedForPrediction{43 get {44 return variablesUsedForPrediction;38 [Storable(OldName = "variablesUsedForPrediction")] 39 private string[] StorableVariablesUsedForPrediction { 40 set { 41 if (value.Length > 1) throw new ArgumentException("A one-dimensional spline model supports only one input variable."); 42 inputVariable = value[0]; 45 43 } 46 44 } 45 46 [Storable] 47 private string inputVariable; 48 public override IEnumerable<string> VariablesUsedForPrediction => new[] { inputVariable }; 47 49 48 50 [StorableConstructor] … … 52 54 53 55 private Spline1dModel(Spline1dModel orig, Cloner cloner) : base(orig, cloner) { 54 this. variablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();56 this.inputVariable = orig.inputVariable; 55 57 this.interpolant = (alglib.spline1d.spline1dinterpolant)orig.interpolant.make_copy(); 56 58 } 57 59 public Spline1dModel(alglib.spline1d.spline1dinterpolant interpolant, string targetVar, string inputVar) 58 : base( "Spline model (1d)", "Spline model (1d)") {60 : base(targetVar, $"Spline model ({inputVar})") { 59 61 this.interpolant = (alglib.spline1d.spline1dinterpolant)interpolant.make_copy(); 60 this.TargetVariable = targetVar; 61 this.variablesUsedForPrediction = new string[] { inputVar }; 62 this.inputVariable = inputVar; 62 63 } 63 64 64 65 65 public override IDeepCloneable Clone(Cloner cloner) { 66 return new Spline1dModel(this, cloner); 66 public override IDeepCloneable Clone(Cloner cloner) => new Spline1dModel(this, cloner); 67 68 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 69 var solution = new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 70 solution.Name = $"Regression Spline ({inputVariable})"; 71 72 return solution; 67 73 } 68 74 69 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 70 return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 71 } 72 73 public double GetEstimatedValue(double x) { 74 return alglib.spline1d.spline1dcalc(interpolant, x); 75 } 75 public double GetEstimatedValue(double x) => alglib.spline1d.spline1dcalc(interpolant, x); 76 76 77 77 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 78 var x = dataset.GetDoubleValues(VariablesUsedForPrediction.First(), rows).ToArray(); 79 foreach (var xi in x) { 80 yield return GetEstimatedValue(xi); 81 } 78 return dataset.GetDoubleValues(inputVariable, rows).Select(GetEstimatedValue); 82 79 } 83 80 -
stable/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r17157 r18014 133 133 <Compile Include="DoubleArrayExtensions.cs" /> 134 134 <Compile Include="FixedDataAnalysisAlgorithm.cs" /> 135 <Compile Include="GAM\GeneralizedAdditiveModelAlgorithm.cs" /> 136 <Compile Include="GAM\Spline1dModel.cs" /> 135 137 <Compile Include="GaussianProcess\CovarianceFunctions\CovarianceSpectralMixture.cs" /> 136 138 <Compile Include="GaussianProcess\CovarianceFunctions\CovariancePiecewisePolynomial.cs" />
Note: See TracChangeset
for help on using the changeset viewer.