private QuantityValues valuesFrom(DataColumn dataColumn, string quantityPath, ISimModelBatch simModel, string[] parameters) { return(new QuantityValues { ColumnId = dataColumn.Id, QuantityPath = quantityPath, Values = dataColumn.Values.ToArray(), Sensitivities = parameters.ToDictionary(p => p, p => simModel?.SensitivityValuesFor(quantityPath, p)) }); }
private static double retrievePartialDerivativeForOutputs(ParameterSelection linkedParameter, OutputMapping outputMapping, ISimModelBatch simModelBatch, int timeIndex) { if (!Equals(linkedParameter.Simulation, outputMapping.Simulation)) { return(0); } var sensitivity = simModelBatch.SensitivityValuesFor(outputMapping.OutputPath, linkedParameter.Path); return(sensitivity[timeIndex]); }
//context shoud represent use case defined in 47-7990 Management of Jacobi Matrix protected override void Context() { _parameterIdentification = A.Fake <ParameterIdentification>(); _runResult = A.Fake <OptimizationRunResult>(); _simModelBatches = new Dictionary <ISimulation, ISimModelBatch>(); _allOutputMappings = new List <OutputMapping>(); _allVariableIdentificationParameters = new List <IdentificationParameter>(); A.CallTo(() => _parameterIdentification.AllOutputMappings).Returns(_allOutputMappings); A.CallTo(() => _parameterIdentification.AllVariableIdentificationParameters).Returns(_allVariableIdentificationParameters); sut = new JacobianMatrixCalculator(); _output1 = A.Fake <OutputMapping>(); _simulation1 = A.Fake <ISimulation>(); _simModelBatch1 = A.Fake <ISimModelBatch>(); _simModelBatches.Add(_simulation1, _simModelBatch1); A.CallTo(() => _output1.Simulation).Returns(_simulation1); A.CallTo(() => _output1.FullOutputPath).Returns("S1|OutputPath1"); A.CallTo(() => _output1.OutputPath).Returns("OutputPath1"); _allOutputMappings.Add(_output1); _output2 = A.Fake <OutputMapping>(); _simulation2 = A.Fake <ISimulation>(); _simModelBatch2 = A.Fake <ISimModelBatch>(); A.CallTo(() => _output2.Simulation).Returns(_simulation2); A.CallTo(() => _output2.FullOutputPath).Returns("S2|OutputPath2"); A.CallTo(() => _output2.OutputPath).Returns("OutputPath2"); _simModelBatches.Add(_simulation2, _simModelBatch2); _allOutputMappings.Add(_output2); _identificationParameter1 = new IdentificationParameter().WithName("IP1"); _identificationParameter2 = new IdentificationParameter().WithName("IP2"); _ps1 = A.Fake <ParameterSelection>(); _ps1.Parameter.Value = 100; A.CallTo(() => _ps1.FullQuantityPath).Returns("S1|ParameterPath1"); A.CallTo(() => _ps1.Path).Returns("ParameterPath1"); A.CallTo(() => _ps1.Simulation).Returns(_simulation1); _identificationParameter1.AddLinkedParameter(_ps1); _ps2 = A.Fake <ParameterSelection>(); _ps2.Parameter.Value = 200; A.CallTo(() => _ps2.FullQuantityPath).Returns("S2|ParameterPath2"); A.CallTo(() => _ps2.Path).Returns("ParameterPath2"); A.CallTo(() => _ps2.Simulation).Returns(_simulation2); A.CallTo(() => _ps2.Dimension).Returns(_ps1.Dimension); _identificationParameter1.AddLinkedParameter(_ps2); _ps3 = A.Fake <ParameterSelection>(); _ps3.Parameter.Value = 300; A.CallTo(() => _ps3.FullQuantityPath).Returns("S2|ParameterPath3"); A.CallTo(() => _ps3.Path).Returns("ParameterPath3"); A.CallTo(() => _ps3.Simulation).Returns(_simulation2); _identificationParameter2.AddLinkedParameter(_ps3); _allVariableIdentificationParameters.Add(_identificationParameter1); _allVariableIdentificationParameters.Add(_identificationParameter2); A.CallTo(() => _runResult.AllResidualsFor(_output1.FullOutputPath)).Returns(new[] { new Residual(1, 11, 1), new Residual(2, 21, 2), new Residual(3, 31, 0) }); A.CallTo(() => _runResult.AllResidualsFor(_output2.FullOutputPath)).Returns(new[] { new Residual(1, 12, 3), new Residual(3, 32, 4), new Residual(4, 42, 5) }); A.CallTo(() => _simModelBatch1.SensitivityValuesFor(_output1.OutputPath, _ps1.Path)).Returns(new[] { 11d, 21d, 31d, 41d, 51d }); A.CallTo(() => _simModelBatch1.SensitivityValuesFor(_output1.OutputPath, _ps2.Path)).Throws(new OSPSuiteException()); A.CallTo(() => _simModelBatch1.SensitivityValuesFor(_output1.OutputPath, _ps3.Path)).Throws(new OSPSuiteException()); A.CallTo(() => _simModelBatch2.SensitivityValuesFor(_output2.OutputPath, _ps1.Path)).Throws(new OSPSuiteException()); A.CallTo(() => _simModelBatch2.SensitivityValuesFor(_output2.OutputPath, _ps2.Path)).Returns(new[] { 12d, 22d, 32d, 42d, 52d, 62d }); A.CallTo(() => _simModelBatch2.SensitivityValuesFor(_output2.OutputPath, _ps3.Path)).Returns(new[] { 13d, 23d, 33d, 43d, 53d, 63d }); _simResults1 = new DataColumn { BaseGrid = new BaseGrid("Time", DomainHelperForSpecs.TimeDimensionForSpecs()) { Values = new[] { 1f, 2f, 3f, 4f, 5f } }, Values = new[] { 10f, 20f, 30f, 40f, 50f } }; A.CallTo(() => _runResult.SimulationResultFor(_output1.FullOutputPath)).Returns(_simResults1); _simResults2 = new DataColumn { BaseGrid = new BaseGrid("Time", DomainHelperForSpecs.TimeDimensionForSpecs()) { Values = new[] { 1f, 2f, 3f, 4f, 5f, 6f } }, Values = new[] { 10f, 20f, 30f, 40f, 50f, 60f } }; A.CallTo(() => _runResult.SimulationResultFor(_output2.FullOutputPath)).Returns(_simResults2); }