sampleroptions
Create Markov chain Monte Carlo (MCMC) sampler options
Description
                uses additional options specified by one or more options = sampleroptions(Name,Value)Name,Value pair
                arguments. For example,
                    'Sampler','hmc','StepSizeTuningMethod','none' specifies
                sampling from the posterior using the Hamiltonian Monte Carlo sampler and no
                step-size tuning method.
Examples
Suppose that you plan to estimate, simulate, or forecast a Bayesian linear regression model that has a custom joint prior distribution. In this case, MATLAB® resorts to MCMC sampling for posterior simulation and estimation. You can choose a sampler and tune its parameters using a sampler options structure.
Create a default sampler options structure.
options = sampleroptions
options = struct with fields:
    Sampler: 'Slice'
      Width: []
options specifies the slice sampler, and its typical width is empty. An empty width indicates usage of the default width for posterior sampling.
Specify a typical width of 10 for the slice sampler.
options.Width = 10
options = struct with fields:
    Sampler: 'Slice'
      Width: 10
To implement slice sampling with a sample width of 10 for posterior estimation, create a customblm model, and then specify sampler options structure options by using the 'Options' name-value pair argument of estimate, simulate, or forecast.
To specify a different MCMC sampler, create a new sampler options structure.
Suppose that you plan to estimate, simulate, or forecast a Bayesian linear regression model that has a custom joint prior distribution, and you want to implement the Hamiltonian Monte Carlo (HMC) sampler.
Create a sampler options structure that specifies sampling using the HMC sampler. Specify a verbosity level of 1.
options = sampleroptions('Sampler','hmc','VerbosityLevel',1)
options = struct with fields:
                        Sampler: 'HMC'
           StepSizeTuningMethod: 'dual-averaging'
         MassVectorTuningMethod: 'iterative-sampling'
    NumStepSizeTuningIterations: 100
          TargetAcceptanceRatio: 0.6500
                  NumStepsLimit: 2000
                 VerbosityLevel: 1
                       NumPrint: 100
options is a structure array, and a list of its fields is displayed at the command line. The fields are the tuning parameters of the sampler. All values are the defaults for the HMC sampler, except VerbosityLevel.
You can also adjust field values at the command line by using dot notation. For example, change the target acceptance ratio to 0.75.
options.TargetAcceptanceRatio = 0.75
options = struct with fields:
                        Sampler: 'HMC'
           StepSizeTuningMethod: 'dual-averaging'
         MassVectorTuningMethod: 'iterative-sampling'
    NumStepSizeTuningIterations: 100
          TargetAcceptanceRatio: 0.7500
                  NumStepsLimit: 2000
                 VerbosityLevel: 1
                       NumPrint: 100
To implement the HMC sampler, create a customblm model, and then specify sampler options structure options by using the 'Options' name-value pair argument of estimate, simulate, or forecast.
Name-Value Arguments
Specify optional pairs of arguments as
      Name1=Value1,...,NameN=ValueN, where Name is
      the argument name and Value is the corresponding value.
      Name-value arguments must appear after other arguments, but the order of the
      pairs does not matter.
    
      Before R2021a, use commas to separate each name and value, and enclose 
      Name in quotes.
    
Example: 'Sampler','hmc','VerbosityLevel',1 specifies the HMC
                sampler and displays details of the step size tuning during
                simulation.
Choose Sampler
MCMC sampler, specified as the comma-separated pair consisting of
                                'Sampler' and a value in this table.
| Value | Description | 
|---|---|
'slice' | Slice sampler | 
'metropolis' | Random walk Metropolis sampler | 
'hmc' | Hamiltonian Monte Carlo (HMC) sampler | 
Example: 'Sampler','hmc'
Data Types: char | string
Slice Sampler Options
Typical sampling-interval width around the current value in the
                            marginal distributions for the slice sampler, specified as the
                            comma-separated pair consisting of 'Width' and a
                            positive numeric scalar or an (intercept +
                                numPredictors + 1)-by-1
                            numeric vector of positive values. numPredictors is
                            the number of predictor variables (columns in the predictor data), and
                                intercept is 1 when the model
                            contains an intercept, and 0 otherwise. The first
                            element of Width corresponds to the model intercept,
                            if one exists in the model. The order of the next
                                numPredictors elements corresponds to the order
                            of the predictor variables in the predictor data. The last element
                            corresponds to the model variance.
If
Widthis a scalar, then MATLAB® appliesWidthto allintercept+numPredictors+1marginal distributions.If
Widthis a numeric vector, then MATLAB applies the first element to the intercept (if one exists), the nextnumPredictorselements to the regression coefficients corresponding to the predictor variables inX, and the last element to the disturbance variance.If the sample size (number of rows in the predictor data) is less than
100, thenWidthis10by default.If the sample size is at least 100, then, by default, MATLAB sets
Widthto the vector of corresponding posterior standard deviations, assuming a diffuse prior model (diffuseblm).
MATLAB dispatches Width to the
                                slicesample function. For more details, see
                                slicesample.
