基于贝叶斯推理估计稳态 (ST) 和非稳态 (NS) LPIII 模型分布拟合到峰值放电(Matlab代码实现)

💥💥💞💞欢迎来到本博客❤️❤️💥💥

🏆博主优势:🌞🌞🌞博客内容尽量做到思维缜密,逻辑清晰,为了方便读者。

⛳️座右铭:行百里者,半于九十。

📋📋📋本文目录如下:🎁🎁🎁

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

在 NS 模型中,LPIII 分布的均值随时间变化。返回周期不是在真正的非平稳意义上计算的,而是针对平均值的固定值计算的。换句话说,假设分布在时间上保持固定,则计算返回周期。默认情况下,在对 NS LPIII 模型参数的估计值应用 bayes_LPIII时,将计算并显示更新的 ST 返回周期。更新的 ST 返回周期是通过计算与拟合期结束时的 NS 均值或 t = t(end) 相关的回报期获得的,假设分布在记录结束后的时间保持固定。

📚2 运行结果

 

 

部分代码:

cf  = 1;                        %multiplication factor to convert input Q to ft^3/s 
Mj  = 2;                        %1 for ST LPIII, 2 for NS LPIII with linear trend in mu
y_r = 0;                        %Regional estimate of gamma (skew coefficient)
SD_yr = 0.55;                   %Standard deviation of the regional estimate

%Prior distributions (input MATLAB abbreviation of distribution name used in 
%function call, i.e 'norm' for normal distribution as in 'normpdf')
marg_prior{1,1} = 'norm'; 
marg_prior{1,2} = 'unif'; 
marg_prior{1,3} = 'unif'; 
marg_prior{1,4} = 'unif';

%Hyper-parameters of prior distributions (input in order of use with 
%function call, i.e [mu, sigma] for normpdf(mu,sigma))
marg_par(:,1) = [y_r, SD_yr]';  %mean and std of informative prior on gamma 
marg_par(:,2) = [0, 6]';        %lower and upper bound of uniform prior on scale
marg_par(:,3) = [-10, 10]';     %lower and upper bound of uniform prior on location
marg_par(:,4) = [-0.15, 0.15]'; %lower and upper bound of uniform prior on trend 

%DREAM_(ZS) Variables
if Mj == 1; d = 3; end          %define number of parameters based on model
if Mj == 2; d = 4; end 
N = 3;                          %number of Markov chains 
T = 8000;                       %number of generations

%create function to initialize from prior
prior_draw = @(r,d)prior_rnd(r,d,marg_prior,marg_par); 
%create function to compute prior density 
prior_density = @(params)prior_pdf(params,d,marg_prior,marg_par);
%create function to compute unnormalized posterior density 
post_density = @(params)post_pdf(params,data,cf,Mj,prior_density);

%call the DREAM_ZS algorithm 
%Markov chains | post. density | archive of past states
[x,              p_x,          Z] = dream_zs(prior_draw,post_density,N,T,d,marg_prior,marg_par); 
%% Post Processing and Figures

%options:
%Which mu_t for calculating return level vs. return period? (don't change
%for estimates corresponding ti distribution at end of record, or updated ST distribution)
t = data(:,1) - min(data(:,1));                              %time (in years from the start of the fitting period)
idx_mu_n = size(t,1);                                        %calculates and plots RL vs RP for mu_t associated with t(idx_mu_n) 
                                                             %(idx_mu_n = size(t,1) for uST distribution) 
%Which return level for denisty plot? 
sRP = 100;                                                   %plots density of return level estimates for this return period

%Which return periods for output table?                      %outputs table of return level estimates for these return periods
RP_out =[200; 100; 50; 25; 10; 5; 2]; 
%end options 

