- Timestamp:
- 03/29/21 09:54:58 (4 years ago)
- Location:
- branches/3105_PythonFormatter
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3105_PythonFormatter
- Property svn:mergeinfo changed
/trunk (added) merged: 17845,17856,17858-17859,17861,17867,17871-17873,17888-17889,17902-17903,17906-17914
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis (added) merged: 17845,17867,17873,17888-17889
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Algorithms.DataAnalysis/3.4
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Algorithms.DataAnalysis/3.4 (added) merged: 17845,17867,17873,17888-17889
- Property svn:mergeinfo changed
-
branches/3105_PythonFormatter/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/GeneralizedAdditiveModelAlgorithm.cs
r17815 r17918 39 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 600)] 40 40 public sealed class GeneralizedAdditiveModelAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 41 41 42 #region ParameterNames 42 43 … … 46 47 private const string SetSeedRandomlyParameterName = "SetSeedRandomly"; 47 48 private const string CreateSolutionParameterName = "CreateSolution"; 49 48 50 #endregion 49 51 … … 141 143 var problemData = Problem.ProblemData; 142 144 var ds = problemData.Dataset; 143 var trainRows = problemData.TrainingIndices ;144 var testRows = problemData.TestIndices ;145 var trainRows = problemData.TrainingIndices.ToArray(); 146 var testRows = problemData.TestIndices.ToArray(); 145 147 var avgY = problemData.TargetVariableTrainingValues.Average(); 146 148 var inputVars = problemData.AllowedInputVariables.ToArray(); … … 178 180 double[] resTest = problemData.TargetVariableTestValues.Select(yi => yi - avgY).ToArray(); 179 181 180 curRMSE.Value = res.StandardDeviation();181 curRMSETest.Value = resTest.StandardDeviation();182 rmseRow.Values.Add( res.StandardDeviation());183 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); 184 186 185 187 … … 197 199 AddInPlace(resTest, f[inputIdx].GetEstimatedValues(ds, testRows)); 198 200 199 rssTable[inputIdx, 0] = res.Variance();201 rssTable[inputIdx, 0] = MSE(res); 200 202 f[inputIdx] = RegressSpline(problemData, inputVar, res, lambda); 201 203 … … 204 206 } 205 207 206 curRMSE.Value = res.StandardDeviation();207 curRMSETest.Value = resTest.StandardDeviation();208 curRMSE.Value = RMSE(res); 209 curRMSETest.Value = RMSE(resTest); 208 210 rmseRow.Values.Add(curRMSE.Value); 209 211 rmseRowTest.Values.Add(curRMSETest.Value); … … 215 217 var model = new RegressionEnsembleModel(f.Concat(new[] { new ConstantModel(avgY, problemData.TargetVariable) })); 216 218 model.AverageModelEstimates = false; 217 var solution = model.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 219 var solution = model.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()); 218 220 Results.Add(new Result("Ensemble solution", solution)); 219 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; 220 233 } 221 234 -
branches/3105_PythonFormatter/HeuristicLab.Algorithms.DataAnalysis/3.4/GAM/Spline1dModel.cs
r17839 r17918 26 26 using HeuristicLab.Core; 27 27 using HeuristicLab.Problems.DataAnalysis; 28 using System; 28 29 29 30 namespace HeuristicLab.Algorithms.DataAnalysis { … … 35 36 private alglib.spline1d.spline1dinterpolant interpolant; 36 37 37 [Storable ]38 private readonly string[] variablesUsedForPrediction;39 public override IEnumerable<string> VariablesUsedForPrediction{40 get {41 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]; 42 43 } 43 44 } 45 46 [Storable] 47 private string inputVariable; 48 public override IEnumerable<string> VariablesUsedForPrediction => new[] { inputVariable }; 44 49 45 50 [StorableConstructor] … … 49 54 50 55 private Spline1dModel(Spline1dModel orig, Cloner cloner) : base(orig, cloner) { 51 this. variablesUsedForPrediction = orig.VariablesUsedForPrediction.ToArray();56 this.inputVariable = orig.inputVariable; 52 57 this.interpolant = (alglib.spline1d.spline1dinterpolant)orig.interpolant.make_copy(); 53 58 } 54 59 public Spline1dModel(alglib.spline1d.spline1dinterpolant interpolant, string targetVar, string inputVar) 55 : base(targetVar, "Spline model (1d)") {56 this.interpolant = (alglib.spline1d.spline1dinterpolant)interpolant.make_copy(); 57 this. variablesUsedForPrediction = new string[] { inputVar };60 : base(targetVar, $"Spline model ({inputVar})") { 61 this.interpolant = (alglib.spline1d.spline1dinterpolant)interpolant.make_copy(); 62 this.inputVariable = inputVar; 58 63 } 59 64 60 65 61 public override IDeepCloneable Clone(Cloner cloner) { 62 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; 63 73 } 64 74 65 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 66 return new RegressionSolution(this, (IRegressionProblemData)problemData.Clone()); 67 } 68 69 public double GetEstimatedValue(double x) { 70 return alglib.spline1d.spline1dcalc(interpolant, x); 71 } 75 public double GetEstimatedValue(double x) => alglib.spline1d.spline1dcalc(interpolant, x); 72 76 73 77 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 74 var x = dataset.GetDoubleValues(VariablesUsedForPrediction.First(), rows).ToArray(); 75 foreach (var xi in x) { 76 yield return GetEstimatedValue(xi); 77 } 78 return dataset.GetDoubleValues(inputVariable, rows).Select(GetEstimatedValue); 78 79 } 79 80 -
branches/3105_PythonFormatter/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r17180 r17918 281 281 new AccuracyMaximizationThresholdCalculator()); 282 282 var classificationProblemData = new ClassificationProblemData(problemData.Dataset, 283 problemData.AllowedInputVariables, problemData.TargetVariable, problemData.Transformations);283 problemData.AllowedInputVariables, problemData.TargetVariable, transformations: problemData.Transformations); 284 284 classificationProblemData.TrainingPartition.Start = Problem.ProblemData.TrainingPartition.Start; 285 285 classificationProblemData.TrainingPartition.End = Problem.ProblemData.TrainingPartition.End; -
branches/3105_PythonFormatter/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestModelSurrogate.cs
r17278 r17918 135 135 } 136 136 137 public override bool IsProblemDataCompatible(IDataAnalysisProblemData problemData, out string errorMessage) { 138 return ActualModel.IsProblemDataCompatible(problemData, out errorMessage); 139 } 140 137 141 //RegressionModel methods 138 142 public bool IsProblemDataCompatible(IRegressionProblemData problemData, out string errorMessage) {
Note: See TracChangeset
for help on using the changeset viewer.