Info

此问题已关闭。 请重新打开它进行编辑或回答。

Using fittype for three dimensions

1 次查看(过去 30 天)
Colin Lynch
Colin Lynch 2018-3-15
关闭: MATLAB Answer Bot 2021-8-20
Hello!
I am attempting to use the fittype function to fit a softmax surface to a sigmoid surface using only one coefficient, beta. I couldn't understand the literature on how to do this, so I attempted to do it in a for loop where I would only fit the two dimensional curve for one dependent axis, y, while iterating over the dependent surface, theta. The output would then be an array of the coefficients I need. My efforts resulted in this code:
x = linspace(0,1);
z = zeros(1,10);
for n = 1:10
theta = n/10;
y = x.^2./(x.^2 + theta.^2);
myfittype = fittype('1/(1+exp(beta*(theta-x)))', 'dependent',{'y'},'independent',{'x'}, 'coefficients',{'beta'});
myfit = fit(x',y',myfittype);
z(n) = myfit.beta;
end
The problem is that fittype doesn't recognize theta as an input variable, so its undefined right now. Does anyone know how to use fittype to directly fit surfaces, or how I can fix this particular for loop?

回答(1 个)

Prajit T R
Prajit T R 2018-3-22
Hi Colin
The variable 'theta' is not being recognized by the fittype function- hence the error. Try this modified code instead:
x = linspace(0,1);
z = zeros(1,10);
for n = 1:10
theta = n/10;
y = x.^2./(x.^2 + theta.^2);
myfittype = fittype('1/(1+exp(beta*(theta-x)))', 'dependent',{'y'},'independent',{'x'}, 'coefficients',{'beta','theta'});
myfit = fit(x',y',myfittype);
z(n) = myfit.beta;
end
The only change is that 'theta' has been defined as a co-efficient.
Cheers

此问题已关闭。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by