基于高斯 Copula 方法对分布的任意组合进行关联样本,并对相关参数进行迭代优化研究(Matlab代码实现)

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

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

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

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

目录

💥1 概述

📚2 运行结果

🎉3 参考文献

🌈4 Matlab代码实现


💥1 概述

高斯Copula方法是一种用于建立多变量分布的方法,它可以将边缘分布和相关性结合起来,从而得到整体的联合分布。在这种方法中,边缘分布可以是任意的分布,而相关性则由Copula函数来描述。

首先,我们需要选择适当的Copula函数来描述变量之间的相关性。常用的Copula函数包括高斯Copula、t Copula、Clayton Copula等。在这里,我们选择高斯Copula作为例子来进行研究。

接下来,我们需要对相关参数进行迭代优化。一种常用的方法是最大似然估计,通过最大化似然函数来估计Copula函数的参数。通过迭代优化,我们可以得到最优的相关参数,从而得到最优的联合分布。

最后,我们可以利用得到的联合分布进行关联样本的生成。通过高斯Copula方法,我们可以生成符合指定边缘分布和相关性的样本,从而实现任意组合分布的关联样本生成。

基于高斯Copula方法对分布的任意组合进行关联样本,并对相关参数进行迭代优化是一种有效的研究方法,可以用于建立多变量分布的模型和生成关联样本。

📚2 运行结果

部分代码:

function [funcVal, stdev, CI, MCfuncVals, MCsamples]= simulateMC(func,dists,N,varargin)
% simulateMC() is a tool for Monte Carlo simulation. It draws many, many 
% samples from user-specified distributions and combines the samples through 
% an arbitrary function. 

% INPUTS:
%   func            Function handle of the function to combine samples through
%                   (func must be vectorizable so use .*, ./ and .^ instead of *, /, and ^)
%   dists           Vertical cell array of cell arrays containing params for each distribution
%   N               Number of samples to generate from each distribution
%   'CI',value      (Optional) Value to use for pseudo CI threshold. Default is 0.68.
%   'hist',nBins    (Optional) Plot histogram of the function outputs. nBins value is optional
%   'varHist',nBins (Optional) Plot histograms of each sample. nBins valueis optional.
%   'mean'|'median'|'max'|'min'
%                   (Optional) Specifies what value to return for 'funcVal'. 
%                    Default is the center of the CI inteval.
%
%   For each cell array inside 'dists' the syntax is:
%       {'DistributionType',param_1,...,paramN[,'truncate',lowerBound,upperBound]}
%   where the truncation arguments inside the square brackets are optional.


% OUTPUTS: 
%   funcVal     Calculated function value. Defaults to center of CI. Can be mean, median, or max/min.
%   stdev       Standard deviation of the function outputs
%   CI          Vector containing the lowerbound and upperbound of the pseudo CI interval.
%               (this is the shortest interval containing some percent of the function outputs)
%   MCfuncVals  Vector of the function outputs.
%   MCsamples   Array containing the samples for each distribution.

% %EXAMPLE 1
% %Combine samples from X and Y through the function 'f'. 
% %'X' is a normal distribution with params [mean=5,sigma=1]. 
% %'Y' is a uniform distribution with params [lowerbound=6,upperbound=7].
% f=@(X,Y)5.*X+Y;
% dists = {{'Normal',5,1};
%          {'Uniform',6,7}};
% n=100000;
% [funcVal,stdev,CI] = simulateMC(f,dists,n)

....

%% Parse varargin to handle optional arguments
%Init defaults
if (~exist('N', 'var'))
   N=100000; 
end
confInterval = 0.68; 
meanFlag=0; medianFlag=0; maxFlag=0; minFlag=0;
histFlag=0; histBins=40;
varHistFlag = 0; varHistBins=40;

for vaIdx = 1:length(varargin)
    currArg = varargin{vaIdx};
    notLastArg = vaIdx~=length(varargin);
    switch(currArg)
        case {'mean','Mean'}
            meanFlag=1;
        case {'median','Median'}
            medianFlag=1;
        case {'max','Max'}
            maxFlag=1;
        case {'min','Min'}
            minFlag=1;
        case {'hist','Hist'}
            histFlag=1;
            if notLastArg && ~ischar(varargin{vaIdx+1})
                histBins=varargin{vaIdx+1};
            end
        case {'varHist','VarHist','varhist','Varhist'}
            varHistFlag=1;
            if notLastArg && ~ischar(varargin{vaIdx+1})
                varHistBins=varargin{vaIdx+1};
            end
        case {'CI','Ci','ci'}
            if notLastArg && ~ischar(varargin{vaIdx+1})
                confInterval=varargin{vaIdx+1};
            else
                disp('simulateMC(): Value is missing from ''CI'' name-value pair.')
            end
        otherwise
            if ischar(currArg)
                disp("simulateMC(): The string '"+currArg+"' in the function parameters was not recognized as a valid option.")
            end
    end
end

%% Generate & Store Samples From the Specified Distributions
distIdx=0;
sampIdx=0;
while(distIdx < size(dists,1))
    distIdx=distIdx+1;
    sampIdx=sampIdx+1;
    distType = dists{distIdx}{1};
    switch(distType)
        case {'Bootstrap','bootstrap'}
            %Bootstrap a sample of size N from user provided data.
            %Syntax is:  {'Bootstrap',datavec}

🎉3 参考文献

文章中一些内容引自网络,会注明出处或引用为参考文献,难免有未尽之处,如有不妥,请随时联系删除。

[1]杨柳.基于Copula函数的风—电—热相关性分析方法研究[D].东北电力大学,2020.

[2]王双成,高瑞,杜瑞杰.基于高斯Copula的约束贝叶斯网络分类器研究[J].计算机学报, 2016, 39(8):14.DOI:10.11897/SP.J.1016.2016.01612.

🌈4 Matlab代码实现

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

荔枝科研社

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值