将伽马变量曲线拟合到 C++ 中的一组数据点

fitting a gamma variate curve to a set of data points in c++

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

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

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

简化版,这样也可以:

我尝试使用矩阵求解拟合线性回归曲线,使用 vnl 库 (https://vxl.github.io/doc/release/core/vnl/html/index.html) looked like this. I was following this guy's tutorial (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 来处理矩阵。有什么办法吗?

感谢您阅读本文!我真的很感谢 help/even 给我指出正确的方向,因为我不知道如何继续。

这个问题不太适合用ITK来解决。虽然您可以使用 ITK 的 Optimizer 基础设施,但有 better/simpler 个选择。

也许可以尝试 NLOpt? Here is an example of how to use it. Also, you could look at this code which fits a polynomial 指向 3D space。