Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/23/19 20:56:15 (5 years ago)
Author:
gkronber
Message:

#2942: merged r16491 from trunk to stable

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.DataAnalysis

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4

  • stable/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs

    r17097 r17164  
    4141    private const string NearestNeighbourRegressionModelResultName = "Nearest neighbour regression solution";
    4242    private const string WeightsParameterName = "Weights";
     43    private const string SelfMatchParameterName = "SelfMatch";
    4344
    4445    #region parameter properties
     
    4647      get { return (IFixedValueParameter<IntValue>)Parameters[KParameterName]; }
    4748    }
    48 
     49    public IFixedValueParameter<BoolValue> SelfMatchParameter {
     50      get { return (IFixedValueParameter<BoolValue>)Parameters[SelfMatchParameterName]; }
     51    }
    4952    public IValueParameter<DoubleArray> WeightsParameter {
    5053      get { return (IValueParameter<DoubleArray>)Parameters[WeightsParameterName]; }
     
    5962      }
    6063    }
    61 
     64    public bool SelfMatch {
     65      get { return SelfMatchParameter.Value.Value; }
     66      set { SelfMatchParameter.Value.Value = value; }
     67    }
    6268    public DoubleArray Weights {
    6369      get { return WeightsParameter.Value; }
     
    7581      Parameters.Add(new FixedValueParameter<IntValue>(KParameterName, "The number of nearest neighbours to consider for regression.", new IntValue(3)));
    7682      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)"));
     83      Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false)));
    7784      Problem = new RegressionProblem();
    7885    }
     
    8491      if (!Parameters.ContainsKey(WeightsParameterName)) {
    8592        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)"));
     93      }
     94      if (!Parameters.ContainsKey(SelfMatchParameterName)) {
     95        Parameters.Add(new FixedValueParameter<BoolValue>(SelfMatchParameterName, "Should we use equal points for classification?", new BoolValue(false)));
    8696      }
    8797      #endregion
     
    96106      double[] weights = null;
    97107      if (Weights != null) weights = Weights.CloneAsArray();
    98       var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K, weights);
     108      var solution = CreateNearestNeighbourRegressionSolution(Problem.ProblemData, K, SelfMatch, weights);
    99109      Results.Add(new Result(NearestNeighbourRegressionModelResultName, "The nearest neighbour regression solution.", solution));
    100110    }
    101111
    102     public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k, double[] weights = null) {
     112    public static IRegressionSolution CreateNearestNeighbourRegressionSolution(IRegressionProblemData problemData, int k, bool selfMatch = false, double[] weights = null) {
    103113      var clonedProblemData = (IRegressionProblemData)problemData.Clone();
    104       return new NearestNeighbourRegressionSolution(Train(problemData, k, weights), clonedProblemData);
     114      return new NearestNeighbourRegressionSolution(Train(problemData, k, selfMatch, weights), clonedProblemData);
    105115    }
    106116
    107     public static INearestNeighbourModel Train(IRegressionProblemData problemData, int k, double[] weights = null) {
     117    public static INearestNeighbourModel Train(IRegressionProblemData problemData, int k, bool selfMatch = false, double[] weights = null) {
    108118      return new NearestNeighbourModel(problemData.Dataset,
    109119        problemData.TrainingIndices,
    110120        k,
     121        selfMatch,
    111122        problemData.TargetVariable,
    112123        problemData.AllowedInputVariables,
Note: See TracChangeset for help on using the changeset viewer.