internal DesignDigestsViewModel(IAppService appService, ModuleState moduleState, EstimationDesigns estimationDesigns) { _moduleState = moduleState; _estimationDesigns = estimationDesigns; LoadEstimationDesign = ReactiveCommand.Create( HandleLoadEstimationDesign, this.WhenAny(vm => vm.SelectedDesignDigestViewModel, _ => SelectedDesignDigestViewModel != default) ); DeleteEstimationDesign = ReactiveCommand.Create( HandleDeleteEstimationDesign, this.WhenAny(vm => vm.SelectedDesignDigestViewModel, _ => SelectedDesignDigestViewModel != default) ); FollowKeyboardInDesignDigests = ReactiveCommand.Create <(Key Key, bool Control, bool Shift)>( HandleFollowKeyboardInDesignDigests ); DesignDigestViewModels = new ObservableCollection <IDesignDigestViewModel>( estimationDesigns.DesignDigests.Map(dd => new DesignDigestViewModel(dd.CreatedOn, dd.Description) )); if (_moduleState.EstimationDesign != default) { TargetEstimationDesign = Some((_moduleState.EstimationDesign.CreatedOn, DateTime.Now)); SelectedDesignDigestViewModel = DesignDigestViewModels .Find(vm => vm.CreatedOn == _moduleState.EstimationDesign.CreatedOn) .Match <IDesignDigestViewModel?>(vm => vm, () => default); } _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); _subscriptions = new CompositeDisposable( moduleState .ObservableForProperty(ms => ms.EstimationDesign) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateEstimationDesign ) ), estimationDesigns.EstimationDesignChanges.Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <(DesignDigest, ObservableQualifier)>( ObserveEstimationDesignChange ) ) ); }
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 ) ) ); } }
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(); } } }
internal SimulationViewModel(IAppState appState, IAppService appService, IAppSettings appSettings, ModuleState moduleState, EstimationDesigns estimationDesigns) { _appService = appService; _moduleState = moduleState; _estimationDesigns = estimationDesigns; _simulation = appState.Target.AssertSome("No simulation"); _simData = appState.SimData; _estimationDesign = moduleState.EstimationDesign; _chainStates = _moduleState.ChainStates; _reactiveSafeInvoke = appService.GetReactiveSafeInvoke(); StartIterating = ReactiveCommand.Create( HandleStartIterating, this.WhenAny(vm => vm.CanStartIterating, _ => CanStartIterating) ); StopIterating = ReactiveCommand.Create( HandleStopIterating, this.WhenAny(vm => vm.CanStopIterating, _ => CanStopIterating) ); ShowSettings = ReactiveCommand.Create( HandleShowSettings, this.WhenAny(vm => vm.CanShowSettings, _ => CanShowSettings) ); SetConvergenceRange = ReactiveCommand.Create( HandleSetConvergenceRange, this.WhenAny(vm => vm.CanSetConvergenceRange, _ => CanSetConvergenceRange) ); PlotModel = new PlotModel(); _horizontalAxis = new LinearAxis { Position = AxisPosition.Bottom, AbsoluteMinimum = 1d, Minimum = 1d, Title = "Iteration" }; PlotModel.Axes.Add(_horizontalAxis); _verticalAxis = new LinearAxis { Position = AxisPosition.Left }; PlotModel.Axes.Add(_verticalAxis); _posteriorAnnotation = new RectangleAnnotation { Fill = OxyColor.FromAColor(120, OxyColors.SkyBlue), MinimumX = 0, MaximumX = 0 }; PlotModel.Annotations.Add(_posteriorAnnotation); PlotModel.MouseDown += HandlePlotModelMouseDown; PlotModel.MouseMove += HandlePlotModelMouseMove; PlotModel.MouseUp += HandlePlotModelMouseUp; PlotModel.ApplyThemeToPlotModelAndAxes(); using (_reactiveSafeInvoke.SuspendedReactivity) { _posteriorBegin = _moduleState.PosteriorState?.BeginIteration; _posteriorEnd = _moduleState.PosteriorState?.EndIteration; PopulateControls(); PopulateChartData(); PopulateChart(); PopulatePosteriorAnnotation(); UpdateEnable(); } _subscriptions = new CompositeDisposable( appSettings .GetWhenPropertyChanged() .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <string?>(ObserveAppSettingsPropertyChange) ), _moduleState .ObservableForProperty(ms => ms.EstimationDesign) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateEstimationDesign ) ), _moduleState .ObservableForProperty(ms => ms.ChainStates) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStateChainStates ) ), _moduleState .ObservableForProperty(ms => ms.PosteriorState) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveModuleStatePosteriorState ) ), this .ObservableForProperty(vm => vm.SelectedParameter) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObserveSelectedParameter ) ), this .ObservableForProperty(vm => vm.PosteriorBegin) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObservePosteriorBegin ) ), this .ObservableForProperty(vm => vm.PosteriorEnd) .Subscribe( _reactiveSafeInvoke.SuspendAndInvoke <object>( ObservePosteriorEnd ) ) ); }
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(); } } }