public DataTable SensitivityAnalysisResultsToDataTable(SensitivityAnalysisRunResult sensitivityAnalysisRunResult, IModelCoreSimulation simulation)
        {
            var dataTable = new DataTable(simulation.Name);

            dataTable.AddColumn <string>(Constants.SensitivityAnalysisResults.QUANTITY_PATH);
            dataTable.AddColumn <string>(Constants.SensitivityAnalysisResults.PARAMETER);
            dataTable.AddColumn <string>(Constants.SensitivityAnalysisResults.PK_PARAMETER);
            dataTable.AddColumn <string>(Constants.SensitivityAnalysisResults.VALUE);
            dataTable.AddColumn <string>(Constants.SensitivityAnalysisResults.PARAMETER_PATH);

            dataTable.BeginLoadData();
            foreach (var pkParameterSensitivity in sensitivityAnalysisRunResult.AllPKParameterSensitivities)
            {
                var row = dataTable.NewRow();
                row[Constants.SensitivityAnalysisResults.QUANTITY_PATH]  = pkParameterSensitivity.QuantityPath.InQuotes();
                row[Constants.SensitivityAnalysisResults.PARAMETER]      = pkParameterSensitivity.ParameterName.InQuotes();
                row[Constants.SensitivityAnalysisResults.PK_PARAMETER]   = pkParameterSensitivity.PKParameterName.InQuotes();
                row[Constants.SensitivityAnalysisResults.VALUE]          = pkParameterSensitivity.Value.ConvertedTo <string>();
                row[Constants.SensitivityAnalysisResults.PARAMETER_PATH] = pkParameterSensitivity.ParameterPath.InQuotes();
                dataTable.Rows.Add(row);
            }

            dataTable.EndLoadData();
            return(dataTable);
        }
예제 #2
0
        protected override void Context()
        {
            base.Context();
            _runOptions = new SensitivityAnalysisRunOptions();
            _allEvents  = new List <SensitivityAnalysisEvent>();
            A.CallTo(() => _eventPublisher.PublishEvent(A <SensitivityAnalysisStartedEvent> ._))
            .Invokes(x => _allEvents.Add(x.GetArgument <SensitivityAnalysisStartedEvent>(0)));

            A.CallTo(() => _eventPublisher.PublishEvent(A <SensitivityAnalysisTerminatedEvent> ._))
            .Invokes(x => _allEvents.Add(x.GetArgument <SensitivityAnalysisTerminatedEvent>(0)));

            A.CallTo(() => _eventPublisher.PublishEvent(A <SensitivityAnalysisResultsUpdatedEvent> ._))
            .Invokes(x => _allEvents.Add(x.GetArgument <SensitivityAnalysisResultsUpdatedEvent>(0)));

            _variationData = A.Fake <VariationData>();
            _dataTable     = new DataTable();
            A.CallTo(() => _variationData.ToDataTable()).Returns(_dataTable);
            A.CallTo(() => _sensitivityAnalysisVariationDataCreator.CreateForRun(_sensitivityAnalysis)).Returns(_variationData);
            _populationRunResult = new PopulationRunResults {
                Results = new SimulationResults()
            };
            A.CallTo(() => _populationRunner.RunPopulationAsync(_modelCoreSimulation, _runOptions, _dataTable, null, null)).ReturnsAsync(_populationRunResult);

            _sensitivityAnalysisResults = new SensitivityAnalysisRunResult();
            A.CallTo(() => _runResultCalculator.CreateFor(_sensitivityAnalysis, _variationData, _populationRunResult.Results, false)).Returns(_sensitivityAnalysisResults);
        }
        public DataTable MapFrom(SensitivityAnalysis sensitivityAnalysis, SensitivityAnalysisRunResult sensitivityAnalysisRunResult)
        {
            var dataTable = new DataTable(Captions.SensitivityAnalysis.Results);

            dataTable.AddColumns <string>(Captions.SensitivityAnalysis.Output, Captions.SensitivityAnalysis.PKParameterName, Captions.SensitivityAnalysis.ParameterName, Captions.SensitivityAnalysis.ParameterDisplayPath, Captions.SensitivityAnalysis.PKParameterDescription, Captions.SensitivityAnalysis.ParameterPath);
            dataTable.AddColumn <double>(Captions.SensitivityAnalysis.Value);
            sensitivityAnalysisRunResult.AllPKParameterSensitivities.Each(x => addParameterSensitivity(x, dataTable, sensitivityAnalysis));
            return(dataTable);
        }
예제 #4
0
        public SensitivityAnalysisRunResult CreateFor(SensitivityAnalysis sensitivityAnalysis, VariationData variationData, SimulationResults simulationResults, bool addOutputParameterSensitivitiesToResult)
        {
            var sensitivityRunResult = new SensitivityAnalysisRunResult();

            addPKAnalysisSensitivities(variationData, simulationResults, sensitivityRunResult, sensitivityAnalysis);

            if (addOutputParameterSensitivitiesToResult)
            {
                addOutputSensitivities(variationData, simulationResults, sensitivityRunResult, sensitivityAnalysis);
            }

            return(sensitivityRunResult);
        }
        protected override void Context()
        {
            base.Context();
            _sensitivityAnalysisRunResult = new SensitivityAnalysisRunResult();
            _simulation = A.Fake <IModelCoreSimulation>().WithName("Sim");
            var pkParameter = new PKParameterSensitivity
            {
                QuantityPath    = "Liver",
                PKParameterName = "AUC",
                ParameterName   = "P1",
                Value           = 0.5,
                ParameterPath   = "ParameterPath"
            };


            _sensitivityAnalysisRunResult.AddPKParameterSensitivity(pkParameter);
        }
