Changeset 16915 for branches/2994-AutoDiffForIntervals
- Timestamp:
- 05/07/19 19:52:59 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedConstantOptimizationEvaluator.cs
r16914 r16915 330 330 alglib.minnlccreate(thetaValues.Count, thetaValues.ToArray(), out state); 331 331 alglib.minnlcsetalgoslp(state); // SLP is more robust but slower 332 alglib.minnlcsetcond(state, 0, maxIterations); 332 alglib.minnlcsetbc(state, thetaValues.Select(_ => -10000.0).ToArray(), thetaValues.Select(_ => +10000.0).ToArray()); 333 alglib.minnlcsetcond(state, 1E-7, maxIterations); 333 334 var s = Enumerable.Repeat(1d, thetaValues.Count).ToArray(); // scale is set to unit scale 334 335 alglib.minnlcsetscale(state, s); … … 347 348 // update parameters in tree 348 349 var pIdx = 0; 349 foreach (var node in tree.IterateNodesPostfix().OfType<ConstantTreeNode>()) { 350 node.Value = xOpt[pIdx++]; 350 foreach (var node in tree.IterateNodesPostfix()) { 351 if(node is ConstantTreeNode constTreeNode) { 352 constTreeNode.Value = xOpt[pIdx++]; 353 } else if(node is VariableTreeNode varTreeNode) { 354 varTreeNode.Weight = xOpt[pIdx++]; 355 } 351 356 } 352 357 … … 432 437 } 433 438 } 439 if (node is VariableTreeNode varTreeNode) { 440 var thetaVar = (VariableTreeNode)new Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode(); 441 thetaVar.Weight = 1; 442 thetaVar.VariableName = $"θ{n++}"; 443 444 thetaNames.Add(thetaVar.VariableName); 445 thetaValues.Add(varTreeNode.Weight); 446 447 var parent = varTreeNode.Parent; 448 if (parent != null) { 449 var index = varTreeNode.Parent.IndexOfSubtree(varTreeNode); 450 parent.RemoveSubtree(index); 451 var prodNode = MakeNode<Multiplication>(); 452 varTreeNode.Weight = 1.0; 453 prodNode.AddSubtree(varTreeNode); 454 prodNode.AddSubtree(thetaVar); 455 parent.InsertSubtree(index, prodNode); 456 } 457 } 434 458 } 435 459 return copy;
Note: See TracChangeset
for help on using the changeset viewer.