MATLAB:多函数拟合
我有一个函数,三个指数之和:
F = f1*exp1 + f2*exp2 + f3*exp3
确切地说:
F=1-((1-f(2)-f(3)).*(exp(-abs(data)./a(1)))+((1-f(1)-f(3)).*(exp(-abs(data)./a(2))))+((1-f(1)-f(2)).*(exp(-abs(data)./a(3)))));
其中 f1、f2、f3 是分数,每个 exp 有一个参数,称为 a1、a2 和 a3。
因此,将该函数与实验数据拟合得到六个参数(f1、f2、f3、a1、a2、a3)。
请注意,
a1 > a2 > a3
拟合是
f1 + f2 + f3 = 1
在几个时间滞后(称为 t1、t2、t3...)内完成的。因此,对于每个时间延迟,都有一组六个参数。
参数a1、a2和a3随着时间延迟以线性方式增加(a1(t1) < a1(t2) < a1(t3)...等等)。每个时间延迟的分数是相同的。
我需要的是 a1(t)、a2(t)、a3(t) 和分数的斜率。 问题是,当我为每个时间延迟拟合函数时,我经常遇到 a1 和 a2 很好地上升(完美线性拟合)但 a3 下降的情况。 另外,我对分数有一个问题 - 我不能取每个分数的平均值,因为当我添加 f1(t) + f2(t) + f3(t) 时,它永远不等于 1。
有没有任何(简单的)方法可以拟合这一切都是“一次”吗?怎么做呢? 谢谢!
I have a function, sum of three exponents:
F = f1*exp1 + f2*exp2 + f3*exp3
exactly:
F=1-((1-f(2)-f(3)).*(exp(-abs(data)./a(1)))+((1-f(1)-f(3)).*(exp(-abs(data)./a(2))))+((1-f(1)-f(2)).*(exp(-abs(data)./a(3)))));
where f1, f2, f3 is a fraction and each exp has one parameter, call it a1, a2 and a3.
So, fitting this function to experimental data gives six parameters (f1, f2, f3, a1, a2, a3).
Note, that
a1 > a2 > a3
and
f1 + f2 + f3 = 1
The fitting is done for several timelags (call it t1, t2, t3....). So for each timelag there is one set of six parameters.
Parameters a1, a2 and a3 are increasing with timelag in linear way ( a1(t1) < a1(t2) < a1(t3)... and so on). Fractions are the same for each timelag.
What I need is slope of a1(t), a2(t), a3(t) and fractions.
The problem is, that when I am fitting the function for each timelag, I often have a situation that a1 and a2 are nicely going up (perfect linear fits) but a3 is going down.
Also I have a problem with fractions - I can't take mean of each fraction because when I add f1(t) + f2(t) + f3(t) its never equal to 1.
Is there any (simple) way to fit it all 'at once'? How to do that?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我建议减少参数数量:
这为每个 ai(t) 提供了两个参数,加上每个时间点的 f1 和 f2,因此总共有 6 + 2 *(时间点数量)个参数。根据 Chris Taylor 的建议,根据时间点的数量,可以使用
fmincon
来拟合这些时间点。使用
fmincon
,您可以以非常灵活的方式添加参数约束。您可能想将约束 0<=f1<=1 (对于 f2 也是如此)添加到已有的约束中。First, I would suggest to reduce the number of parameters:
That gives you two parameters for each ai(t), plus f1 and f2 for each time point, so a total of 6 + 2 * (# of timepoints) parameters. Depending on the number of timepoints, it may be possible to fit those with
fmincon
, as suggested by Chris Taylor.With
fmincon
, you can add the parameter constraints in quite flexible ways. You probably want to add the constraint 0<=f1<=1 (and the same for f2) to the ones you already have.