protected override void Context()
        {
            base.Context();
            _bestColumn    = DomainHelperForSpecs.ObservedData().FirstDataColumn();
            _currentColumn = DomainHelperForSpecs.ObservedData().FirstDataColumn();

            _bestResult    = A.Fake <OptimizationRunResult>();
            _currentResult = A.Fake <OptimizationRunResult>();
            sut.EditParameterIdentification(_parameterIdentification);
            sut.SelectedOutput = A.Fake <OutputMapping>();

            A.CallTo(() => _bestResult.SimulationResultFor(A <string> ._)).Returns(_bestColumn);
            A.CallTo(() => _currentResult.SimulationResultFor(A <string> ._)).Returns(_currentColumn);

            _runState = A.Fake <ParameterIdentificationRunState>();
            A.CallTo(() => _runState.BestResult).Returns(_bestResult);
            A.CallTo(() => _runState.CurrentResult).Returns(_currentResult);
        }
Exemple #2
0
        public JacobianMatrix CalculateFor(ParameterIdentification parameterIdentification, OptimizationRunResult runResult, ICache <ISimulation, ISimModelBatch> simModelBatches)
        {
            var allVariableIdentificationParameters = parameterIdentification.AllVariableIdentificationParameters.ToList();
            var matrix = new JacobianMatrix(allVariableIdentificationParameters.AllNames());

            foreach (var outputMappings in parameterIdentification.AllOutputMappings.GroupBy(x => x.FullOutputPath))
            {
                var outputMapping  = outputMappings.ElementAt(0);
                var simModelBatch  = simModelBatches[outputMapping.Simulation];
                var fullOutputPath = outputMappings.Key;
                var outputResult   = runResult.SimulationResultFor(fullOutputPath);

                matrix.AddRows(jacobianRowFrom(runResult, fullOutputPath, outputResult, allVariableIdentificationParameters, outputMapping, simModelBatch));
                matrix.AddPartialDerivatives(partialDerivativesFrom(fullOutputPath, outputResult, allVariableIdentificationParameters, outputMapping, simModelBatch));
            }

            return(matrix);
        }
Exemple #3
0
        public DataRepository CreateFor(string confidenceIntervalName, double[] confidenceInterval, OutputMapping outputMapping, OptimizationRunResult runResult)
        {
            if (confidenceInterval == null)
            {
                return(new NullDataRepository());
            }

            var fullOutputPath = outputMapping.FullOutputPath;
            var dataRepository = new DataRepository().WithName(fullOutputPath);

            var simulationResult   = runResult.SimulationResultFor(fullOutputPath);
            var simulationBaseGrid = simulationResult.BaseGrid;
            var timeGrid           = new BaseGrid(simulationBaseGrid.Name, simulationBaseGrid.Dimension)
            {
                Values       = simulationBaseGrid.Values,
                DataInfo     = simulationBaseGrid.DataInfo.Clone(),
                QuantityInfo = simulationBaseGrid.QuantityInfo.Clone(),
            };

            var outputColumn = new DataColumn(simulationResult.Name, simulationResult.Dimension, timeGrid)
            {
                Values       = simulationResult.Values,
                DataInfo     = simulationResult.DataInfo.Clone(),
                QuantityInfo = simulationResult.QuantityInfo.Clone(),
            };

            outputColumn.DataInfo.AuxiliaryType = outputMapping.Scaling == Scalings.Linear ? AuxiliaryType.ArithmeticMeanPop : AuxiliaryType.GeometricMeanPop;

            var interval = new DataColumn(confidenceIntervalName, simulationResult.Dimension, timeGrid)
            {
                DisplayUnit  = simulationResult.DisplayUnit,
                Values       = confidenceInterval.ToFloatArray(),
                QuantityInfo = simulationResult.QuantityInfo.Clone(),
                DataInfo     = { Origin = ColumnOrigins.CalculationAuxiliary, MolWeight = outputColumn.DataInfo.MolWeight },
            };

            outputColumn.IsInternal = true;
            interval.AddRelatedColumn(outputColumn);
            dataRepository.Add(interval);

            return(dataRepository);
        }
Exemple #4
0
        protected override void Context()
        {
            base.Context();
            _runResult     = A.Fake <OptimizationRunResult>();
            _outputMapping = A.Fake <OutputMapping>();
            A.CallTo(() => _outputMapping.FullOutputPath).Returns("A|B|C");
            _outputMapping.Scaling = Scalings.Linear;
            var outputTime = new BaseGrid("Time", DomainHelperForSpecs.TimeDimensionForSpecs())
            {
                Values = new [] { 1f, 2f, 3f }
            };

            _outputValues = new DataColumn("Output", DomainHelperForSpecs.ConcentrationDimensionForSpecs(), outputTime)
            {
                Values   = new[] { 15f, 16f, 17f },
                DataInfo = { MolWeight = 150 }
            };

            A.CallTo(() => _runResult.SimulationResultFor(_outputMapping.FullOutputPath)).Returns(_outputValues);
            _confidenceInterval = new[] { 10d, 20d, 30d };
        }
        //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);
        }