Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Using the intermediate values in a search algorithm.
조회 수: 1 (최근 30일)
이전 댓글 표시
I was wondering whether there is a way to store the value of the x's inside the objective function to be used in the next iteration. I am using fmincon to minimize some function but I want it to do the following:
- Start from x0, calculate the objective function using x0, calculate the gradient, produce x1.
- Recalculate the objective function using x1 and x0 in the process, calculate the gradient, produce x2.
- Recalculate the objective function using x2 and x1 in the process ....
To be more precise, I need one of the intermediate calculations in each step to be used in the next step, but if it's not possible, then I can also reproduce it given that the value of x's from the previous iteration are kept and feeded back into the objective function.
Is there any "smart" way of doing that without rewriting all the optimization procedures?
Thanks
댓글 수: 0
답변 (1개)
David Ding
2017년 9월 27일
Hi Gleb,
One crude way of storing the values of the inputs inside a function without feeding back the value into the function is to store the value inside the base workspace. That way, when the function returns, the intermediate values are still present and accessible in the base workspace. If you wish to do this, you may use the " assignin " function. For example:
function y = multAdd(x, a, b)
% returns y = ax + b
u = a*x;
assignin('base', 'u', u); % stores the intermediate result u in the base workspace
y = u + b;
end
Thanks,
David
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!