%apply burn in (use only half of each chain) and rearrange chains to one sample 
x1 = x(round(T/2)+1:end,:,:);                                %burn in    
p_x1 = p_x(round(T/2)+1:end,:,:); 
post_sample = reshape(permute(x1,[1 3 2]),size(x1,1)*N,d,1); %columns are marginal posterior samples                                                           
sample_density = reshape(p_x1,size(p_x1,1)*N,1);             %corresponding unnormalized density 

%find MAP estimate of theta 
idx_theta_MAP = max(find(sample_density == max(sample_density))); 
theta_MAP = post_sample(idx_theta_MAP,:);                    %most likely parameter estimate 

%Compute mu as a function of time and credible intervals  
if Mj == 1; mu_t = repmat(post_sample(:,3),1,length(t));end  %ST model, mu is constant
if Mj == 2; mu_t = repmat(post_sample(:,3),1,length(t)) + post_sample(:,4)*t';end %NS mu = f(t)
MAP_mu_t = mu_t(idx_theta_MAP,:);                            %most likely estimate of the location parameter
low_mu_t = prctile(mu_t,2.5,1);                              %2.5 percentile of location parameter
high_mu_t = prctile(mu_t,97.5,1);                            %97.5 percentile of location parameter

%compute quantiles of the LPIII distribution 
p = 0.01:0.005:0.995;                                        %1st - 99.5th quantile (1 - 200 year RP)
a=1;
RLs = nan(size(post_sample,1),size(p,2));
for i = 1:size(post_sample,1);                               %compute return levels for each posterior sample
    RLs(i,:) = lp3inv(p,post_sample(i,1),post_sample(i,2),mu_t(i,idx_mu_n)); 
    a = a+1;
    if a == round(size(post_sample,1)/10) || i == size(post_sample,1);
    clc
    disp(['Calculating Return Levels ' num2str(round(i/size(post_sample,1)*100)) '% complete'])
    a = 1; 
    end
end
MAP_RL = RLs(idx_theta_MAP,:);                               %Return levels associated with most likely parameter estimate
low_RL = prctile(RLs,2.5,1);                                 %2.5 percentile of return level estimates
high_RL = prctile(RLs,97.5,1);                               %97.5 percentile of return level estimates

🎉3 参考文献

部分理论来源于网络,如有侵权请联系删除。

[1]Adam Luke (2022). Non-Stationary Flood Frequency Analysis .

🌈4 Matlab代码实现

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
贝叶斯理论是一种用来描述不确定性问题的概率理论方法。在贝叶斯理论中,参数被认为是一个随机变量,而不是一个固定值。参数的取值在先验分布中被指定。在观察到新数据之后,参数的后验分布被计算。这个后验分布是新数据和先验信息的加权和,权重是数据的似然函数和先验分布的密度。这种方法被广泛应用于数据分析、模型选择、参数估计等问题。 在 MATLAB 中,贝叶斯方法可以用于分布拟合分布拟合是一种将数据与概率分布进行比较的方法,通常用于检验一组数据是否符合某种分布MATLAB 中有两种方法进行分布拟合:最大似然估计贝叶斯方法。 最大似然估计是基于已知数据的似然函数,寻找使似然函数最大的参数估计值。该方法适用于样本量较大的情况下,具有较高的计算效率和统计效率。但是,它无法利用先验信息,并且在样本量较小和似然函数多峰的情况下可能会失效。 贝叶斯方法则可以更好地利用先验信息。它可以在数据样本量较小的情况下有效地进行分布拟合,并且可以处理高度不确定的分布。在 MATLAB 中,贝叶斯方法可以用 bayesfit 函数实现。bayesfit 函数使用贝叶斯方法进行分布拟合,同时可以使用先验函数进行参数估计。它可以输出后验分布估计的置信区间,这对于应对不确定性问题常有用。 总之,MATLAB 中的贝叶斯方法可以有效地进行分布拟合,尤其是在数据样本量较小的情况下。在分布拟合中,应该根据具体情况选择最大似然估计贝叶斯方法,以获得更准确的估计结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值