Tip
The typical width of the slice sampler does not affect convergence of the MCMC sample. However, it does affect the number of required function evaluations, that is, the efficiency of the algorithm. If the width is too small, then the algorithm can implement an excessive number of function evaluations to determine the appropriate sampling width. If the width is too large, then the algorithm might have to decrease the width to an appropriate size, which requires function evaluations.
Example: 'Width',[100*ones(3,1);10]
Random Walk Metropolis Sampler Options
Proposal distribution, specified as the comma-separated pair
                            consisting of 'Distribution' and a value in this
                                table.
| Value | Description | 
|---|---|
'mvn' | Multivariate normal distribution. To tune the
                                                sampler, specify its covariance matrix by using the
                                                  'ScaleMatrix' name-value pair
                                                argument. | 
'mvt' | Multivariate t distribution.
                                                To tune the sampler, specify its covariance matrix
                                                or degrees of freedom (or both)  by using the
                                                  'ScaleMatrix' or 'DegreeOfFreedom' name-value pair
                                                argument, respectively. | 
Example: 'Distribution','mvt'
Data Types: string | char
Proposal distribution scale matrix, specified as the comma-separated
                            pair consisting of 'ScaleMatrix' and an
                                (intercept + numPredictors +
                                1)-by-(intercept + numPredictors + 1)
                            symmetric, positive definite, numeric matrix. For the meaning of the
                            rows and columns, see 'Width'.
By default, ScaleMatrix is the posterior covariance
                            matrix of the regression coefficients (Beta) and the
                            model variance (Sigma2) assuming the diffuse
                            model.
Example: 'ScaleMatrix',eye(intercept + numPredictors +
                                1)
Data Types: double
Proposal distribution degrees of freedom, specified as the
                            comma-separated pair consisting of 'DegreeOfFreedom'
                            and a positive scalar. If 'Distribution' is 'mvn', then
                                sampleroptions ignores
                                DegreeOfFreedom.
Example: 'DegreeOfFreedom',3
Data Types: double
HMC Sampler Options
Method for tuning the step size, specified as the comma-separated pair
                            consisting of 'StepSizeTuningMethod' and
                                'dual-averaging' or 'none'.
                            For more details, see 'StepSizeTuningMethod'.
Example: 'StepSizeTuningMethod','none'
Data Types: char
Method for tuning the mass vector, specified as the comma-separated
                            pair consisting of 'MassVectorTuningMethod' and
                                'iterative-sampling',
                                'hessian', or 'none'. For more
                            details, see 'MassVectorTuningMethod'.
Example: 'MassVectorTuningMethod','hessian'
Data Types: char
Number of iterations for tuning the step size, specified as the
                            comma-separated pair consisting of
                                'NumStepSizeTuningIterations' and a positive
                            integer. For more details, see 'NumStepSizeTuningIterations'.
Example: 'NumStepSizeTuningIterations',200
Data Types: single | double
Target acceptance ratio, specified as the comma-separated pair
                            consisting of 'TargetAcceptanceRatio' and a scalar
                            from 0 through 1. For more
                            details, see 'TargetAcceptanceRatio'.
Example: 'TargetAcceptanceRatio',0.5
Data Types: single | double
Maximum number of leapfrog steps, specified as the comma-separated
                            pair consisting of 'NumStepsLimit' and a positive
                            integer. For more details, see 'NumStepsLimit'.
Example: 'NumStepsLimit',5000
Data Types: single | double
Verbosity level of Command Window output, specified as the
                            comma-separated pair consisting of 'VerbosityLevel'
                            and a nonnegative integer. For more details, see 'VerbosityLevel'.
Example: 'VerbosityLevel',1
Data Types: single | double
Verbose output frequency, specified as the comma-separated pair
                            consisting of 'NumPrint' and a positive integer. For
                            more details, see 'NumPrint'.
Example: 'NumPrint',10
Data Types: single | double
Output Arguments
Sampler options for a Bayesian linear regression model with custom prior distribution, returned as a structure array. After creating a sampler options structure, you can adjust tuning parameter values, except the sampler, by using dot notation.
Version History
Introduced in R2017b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
 - Canada (English)
 - United States (English)
 
ヨーロッパ
- Belgium (English)
 - Denmark (English)
 - Deutschland (Deutsch)
 - España (Español)
 - Finland (English)
 - France (Français)
 - Ireland (English)
 - Italia (Italiano)
 - Luxembourg (English)
 
- Netherlands (English)
 - Norway (English)
 - Österreich (Deutsch)
 - Portugal (English)
 - Sweden (English)
 - Switzerland
 - United Kingdom (English)