Beispiel #1
0
        internal PosteriorViewModel(IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState)
        {
            _appState    = appState;
            _moduleState = moduleState;

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            PlotModel = new PlotModel()
            {
                LegendPlacement   = LegendPlacement.Inside,
                LegendPosition    = LegendPosition.RightTop,
                LegendOrientation = LegendOrientation.Vertical
            };

            _horizontalAxis = new LinearAxis
            {
                Position = AxisPosition.Bottom
            };
            PlotModel.Axes.Add(_horizontalAxis);

            _leftVerticalAxis = new LinearAxis
            {
                Title    = "Frequency",
                Position = AxisPosition.Left,
                Key      = nameof(_leftVerticalAxis)
            };
            PlotModel.Axes.Add(_leftVerticalAxis);

            _rightVerticalAxis = new LinearAxis
            {
                Title    = "Probability",
                Position = AxisPosition.Right,
                Key      = nameof(_rightVerticalAxis)
            };
            PlotModel.Axes.Add(_rightVerticalAxis);

            PlotModel.ApplyThemeToPlotModelAndAxes();

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                _subscriptions = new CompositeDisposable(

                    appSettings
                    .GetWhenPropertyChanged()
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <string?>(
                            ObserveAppSettingsPropertyChange
                            )
                        ),

                    moduleState
                    .ObservableForProperty(ms => ms.EstimationDesign)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveModuleStateEstimationDesign
                            )
                        ),

                    moduleState
                    .WhenAnyValue(
                        ms => ms.ChainStates,
                        ms => ms.PosteriorState
                        )
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ChainState>, PosteriorState?)>(
                            ObserveModuleStateEstimationDataChange
                            )
                        ),

                    this
                    .ObservableForProperty(vm => vm.SelectedParameterName)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveSelectedParameterName
                            )
                        )

                    );

                if (CanConfigureControls)
                {
                    PopulateControls();
                }
                if (CanViewPosterior)
                {
                    PopulatePosterior();
                }
            }
        }
Beispiel #2
0
        internal DesignViewModel(
            IAppState appState,
            IAppService appService,
            IAppSettings appSettings,
            ModuleState moduleState,
            EstimationDesigns estimationDesigns
            )
        {
            _appState          = appState;
            _appService        = appService;
            _appSettings       = appSettings;
            _moduleState       = moduleState;
            _estimationDesigns = estimationDesigns;

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                if (_moduleState.EstimationDesign == default)
                {
                    Populate();
                }
                else
                {
                    Populate(_moduleState.EstimationDesign);
                }

                UpdateDesignEnable();
            }

            CreateDesign = ReactiveCommand.Create(
                HandleCreateDesign,
                this.WhenAny(
                    vm => vm.CanCreateDesign,
                    vm => vm.Iterations,
                    vm => vm.BurnIn,
                    (_, __, ___) =>
                    CanCreateDesign &&
                    BurnIn >= 0 &&
                    BurnIn < Iterations
                    )
                );

            UnloadDesign = ReactiveCommand.Create(
                HandleUnloadDesign,
                this.WhenAny(vm => vm.CanUnloadDesign, _ => CanUnloadDesign)
                );

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                _subscriptions = new CompositeDisposable(

                    moduleState
                    .WhenAnyValue(
                        ms => ms.PriorStates,
                        ms => ms.OutputStates,
                        ms => ms.SelectedObservations
                        )
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ParameterState>, Arr <OutputState>, Arr <SimObservations>)>(
                            ObserveEstimationStateChange
                            )
                        ),

                    moduleState
                    .ObservableForProperty(vm => vm.EstimationDesign)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveModuleStateEstimationDesign
                            )
                        ),

                    _appSettings
                    .ObservableForProperty(@as => @as.RThrottlingUseCores)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveAppSettingsRThrottlingUseCores
                            )
                        ),

                    this
                    .WhenAnyValue(vm => vm.Iterations, vm => vm.BurnIn, vm => vm.ChainsIndex)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <(int?, int?, int)>(
                            ObserveInputs
                            )
                        )

                    );
            }
        }
Beispiel #3
0
        internal FitViewModel(IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState)
        {
            _appState    = appState;
            _moduleState = moduleState;

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            PlotModel = new PlotModel()
            {
                LegendPlacement   = LegendPlacement.Inside,
                LegendPosition    = LegendPosition.RightTop,
                LegendOrientation = LegendOrientation.Vertical
            };

            var simulation          = _appState.Target.AssertSome();
            var output              = simulation.SimConfig.SimOutput;
            var independentVariable = output.IndependentVariable;

            _horizontalAxis = new LinearAxis
            {
                Title    = independentVariable.Name,
                Unit     = independentVariable.Unit,
                Position = AxisPosition.Bottom
            };
            PlotModel.Axes.Add(_horizontalAxis);

            _verticalAxis = new LinearAxis {
                Position = AxisPosition.Left
            };
            PlotModel.Axes.Add(_verticalAxis);

            PlotModel.ApplyThemeToPlotModelAndAxes();

            using (_reactiveSafeInvoke.SuspendedReactivity)
            {
                _subscriptions = new CompositeDisposable(

                    appSettings
                    .GetWhenPropertyChanged()
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <string?>(
                            ObserveAppSettingsPropertyChange
                            )
                        ),

                    moduleState
                    .ObservableForProperty(ms => ms.EstimationDesign)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveModuleStateEstimationDesign
                            )
                        ),

                    moduleState
                    .WhenAnyValue(
                        ms => ms.ChainStates,
                        ms => ms.PosteriorState
                        )
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <(Arr <ChainState>, PosteriorState?)>(
                            ObserveModuleStateEstimationDataChange
                            )
                        ),

                    this
                    .ObservableForProperty(vm => vm.SelectedOutputName)
                    .Subscribe(
                        _reactiveSafeInvoke.SuspendAndInvoke <object>(
                            ObserveSelectedOutputName
                            )
                        )

                    );

                if (CanConfigureControls)
                {
                    PopulateControls();
                }
                if (CanViewFit)
                {
                    PopulateChart();
                }
            }
        }