微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 使用Math.Net的基于指数的曲线拟合

我是Math.Net库的新手,我在尝试基于指数函数进行曲线拟合时遇到了问题.更具体地说,我打算使用这个功能
f(x) = a*exp(b*x) + c*exp(d*x)

使用MATLAB我得到了相当不错的结果,如下图所示:

MATLAB计算以下参数:

f(x) = a*exp(b*x) + c*exp(d*x)
Coefficients (with 95% confidence bounds):
a =   29.6       ( 29.49,29.71)
b =    0.000408  (  0.0003838,0.0004322)
c =   -6.634     ( -6.747,-6.521)
d =   -0.03818   ( -0.03968,-0.03667)

是否可以使用Math.Net实现这些结果?

解决方法

没有看起来目前没有指数支持.然而,有一个关于Math.NET论坛的讨论,其中维护者提出了一个解决方法

https://discuss.mathdotnet.com/t/exponential-fit/131

案例链接中的内容重复:

You can,by transforming it,similar to Linearizing non-linear models
by transformation. Something along the lines of the following should
work:

double[] Exponential(double[] x,double[] y,DirectRegressionMethod method = DirectRegressionMethod.QR)
{
    double[] y_hat = Generate.Map(y,Math.Log);
    double[] p_hat = Fit.LinearCombination(x,y_hat,method,t => 1.0,t => t);
    return new[] {Math.Exp(p_hat[0]),p_hat[1]}; 
}

Example usage:

double[] x = new[] { 1.0,2.0,3.0 };
double[] y = new[] { 2.0,4.1,7.9 };
double[] p = Exponential(x,y); // a=1.017,r=0.687
double[] yh = Generate.Map(x,k => p[0]*Math.Exp(p[1]*k)) // 2.02,4.02,7.98

原文地址:https://www.jb51.cc/csharp/99909.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