Changeset 17434 for branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
- Timestamp:
- 02/11/20 13:36:02 (4 years ago)
- Location:
- branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
-
branches/1772_HeuristicLab.EvolutionTracking/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/TreeToAutoDiffTermConverter.cs
r16130 r17434 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-2018Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 76 76 eval: Math.Tan, 77 77 diff: x => 1 + Math.Tan(x) * Math.Tan(x)); 78 78 private static readonly Func<Term, UnaryFunc> tanh = UnaryFunc.Factory( 79 eval: Math.Tanh, 80 diff: x => 1 - Math.Tanh(x) * Math.Tanh(x)); 79 81 private static readonly Func<Term, UnaryFunc> erf = UnaryFunc.Factory( 80 82 eval: alglib.errorfunction, … … 84 86 eval: alglib.normaldistribution, 85 87 diff: x => -(Math.Exp(-(x * x)) * Math.Sqrt(Math.Exp(x * x)) * x) / Math.Sqrt(2 * Math.PI)); 88 89 private static readonly Func<Term, UnaryFunc> abs = UnaryFunc.Factory( 90 eval: Math.Abs, 91 diff: x => Math.Sign(x) 92 ); 93 94 private static readonly Func<Term, UnaryFunc> cbrt = UnaryFunc.Factory( 95 eval: x => x < 0 ? -Math.Pow(-x, 1.0 / 3) : Math.Pow(x, 1.0 / 3), 96 diff: x => { var cbrt_x = x < 0 ? -Math.Pow(-x, 1.0 / 3) : Math.Pow(x, 1.0 / 3); return 1.0 / (3 * cbrt_x * cbrt_x); } 97 ); 98 99 86 100 87 101 #endregion … … 213 227 else return terms.Aggregate((a, b) => new AutoDiff.Product(a, 1.0 / b)); 214 228 } 229 if (node.Symbol is Absolute) { 230 var x1 = ConvertToAutoDiff(node.GetSubtree(0)); 231 return abs(x1); 232 } 233 if (node.Symbol is AnalyticQuotient) { 234 var x1 = ConvertToAutoDiff(node.GetSubtree(0)); 235 var x2 = ConvertToAutoDiff(node.GetSubtree(1)); 236 return x1 / (TermBuilder.Power(1 + x2 * x2, 0.5)); 237 } 215 238 if (node.Symbol is Logarithm) { 216 239 return AutoDiff.TermBuilder.Log( … … 229 252 ConvertToAutoDiff(node.GetSubtree(0)), 0.5); 230 253 } 254 if (node.Symbol is Cube) { 255 return AutoDiff.TermBuilder.Power( 256 ConvertToAutoDiff(node.GetSubtree(0)), 3.0); 257 } 258 if (node.Symbol is CubeRoot) { 259 return cbrt(ConvertToAutoDiff(node.GetSubtree(0))); 260 } 231 261 if (node.Symbol is Sine) { 232 262 return sin( … … 239 269 if (node.Symbol is Tangent) { 240 270 return tan( 271 ConvertToAutoDiff(node.GetSubtree(0))); 272 } 273 if (node.Symbol is HyperbolicTangent) { 274 return tanh( 241 275 ConvertToAutoDiff(node.GetSubtree(0))); 242 276 } … … 299 333 !(n.Symbol is Cosine) && 300 334 !(n.Symbol is Tangent) && 335 !(n.Symbol is HyperbolicTangent) && 301 336 !(n.Symbol is Erf) && 302 337 !(n.Symbol is Norm) && 303 !(n.Symbol is StartSymbol) 338 !(n.Symbol is StartSymbol) && 339 !(n.Symbol is Absolute) && 340 !(n.Symbol is AnalyticQuotient) && 341 !(n.Symbol is Cube) && 342 !(n.Symbol is CubeRoot) 304 343 select n).Any(); 305 344 return !containsUnknownSymbol;
Note: See TracChangeset
for help on using the changeset viewer.