简体   繁体   English

在Matlab中找到离散数据集的拐点

[英]Find the inflection point of a discrete dataset in Matlab

I have a dataset (an array with x and y values) to which I eventually want to fit a nonlinear model. 我有一个数据集(具有x和y值的数组),最终我希望将其拟合到非线性模型。 In order to increase the chances that the fit will be good and that the model will converge, I want to supply initial parameters as close to the solution as possible. 为了增加拟合良好和模型收敛的机会,我想提供尽可能接近解决方案的初始参数。 One of the parameter of the model I want to fit corresponds to the inflection point of the curve. 我要拟合的模型参数之一对应于曲线的拐点。 Is there a way I can estimate the inflection point of a discrete dataset (not a continuous function) in Matlab? 有没有办法可以估计Matlab中离散数据集(不是连续函数)的拐点? I don't want to have to curvefit beforehand since this is intended to accelerate the curvefit and increase its probability of being successful. 我不想事先进行曲线拟合,因为这是为了加快曲线拟合并增加其成功的可能性。

The idea is to work in 2 steps: 这个想法分两个步骤进行:

  1. First define what is the noise level, and "simplify" the ( x , y ) polygonal line to some "smooth" subset ( xs , ys ). 首先定义什么是噪声水平,然后将( xy )折线“简化”为某些“平滑”子集( xsys )。 After the simplification, every change in curve features will be considered significant. 简化之后,曲线特征的每一次变化都将被认为是重要的。

  2. Look for the changes in convexity of the polygonal line ( xs , ys ). 寻找折线( xsys )的凸度变化。

For first point you may use the Douglas-Peucker algorithm, implemented here . 首先,您可以使用在此处实现的Douglas-Peucker算法。

The second point is based on the signed area constructed from 3 consecutive points of the polyline: 第二点基于由折线的三个连续点构成的有符号区域:

      | x0   y0   1 |
    1 |             |
A = - | x1   y1   1 |
    2 |             |
      | x2   y2   1 |

The polyline is "convex" - ie positive curvature - where these areas are positive, and "concave" - ie negative curvature - when the area is negative. 折线是“凸”(即正曲率)(在这些区域为正),“凹”(即负曲率)在这些区域为负时。 The changes in curvature are the places where the inflection points are located. 曲率的变化是拐点所在的位置。

After downloading the dpsimplify function from File Exchange, you could run the following code (suppose that x and y vectors are already existing): 从File Exchange下载dpsimplify函数后,您可以运行以下代码(假设xy向量已经存在):

%// Part 1.
[ps,~] = dpsimplify([x(:),y(:)], 1e-3);  %// adjust "tol" above noise level
xs = ps(:,1);
ys = ps(:,2);

%// Part 2
I = 1:numel(xs)-2;
sgnA = sign( ...
    xs(I+0).*ys(I+1) ...
  + xs(I+1).*ys(I+2) ...
  + xs(I+2).*ys(I+0) ...
  - xs(I+0).*ys(I+2) ...
  - xs(I+1).*ys(I+0) ...
  - xs(I+2).*ys(I+1) ...
);
k_inflex = find(2 == abs(diff(sgnA)));
x_inflex = xs(k_inflex);
y_inflex = ys(k_inflex);

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

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