Optimization of Logistic Function Variable K for multiple Inputs Simultaneously
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to optimize the 'slope' variable (k) for the logistic function:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1036800/image.jpeg)
Where L = 2, and my input values (more details in a bit) are the (x -x0) term, and k is the term I am trying to determine for a known output(f(x)).
I am trying to squash some values using this function so that the tranformed values lie between -1 and 1. In my code I refer to K as alpha.
The major issue I am having is that I want to find one output k for tranforming:
promAngles = [146.7589 115.7733 98.1666 66.8909 41.9377 26.2680 11.4212 -29.8628 -45.2301 -68.8243 -100.6234 -117.7418 -147.8271]
into this:
sC = [1.0000 0.9703 0.8210 0.5797 0.4067 0.2974 0.1467 -0.2974 -0.4067 -0.5797 -0.8210 -0.9703 -1.0000]
At first I tried this which I think is a correctly rewritten expression for the logistic function in terms of K but it returns a vector of Ks that make it true. PromAngles are my data:
eqnNew = -(log((power((1 + (2./(sC+1))), 1./promAngles))));
which returns
newVarTemp = [ -0.0047 -0.0061 -0.0075 -0.0122 -0.0211 -0.0355 -0.0884 0.0451 0.0326 0.0254 0.0248 0.0359 0.1408]
However I am looking for a single value that minimizes the error between promAngles and sC.
Below is something else I have tried, which I put a value in for the k variable as well as my input values which exist in a 1x13 vector.
%Possible alpha candiates
candVals = [0:0.001:100];
%Logistic Function
functAlpha = @(inputCurv, estAlpha) ((2./(1 + exp(-1*estAlpha.*inputCurv))) - 1);
lossList = nan(length(candVals), 1);
for cand = 1:length(candVals)
%Produces the scaled outputs associated with the alpha input
fAlpha = functAlpha(promAngles, candVals(cand));
%Determines the loss
fLoss = norm(fAlpha - sC, 2);
lossList(cand) = fLoss;
end
%Find the alpha with the minimum loss --> should allow to produce desired
%outputs (sC(2, :))
[minVal, linIndx] = min(lossList);
This produces the minimum error at alpha == 0.0230, which in turn has this as the output:
fAlpha = [0.9339 0.8696 0.8106 0.6465 0.4481 0.2932 0.1306 -0.3305 -0.4778 -0.6592 -0.8201 -0.8750 -0.9354]
Which is close, but not as close as I can be. Is there a better way to do this than increasing the sampling for the candidate k values?
Let me know if I should clarify more
댓글 수: 0
채택된 답변
Torsten
2022년 6월 18일
편집: Torsten
2022년 6월 18일
I think you will have to work on the approximation function "fun" in order to get better results.
promAngles = [146.7589 115.7733 98.1666 66.8909 41.9377 26.2680 11.4212 -29.8628 -45.2301 -68.8243 -100.6234 -117.7418 -147.8271];
sC = [1.0000 0.9703 0.8210 0.5797 0.4067 0.2974 0.1467 -0.2974 -0.4067 -0.5797 -0.8210 -0.9703 -1.0000];
fun = @(K) (2./(1 + exp(-K*promAngles)) - 1) - sC;
k0 = 0.02;
k = lsqnonlin(fun,k0)
fun(k);
plot(promAngles,sC);
hold on
plot(promAngles,fun(k)+sC)
댓글 수: 2
추가 답변 (1개)
Sam Chak
2022년 6월 18일
Hi @Ezra Sutter
Is it allowed to fit using other type of function?
promAngles = [146.7589 115.7733 98.1666 66.8909 41.9377 26.2680 11.4212 -29.8628 -45.2301 -68.8243 -100.6234 -117.7418 -147.8271];
sC = [1.0000 0.9703 0.8210 0.5797 0.4067 0.2974 0.1467 -0.2974 -0.4067 -0.5797 -0.8210 -0.9703 -1.0000];
fun = @(p) (1/4)*(-p(1)*promAngles.*sign(promAngles - p(2)) - p(1)*promAngles.*sign(promAngles - p(2)).*sign(promAngles + p(2)) + p(1)*promAngles.*sign(promAngles + p(2)) + 3*sign(promAngles - p(2)) - sign(promAngles - p(2)).*sign(promAngles + p(2)) + sign(promAngles + p(2)) + p(1)*promAngles + 1) - sC;
p0 = [0.01 105];
p = lsqnonlin(fun, p0)
plot(promAngles, sC, 'ro', promAngles, (1/4)*(-p(1)*promAngles.*sign(promAngles - p(2)) - p(1)*promAngles.*sign(promAngles - p(2)).*sign(promAngles + p(2)) + p(1)*promAngles.*sign(promAngles + p(2)) + 3*sign(promAngles - p(2)) - sign(promAngles - p(2)).*sign(promAngles + p(2)) + sign(promAngles + p(2)) + p(1)*promAngles + 1), 'b-')
grid on
legend('Data', 'Best fit', 'location', 'best', 'FontSize', 14)
xlabel('promAngles')
ylabel('sC')
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!