[15064] | 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Linq;
|
---|
[17332] | 24 | using HEAL.Attic;
|
---|
[15064] | 25 | using HeuristicLab.Algorithms.DataAnalysis;
|
---|
| 26 | using HeuristicLab.Common;
|
---|
| 27 | using HeuristicLab.Core;
|
---|
| 28 | using HeuristicLab.Encodings.RealVectorEncoding;
|
---|
| 29 |
|
---|
| 30 | // ReSharper disable once CheckNamespace
|
---|
| 31 | namespace HeuristicLab.Algorithms.EGO {
|
---|
| 32 |
|
---|
[17332] | 33 | [StorableType("96160d45-3abb-460b-aa31-c00204c1e914")]
|
---|
| 34 | [Item("NeighbourDistance", "Exploration by maximizing the distance to the nearest neighbour")]
|
---|
[15064] | 35 | public class NeighbourDistance : InfillCriterionBase {
|
---|
| 36 |
|
---|
[15338] | 37 | private VantagePointTree<IEnumerable<double>> Points;
|
---|
[15064] | 38 | #region Constructors, Serialization and Cloning
|
---|
| 39 | [StorableConstructor]
|
---|
[17332] | 40 | protected NeighbourDistance(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
[15338] | 41 | protected NeighbourDistance(NeighbourDistance original, Cloner cloner) : base(original, cloner) { }
|
---|
[15064] | 42 | public NeighbourDistance() { }
|
---|
[15338] | 43 | public override IDeepCloneable Clone(Cloner cloner) { return new NeighbourDistance(this, cloner); }
|
---|
[15064] | 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 | }
|
---|