科学网

 找回密码
  注册
科学网 标签 mle

tag 标签: mle

相关帖子

版块 作者 回复/查看 最后发表

没有相关内容

相关日志

机器学习 --- 2.从最大似然再看线性回归
热度 1 ppn029012 2013-5-10 01:43
1. 线性回归的回顾 上一节我们尝试解决“房价与房子大小”之间关系的时候,使用了线性回归去拟合一个线性的方程,使得这个线性方程与所获得的 房价 与 房大小 数据最大限度地吻合。 所以,我们的问题的解决思路是, 把数据当成事实 用一个特定的模型(e.g.线性方程或非线性方程)去匹配数据 这些数据被当成了 上帝 ,而让我们用模型去匹配他们。数据就是事实,当误差很大时,只能说明模型不够好,仍需努力来匹配我们的数据。 2. 换个角度看线性回归 刚才是数据是事实,换个角度来看,数据应该是事实的一个表现。也就是”房价 数据 ”应该是“ 房价与房子大小关系 ”的一个表现。现在假设北京某地房价和房子大小之间关系已经确定了 房价=房子大小*500, 但是我们不知道,现在拿到了5个数据, (500, 1), (502, 1), (1510, 3), (1120, 2), (1500, 2). 会发现这5个数据并不符合关系。这是为什么,这是因为这些数据里面并不仅仅包含了房价”与房子大小”之间的关系,还很可能包含了, 房价”与“新旧”,“房屋”与“朝向”,“房屋”与“小区环境”...等等各种因素,而且这些因素很可能是可以观察到,也有可能是观察不到的。 所以说想 完美准确 的预测房价与房子大小的关系是 有可能的!! 只要找出所有影响房价的因素. 找到所有影响房价的因素这是 不可能的 !! 所以我们可能勉为其难,只需要一个最近似的关系就好了,所以只要把其他因素都看成是一些与房子大小无关的小噪声就好了。于是, y就是我们的房价,f(x)就是房价与房子大小之间的关系,\epsilon就是一些与房子大小无关的小噪声,当然,因为 \epsilon 是一个随机的东西,我们可以用随机变量E来表示它, 3.最大似然 无论如何, 现在我们有了一串X,Y,就可以尝试地找出一个最有可能的f(x)去拟合数据了。 什么叫最有可能? 假如有M个f(x), 那么我们需要评估哪个模型最有可能产生这一串数据D (Y, X). 可能性应该用概率来表示, 是f(x)的参数, 如果这些数据与数据之间是 独立 的,就有 下面这个方程,表示了模型产生数据X,Y的可能性 因为X,Y已经确定了,现在要使得可能性最大,我们只能通过调整的值了。 对任意一个数据,(xi, yi),我们可以计算 现在要计算一个模型产生数据的可能性,我们只要知道这个模型预测值与实际值之间的误差 ,和这个噪声随机变量E的分布就可以了。 解决最大似然问题的流程 到这,问题已经可以解决了,也就是,对于已有的数据D(X,Y)和任意一个参数为的f(x),找到最好的参数我们需要, 选择一个模型f(x), 和初始化其参数 估测噪声随机变量E的分布情况(e.g. 均匀分布,高斯分布...), 得到Likelihood表达式 计算Likelihood函数, 并调整使得Likelihood达到最大 调整的方法可以使用像前一章中介绍的“导数下降法”,当然也可以直接找极值点(导数为0)来得到其极大极小值。 Likelihood 函数会随着 模型f(x) 的选择和 噪声随机变量E 的选择出现不同的情况。下面就由我展示一下,最大似然怎么与前面两位回归(线性回归(Linear Regression)和分类回归(Logistic Regression))联系起来的吧! 4. 最大似然变身线性回归 这时候, 模型 我选 f(x) = ax + b, 噪声随机变量 E一个正态分布N(0,2). 要让Likelihood最大,只需要把 最小化就好了。啊啊啊!这个公式熟悉么? 这正是 前面线性回归的cost函数 吗?原来线性回归只是最大似然的一种 特殊情况 ! 5. 最大似然与分类 这时候, 模型 我选f(x)= , 这时随机噪声变量的分布就不再是高斯分布了,是一个极其复杂的分布。但是幸运的是,我们可以得到Likelihood的表达式, 因为 统一一下这个式子, 于是有, 最后可以看到,这个Likelihood函数变成了,分类回归中的cost函数的取负。所以最大化Likelihood就等同于最小化分类回归中的cost函数。 以上两类问题,线性回归和分类回归,都可以由最大似然估计法推导而来,说明了最大似然估计法是一种 更普适 的描述模型匹配的方法。
个人分类: 机器学习|6748 次阅读|1 个评论
Maximum likelihood estimation
热度 1 seikou1100 2012-11-3 21:32
Suppose there is a sample x 1 , x 2 , ..., x n of n independent and identically distributed observations, coming from a distribution with an unknown probability density function f 0 (·). It is however surmised that the function f 0 belongs to a certain family of distributions {  f (·|  θ ), θ ∈ Θ  }, called the parametric model , so that f 0 = f (·|  θ 0 ) . The value θ 0 is unknown and is referred to as the true value of the parameter. It is desirable to find an estimator which would be as close to the true value θ 0 as possible. Both the observed variables x i and the parameter θ can be vectors. To use the method of maximum likelihood, one first specifies the joint density function for all observations. For an independent and identically distributed sample, this joint density function is Now we look at this function from a different perspective by considering the observed values x 1 , x 2 , ..., x n to be fixed "parameters" of this function, whereas θ will be the function's variable and allowed to vary freely; this function will be called the likelihood : In practice it is often more convenient to work with the logarithm of the likelihood function, called the log-likelihood : or the average log-likelihood: The hat over ℓ indicates that it is akin to some estimator. Indeed, estimates the expected log-likelihood of a single observation in the model. The method of maximum likelihood estimates θ 0 by finding a value of θ that maximizes . This method of estimation defines a maximum-likelihood estimator ( MLE ) of θ 0 if any maximum exists. An MLE estimate is the same regardless of whether we maximize the likelihood or the log-likelihood function, since log is a monotonically increasing function. For many models, a maximum likelihood estimator can be found as an explicit function of the observed data x 1 , ..., x n . For many other models, however, no closed-form solution to the maximization problem is known or available, and an MLE has to be found numerically using optimization methods . For some problems, there may be multiple estimates that maximize the likelihood. For other problems, no maximum likelihood estimate exists (meaning that the log-likelihood function increases without attaining the supremum value). In the exposition above, it is assumed that the data are independent and identically distributed . The method can be applied however to a broader setting, as long as it is possible to write the joint density function f ( x 1 , ..., x n | θ ) , and its parameter θ has a finite dimension which does not depend on the sample size n . In a simpler extension, an allowance can be made for data heterogeneity , so that the joint density is equal to f 1 ( x 1 | θ )· f 2 ( x 2 | θ )····· f n ( x n | θ ) . In the more complicated case of time series models, the independence assumption may have to be dropped as well. A maximum likelihood estimator coincides with the most probable Bayesian estimator given a uniform prior distribution on the parameters . From: http://en.wikipedia.org/wiki/Maximum_likelihood As an example, consider a set C of N Bernoulli experiments with unknown parameter p, e.g., realised by tossing a deformed coin. The Bernoulli density function for the r.v. C for one experiment is: $p(C=c|p)$=$p^c(1-p)^{1-c}$ where we define c=1 for heads and c=0 for tails. Building an ML estimator for the parameter p can be done by expressing the (log) likelihood as a function of the data: $\mathcal{L}$=$\log \prod^{N}_{i=1}p(C=c_i)$=$\sum^{N}_{i=1} p(C=c_i|p)$=$n^{(1)} \log p(C=1|p)$ + $n^{(0)} \log p(C=0|p)$ = $n^{(1)}\log p$ + $n^{(0)} \log (1-p)$ where$n^{(c)}$ is the number of times a Bernoulli experiment yielded event c. Differentiating with respect to (w.r.t.) the parameter p yields: $\frac{\partial \mathcal{L}}{\partial p} = \frac{n^{(1)}}{p} - \frac{n^{(0)}}{1-p}=0$ $\hat{p}_{ML} = \frac{n^{(1)}}{n^{(0)} + n^{(1)}} = \frac{n^{(1)}}{N} $ which is simply the ratio of heads results to the total number of samples. To put some numbers into the example, we could imagine that our coin is strongly deformed, and after 20 trials, we have$n^{(1)}=12$ times heads and $n^{(0)}=8$ times tails. This results in an ML estimation of of $\hat{p}_{ML} = 12=20 = 0.6$.
个人分类: LDA|4075 次阅读|1 个评论
matlab实现:混合分布极大似然估计
caffery 2012-6-17 22:25
背景:有一组数据,由两组数据序列组成,两组数据序列分别服从不同参数的对数正态分布g(x)、h(x),假定这组数据服从混合分布f(x)=a*g(x)+(1-a)*h(x),a为权重系数,求混合分布涉及的参数的极大似然估计值,并画出此混合分布的图形。 用matlab程序实现如下: clear; clc; load('test.mat'); test = A_pastespecial; c2 = test(1:32,:); c3 = test(33:49,:); c6 = ; c3(13) = 15; c3(5) = 50; c4 = log(c2); c5 = log(c3); c5 = abs(c5); %c6 = ; c7 = ; =mle(c4,'distribution','norm'); =mle(c5,'distribution','norm'); mixedpdf=@(x,mu1,mu2,s1,s2,rho)(rho*normpdf(x,mu1,s1)+(1-rho)*normpdf(x,mu2,s2 )); =mle(c7,'pdf',mixedpdf,'start', ); =mle(c7,'pdf',mixedpdf,'start',phat1); =mle(c7,'pdf',mixedpdf,'start',phat1); mu1 = phat1(1); mu2 = phat1(2); s1 = phat1(3); s2 = phat1(4); rho = phat1(5); x = 0:0.05:10; y = (rho*normpdf(x,mu1,s1)+(1-rho)*normpdf(x,mu2,s2)); figure; plot(x,y,'b-.'); 对数正态分布:一个随机变量的对数服从正态分布,则该随机变量服从对数正态分布。 这个程序有个问题,是最后要画出混合分布图时,用的是normpdf函数即正态分布条件概率密度函数,而不是对数正态分布的条件概率密度函数。 对于matlab里面的极大似然估计函数调用,其中matlab运行不清楚具体运用的是什么算法? 不清楚程序中间还会不会有什么问题,还请高手指点!
11576 次阅读|0 个评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-1 07:10

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部