How to write code for projected gradient descent?
10 ビュー (過去 30 日間)
古いコメントを表示
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/428803/image.png)
clc;
clear;
a=0.01;
x=[0;0;0]
b=1
for i=1:1000
if b<10^-6
break
end
r=x-a*f(x)
b=proj(r-x)
x=r
end
display(x)
I want to write a code to find projected gradient descent of a function. (f(x) is gradient of a function, it is not the function itself)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/428808/image.png)
I'm thinking about define a function proj(). But I don't understand how to write the argmin norm(x-y)^2 part
function f=proj(x)
...
end
Can you give me an example on how to write this code?
0 件のコメント
回答 (1 件)
Aditya Patil
2020 年 12 月 23 日
The min function in MATLAB optionally returns the index of the minimum value. You can calculate the function for all input values, and then use the minimum index to find which inputs are the argmin.
A = [1 9 -2; 8 4 -5]
[M,I] = min(A)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!