【问题标题】:fitting a gamma variate curve to a set of data points in c++将伽玛变量曲线拟合到c ++中的一组数据点
【发布时间】:2021-07-31 04:07:16
【问题描述】:

我有一个值数组(浓度值),每个值取自不同的时间点。我需要将 gamma 变量曲线(公式在下图中)拟合到这些值(即找到 alpha 和 beta 以使曲线最适合这些点 - 所有其他变量都是已知的。)

我可能得到的值的示例(交叉)以及我想要拟合的曲线:

我不知道该怎么做。我试图拟合公式的简化版本,可以通过使用线性回归,通过使用矩阵来解决,但我无法让它工作。 该版本的公式(您只求解一个变量 alpha)如下所示:

简化版,也可以:

我尝试使用矩阵求解拟合线性回归曲线,使用 vnl 库 (https://vxl.github.io/doc/release/core/vnl/html/index.html) 看起来像这样。我正在关注这个人的教程 (https://machinelearningmastery.com/solve-linear-regression-using-linear-algebra/)

  //this is the "data", m_Timing is a vector containing the time each of the data were taken at. 
  vectorVoxel = inputVectorVolumeIter.Get();

  // linear regression 
  
  //declaring the independent (y) and dependent values (x) for our linear regression 
  vnl_matrix<double> ind_var(timeSize, 1);  
  vnl_vector<double> dep_var(timeSize); 
 
  //this vector will hold the "weights" of the fitted line - although in this case there should only be 1 weight 
  vnl_vector<double> weights(1); 

  //loading the values into our independent and dependent variable holders 
  for (index = 0; index < timeSize; index++) {
    ind_var(index, 0) =  (1 + log(m_Timing[index]/tempTTP) - (m_Timing[index]/tempTTP)); 
    dep_var.put(index, log(vectorVoxel[index]));
 }
  
  //fitting the curve! 
  weights = (ind_var.transpose() * ind_var) * ind_var.transpose() * dep_var; 
 

它不起作用 - 应该包含拟合线的系数 (alpha) 的权重向量只包含“null”。

我正在编写的代码使用了 itk 库(一个用于医学图像处理的库),并且我还在使用 vnl 来处理矩阵。有没有办法做到这一点?

感谢您阅读本文!我非常感谢任何帮助/甚至只是指出我正确的方向,因为我不知道如何继续。

【问题讨论】:

  • 我需要你的数据(数字,而不是图表)来检查特定的回归方法,看看这种方法在你的情况下是否方便。
  • @JJacquelin 感谢您的回复!每次使用程序时,数据都会发生变化(程序生成对大脑 CT 扫描进行数学处理,重复进行大约一分钟,因为患者被注射了对比剂 - 每组数据实际上是(密度测量)单个在那一分钟的不同时间点从一个人的大脑中获取的“像素”。这是示例数据(已转换以便可以进行回归 - 我不确定这是否正确):
  • @JJacquelin 因变量(当时密度的对数):[3.55, 2.77, 3.13, 3.25, 3.465, 2.89, 3.58, 2.39, 3.46, 3.13, 3.61, 2.9, 2.19, 3.29 ] 自变量(源自时间值):0.0、-2.1、-1.5、-1.16、0.0、-0.0035、-0.007、-0.021、-0.038、-0.059、-0.08、-0.1、-0.14
  • 不能用,因为第一个文件是14个数字,第二个文件只有13个。
  • 您在问题的末尾写了“它不起作用”。我想在它不起作用的情况下使用与你相同的数据,以便重现你遇到的麻烦,看看到底哪里有困难。

标签: c++ linear-regression curve-fitting itk gamma-distribution


【解决方案1】:

这是一个不适合由 ITK 解决的问题。虽然您可以使用 ITK 的 Optimizer 基础架构,但还有更好/更简单的选择。

也许试试NLOpt?这是如何使用它的example。此外,您可以查看fits a polynomial 指向 3D 空间中的代码。

【讨论】:

    猜你喜欢
    • 2014-03-01
    • 1970-01-01
    • 2012-06-22
    • 2014-05-18
    • 1970-01-01
    • 1970-01-01
    • 2012-07-14
    • 1970-01-01
    • 2013-08-13
    相关资源
    最近更新 更多