加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 07:54:36 所属栏目:百科 来源:网络整理
导读:我是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
我是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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读