Data generation | MATLAB implements data generation for MCMC Markov Monte Carlo simulation

Data generation | MATLAB implements data generation for MCMC Markov Monte Carlo simulation

generate effect

1

Basic description

1. MATLAB realizes the data generation of MCMC Markov Monte Carlo simulation;
2. Markov Chain Monte Carlo method (Markov Chain Monte Carlo), referred to as MCMC, the core idea of ​​the MCMC algorithm is that we know a probability density function, It is necessary to sample from this probability distribution to analyze some statistical properties of this distribution.

Model description

Markov Monte Carlo simulation (Markov Monte Carlo simulation) is a stochastic simulation method based on Markov chains, which is used to generate data samples that obey a specific distribution. The following is the general process of generating data using Markov Monte Carlo simulation:
Define the state space: Determine the possible value range of the data, which can be a discrete state space or a continuous state space.
Construct transition matrix: According to the characteristics of the problem, determine the transition probability between states. A transition matrix describes the probability of transitioning from one state to another.
Initial state: Choose an initial state from the state space.
Perform simulation: According to the transition matrix and the current state, transfer to the next state according to certain probability rules. Repeat this process multiple times until the desired sample size is reached.
Generate samples: record the value of each state to get the generated data samples.

programming

  • Complete program and data acquisition method: Private message bloggers reply to MATLAB to realize data generation of MCMC Markov Monte Carlo simulation .

tempLayers = [
    convolution2dLayer([3, 1], 16, "Name", "conv_1", "Padding", "same")  % 建立卷积层,卷积核大小[3, 1]16个特征图
    reluLayer("Name", "relu_1")                                          % Relu 激活层
    convolution2dLayer([3, 1], 32, "Name", "conv_2", "Padding", "same")  % 建立卷积层,卷积核大小[3, 1]32个特征图
    reluLayer("Name", "relu_2")];                                        % Relu 激活层
lgraph = addLayers(lgraph, tempLayers);                                  % 将上述网络结构加入空白结构中

tempLayers = [
    sequenceUnfoldingLayer("Name", "sequnfold")                      % 建立序列反折叠层
    flattenLayer("Name", "flatten")                                  % 网络铺平层

lgraph = addLayers(lgraph, tempLayers);                              % 将上述网络结构加入空白结构中
lgraph = connectLayers(lgraph, "seqfold/out", "conv_1");             % 折叠层输出 连接 卷积层输入
lgraph = connectLayers(lgraph, "seqfold/miniBatchSize", "sequnfold/miniBatchSize"); 
                                                                     % 折叠层输出连接反折叠层输入
lgraph = connectLayers(lgraph, "relu_2", "sequnfold/in");            % 激活层输出 连接 反折叠层输入

%% 参数设置
options = trainingOptions('adam', ...     % Adam 梯度下降算法
    'MaxEpochs', 500,...                 % 最大训练次数 1000
    'InitialLearnRate', best_lr,...          % 初始学习率为0.001
    'L2Regularization', best_l2,...         % L2正则化参数
    'LearnRateSchedule', 'piecewise',...  % 学习率下降
    'LearnRateDropFactor', 0.1,...        % 学习率下降因子 0.1
    'LearnRateDropPeriod', 400,...        % 经过800次训练后 学习率为 0.001*0.1
    'Shuffle', 'every-epoch',...          % 每次训练打乱数据集
    'ValidationPatience', Inf,...         % 关闭验证
    'Plots', 'training-progress',...      % 画出曲线
    'Verbose', false);

%% 训练
net = trainNetwork(p_train, t_train, lgraph, options);

References

[1] https://blog.csdn.net/kjm13182345320/article/details/129036772?spm=1001.2014.3001.5502
[2] https://blog.csdn.net/kjm13182345320/article/details/128690229

Guess you like

Origin blog.csdn.net/kjm13182345320/article/details/132462976