Changeset 14239 for branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs
- Timestamp:
- 08/05/16 17:40:11 (8 years ago)
- Location:
- branches/symbreg-factors-2650
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/symbreg-factors-2650
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 14234-14236
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Algorithms.DataAnalysis (added) merged: 14235-14236
- Property svn:mergeinfo changed
-
branches/symbreg-factors-2650/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs
r14185 r14239 39 39 private const string KParameterName = "K"; 40 40 private const string NearestNeighbourRegressionModelResultName = "Nearest neighbour regression solution"; 41 private const string WeightsParameterName = "Weights"; 41 42 42 43 #region parameter properties 43 44 public IFixedValueParameter<IntValue> KParameter { 44 45 get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; } 46 } 47 48 public IValueParameter<DoubleArray> WeightsParameter { 49 get { return (IValueParameter<DoubleArray>)Parameters[WeightsParameterName]; } 45 50 } 46 51 #endregion … … 52 57 else KParameter.Value.Value = value; 53 58 } 59 } 60 61 public DoubleArray Weights { 62 get { return WeightsParameter.Value; } 63 set { WeightsParameter.Value = value; } 54 64 } 55 65 #endregion … … 63 73 : base() { 64 74 Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3))); 75 Parameters.Add(new OptionalValueParameter<DoubleArray>(WeightsParameterName, "Optional: use weights to specify individual scaling values for all features. If not set the weights are calculated automatically (each feature is scaled to unit variance)")); 65 76 Problem = new RegressionProblem(); 66 77 } 78 67 79 [StorableHook(HookType.AfterDeserialization)] 68 private void AfterDeserialization() { } 80 private void AfterDeserialization() { 81 // BackwardsCompatibility3.3 82 #region Backwards compatible code, remove with 3.4 83 if (!Parameters.ContainsKey(WeightsParameterName)) { 84 Parameters.Add(new OptionalValueParameter<DoubleArray>(WeightsParameterName, "Optional: use weights to specify individual scaling values for all features. If not set the weights are calculated automatically (each feature is scaled to unit variance)")); 85 } 86 #endregion 87 } 69 88 70 89 public override IDeepCloneable Clone(Cloner cloner) { … … 74 93 #region nearest neighbour 75 94 protected override void Run() { 76 var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K); 95 double[] weights = null; 96 if (Weights != null) weights = Weights.CloneAsArray(); 97 var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K, weights); 77 98 Results.Add(new Result(NearestNeighbourRegressionModelResultName, "The nearest neighbour regression solution.", solution)); 78 99 } 79 100 80 public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k ) {101 public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k, double[] weights = null) { 81 102 var clonedProblemData = (IRegressionProblemData)problemData.Clone(); 82 return new NearestNeighbourRegressionSolution(Train(problemData, k ), clonedProblemData);103 return new NearestNeighbourRegressionSolution(Train(problemData, k, weights), clonedProblemData); 83 104 } 84 105 85 public static INearestNeighbourModel Train(IRegressionProblemData problemData, int k ) {106 public static INearestNeighbourModel Train(IRegressionProblemData problemData, int k, double[] weights = null) { 86 107 return new NearestNeighbourModel(problemData.Dataset, 87 108 problemData.TrainingIndices, 88 109 k, 89 110 problemData.TargetVariable, 90 problemData.AllowedInputVariables); 111 problemData.AllowedInputVariables, 112 weights); 91 113 } 92 114 #endregion
Note: See TracChangeset
for help on using the changeset viewer.