【问题标题】:Simple MLE solution from MATLAB来自 MATLAB 的简单 MLE 解决方案
【发布时间】:2017-04-19 12:06:07
【问题描述】:

所以我试图在 MATLAB 上为自定义函数拟合线性最小二乘模型。我的数据名为logprice_hour_seas,看起来像一个复杂的非线性函数,我想使用名为seasonMatrix 的自定义函数来拟合它,但为了理解MATLAB 的MLE 的工作原理,我做了这个愚蠢的拟合,说seasonMatrix 只是一个线性函数。帮助我理解我从 MATLAB 网站复制的这段代码以及逻辑(阅读下文)

Times = [0:1/8760:8712/8760];
% Calibrate parameters for the seasonality model
seasonMatrix = @(t) [t];
C = seasonMatrix(Times);
seasonParam = C\logprice_hour_seas;

现在我的模型应该有一些错误(很多!)。但我做logprice_hour_seas-C*seasonParam,这都是零!好吧,MLE 是使用logprice_hour_seas=C*seasonParam 解决的,所以这并不奇怪。我有什么不明白的??

【问题讨论】:

  • 你缺乏信息。你不需要有错误,有些模型可以完美地拟合数据,它只取决于数据。您刚才是不是说您使用相同的数据创建了数据logprice_hour_seas?我的意思是,如果您使用模型创建数据,然后对其进行求解,那么您显然会得到数据,对吗?没有噪音。你在提交the inverse crime吗?
  • @AnderBiguri 不,我使用的模型不适合数据。事实上,如果我选择任何其他模型,也会发生同样的问题。我没有创建数据。
  • 那你需要给我们看一个完整的例子
  • @AnderBiguri 正如我所说,任何虚构的数据都可以使用。但如果你坚持,试试这个:logprice_hour_seas=[5.2560 5.2151 5.2324 5.2224 5.2292]; PriceTimes = [0:1/8760:4/8760]; seasonMatrix = @(t) [sin(2.*pi.*t) cos(2.*pi.*t) sin(4.*pi.*t) ... cos(4.*pi.*t) t 个(大小(t, 1), 1)]; C = seasonMatrix(PriceTimes); seasonParam = C\logprice_hour_seas;
  • 您确定您的矩阵构建正确吗?在您的示例中,C 是行向量,logprice_hour_seas 是列向量。因此,结果seasonParam 对每个组合都有一个值。你得到零错误,因为seasonParam 将所有内容设置为零,但对应于seasonMatrix==1 的那个,因此值乘以 1 等于值,零错误。 TDLR:你搞砸了矩阵大小。

标签: matlab least-squares mle


【解决方案1】:

正如评论中提到的,你搞砸了矩阵大小。

您创建值的方式seasonParam 变为5x26 矩阵。和C 一个1x26 矩阵。您正在模拟一个欠定方程组,它可以有多个解。

在这种情况下,对于算法来说幸运的是,C 的一些值是 1 !这意味着在解决方案 (seasonParam) 中的所有 26 个 5x1 向量中,只有乘以 1 的向量需要设置为结果值 (logprice_hour_seas) 才能完美匹配!因此,您的解决方案seasonParam

 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
5.2560    5.2151    5.2324    5.2224    5.2292
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0
 0         0         0         0         0

整个模型毫无意义,所以我假设您只是在搞乱尺寸。 请尝试以下操作:

 logprice_hour_seas=[5.2560 5.2151 5.2324 5.2224 5.2292]'; 
 PriceTimes = [0:1/8760:4/8760]'; 
 seasonMatrix = @(t) [sin(2.*pi.*t) cos(2.*pi.*t) sin(4.*pi.*t)  cos(4.*pi.*t) t ones(size(t, 1), 1)];
 C = seasonMatrix(PriceTimes);
 seasonParam = C\logprice_hour_seas;

【讨论】:

  • 是的,尺寸已转置。谢谢。
猜你喜欢
  • 2010-09-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-28
  • 2010-11-28
  • 1970-01-01
相关资源
最近更新 更多