Changeset 17001
- Timestamp:
- 06/02/19 07:44:35 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs
r16999 r17001 238 238 InitAllParameters(); 239 239 240 // TODO: alglib gradient check fails for integration autodiff 241 // TODO: implement CVODES solver and use gradient check in alglib to verify 240 242 // TODO: optimization of starting values for latent variables in CVODES solver 241 243 // TODO: allow to specify the name for the time variable in the dataset and allow variable step-sizes … … 446 448 alglib.minlmsetbc(state, lowerBounds, upperBounds); 447 449 #if DEBUG 448 //alglib.minlmsetgradientcheck(state, 1.0e-7);450 alglib.minlmsetgradientcheck(state, 1.0e-7); 449 451 #endif 450 452 alglib.minlmoptimize(state, EvaluateObjectiveVector, EvaluateObjectiveVectorAndJacobian, null, myState); … … 1667 1669 for (int i = 1; i < node.SubtreeCount; i++) { 1668 1670 InterpretRec(node.GetSubtree(i), nodeValues, out g, out dg); 1669 f= f * g;1671 var newF = f * g; 1670 1672 df = df.Scale(g).Add(dg.Scale(f)); // f'*g + f*g' 1673 1674 f = newF; 1671 1675 } 1672 1676 z = f; … … 1735 1739 InterpretRec(node.GetSubtree(0), nodeValues, out f, out df); 1736 1740 z = Math.Exp(f); 1737 dz = df.Scale( Math.Exp(f));1741 dz = df.Scale(z); 1738 1742 } else if (node.Symbol is Logarithm) { 1739 1743 Assert(node.SubtreeCount == 1); … … 2148 2152 public Tuple<double, Vector> VariableNodeValueAndGradient(VariableTreeNode node) { 2149 2153 // (f*g)' = (f'*g)+(g'*f) 2150 var g= node2val[node];2151 var f= variableValues[node.VariableName];2154 var w = node2val[node]; 2155 var x = variableValues[node.VariableName]; 2152 2156 2153 2157 return Tuple.Create( 2154 g.Item1 * f.Item1, 2155 Vector.CreateNew(f.Item2).Scale(g.Item1).Add(Vector.CreateNew(g.Item2).Scale(f.Item1))); 2158 w.Item1 * x.Item1, 2159 x.Item2 == Vector.Zero ? Vector.CreateNew(w.Item2).Scale(x.Item1) : 2160 Vector.CreateNew(w.Item2).Scale(x.Item1).Add(Vector.CreateNew(x.Item2).Scale(w.Item1))); 2156 2161 } 2157 2162 … … 2171 2176 } 2172 2177 } else { 2178 throw new NotImplementedException(); 2173 2179 // variable gradient means we want to calculate the gradient over the target variables instead of parameters 2174 2180 for (int paramIdx = 0; paramIdx < leafNodes.Length; paramIdx++) {
Note: See TracChangeset
for help on using the changeset viewer.