一个有偏的硬币,抛了100次,出现1次人头,99次字。请用最大似然估计(ML)和最小均方误差(LSE)估计出现人头的概率
#include <iostream> #include <algorithm> using namespace std; double MaxLikelihood(const int &x) {double p;//人头概率 double L,ML,F;//似然、概率函数 L=p^x*(1-p)^(100-x); ML=(1-p)^(99-x)*p^(x-1)*(x*(1-p)-p); return p=x/(x+1);}
int main()
{
double p;//人头概率
int x=1;//结果
p=MaxLikelihood(&x);//最大似然估计
cout<<p<<endl;
return 0;
}