Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16664 for branches


Ignore:
Timestamp:
03/07/19 19:17:18 (5 years ago)
Author:
gkronber
Message:

#2925: generate individual solutions for each of the trees to allow individual analysis of functions e.g. using PDP (only works without latent variables so far)

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  
    220220      <Private>False</Private>
    221221    </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>
    222226    <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj">
    223227      <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project>
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs

    r16663 r16664  
    3939using Variable = HeuristicLab.Problems.DataAnalysis.Symbolic.Variable;
    4040using HEAL.Attic;
     41using HeuristicLab.Problems.DataAnalysis.Symbolic.Regression;
    4142
    4243namespace HeuristicLab.Problems.DynamicalSystemsModelling {
     
    766767          simplifiedTreeVar.Value = TreeSimplifier.Simplify(tree);
    767768          models.Add(simplifiedTreeVar);
    768 
    769769        }
    770770
    771771        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        }
    772788        #endregion
    773789      }
     
    13331349        var f = InterpretRec(node.GetSubtree(0), nodeValues);
    13341350        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);
    13351362      } else throw new NotSupportedException("unsupported symbol");
    13361363    }
     
    14401467        z = Math.Log(f);
    14411468        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);
    14421481      } else {
    14431482        throw new NotSupportedException("unsupported symbol");
     
    15451584      l.Add(new StringValue("Cosine").AsReadOnly());
    15461585      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());
    15471590      return l.AsReadOnly();
    15481591    }
Note: See TracChangeset for help on using the changeset viewer.