python - 将 3d sigmoid 拟合到数据

标签 python matlab curve-fitting data-fitting interpolation

我有与多元 sigmoidal 函数相关的数据:x y r(x,y)

x           y         r(x,y)

0.468848997 0.487599    0
0.468848997 0.512929    0
0.468848997 0.538259    0
0.468848997 0.563589    0
0.468848997 0.588918    0
0.468848997 0.614248    0
0.468848997 0.639578    0
0.468848997 0.664908    0.000216774
0.468848997 0.690238    0.0235043
0.468848997 0.715568    0.319768
0.468848997 0.740897    0.855861
0.468848997 0.766227    0.994637
0.468848997 0.791557    0.999524
0.468848997 0.816887    0.99954
0.468848997 0.842217    0.99958
0.468848997 0.867547    0.999572
0.468848997 0.892876    0.999634
0.468848997 0.918206    0.999566
0.468848997 0.943536    0.999656
0.468848997 0.968866    0.999637
0.468848997 0.994196    0.999685
.           .            .
.           .            .
.           .            .
0.481520591 0.487599    0
0.481520591 0.512929    0
0.481520591 0.538259    0
0.481520591 0.563589    0
0.481520591 0.588918    0
0.481520591 0.614248    0
0.481520591 0.639578    1.09E-06
0.481520591 0.664908    0.000755042
0.481520591 0.690238    0.0498893
0.481520591 0.715568    0.449531
0.481520591 0.740897    0.919786
0.481520591 0.766227    0.998182
0.481520591 0.791557    0.99954

我想知道是否有一个 sigmoid 函数可以用来拟合我的 3D 数据。 我遇到了这个答案for 2D data但我无法为我的问题扩展它。

我认为辅助功能可能如下所示:

f(x,y)=1\(1+e^(-A0 x+A1))*( 1\(1+e^(-A2 y+A3)) with A0=A2 and A1=A3

我不知道如何从这里开始思考。

我将不胜感激任何见解或建议,因为我现在完全无助。

最佳答案

在你的例子中,输出变量(我将其表示为r_xy)似乎在[0 1]范围内。在这种情况下,多元 sigmoid 可以模拟如下:

x = -10:0.5:10;
y = -10:0.5:10;

x_grid = reshape(repmat(x, numel(x), 1), 1, numel(x) ^ 2);
y_grid = repmat(y, 1, numel(y));

% Add some noise
x_noise = x_grid + randn(size(x_grid));
y_noise = y_grid + randn(size(y_grid));

% Randomly define the B parameter of the sigmoid, with the number of
% variables and an offset.
B = randn(1, 3) + 1;

% Calculate the sample data
r_xy = (1 ./ (1+exp(-B * ([ones(size(x_noise)); x_noise; y_noise]))));

% Plot the data
figure
scatter3(x_grid, y_grid, r_xy)

这在三个维度上看起来像一个 sigmoid:

enter image description here

这可以被视为具有二项式分布和 logit 链接函数的广义线性模型。

Matlab 可以使用 fitglm 函数拟合广义线性模型,如下所示:

% Fit the model
model = fitglm([x_grid; y_grid]', r_xy', 'linear', 'Distribution', 'binomial', 'Link', 'logit');

% Plot the model on the scatter plot
hold on;
mesh(x, y, reshape(predict(model, [x_grid; y_grid]'), numel(x), numel(y)), 'LineWidth', 0.5)

结果如下:

enter image description here

模型的参数可以从model变量中读取。

关于python - 将 3d sigmoid 拟合到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29360872/

相关文章:

android - 如何将对象附加到多维列表

python - 如何重载打印功能以扩展其功能?

python - Matplotlib : how to label points individually?

matlab - 在没有显示的情况下安装附加组件

string - MATLAB 字符串处理

python - 为什么最后一个命令变量 "_"没有出现在 dir() 中?

matlab - Octave信号包安装

python - python中的非线性曲线拟合程序

Python 拟合任意高斯函数 - 拟合不佳?

r - ggplot2 stat_function 具有计算参数的 facet_grid 内不同数据子集