简体   繁体   English

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

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

I have an array of values (concentration values), with each value taken at a different time point.我有一个值数组(浓度值),每个值取自不同的时间点。 I need to fit a gamma-variate curve (formula is in the picture below) to these values (ie find alpha and beta such that the curve best fits those points - all other variables are known.)我需要将伽玛变量曲线(公式在下图中)拟合到这些值(即找到 alpha 和 beta 以使曲线最适合这些点 - 所有其他变量都是已知的。)

伽马变量曲线公式

an example of the values i might get (crosses), and the curve I'd want to fit:我可能得到的值的一个例子(交叉),以及我想要拟合的曲线:
我可能得到的值的一个例子(交叉),以及我想要拟合的曲线

I have no idea how to do this.我不知道该怎么做。 I tried to fit a simplified version of the formula, one that can be solved by using linear regression, by using matrices but I couldn't get it to work.我试图拟合公式的简化版本,可以通过使用线性回归和矩阵来解决,但我无法让它工作。 That version of the formula (in which you only solve for one variable, alpha) looks like this:该版本的公式(您只求解一个变量 alpha)如下所示:

simplified version, which would also be fine:简化版,也可以:
简化版,也可以

my attempt to solve fit the linear regression curve using matrices, using the vnl library ( https://vxl.github.io/doc/release/core/vnl/html/index.html ) looked like this.我尝试使用矩阵求解拟合线性回归曲线,使用 vnl 库( https://vxl.github.io/doc/release/core/vnl/html/index.ZFC35FDC70D5FC69D253EZC83 I was following this guy's tutorial ( https://machinelearningmastery.com/solve-linear-regression-using-linear-algebra/ )我正在关注这个人的教程( 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; 
 

It doesn't work - the weights vector, which should contain the coefficient (alpha) of the fitted line, just contains "null".它不起作用 - 应该包含拟合线的系数 (alpha) 的权重向量只包含“null”。

The code I'm working on uses the itk library (a library for medical image processsing), and I'm also using vnl for matrices.我正在编写的代码使用了 itk 库(一个用于医学图像处理的库),并且我还在使用 vnl 来处理矩阵。 Is there any way to do this?有没有办法做到这一点?

Thank you for reading this.谢谢您阅读此篇。 I really appreciate any help/even just pointing me in the right direction because I have no idea how to proceed.我非常感谢任何帮助/甚至只是指出我正确的方向,因为我不知道如何继续。

This is a problem which is not best suitable to solving by ITK.这是一个不适合 ITK 解决的问题。 While you could use ITK's Optimizer infrastructure, there are better/simpler choices.虽然您可以使用 ITK 的Optimizer基础架构,但还有更好/更简单的选择。

Maybe try NLOpt ?也许试试NLOpt Here is an example of how to use it.这是一个如何使用它的示例 Also, you could look at this code which fits a polynomial to points in 3D space.此外,您可以查看将多项式拟合到 3D 空间中的点的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM