Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16126


Ignore:
Timestamp:
09/06/18 13:27:50 (6 years ago)
Author:
lkammere
Message:

#2925: added constants values to tree in result view and minor bugfix when initializing problem.

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

    r15968 r16126  
    180180      <Private>False</Private>
    181181    </ProjectReference>
     182    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
     183      <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
     184      <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name>
     185    </ProjectReference>
    182186    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis\3.4\HeuristicLab.Problems.DataAnalysis-3.4.csproj">
    183187      <Project>{DF87C13E-A889-46FF-8153-66DCAA8C5674}</Project>
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs

    r15971 r16126  
    3434using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3535using HeuristicLab.Problems.DataAnalysis;
     36using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3637using HeuristicLab.Problems.Instances;
    3738
     
    248249        alglib.minlbfgscreate(Math.Min(theta.Length, 5), theta, out state);
    249250        alglib.minlbfgssetcond(state, 0.0, 0.0, 0.0, MaximumParameterOptimizationIterations);
    250         alglib.minlbfgsoptimize(state, EvaluateObjectiveAndGradient, null, 
     251        alglib.minlbfgsoptimize(state, EvaluateObjectiveAndGradient, null,
    251252          new object[] { trees, targetVars, problemData, nodeIdx, targetValues, rows, NumericIntegrationSteps, latentVariables }); //TODO: create a type
    252253        alglib.minlbfgsresults(state, out optTheta, out report);
     
    284285      double[] grad = new double[optTheta.Length];
    285286      double optQuality = double.NaN;
    286       EvaluateObjectiveAndGradient(optTheta, ref optQuality, grad, 
     287      EvaluateObjectiveAndGradient(optTheta, ref optQuality, grad,
    287288        new object[] { trees, targetVars, problemData, nodeIdx, targetValues, rows, NumericIntegrationSteps, latentVariables });
    288289      if (double.IsNaN(optQuality) || double.IsInfinity(optQuality)) return 10E6; // return a large value (TODO: be consistent by using NMSE)
     
    383384       trainingRows,
    384385       nodeIdx,
    385        optTheta, 
     386       optTheta,
    386387       NumericIntegrationSteps).ToArray();
    387388
     
    407408       testRows,
    408409       nodeIdx,
    409        optTheta, 
     410       optTheta,
    410411       NumericIntegrationSteps).ToArray();
    411412
     
    422423      results["Prediction (training)"].Value = trainingList.AsReadOnly();
    423424      results["Prediction (test)"].Value = testList.AsReadOnly();
    424       results["Models"].Value = new ItemList<ISymbolicExpressionTree>(trees).AsReadOnly(); // TODO: simplify trees
     425
     426      var modelList = new ItemList<ISymbolicExpressionTree>();
     427      foreach (var tree in trees) {
     428        var shownTree = (ISymbolicExpressionTree)tree.Clone();
     429        var constantsNodeOrig = tree.IterateNodesPrefix().Where(IsConstantNode);
     430        var constantsNodeShown = shownTree.IterateNodesPrefix().Where(IsConstantNode);
     431
     432        foreach (var n in constantsNodeOrig.Zip(constantsNodeShown, (original, shown) => new { original, shown })) {
     433          double constantsVal = optTheta[nodeIdx[n.original]];
     434
     435          ConstantTreeNode replacementNode = new ConstantTreeNode(new Constant()) { Value = constantsVal };
     436
     437          var parentNode = n.shown.Parent;
     438          int replacementIndex = parentNode.IndexOfSubtree(n.shown);
     439          parentNode.RemoveSubtree(replacementIndex);
     440          parentNode.InsertSubtree(replacementIndex, replacementNode);
     441        }
     442        // TODO: simplify trees
     443
     444        modelList.Add(shownTree);
     445      }
     446      results["Models"].Value = modelList.AsReadOnly();
    425447    }
    426448
     
    613635    private void OnProblemDataChanged() {
    614636      UpdateTargetVariables();        // implicitly updates other dependent parameters
    615 
     637      UpdateGrammarAndEncoding();
    616638      var handler = ProblemDataChanged;
    617639      if (handler != null) handler(this, EventArgs.Empty);
Note: See TracChangeset for help on using the changeset viewer.