示例#1
0
        private ModuleState(
            _ModuleStateDTO dto,
            ISimEvidence evidence,
            IAppService appService,
            EstimationDesigns estimationDesigns
            )
        {
            _estimationDesigns = estimationDesigns;

            PriorsState.SelectedPrior = dto.PriorsState?.SelectedPrior;

            LikelihoodState.SelectedOutput = dto.LikelihoodState?.SelectedOutput;

            DesignState.Iterations = dto.DesignState?.Iterations;
            DesignState.BurnIn     = dto.DesignState?.BurnIn;
            DesignState.Chains     = dto.DesignState?.Chains;

            SimulationState.SelectedParameter = dto.SimulationState?.SelectedParameter;

            if (!dto.PriorStates.IsNullOrEmpty())
            {
                _priorStates = dto.PriorStates
                               .Select(ps =>
                {
                    var name               = ps.Name.AssertNotNull();
                    var distributionType   = Enum.TryParse(ps.DistributionType, out DistributionType dt) ? dt : DistributionType.None;
                    var distributionStates = Distribution.DeserializeDistributions(ps.DistributionStates.AssertNotNull());
                    var isSelected         = ps.IsSelected;
                    return(new ParameterState(name, distributionType, distributionStates, isSelected));
                })
                               .ToArr();
            }

            if (!dto.OutputStates.IsNullOrEmpty())
            {
                _outputStates = dto.OutputStates
                                .Select(os =>
                {
                    var name             = os.Name.AssertNotNull();
                    var errorModelType   = Enum.TryParse(os.ErrorModelType, out ErrorModelType emt) ? emt : ErrorModelType.None;
                    var errorModelStates = ErrorModel.DeserializeErrorModels(os.ErrorModelStates.AssertNotNull());
                    var isSelected       = os.IsSelected;
                    return(new OutputState(name, errorModelType, errorModelStates, isSelected));
                })
                                .ToArr();
            }

            _selectedObservations = dto.SelectedObservationsReferences.IsNullOrEmpty()
        ? default
        : dto.SelectedObservationsReferences
                                    .Select(r => evidence.GetObservations(r))
                                    .Somes()
                                    .ToArr();

            if (dto.EstimationDesign.IsAString())
            {
                try
                {
                    var createdOn = dto.EstimationDesign.FromDirectoryName();
                    EstimationDesign = estimationDesigns.Load(createdOn);
                    var pathToEstimationDesign = estimationDesigns.GetPathToEstimationDesign(EstimationDesign);
                    ChainStates    = ChainState.Load(pathToEstimationDesign);
                    PosteriorState = PosteriorState.Load(pathToEstimationDesign);
                }
                catch (Exception) { /* logged elsewhere */ }
            }

            RootExportDirectory = dto.RootExportDirectory;
            OpenAfterExport     = dto.OpenAfterExport;

            _autoApplyParameterSharedState    = dto.AutoApplyParameterSharedState;
            _autoShareParameterSharedState    = dto.AutoShareParameterSharedState;
            _autoApplyElementSharedState      = dto.AutoApplyElementSharedState;
            _autoShareElementSharedState      = dto.AutoShareElementSharedState;
            _autoApplyObservationsSharedState = dto.AutoApplyObservationsSharedState;
            _autoShareObservationsSharedState = dto.AutoShareObservationsSharedState;

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _subscriptions = new CompositeDisposable(

                evidence.ObservationsChanges.Subscribe(
                    _reactiveSafeInvoke.SuspendAndInvoke <(Arr <SimObservations> Observations, ObservableQualifier ObservableQualifier)>(
                        ObserveEvidenceObservationsChanges
                        )
                    )

                );
        }
示例#2
0
 public static int GetCompletedIterations(this ChainState chainState) =>
 chainState.ChainData?.Rows
 .Cast <DataRow>()
 .Count(dr => chainState.ModelParameters.All(mp => !IsNaN(dr.Field <double>(mp.Name))))
 ?? 0;