将伽马变量曲线拟合到 C++

问题描述

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

gamma-variate curve formula

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

an example of the values i might get (crosses),and the curve I'd want to fit

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

简化版,也可以:

simplified version,which would also be fine

我尝试使用矩阵求解拟合线性回归曲线,使用 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 来处理矩阵。有没有办法做到这一点?

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

解决方法

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

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...