필터 지우기
필터 지우기

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