Changeset 16653 for branches/2925_AutoDiffForDynamicalModels
- Timestamp:
- 03/06/19 16:20:36 (6 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Problem.cs
r16652 r16653 23 23 using System.Collections.Generic; 24 24 using System.Diagnostics; 25 using System.Globalization; 25 26 using System.Linq; 26 27 using HeuristicLab.Analysis; … … 286 287 } 287 288 var adjustedEpisodes = episodes.Select(ep => new IntRange(ep.Start, ep.End - 1)); // because we lose the last row in the differencing step 289 290 // data for input variables is assumed to be known 291 // input variables in pretuning are all target variables and all variable names that occur in the tree 292 var inputVariables = targetVars.Concat(t.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName)); 293 288 294 var myState = new OptimizationData(new[] { t }, 289 295 targetVars, 290 problemData.AllowedInputVariables.Concat(targetVars).ToArray(),296 inputVariables.ToArray(), 291 297 problemData, new[] { targetValuesDiff.ToArray() }, adjustedEpisodes.ToArray(), -99, latentVariables, string.Empty); // TODO 292 298 var paramCount = myState.nodeValueLookup.ParameterCount; … … 346 352 } 347 353 348 var myState = new OptimizationData(trees, targetVars, problemData.AllowedInputVariables.ToArray(), problemData, targetValues, episodes.ToArray(), numericIntegrationSteps, latentVariables, odeSolver); 354 // data for input variables is assumed to be known 355 // input variables are all variable names that occur in the trees except for target variables (we assume that trees have been generated correctly) 356 var inputVariables = trees.SelectMany(t => t.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName)).Except(targetVars); 357 358 var myState = new OptimizationData(trees, targetVars, inputVariables.ToArray(), problemData, targetValues, episodes.ToArray(), numericIntegrationSteps, latentVariables, odeSolver); 349 359 optTheta = initialTheta; 350 360 … … 402 412 // update variable values 403 413 foreach (var variable in variables) { 404 nodeValueLookup.SetVariableValue(variable, ds.GetDoubleValue(variable, rows[trainIdx])); // TODO: perf 414 // in this problem we also allow fixed numeric parameters (represented as variables with the value as name) 415 if (double.TryParse(variable, NumberStyles.Float, CultureInfo.InvariantCulture, out double value)) { 416 nodeValueLookup.SetVariableValue(variable, value); // TODO: Perf we don't need to set this for each index 417 } else { 418 nodeValueLookup.SetVariableValue(variable, ds.GetDoubleValue(variable, rows[trainIdx])); // TODO: perf 419 } 405 420 } 406 421 // interpret all trees … … 431 446 // update variable values 432 447 foreach (var variable in variables) { 433 nodeValueLookup.SetVariableValue(variable, ds.GetDoubleValue(variable, rows[trainIdx])); // TODO: perf 448 // in this problem we also allow fixed numeric parameters (represented as variables with the value as name) 449 if (double.TryParse(variable, NumberStyles.Float, CultureInfo.InvariantCulture, out double value)) { 450 nodeValueLookup.SetVariableValue(variable, value); // TODO: Perf we don't need to set this for each index 451 } else { 452 nodeValueLookup.SetVariableValue(variable, ds.GetDoubleValue(variable, rows[trainIdx])); // TODO: perf 453 } 434 454 } 435 455 … … 561 581 results["Models"].Value = models; 562 582 } else { 563 var optimizationData = new OptimizationData(trees, targetVars, problemData.AllowedInputVariables.ToArray(), problemData, null, TrainingEpisodes.ToArray(), NumericIntegrationSteps, latentVariables, OdeSolver); 583 // data for input variables is assumed to be known 584 // input variables are all variable names that occur in the trees except for target variables (we assume that trees have been generated correctly) 585 var inputVariables = trees.SelectMany(t => t.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName)).Except(targetVars); 586 587 var optimizationData = new OptimizationData(trees, targetVars, inputVariables.ToArray(), problemData, null, TrainingEpisodes.ToArray(), NumericIntegrationSteps, latentVariables, OdeSolver); 564 588 var trainingPrediction = Integrate(optimizationData).ToArray(); 565 589 … … 731 755 var trees = optimizationData.trees; 732 756 var dataset = optimizationData.problemData.Dataset; 733 var inputVariables = optimizationData. problemData.AllowedInputVariables.ToArray();757 var inputVariables = optimizationData.variables; 734 758 var targetVariables = optimizationData.targetVariables; 735 759 var latentVariables = optimizationData.latentVariables; … … 753 777 // initialize values for inputs and targets from dataset 754 778 foreach (var varName in inputVariables) { 755 var y0 = dataset.GetDoubleValue(varName, t0); 756 nodeValues.SetVariableValue(varName, y0, Vector.Zero); 779 // in this problem we also allow fixed numeric parameters (represented as variables with the value as name) 780 if (double.TryParse(varName, NumberStyles.Float, CultureInfo.InvariantCulture, out double value)) { 781 nodeValues.SetVariableValue(varName, value, Vector.Zero); 782 } else { 783 var y0 = dataset.GetDoubleValue(varName, t0); 784 nodeValues.SetVariableValue(varName, y0, Vector.Zero); 785 } 757 786 } 758 787 foreach (var varName in targetVariables) { … … 815 844 // update for next time step (only the inputs) 816 845 foreach (var varName in inputVariables) { 817 nodeValues.SetVariableValue(varName, dataset.GetDoubleValue(varName, t), Vector.Zero); 846 // in this problem we also allow fixed numeric parameters (represented as variables with the value as name) 847 if (double.TryParse(varName, NumberStyles.Float, CultureInfo.InvariantCulture, out double value)) { 848 // value is unchanged 849 } else { 850 nodeValues.SetVariableValue(varName, dataset.GetDoubleValue(varName, t), Vector.Zero); 851 } 818 852 } 819 853 } -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DynamicalSystemsModelling/3.3/Solution.cs
r16610 r16653 91 91 // var random = new FastRandom(12345); 92 92 // snmse = Problem.OptimizeForEpisodes(trees, problemData, targetVars, latentVariables, random, new[] { forecastEpisode }, 100, numericIntegrationSteps, odeSolver); 93 var optimizationData = new Problem.OptimizationData(trees, targetVars, problemData.AllowedInputVariables.ToArray(), problemData, null, new[] { forecastEpisode }, numericIntegrationSteps, latentVariables, odeSolver); 93 94 var inputVariables = trees.SelectMany(t => t.IterateNodesPrefix().OfType<VariableTreeNode>().Select(n => n.VariableName)).Except(targetVars); 95 96 var optimizationData = new Problem.OptimizationData(trees, targetVars, inputVariables.ToArray(), problemData, null, new[] { forecastEpisode }, numericIntegrationSteps, latentVariables, odeSolver); 94 97 // 95 98 //
Note: See TracChangeset
for help on using the changeset viewer.