怎么用MATLAB实现argmin函数?

怎么用MATLAB实现argmin函数?,第1张

function x = Corresponding_index(A,B)

% Function: Determine the position of the element in array B corresponding to the equivalent element in array A

% Author:Gong Pf. Time:2019-7-2

% Remark: Only consider A and B is one or two dimension

% And x is a size(B,1)*size(B,2) cell

% Each cell x{i,j} is a t*2 array

% (t is the number of times that the element B(i,j) appears in A)

% And x{i,j}(n,1),x{i,j}(n,2) represent the row and column of the element in A

% Example1:A = [1 2 3 4 1 2 8]

% B = [0 1 2]

% x = argmax_min(A,B)

% x = [][2x2 double][2x2 double] = [] [1 11 5] [1 21 6]

% Example2:A = [1 2 42 4 25 9 83 9 3]

% B = [1 32 9]

% x = argmax_min(A,B)

% x = [1x2 double][2x2 double]= [1 1][4 14 3]

% [3x2 double][2x2 double] [1 22 12 3] [3 24 2]

% Interpret the result: (x{1,1}(1,1),x{1,1}(1,2))=(1,1)

%This is where B(1,1) appears in A

% (x{1,2}(1,1),x{1,2}(1,2))=(4,1) and (x{1,2}(2,1),x{1,2}(2,2))=(4,3)

% These are where B(1,2) appears in A

% Can be used to implement argmin and argmax functions

%% A and B array is less or equal two-dimensional

row_col = size(A)

ii = 1

jj = 1

% Count the number of occurrences of elements in one-dimensional array B in A

B_times = zeros(size(B))

for i = 1:size(B,1)

for j = 1:size(B,2)

B_times(i,j) = length(find(A == B(i,j)))

end

end

% Count the position of the element in B in A

for i = 1:size(B,1)

for j = 1:size(B,2)

for m = 1:row_col(1)

for n = 1:row_col(2)

if A(m,n) == B(i,j)

x{i,j}(1,ii) = m

x{i,j}(2,jj) = n

ii = ii + 1

jj = jj + 1

end

end

end

ii = 1

jj = 1

end

end

x=norm(y-ah,2)

x1=min(min(x))

x2=Corresponding_index(x,x1)

disp(x2)

y=λ*norm(h,1)

argmax是一种对函数求参数(集合)的函数。下面是关于argmax函数的简要介绍,大家可以参考一下。

arg函数是什么

当我们有另一个函数y=f(x)时,若有结果x0= argmax(f(x)),则表示当函数f(x)取x=x0的时候,得到f(x)取值范围的最大

若有多个点使得f(x)取得相同的最大值,那么argmax(f(x))的结果就是一个点集。

换句话说,argmax(f(x))是使得 f(x)取得最大值所对应的变量点x(或x的集埋告合)。arg即argument,此处意为“自变量”。

max 和 argmax的区别

1、y = f(t) 是一般常见的函数式,如果给定一个t值,f(t)函数式会赋一个值给y。

2、y = max f(t) 代表:y 是f(t)函式所有的值中最大的output。

3、y = argmax f(t) 代表:y 是f(t)函式中,会产生最大output的那个参数源液肆t。

例如:假设有雹轿一个函式 f(t),t 的可能范围是 {0,1,2},f(t=0) = 10 f(t=1) = 20 f(t=2) = 7,那分别对应的y如下:y = max f(t) = 20;y= argmax f(t) = 1。

argmax() 函数详解慧庆

[[ 0, 1, 2, 3],

[ 4, 5, 6, 7],

[ 8, 9, 10, 11]] 中[ 8, 9, 10, 11]是槐行最大的铅碧哗

[ 0, 1, 2, 3]中[3]是最大的


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12287575.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存