Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2745_EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/NeighbourDistance.cs @ 18132

Last change on this file since 18132 was 17332, checked in by bwerth, 5 years ago

#2745 updated persistence to HEAL.Attic

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24using HEAL.Attic;
25using HeuristicLab.Algorithms.DataAnalysis;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Encodings.RealVectorEncoding;
29
30// ReSharper disable once CheckNamespace
31namespace HeuristicLab.Algorithms.EGO {
32
33    [StorableType("96160d45-3abb-460b-aa31-c00204c1e914")]
34    [Item("NeighbourDistance", "Exploration by maximizing the distance to the nearest neighbour")]
35  public class NeighbourDistance : InfillCriterionBase {
36
37    private VantagePointTree<IEnumerable<double>> Points;
38    #region Constructors, Serialization and Cloning
39    [StorableConstructor]
40    protected NeighbourDistance(StorableConstructorFlag deserializing) : base(deserializing) { }
41    protected NeighbourDistance(NeighbourDistance original, Cloner cloner) : base(original, cloner) { }
42    public NeighbourDistance() { }
43    public override IDeepCloneable Clone(Cloner cloner) { return new NeighbourDistance(this, cloner); }
44    #endregion
45
46    public override double Evaluate(RealVector vector) {
47      if (Points == null) Points = CreateTree();
48      IList<IEnumerable<double>> neighbours;
49      IList<double> distances;
50      Points.Search(vector, 1, out neighbours, out distances);
51      return distances[0];
52    }
53
54    public override void Initialize() {
55      Points = CreateTree();
56    }
57
58    private VantagePointTree<IEnumerable<double>> CreateTree() {
59      var data = RegressionSolution.ProblemData.Dataset;
60      var rows = RegressionSolution.ProblemData.AllIndices;
61      var cols = RegressionSolution.ProblemData.AllowedInputVariables;
62      return new VantagePointTree<IEnumerable<double>>(new EuclideanDistance(), rows.Select(r => cols.Select(c => data.GetDoubleValue(c, r)).ToArray()));
63    }
64  }
65}
Note: See TracBrowser for help on using the repository browser.