1 | using HEAL.Attic;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using System.Collections.Generic;
|
---|
8 | using System.Linq;
|
---|
9 |
|
---|
10 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
11 | [Item("User-defined Multi-objective Evaluator", "A multi-objective evaluator that aggregates the output of its evaluator collection.")]
|
---|
12 | [StorableType("779F7C15-63E0-4407-A28D-F4DCB1AA8267")]
|
---|
13 | public class SymbolicDataAnalysisMultiObjectiveUserDefinedEvaluator<T> : SymbolicDataAnalysisMultiObjectiveEvaluator<T> where T : class, IDataAnalysisProblemData {
|
---|
14 | private const string EvaluatorsParameterName = "Evaluators";
|
---|
15 | private const string MaximizationParameterName = "Maximization";
|
---|
16 |
|
---|
17 | public IFixedValueParameter<ItemList<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>> EvaluatorsParameter {
|
---|
18 | get { return (IFixedValueParameter<ItemList<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>>)Parameters[EvaluatorsParameterName]; }
|
---|
19 | }
|
---|
20 |
|
---|
21 | public ILookupParameter<BoolArray> MaximizationParameter {
|
---|
22 | get { return (ILookupParameter<BoolArray>)Parameters[MaximizationParameterName]; }
|
---|
23 | }
|
---|
24 |
|
---|
25 | public ItemList<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>> Evaluators {
|
---|
26 | get { return EvaluatorsParameter.Value; }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public override IEnumerable<bool> Maximization => Evaluators.Select(x => x.Maximization);
|
---|
30 |
|
---|
31 | public SymbolicDataAnalysisMultiObjectiveUserDefinedEvaluator() {
|
---|
32 | Parameters.Add(new FixedValueParameter<ItemList<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>>(EvaluatorsParameterName, new ItemList<ISymbolicDataAnalysisSingleObjectiveEvaluator<T>>()));
|
---|
33 | Parameters.Add(new LookupParameter<BoolArray>(MaximizationParameterName));
|
---|
34 | }
|
---|
35 |
|
---|
36 | public SymbolicDataAnalysisMultiObjectiveUserDefinedEvaluator(SymbolicDataAnalysisMultiObjectiveUserDefinedEvaluator<T> original, Cloner cloner) : base(original, cloner) { }
|
---|
37 |
|
---|
38 | [StorableConstructor]
|
---|
39 | protected SymbolicDataAnalysisMultiObjectiveUserDefinedEvaluator(StorableConstructorFlag deserializing) : base(deserializing) { }
|
---|
40 |
|
---|
41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
42 | return new SymbolicDataAnalysisMultiObjectiveUserDefinedEvaluator<T>(this, cloner);
|
---|
43 | }
|
---|
44 |
|
---|
45 | public override double[] Evaluate(IExecutionContext context, ISymbolicExpressionTree tree, T problemData, IEnumerable<int> rows) {
|
---|
46 | var evaluators = Evaluators;
|
---|
47 | var qualities = new double[evaluators.Count];
|
---|
48 | for (int i = 0; i < qualities.Length; ++i) {
|
---|
49 | qualities[i] = evaluators[i].Evaluate(context, tree, problemData, rows);
|
---|
50 | }
|
---|
51 | QualitiesParameter.ActualValue = new DoubleArray(qualities);
|
---|
52 | return qualities;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public override IOperation InstrumentedApply() {
|
---|
56 | var solution = SymbolicExpressionTreeParameter.ActualValue;
|
---|
57 | var problemData = ProblemDataParameter.ActualValue;
|
---|
58 |
|
---|
59 | if (MaximizationParameter.ActualValue.Length != Evaluators.Count) {
|
---|
60 | MaximizationParameter.ActualValue = new BoolArray(Maximization.ToArray());
|
---|
61 | }
|
---|
62 |
|
---|
63 | var qualities = Evaluate(ExecutionContext, solution, problemData, problemData.TrainingIndices);
|
---|
64 | QualitiesParameter.ActualValue = new DoubleArray(qualities);
|
---|
65 | return base.InstrumentedApply();
|
---|
66 | }
|
---|
67 | }
|
---|
68 | } |
---|