Exemplo n.º 1
0
        protected override void Context()
        {
            base.Context();
            _outputMapping1 = A.Fake <OutputMapping>();
            _outputMapping2 = A.Fake <OutputMapping>();
            _outputMapping3 = A.Fake <OutputMapping>();

            var observation1 = DomainHelperForSpecs.ObservedData("OBS1");

            A.CallTo(() => _outputMapping1.WeightedObservedData.ObservedData).Returns(observation1);
            var observation2 = DomainHelperForSpecs.ObservedData("OBS2");

            A.CallTo(() => _outputMapping2.WeightedObservedData.ObservedData).Returns(observation2);
            var observation3 = DomainHelperForSpecs.ObservedData("OBS3");

            A.CallTo(() => _outputMapping3.WeightedObservedData.ObservedData).Returns(observation3);


            _outputResiduals1 = new OutputResiduals("OutputPath1", _outputMapping1.WeightedObservedData, new[] { new Residual(11f, 12f, 1), new Residual(21f, 22f, 1) });
            _outputResiduals2 = new OutputResiduals("OutputPath2", _outputMapping2.WeightedObservedData, new[] { new Residual(31f, 32f, 1), new Residual(41f, 42f, 1) });
            _outputResiduals3 = new OutputResiduals("OutputPath1", _outputMapping3.WeightedObservedData, new[] { new Residual(51f, 52f, 1), new Residual(61f, 62f, 1) });

            _residualResults.AddOutputResiduals(_outputResiduals1);
            _residualResults.AddOutputResiduals(_outputResiduals2);
            _residualResults.AddOutputResiduals(_outputResiduals3);


            A.CallTo(() => _outputMapping1.FullOutputPath).Returns("OutputPath1");
            A.CallTo(() => _outputMapping2.FullOutputPath).Returns("OutputPath2");
            A.CallTo(() => _outputMapping3.FullOutputPath).Returns("OutputPath1");


            A.CallTo(() => _parameterIdentification.AllOutputMappings).Returns(new[] { _outputMapping1, _outputMapping2, _outputMapping3 });
            A.CallTo(() => _parameterIdentification.AllObservedData).Returns(new[] { observation3, observation1, observation2 });
        }
        protected override void Context()
        {
            base.Context();
            _outputResidual1 = new OutputResiduals("O1", _observedData, new[] { new Residual(1f, 5f, 1), new Residual(2f, 10f, 1) });
            _outputResidual2 = new OutputResiduals("O2", _observedData, new[] { new Residual(3f, 15f, 1), new Residual(4f, 19f, 1), new Residual(4f, 20f, 1) });

            _residualResults       = new ResidualsResult();
            _optimizationRunResult = new OptimizationRunResult {
                ResidualsResult = _residualResults
            };
            _residualResults.AddOutputResiduals(_outputResidual1);
            _residualResults.AddOutputResiduals(_outputResidual2);

            _binInterval1 = new BinInterval(0, 17);
            _binInterval2 = new BinInterval(18, 25);
            A.CallTo(_binIntervalCreator).WithReturnType <IReadOnlyList <BinInterval> >().Returns(new[] { _binInterval1, _binInterval2 });
        }
Exemplo n.º 3
0
        private DataRepository getOrCreateScatterDataRepositoryFor(int runIndex, OutputResiduals outputResidual)
        {
            var repositoryName = Captions.ParameterIdentification.SimulationResultsForRun(runIndex);
            var id             = $"{Chart.Id}-{outputResidual.FullOutputPath}-{outputResidual.ObservedData.Id}-{runIndex}";

            var timeValues   = outputResidual.Residuals.Select(x => x.Time).ToList();
            var outputValues = outputResidual.Residuals.Select(x => x.Value).ToList();

            var dataRepository = Chart.DataRepositories.FindById(id);

            if (dataRepository == null)
            {
                dataRepository = createScatterDataRepository(id, repositoryName, outputResidual);
                Chart.AddRepository(dataRepository);
            }

            dataRepository.BaseGrid.Values = timeValues.ToFloatArray();
            dataRepository.FirstDataColumn().Values = outputValues.ToFloatArray();

            return(dataRepository);
        }
        /// <summary>
        ///    Optimize objective function (x[0]-3)^2+(x[1]-4)^2
        /// </summary>
        /// <param name="values"></param>
        /// <returns></returns>
        protected virtual OptimizationRunResult ObjectiveFunction(IReadOnlyList <OptimizedParameterValue> values)
        {
            var residualResult  = new ResidualsResult();
            var outputResiduals = new OutputResiduals("A|B", new DataRepository(), new[]
            {
                new Residual(0, values[0].Value - 3, 1),
                new Residual(0, values[1].Value - 4, 1)
            });

            residualResult.AddOutputResiduals(outputResiduals);

            var optimizationRunResult = new OptimizationRunResult
            {
                ResidualsResult = residualResult,
                Values          = values,
            };

            if (optimizationRunResult.TotalError < _optimizationResult.TotalError)
            {
                _optimizationResult = optimizationRunResult;
            }

            return(optimizationRunResult);
        }
Exemplo n.º 5
0
        private DataRepository createScatterDataRepository(string id, string repositoryName, OutputResiduals outputResidual)
        {
            var dataRepository = createEmptyRepository(id, repositoryName, "Values");
            var scatterColumn  = dataRepository.FirstDataColumn();
            var outputPath     = new List <string>(outputResidual.FullOutputPath.ToPathArray());

            //need to create a unique path containing the observed data name. Since we want to keep the entity name and simulation name, we have to insert before the name
            if (outputPath.Count > 0)
            {
                outputPath.Insert(outputPath.Count - 1, outputResidual.ObservedDataName);
            }

            scatterColumn.QuantityInfo.Path = outputPath;
            return(dataRepository);
        }
 protected override void Because()
 {
     _residualResult  = sut.Calculate(_simulationRunResultsList, _outputMappings);
     _outputResiduals = _residualResult.AllOutputResidualsFor(_fullOutputPath).First();
 }
Exemplo n.º 7
0
 private void updateOutputResidualPath(OutputResiduals residual, string oldName, string newName)
 {
     residual.UpdateFullOutputPath(oldName, newName);
 }