예제 #6
0
        public SensitivityAnalysisRunResult CreateFor(SensitivityAnalysis sensitivityAnalysis, VariationData variationData, SimulationResults simulationResults)
        {
            var sensitivityRunResult = new SensitivityAnalysisRunResult();

            var pkAnalyses = _pkAnalysesTask.CalculateFor(sensitivityAnalysis.Simulation, variationData.NumberOfVariations, simulationResults);

            foreach (var pkParameter in pkAnalyses.All())
            {
                sensitivityAnalysis.AllSensitivityParameters.Each((sensitivityParameter, index) =>
                {
                    var pkSensitivity = calculateParameterSensitivity(sensitivityParameter, index, variationData, pkParameter);
                    if (pkSensitivity != null)
                    {
                        sensitivityRunResult.AddPKParameterSensitivity(pkSensitivity);
                    }
                });
            }

            return(sensitivityRunResult);
        }
        public override void GlobalContext()
        {
            base.GlobalContext();
            var simulationFile      = HelperForSpecs.DataFile("S1.pkml");
            var simulationPersister = Api.GetSimulationPersister();

            _simulation          = simulationPersister.LoadSimulation(simulationFile);
            _sensitivityAnalysis = new SensitivityAnalysis(_simulation)
            {
                NumberOfSteps = 2, VariationRange = 0.2
            };
            var containerTask = Api.GetContainerTask();
            var liverVolumes  = containerTask.AllParametersMatching(_simulation, "Organism|Liver|Volume");

            _sensitivityAnalysis.AddParameters(liverVolumes);
            _sensitivityAnalysisRunner = Api.GetSensitivityAnalysisRunner();

            _sensitivityAnalysisRunResult = _sensitivityAnalysisRunner.Run(_sensitivityAnalysis);
            _allPKParameterSensitivities  = _sensitivityAnalysisRunResult.AllPKParameterSensitivities;
        }
 protected override void Because()
 {
     _result = sut.CreateFor(_sensitivityAnalysis, _variationData, _simulationResults);
 }
예제 #9
0
        private void addPKAnalysisSensitivities(VariationData variationData, SimulationResults simulationResults, SensitivityAnalysisRunResult sensitivityRunResult, SensitivityAnalysis sensitivityAnalysis)
        {
            var pkAnalyses = _pkAnalysesTask.CalculateFor(sensitivityAnalysis.Simulation, simulationResults);

            foreach (var pkParameter in pkAnalyses.All())
            {
                sensitivityAnalysis.AllSensitivityParameters.Each(sensitivityParameter =>
                {
                    var pkSensitivity = calculatePKParameterSensitivity(sensitivityParameter, variationData, pkParameter);
                    if (pkSensitivity != null)
                    {
                        sensitivityRunResult.AddPKParameterSensitivity(pkSensitivity);
                    }
                });
            }
        }
예제 #10
0
        private void addOutputSensitivities(VariationData variationData, SimulationResults simulationResults, SensitivityAnalysisRunResult sensitivityRunResult, SensitivityAnalysis sensitivityAnalysis)
        {
            variationData.AllVariations.Each(variation =>
            {
                //one variation corresponds to one row in the simulation table (e.g. one IndividualId)
                //this is the variation of one parameter compared to the base simulation
                var resultsForVariation = simulationResults.ResultsFor(variation.VariationId);

                //Retrieve this parameter
                var sensitivityParameter = sensitivityAnalysis.SensitivityParameterByName(variation.ParameterName);
                var parameterPath        = sensitivityParameter.ParameterSelection.Path;

                //For all output, we add the sensitivity
                resultsForVariation.AllValues.Each(outputValue =>
                {
                    var outputParameterSensitivity = calculateOutputParameterSensitivity(outputValue, variation, parameterPath);
                    sensitivityRunResult.AddOutputParameterSensitivity(outputParameterSensitivity);
                });
            });
        }
        public void ExportResultsToCSV(SensitivityAnalysisRunResult simulationResults, ISimulation simulation, string csvFile)
        {
            var dataTable = _simulationResultsToDataTableConverter.SensitivityAnalysisResultsToDataTable(simulationResults, simulation);

            dataTable.ExportToCSV(csvFile);
        }
예제 #12
0
 public SensitivityAnalysisRunResultsImport()
 {
     SensitivityAnalysisRunResult        = new SensitivityAnalysisRunResult();
     PKParameterSensitivitiesImportFiles = new List <PKParameterSensitivitiesImportFile>();
 }
 protected override void Because()
 {
     _result = sut.CreateFor(_sensitivityAnalysis, _variationData, _simulationResults, addOutputParameterSensitivitiesToResult: false);
 }
 protected override void Because()
 {
     sut.ExportResultsToCSV(_sensitivityAnalysisRunResult, _simulation, _csvFile);
     _importedResults = sut.ImportResultsFromCSV(_simulation, _csvFile);
 }