Changeset 16268
- Timestamp:
- 11/01/18 19:39:05 (6 years ago)
- 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 112 112 <ItemGroup> 113 113 <Compile Include="CVODES.cs" /> 114 <Compile Include="OdeParameterIdentification.cs" /> 114 115 <Compile Include="Plugin.cs" /> 115 116 <Compile Include="Problem.cs" /> … … 124 125 </ItemGroup> 125 126 <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> 126 131 <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj"> 127 132 <Project>{887425B4-4348-49ED-A457-B7D2C26DDBF9}</Project> -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs
r16253 r16268 69 69 get { return (IValueParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; } 70 70 } 71 public IValueParameter<ReadOnlyCheckedItem Collection<StringValue>> TargetVariablesParameter {72 get { return (IValueParameter<ReadOnlyCheckedItem Collection<StringValue>>)Parameters[TargetVariablesParameterName]; }73 } 74 public IValueParameter<ReadOnlyCheckedItem Collection<StringValue>> FunctionSetParameter {75 get { return (IValueParameter<ReadOnlyCheckedItem Collection<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]; } 76 76 } 77 77 public IFixedValueParameter<IntValue> MaximumLengthParameter { … … 105 105 IDataAnalysisProblemData IDataAnalysisProblem.ProblemData { get { return ProblemData; } } 106 106 107 public ReadOnlyCheckedItem Collection<StringValue> TargetVariables {107 public ReadOnlyCheckedItemList<StringValue> TargetVariables { 108 108 get { return TargetVariablesParameter.Value; } 109 109 } 110 110 111 public ReadOnlyCheckedItem Collection<StringValue> FunctionSet {111 public ReadOnlyCheckedItemList<StringValue> FunctionSet { 112 112 get { return FunctionSetParameter.Value; } 113 113 } … … 171 171 public Problem() 172 172 : base() { 173 var targetVariables = new CheckedItem Collection<StringValue>().AsReadOnly(); // HACK: it would be better to provide a new class derived from IDataAnalysisProblem173 var targetVariables = new CheckedItemList<StringValue>().AsReadOnly(); // HACK: it would be better to provide a new class derived from IDataAnalysisProblem 174 174 var functions = CreateFunctionSet(); 175 175 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<ReadOnlyCheckedItem Collection<StringValue>>(TargetVariablesParameterName, "Target variables (overrides setting in ProblemData)", targetVariables));177 Parameters.Add(new ValueParameter<ReadOnlyCheckedItem Collection<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)); 178 178 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))); 179 179 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))); … … 235 235 var rows = episodes.SelectMany(e => Enumerable.Range(e.Start, e.End - e.Start)).ToArray(); 236 236 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(); 238 238 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 239 239 var targetValues = new double[rows.Length, targetVars.Length]; … … 258 258 } 259 259 } 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(); 261 262 262 263 optTheta = new double[0]; … … 266 267 alglib.minlbfgscreate(Math.Min(theta.Length, 5), theta, out state); 267 268 alglib.minlbfgssetcond(state, 0.0, 0.0, 0.0, MaximumParameterOptimizationIterations); 269 alglib.minlbfgssetgradientcheck(state, 1e-6); 268 270 alglib.minlbfgsoptimize(state, EvaluateObjectiveAndGradient, null, 269 271 new object[] { trees, targetVars, problemData, targetValues, episodes.ToArray(), NumericIntegrationSteps, latentVariables, OdeSolver }); //TODO: create a type … … 386 388 387 389 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(); 389 391 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 390 392 … … 741 743 var varName = n.Symbol.Name; 742 744 var varIdx = Array.IndexOf(calculatedVariables, varName); // TODO: perf! 745 if (varIdx < 0) throw new InvalidProgramException(); 743 746 var y_i = CVODES.NV_Get_Ith_S(y, (long)varIdx); 744 747 nodeValues.Add(n, Tuple.Create(y_i, Vector.Zero)); // no gradient needed … … 782 785 var varName = n.Symbol.Name; 783 786 var varIdx = Array.IndexOf(calculatedVariables, varName); // TODO: perf! 787 if (varIdx < 0) throw new InvalidProgramException(); 788 784 789 var y_i = CVODES.NV_Get_Ith_S(y, (long)varIdx); 785 790 var gArr = new double[CVODES.NV_LENGTH_S(y)]; // backing array … … 829 834 var varName = n.Symbol.Name; 830 835 var varIdx = Array.IndexOf(calculatedVariables, varName); // TODO: perf! 836 if (varIdx < 0) throw new InvalidProgramException(); 837 831 838 var y_i = CVODES.NV_Get_Ith_S(y, (long)varIdx); 832 839 var gArr = new double[d]; // backing array … … 1053 1060 } 1054 1061 1055 private void CheckedFunctionsChanged(object sender, CollectionItemsChangedEventArgs< StringValue> e) {1062 private void CheckedFunctionsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> e) { 1056 1063 UpdateGrammarAndEncoding(); 1057 1064 } … … 1061 1068 } 1062 1069 1063 private void CheckedTargetVariablesChanged(object sender, CollectionItemsChangedEventArgs< StringValue> e) {1070 private void CheckedTargetVariablesChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<StringValue>> e) { 1064 1071 UpdateGrammarAndEncoding(); 1065 1072 } … … 1090 1097 } 1091 1098 1092 private ReadOnlyCheckedItem Collection<StringValue> CreateFunctionSet() {1093 var l = new CheckedItem Collection<StringValue>();1099 private ReadOnlyCheckedItemList<StringValue> CreateFunctionSet() { 1100 var l = new CheckedItemList<StringValue>(); 1094 1101 l.Add(new StringValue("+").AsReadOnly()); 1095 1102 l.Add(new StringValue("*").AsReadOnly()); … … 1113 1120 1114 1121 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(); 1118 1128 var matchingItems = newVariablesList.Where(item => currentlySelectedVariables.Contains(item.Value)).ToArray(); 1119 1129 foreach (var matchingItem in matchingItems) { … … 1138 1148 // whenever ProblemData is changed we create a new grammar with the necessary symbols 1139 1149 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); 1141 1151 1142 1152 // TODO … … 1147 1157 //}, 1, 1); 1148 1158 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))) 1150 1160 g.AddTerminalSymbol(variableName); 1151 1161
Note: See TracChangeset
for help on using the changeset viewer.