[2616] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2008 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 HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Data;
|
---|
| 25 | using HeuristicLab.GP.Interfaces;
|
---|
| 26 | using HeuristicLab.GP;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.GP.StructureIdentification.Networks {
|
---|
| 29 | public class FunctionLibraryInjector : FunctionLibraryInjectorBase {
|
---|
| 30 |
|
---|
| 31 | public override string Description {
|
---|
| 32 | get { return @"Injects a function library for network structure identification."; }
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | protected override FunctionLibrary CreateFunctionLibrary() {
|
---|
[2843] | 36 | return Create();
|
---|
[2616] | 37 | }
|
---|
| 38 |
|
---|
[2843] | 39 | public static FunctionLibrary Create() {
|
---|
[2616] | 40 | FunctionLibrary functionLibrary = new FunctionLibrary();
|
---|
| 41 |
|
---|
| 42 | #region f0 (...) -> double
|
---|
| 43 | Variable variable = new Variable();
|
---|
| 44 | Constant constant = new Constant();
|
---|
| 45 | Differential differential = new Differential();
|
---|
| 46 | Addition addition = new Addition();
|
---|
| 47 | Division division = new Division();
|
---|
| 48 | Multiplication multiplication = new Multiplication();
|
---|
| 49 | Subtraction subtraction = new Subtraction();
|
---|
| 50 |
|
---|
| 51 | List<IFunction> f0Functions =
|
---|
| 52 | new List<IFunction>() {
|
---|
[2821] | 53 | differential, variable, constant, addition, subtraction,
|
---|
[2616] | 54 | division, multiplication};
|
---|
| 55 |
|
---|
[2821] | 56 |
|
---|
[2616] | 57 | #endregion
|
---|
| 58 |
|
---|
| 59 | #region f1: (...) -> (double -> double)
|
---|
| 60 | OpenParameter openPar = new OpenParameter();
|
---|
| 61 | OpenExp openExp = new OpenExp();
|
---|
| 62 | OpenLog openLog = new OpenLog();
|
---|
[2624] | 63 | //OpenSqrt openSqrt = new OpenSqrt();
|
---|
| 64 | //OpenSqr openSqr = new OpenSqr();
|
---|
[2616] | 65 | Flip flip = new Flip();
|
---|
| 66 | AdditionF1 addF1 = new AdditionF1();
|
---|
| 67 | SubtractionF1 subF1 = new SubtractionF1();
|
---|
| 68 | MultiplicationF1 mulF1 = new MultiplicationF1();
|
---|
| 69 | DivisionF1 divF1 = new DivisionF1();
|
---|
| 70 |
|
---|
| 71 | List<IFunction> f1Functions = new List<IFunction>() {
|
---|
| 72 | openPar,
|
---|
[2624] | 73 | openExp, openLog, flip, // openSqrt, openSqr,
|
---|
[2616] | 74 | addF1, subF1, mulF1, divF1
|
---|
| 75 | };
|
---|
| 76 | #endregion
|
---|
| 77 |
|
---|
| 78 | #region f2: (...) -> (double, double -> double)
|
---|
| 79 | Cycle cycle = new Cycle();
|
---|
| 80 | OpenAddition openAdd = new OpenAddition();
|
---|
| 81 | OpenSubtraction openSub = new OpenSubtraction();
|
---|
| 82 | OpenMultiplication openMul = new OpenMultiplication();
|
---|
| 83 | OpenDivision openDivision = new OpenDivision();
|
---|
| 84 | List<IFunction> f2Functions = new List<IFunction>() { openAdd, openSub, openMul, openDivision, cycle };
|
---|
| 85 | #endregion
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | SetAllowedSubOperators(addition, f0Functions);
|
---|
| 89 | SetAllowedSubOperators(division, f0Functions);
|
---|
| 90 | SetAllowedSubOperators(multiplication, f0Functions);
|
---|
| 91 | SetAllowedSubOperators(subtraction, f0Functions);
|
---|
| 92 |
|
---|
| 93 | SetAllowedSubOperators(openExp, f1Functions);
|
---|
| 94 | SetAllowedSubOperators(openLog, f1Functions);
|
---|
[2624] | 95 | //SetAllowedSubOperators(openSqrt, f1Functions);
|
---|
| 96 | //SetAllowedSubOperators(openSqr, f1Functions);
|
---|
[2616] | 97 | SetAllowedSubOperators(flip, f1Functions);
|
---|
| 98 | SetAllowedSubOperators(addF1, 0, f1Functions);
|
---|
| 99 | SetAllowedSubOperators(addF1, 1, f0Functions);
|
---|
| 100 | SetAllowedSubOperators(subF1, 0, f1Functions);
|
---|
| 101 | SetAllowedSubOperators(subF1, 1, f0Functions);
|
---|
| 102 | SetAllowedSubOperators(mulF1, 0, f1Functions);
|
---|
| 103 | SetAllowedSubOperators(mulF1, 1, f0Functions);
|
---|
| 104 | SetAllowedSubOperators(divF1, 0, f1Functions);
|
---|
| 105 | SetAllowedSubOperators(divF1, 1, f0Functions);
|
---|
| 106 |
|
---|
| 107 | SetAllowedSubOperators(cycle, f2Functions);
|
---|
| 108 | SetAllowedSubOperators(openAdd, f1Functions);
|
---|
| 109 | SetAllowedSubOperators(openDivision, f1Functions);
|
---|
| 110 | SetAllowedSubOperators(openMul, f1Functions);
|
---|
[2627] | 111 | SetAllowedSubOperators(openSub, f1Functions);
|
---|
[2616] | 112 |
|
---|
| 113 | f0Functions.ForEach(x => functionLibrary.AddFunction(x));
|
---|
| 114 | f1Functions.ForEach(x => functionLibrary.AddFunction(x));
|
---|
| 115 | f2Functions.ForEach(x => functionLibrary.AddFunction(x));
|
---|
| 116 |
|
---|
[2843] | 117 | openPar.SetConstraints(0, 0);
|
---|
[2616] | 118 |
|
---|
[2627] | 119 |
|
---|
[2616] | 120 | return functionLibrary;
|
---|
| 121 | }
|
---|
| 122 | }
|
---|
| 123 | }
|
---|