Changeset 16664
- Timestamp:
- 03/07/19 19:17:18 (6 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/HeuristicLab.Problems.DynamicalSystemsModelling-3.3.csproj
r16663 r16664 220 220 <Private>False</Private> 221 221 </ProjectReference> 222 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj"> 223 <Project>{5AC82412-911B-4FA2-A013-EDC5E3F3FCC2}</Project> 224 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4</Name> 225 </ProjectReference> 222 226 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj"> 223 227 <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project> -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs
r16663 r16664 39 39 using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable; 40 40 using HEAL.Attic; 41 using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression; 41 42 42 43 namespace HeuristicLab.Problems.DynamicalSystemsModelling { … … 766 767 simplifiedTreeVar.Value = TreeSimplifier.Simplify(tree); 767 768 models.Add(simplifiedTreeVar); 768 769 769 } 770 770 771 771 results["Models"].Value = models; 772 #endregion 773 774 #region produce classical solutions to allow visualization with PDP 775 for (int treeIdx = 0; treeIdx < trees.Length; treeIdx++) { 776 var t = (ISymbolicExpressionTree)trees[treeIdx].Clone(); 777 var name = targetVars.Concat(latentVariables).ElementAt(treeIdx); // whatever 778 var model = new SymbolicRegressionModel(name + "_diff", t, new SymbolicDataAnalysisExpressionTreeLinearInterpreter()); 779 var solutionDataset = ((Dataset)problemData.Dataset).ToModifiable(); 780 if (treeIdx < targetVars.Length) { 781 var absValues = solutionDataset.GetDoubleValues(name).ToArray(); 782 solutionDataset.AddVariable(name + "_diff", absValues.Skip(1).Zip(absValues, (v1, v0) => v1 - v0).Concat(new double[] { 0.0 }).ToList()); 783 } 784 var solutionProblemData = new RegressionProblemData(solutionDataset, problemData.AllowedInputVariables, name + "_diff"); 785 var solution = model.CreateRegressionSolution(solutionProblemData); 786 results.AddOrUpdateResult("Solution " + name, solution); 787 } 772 788 #endregion 773 789 } … … 1333 1349 var f = InterpretRec(node.GetSubtree(0), nodeValues); 1334 1350 return Math.Log(f); 1351 } else if (node.Symbol is HyperbolicTangent) { 1352 Assert(node.SubtreeCount == 1); 1353 1354 var f = InterpretRec(node.GetSubtree(0), nodeValues); 1355 return Math.Tanh(f); 1356 } else if (node.Symbol is AnalyticQuotient) { 1357 Assert(node.SubtreeCount == 2); 1358 1359 var f = InterpretRec(node.GetSubtree(0), nodeValues); 1360 var g = InterpretRec(node.GetSubtree(1), nodeValues); 1361 return f / Math.Sqrt(1 + g * g); 1335 1362 } else throw new NotSupportedException("unsupported symbol"); 1336 1363 } … … 1440 1467 z = Math.Log(f); 1441 1468 dz = df.Scale(1.0 / f); 1469 } else if (node.Symbol is HyperbolicTangent) { 1470 Assert(node.SubtreeCount == 1); 1471 InterpretRec(node.GetSubtree(0), nodeValues, out f, out df); 1472 z = Math.Tanh(f); 1473 dz = df.Scale(1 - z * z); // tanh(f(x))' = f(x)'sech²(f(x)) = f(x)'(1 - tanh²(f(x))) 1474 } else if (node.Symbol is AnalyticQuotient) { 1475 Assert(node.SubtreeCount == 2); 1476 InterpretRec(node.GetSubtree(0), nodeValues, out f, out df); 1477 InterpretRec(node.GetSubtree(0), nodeValues, out g, out dg); 1478 z = f / Math.Sqrt(1 + g * g); 1479 var denom = 1.0 / Math.Pow(1 + g * g, 1.5); 1480 dz = df.Scale(1 + g * g).Subtract(dg.Scale(f * g)).Scale(denom); 1442 1481 } else { 1443 1482 throw new NotSupportedException("unsupported symbol"); … … 1545 1584 l.Add(new StringValue("Cosine").AsReadOnly()); 1546 1585 l.Add(new StringValue("Square").AsReadOnly()); 1586 l.Add(new StringValue("Logarithm").AsReadOnly()); 1587 l.Add(new StringValue("Exponential").AsReadOnly()); 1588 l.Add(new StringValue("HyperbolicTangent").AsReadOnly()); 1589 l.Add(new StringValue("AnalyticQuotient").AsReadOnly()); 1547 1590 return l.AsReadOnly(); 1548 1591 }
Note: See TracChangeset
for help on using the changeset viewer.