使用fminsearch进行分布拟合 [英] Using fminsearch to perform distribution fitting

查看:272
本文介绍了使用fminsearch进行分布拟合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在数组errors中保存了一组单变量数据.

Suppose I have a set of univariate data held in the array errors.

我想使PDF适应我观察到的数据分布.

I would like to fit a PDF to my observed data distribution.

我的PDF是在函数poissvmwalkpdf中定义的,其定义行如下所示:

My PDF is defined in a function poissvmwalkpdf, whose definition line looks like this:

function p = poissvmwalkpdf(theta, mu, kappa, xi)

在这里,theta是错误(errors中的值是实例的变量),并且mukappaxi是我要查找其PDF的参数.使用最大似然估计的最佳拟合.此函数返回给定值theta的概率密度.

Here, theta is the error (the variable for which values in errors are instances), and mu, kappa, and xi are parameters of the PDF for which I want to find the best fit using maximum-likelihood estimation. This function returns the probability density at a given value of theta.

鉴于所有这些,我将如何使用fminsearch查找最适合我观察到的errorsmukappaxi值? fminsearch文档对此并不清楚.文档中的所有示例都不是分布拟合的示例.

Given all this, how would I use fminsearch to find the values for mu, kappa, and xi that best fit my observed errors? The fminsearch documentation doesn't make this clear. None of the examples in the documentation are examples of distribution fitting.

注意:教程此处清楚地描述了什么是分布拟合(与曲线拟合不同),但是给出的示例未使用fminsearch.

Note: The tutorial here clearly describes what distribution fitting is (as distinguished from curve fitting), but the example given does not use fminsearch.

推荐答案

以下是使用fminsearch来获得最大似然估计的最小示例(如评论中所述):

Here is a minimal example of using fminsearch to obtain maximum likelihood estimates (as requested in the comments):

function mle_fit_minimal

n       = 100;
% for reproducibility
rng(333)
% generate dummy data
errors  = normrnd(0,1,n,1);

par0    = [1, 1];
[par_hat, nll] = fminsearch(@nloglike, par0)

% custom pdf
    function p = my_pdf(data, par)
        mu      = par(1);
        sigma   = par(2);
        p       = normpdf(data, mu, sigma);
    end

% negative loglikelihood function -- note that the parameters must be passed in a 
% single argument (here called par).
    function nll = nloglike(par)
        nll     = -sum(log(my_pdf(errors, par)));
    end
end

公式化似然函数(或负对数似然)后,这只是一个简单的优化.

After formulating the likelihood function (or negative loglikelihood) it is just a simple optimization.

这篇关于使用fminsearch进行分布拟合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