Free cookie consent management tool by TermsFeed Policy Generator

Changeset 16268


Ignore:
Timestamp:
11/01/18 19:39:05 (6 years ago)
Author:
gkronber
Message:

#2925 created a separate algorithm (similar to NLR but for parameter identification of ODE systems) for debugging of the parameter optimization and fixed a problem with the order of items in the checkedItemCollection for TargetVariables

Location:
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/HeuristicLab.Problems.DynamicalSystemsModelling-3.3.csproj

    r16256 r16268  
    112112  <ItemGroup>
    113113    <Compile Include="CVODES.cs" />
     114    <Compile Include="OdeParameterIdentification.cs" />
    114115    <Compile Include="Plugin.cs" />
    115116    <Compile Include="Problem.cs" />
     
    124125  </ItemGroup>
    125126  <ItemGroup>
     127    <ProjectReference Include="..\..\HeuristicLab.Algorithms.DataAnalysis\3.4\HeuristicLab.Algorithms.DataAnalysis-3.4.csproj">
     128      <Project>{2E782078-FA81-4B70-B56F-74CE38DAC6C8}</Project>
     129      <Name>HeuristicLab.Algorithms.DataAnalysis-3.4</Name>
     130    </ProjectReference>
    126131    <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
    127132      <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project>
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs

    r16253 r16268  
    6969      get { return (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
    7070    }
    71     public IValueParameter<ReadOnlyCheckedItemCollection<StringValue>> TargetVariablesParameter {
    72       get { return (IValueParameter<ReadOnlyCheckedItemCollection<StringValue>>)Parameters[TargetVariablesParameterName]; }
    73     }
    74     public IValueParameter<ReadOnlyCheckedItemCollection<StringValue>> FunctionSetParameter {
    75       get { return (IValueParameter<ReadOnlyCheckedItemCollection<StringValue>>)Parameters[FunctionSetParameterName]; }
     71    public IValueParameter<ReadOnlyCheckedItemList<StringValue>> TargetVariablesParameter {
     72      get { return (IValueParameter<ReadOnlyCheckedItemList<StringValue>>)Parameters[TargetVariablesParameterName]; }
     73    }
     74    public IValueParameter<ReadOnlyCheckedItemList<StringValue>> FunctionSetParameter {
     75      get { return (IValueParameter<ReadOnlyCheckedItemList<StringValue>>)Parameters[FunctionSetParameterName]; }
    7676    }
    7777    public IFixedValueParameter<IntValue> MaximumLengthParameter {
     
    105105    IDataAnalysisProblemData IDataAnalysisProblem.ProblemData { get { return ProblemData; } }
    106106
    107     public ReadOnlyCheckedItemCollection<StringValue> TargetVariables {
     107    public ReadOnlyCheckedItemList<StringValue> TargetVariables {
    108108      get { return TargetVariablesParameter.Value; }
    109109    }
    110110
    111     public ReadOnlyCheckedItemCollection<StringValue> FunctionSet {
     111    public ReadOnlyCheckedItemList<StringValue> FunctionSet {
    112112      get { return FunctionSetParameter.Value; }
    113113    }
     
    171171    public Problem()
    172172      : base() {
    173       var targetVariables = new CheckedItemCollection<StringValue>().AsReadOnly(); // HACK: it would be better to provide a new class derived from IDataAnalysisProblem
     173      var targetVariables = new CheckedItemList<StringValue>().AsReadOnly(); // HACK: it would be better to provide a new class derived from IDataAnalysisProblem
    174174      var functions = CreateFunctionSet();
    175175      Parameters.Add(new ValueParameter<IRegressionProblemData>(ProblemDataParameterName, "The data captured from the dynamical system. Use CSV import functionality to import data.", new RegressionProblemData()));
    176       Parameters.Add(new ValueParameter<ReadOnlyCheckedItemCollection<StringValue>>(TargetVariablesParameterName, "Target variables (overrides setting in ProblemData)", targetVariables));
    177       Parameters.Add(new ValueParameter<ReadOnlyCheckedItemCollection<StringValue>>(FunctionSetParameterName, "The list of allowed functions", functions));
     176      Parameters.Add(new ValueParameter<ReadOnlyCheckedItemList<StringValue>>(TargetVariablesParameterName, "Target variables (overrides setting in ProblemData)", targetVariables));
     177      Parameters.Add(new ValueParameter<ReadOnlyCheckedItemList<StringValue>>(FunctionSetParameterName, "The list of allowed functions", functions));
    178178      Parameters.Add(new FixedValueParameter<IntValue>(MaximumLengthParameterName, "The maximally allowed length of each expression. Set to a small value (5 - 25). Default = 10", new IntValue(10)));
    179179      Parameters.Add(new FixedValueParameter<IntValue>(MaximumParameterOptimizationIterationsParameterName, "The maximum number of iterations for optimization of parameters (using L-BFGS). More iterations makes the algorithm slower, fewer iterations might prevent convergence in the optimization scheme. Default = 100", new IntValue(100)));
     
    235235      var rows = episodes.SelectMany(e => Enumerable.Range(e.Start, e.End - e.Start)).ToArray();
    236236      var problemData = ProblemData;
    237       var targetVars = TargetVariables.CheckedItems.Select(i => i.Value).ToArray();
     237      var targetVars = TargetVariables.CheckedItems.OrderBy(i => i.Index).Select(i => i.Value.Value).ToArray();
    238238      var latentVariables = Enumerable.Range(1, NumberOfLatentVariables).Select(i => "λ" + i).ToArray(); // TODO: must coincide with the variables which are actually defined in the grammar and also for which we actually have trees
    239239      var targetValues = new double[rows.Length, targetVars.Length];
     
    258258        }
    259259      }
    260       var theta = paramNodes.Select(_ => random.NextDouble() * 2.0 - 1.0).ToArray(); // init params randomly from Unif(-1,1)
     260      // init params randomly from Unif(-1e-5, 1e-5)
     261      var theta = paramNodes.Select(_ => random.NextDouble() * 2.0e-5 - 1.0e-5).ToArray();
    261262
    262263      optTheta = new double[0];
     
    266267        alglib.minlbfgscreate(Math.Min(theta.Length, 5), theta, out state);
    267268        alglib.minlbfgssetcond(state, 0.0, 0.0, 0.0, MaximumParameterOptimizationIterations);
     269        alglib.minlbfgssetgradientcheck(state, 1e-6);
    268270        alglib.minlbfgsoptimize(state, EvaluateObjectiveAndGradient, null,
    269271          new object[] { trees, targetVars, problemData, targetValues, episodes.ToArray(), NumericIntegrationSteps, latentVariables, OdeSolver }); //TODO: create a type
     
    386388
    387389      var problemData = ProblemData;
    388       var targetVars = TargetVariables.CheckedItems.Select(i => i.Value).ToArray();
     390      var targetVars = TargetVariables.CheckedItems.OrderBy(i => i.Index).Select(i => i.Value.Value).ToArray();
    389391      var latentVariables = Enumerable.Range(1, NumberOfLatentVariables).Select(i => "λ" + i).ToArray(); // TODO: must coincide with the variables which are actually defined in the grammar and also for which we actually have trees
    390392
     
    741743                      var varName = n.Symbol.Name;
    742744                      var varIdx = Array.IndexOf(calculatedVariables, varName); // TODO: perf!
     745                      if (varIdx < 0) throw new InvalidProgramException();
    743746                      var y_i = CVODES.NV_Get_Ith_S(y, (long)varIdx);
    744747                      nodeValues.Add(n, Tuple.Create(y_i, Vector.Zero)); // no gradient needed
     
    782785              var varName = n.Symbol.Name;
    783786              var varIdx = Array.IndexOf(calculatedVariables, varName); // TODO: perf!
     787              if (varIdx < 0) throw new InvalidProgramException();
     788
    784789              var y_i = CVODES.NV_Get_Ith_S(y, (long)varIdx);
    785790              var gArr = new double[CVODES.NV_LENGTH_S(y)]; // backing array
     
    829834                var varName = n.Symbol.Name;
    830835                var varIdx = Array.IndexOf(calculatedVariables, varName); // TODO: perf!
     836                if (varIdx < 0) throw new InvalidProgramException();
     837
    831838                var y_i = CVODES.NV_Get_Ith_S(y, (long)varIdx);
    832839                var gArr = new double[d]; // backing array
     
    10531060    }
    10541061
    1055     private void CheckedFunctionsChanged(object sender, CollectionItemsChangedEventArgs<StringValue> e) {
     1062    private void CheckedFunctionsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> e) {
    10561063      UpdateGrammarAndEncoding();
    10571064    }
     
    10611068    }
    10621069
    1063     private void CheckedTargetVariablesChanged(object sender, CollectionItemsChangedEventArgs<StringValue> e) {
     1070    private void CheckedTargetVariablesChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> e) {
    10641071      UpdateGrammarAndEncoding();
    10651072    }
     
    10901097    }
    10911098
    1092     private ReadOnlyCheckedItemCollection<StringValue> CreateFunctionSet() {
    1093       var l = new CheckedItemCollection<StringValue>();
     1099    private ReadOnlyCheckedItemList<StringValue> CreateFunctionSet() {
     1100      var l = new CheckedItemList<StringValue>();
    10941101      l.Add(new StringValue("+").AsReadOnly());
    10951102      l.Add(new StringValue("*").AsReadOnly());
     
    11131120
    11141121    private void UpdateTargetVariables() {
    1115       var currentlySelectedVariables = TargetVariables.CheckedItems.Select(i => i.Value).ToArray();
    1116 
    1117       var newVariablesList = new CheckedItemCollection<StringValue>(ProblemData.Dataset.VariableNames.Select(str => new StringValue(str).AsReadOnly()).ToArray()).AsReadOnly();
     1122      var currentlySelectedVariables = TargetVariables.CheckedItems
     1123        .OrderBy(i => i.Index)
     1124        .Select(i => i.Value.Value)
     1125        .ToArray();
     1126
     1127      var newVariablesList = new CheckedItemList<StringValue>(ProblemData.Dataset.VariableNames.Select(str => new StringValue(str).AsReadOnly()).ToArray()).AsReadOnly();
    11181128      var matchingItems = newVariablesList.Where(item => currentlySelectedVariables.Contains(item.Value)).ToArray();
    11191129      foreach (var matchingItem in matchingItems) {
     
    11381148      // whenever ProblemData is changed we create a new grammar with the necessary symbols
    11391149      var g = new SimpleSymbolicExpressionGrammar();
    1140       g.AddSymbols(FunctionSet.CheckedItems.Select(i => i.Value).ToArray(), 2, 2);
     1150      g.AddSymbols(FunctionSet.CheckedItems.OrderBy(i => i.Index).Select(i => i.Value.Value).ToArray(), 2, 2);
    11411151
    11421152      // TODO
     
    11471157      //}, 1, 1);
    11481158
    1149       foreach (var variableName in ProblemData.AllowedInputVariables.Union(TargetVariables.CheckedItems.Select(i => i.Value)))
     1159      foreach (var variableName in ProblemData.AllowedInputVariables.Union(TargetVariables.CheckedItems.Select(i => i.Value.Value)))
    11501160        g.AddTerminalSymbol(variableName);
    11511161
Note: See TracChangeset for help on using the changeset viewer.