Changeset 16915


Ignore:
Timestamp:
05/07/19 19:52:59 (3 months ago)
Author:
gkronber
Message:

#2994: add boundary constraints and threshold for epsx hoping to prevent endless loop in alglib, add optimization of variable weights

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2994-AutoDiffForIntervals/HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Extensions/ConstrainedConstantOptimizationEvaluator.cs

    r16914 r16915  
    330330        alglib.minnlccreate(thetaValues.Count, thetaValues.ToArray(), out state);
    331331        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);
    333334        var s = Enumerable.Repeat(1d, thetaValues.Count).ToArray();  // scale is set to unit scale
    334335        alglib.minnlcsetscale(state, s);
     
    347348          // update parameters in tree
    348349          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            }
    351356          }
    352357
     
    432437          }
    433438        }
     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        }
    434458      }
    435459      return copy;
Note: See TracChangeset for help on using the changeset viewer.