Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2205_OptimizationNetworks/HeuristicLab.Networks/3.3/FeatureSelection Network/SelectionProblem.cs @ 16674

Last change on this file since 16674 was 12326, checked in by gkronber, 10 years ago

#2205: derived selection problem from BinaryProblem (now PPP can be used as feature selection algorithm)

File size: 1.5 KB
Line 
1using System;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Encodings.BinaryVectorEncoding;
6using HeuristicLab.Optimization;
7using HeuristicLab.Parameters;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Problems.Binary;
10
11namespace HeuristicLab.Networks.FeatureSelection_Network {
12  public class SelectionProblem : BinaryProblem {
13    private Func<BinaryVector, double> eval;
14
15    protected SelectionProblem(SelectionProblem original, Cloner cloner)
16      : base(original, cloner) {
17    }
18    [StorableConstructor]
19    protected SelectionProblem(bool deserializing) : base(deserializing) { }
20
21    public SelectionProblem(Func<BinaryVector, double> eval, bool maximization)
22      : base() {
23      this.maximization = maximization;
24      this.eval = eval;
25
26
27      var lengthParam = new ValueParameter<IntValue>("Length");
28
29
30      lengthParam.ValueChanged += (o, s) => { Length = lengthParam.Value.Value; };
31      // we cannot use the fixed value parameter from BinaryProblem in the network
32      Parameters.Remove("Length");
33      Parameters.Add(lengthParam);
34    }
35
36    public override IDeepCloneable Clone(Cloner cloner) {
37      return new SelectionProblem(this, cloner);
38    }
39
40    public override double Evaluate(BinaryVector vector, IRandom random) {
41      return eval(vector);
42
43    }
44
45    private readonly bool maximization;
46    public override bool Maximization {
47      get { return maximization; }
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.