Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16353


Ignore:
Timestamp:
12/08/18 07:52:35 (6 years ago)
Author:
gkronber
Message:

#2937: added partial support for rectifier, leaky-rectifier and soft-plus functions

Location:
branches/2937_SymReg_AnalyticalQuotient/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
3 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/2937_SymReg_AnalyticalQuotient/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs

    r16083 r16353  
    8585      diff: x => -(Math.Exp(-(x * x)) * Math.Sqrt(Math.Exp(x * x)) * x) / Math.Sqrt(2 * Math.PI));
    8686
     87    private static readonly Func<Term, UnaryFunc> rectifier = UnaryFunc.Factory(
     88      eval: x => Math.Max(x, 0),
     89      diff: x => x > 0 ? 1.0 : 0.0);
     90
     91    private static readonly Func<Term, UnaryFunc> leakyRectifier = UnaryFunc.Factory(
     92      eval: x => Math.Max(x, 0.01 * x),
     93      diff: x => x > 0 ? 1.0 : 0.01);
     94
    8795    #endregion
    8896
     
    254262          ConvertToAutoDiff(node.GetSubtree(0)));
    255263      }
     264      if (node.Symbol is Rectifier) {
     265        return rectifier(ConvertToAutoDiff(node.GetSubtree(0)));
     266      }
     267      if (node.Symbol is LeakyRectifier) {
     268        return leakyRectifier(ConvertToAutoDiff(node.GetSubtree(0)));
     269      }
     270      if (node.Symbol is Softplus) {
     271        return TermBuilder.Log(1.0 + TermBuilder.Exp(ConvertToAutoDiff(node.GetSubtree(0))));
     272      }
    256273      if (node.Symbol is StartSymbol) {
    257274        if (addLinearScalingTerms) {
     
    296313          !(n.Symbol is Subtraction) &&
    297314          !(n.Symbol is Multiplication) &&
     315          !(n.Symbol is AnalyticalQuotient) &&
     316          !(n.Symbol is Rectifier) &&
     317          !(n.Symbol is LeakyRectifier) &&
     318          !(n.Symbol is Softplus) &&
    298319          !(n.Symbol is Division) &&
    299320          !(n.Symbol is Logarithm) &&
  • branches/2937_SymReg_AnalyticalQuotient/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/FullFunctionalExpressionGrammar.cs

    r16083 r16353  
    9393      sineIntegral.InitialFrequency = 0.0;
    9494
     95      var rect = new Rectifier();
     96      var softplus = new Softplus();
     97      var leakyRect = new LeakyRectifier();
     98
    9599      var exp = new Exponential();
    96100      var @if = new IfThenElse();
     
    126130      var allSymbols = new List<Symbol>() { add, sub, mul, div, aq, mean, sin, cos, tan, log, square, pow, sqrt, root, exp,
    127131        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral,
    128         @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition };
     132        @if, gt, lt, and, or, not,xor, timeLag, integral, derivative, constant, variableSymbol, binFactorVariable, factorVariable, laggedVariable,autoregressiveVariable, variableCondition,
     133      softplus, rect, leakyRect};
    129134      var unaryFunctionSymbols = new List<Symbol>() { square, sqrt, sin, cos, tan, log, exp, not, timeLag, integral, derivative,
    130135        airyA, airyB, bessel, cosineIntegral, dawson, erf, expIntegralEi, fresnelCosineIntegral, fresnelSineIntegral, gamma, hypCosineIntegral, hypSineIntegral, norm, psi, sineIntegral
     136        , rect, softplus, leakyRect
    131137      };
    132138
  • branches/2937_SymReg_AnalyticalQuotient/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj

    r16083 r16353  
    198198    <Compile Include="SymbolicDataAnalysisSolutionImpactValuesCalculator.cs" />
    199199    <Compile Include="Symbols\Addition.cs" />
     200    <Compile Include="Symbols\LeakyRectifier.cs" />
     201    <Compile Include="Symbols\Rectifier.cs" />
     202    <Compile Include="Symbols\SoftSum.cs" />
    200203    <Compile Include="Symbols\And.cs" />
    201204    <Compile Include="Symbols\AutoregressiveVariable.cs" />
  • branches/2937_SymReg_AnalyticalQuotient/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/OpCodes.cs

    r16083 r16353  
    8686    public const byte BinaryFactorVariable = 47;
    8787    public const byte AnalyticalQuotient = 48;
     88    public const byte Rectifier = 49;
     89    public const byte Softplus = 50;
     90    public const byte LeakyRectifier = 51;
    8891
    8992
     
    137140      { typeof(FactorVariable), OpCodes.FactorVariable },
    138141      { typeof(BinaryFactorVariable), OpCodes.BinaryFactorVariable },
    139       {typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient }
     142      {typeof(AnalyticalQuotient), OpCodes.AnalyticalQuotient },
     143      {typeof(Rectifier), OpCodes.Rectifier },
     144      {typeof(Softplus), OpCodes.Softplus},
     145      {typeof(LeakyRectifier), OpCodes.LeakyRectifier },
    140146    };
    141147
  • branches/2937_SymReg_AnalyticalQuotient/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeLinearInterpreter.cs

    r16083 r16353  
    346346          }
    347347          instr.value = result;
     348        } else if (instr.opCode == OpCodes.Rectifier) {
     349          return Math.Max(code[instr.childIndex].value, 0.0);
     350        } else if (instr.opCode == OpCodes.LeakyRectifier) {
     351          var x = code[instr.childIndex].value;
     352          if (x > 0) return x; else return 0.01 * x;
     353        } else if (instr.opCode == OpCodes.Softplus) {
     354          var x = code[instr.childIndex].value;
     355          return Math.Log(1.0 + Math.Exp(x));
    348356        } else if (instr.opCode == OpCodes.AND) {
    349357          double result = code[instr.childIndex].value;
Note: See TracChangeset for help on using the changeset viewer.