我如何检查这个成本函数是凹的还是凸的?我还想知道这是否有一个或多个最小值。
努力;
function [w,pi,costvalue] = main_cost(inputdata, tmax, alpha_ini,somrow,somcol)
%main cost function; To get cost value for all possible random weights
%Input:
%inputdata : Data sample
%tmax : Maximum Iteraitions - This determines the number of generated
%random w and pi with cost function computation for each set.
%alpha_ini : The learning rate
%Somrow,somcol : map size
%Output
%w: Som weights
%pi: Global weights
%costvalue: cost for a set of w,pi and input data
%Example
%load expdata_normalized;
%[w,pi,costvalue]=main_cost(expdata_normalized,500,0.1,5,5);
N = somrow * somcol; %all neurons
Dimension = size(inputdata,2);%input data dimension
% Get the corresponding 2D locations of the N neurons on the map
[u(:,1) u(:,2)] = ind2sub([somrow somcol], 1:N);
alpha = alpha_ini; %set initial learning rate
%set map effective width
sigma_ini = 2;
sigma = sigma_ini;
%initialise costvalues
costval=zeros(1,tmax);
%for 1 to max iterations
for t = 1:tmax
tic
%generate random SOM weights
w{t} = round(rand(N,Dimension),1);
%generate random Global weights
pi{t} = round (rand(1,Dimension),1);
% For 1 to all samples in the data
for j = 1:size(inputdata,1)
% Pick a single sample
samplei = inputdata(j,:);
% make global weight same dimension with SOM weights
pirepmat = repmat(pi{t},N,1);
% determine the winning node, from weights at iter(t) to picked
% sample
bmu = part1_closestNeuron(samplei, w{t},1,pirepmat);
% calculate neighbourhood for SOM at iter (t)
for k = 1:size(w{t},1)
neighbourhoodF = exp(-eucdist(u(bmu,:),u(k,:), somrow, somcol, 1)^2 / (2*sigma^2));
allneighbourhoodF(k)= neighbourhoodF;
end
% now get cost value with; inputdata(all-static), Somweights at
% iter(t), and Global weights at iter(t)
costval(t) = costval(t)+CostFunction_iter(inputdata, w{t},pi{t},allneighbourhoodF);
end
toc
end
costvalue = costval;
end
我在上面的代码中尝试做的是获取一个随机权重值作为上述成本函数的输入,然后使用不变的样本计算这些随机输入的成本值,如果我找到多个最小成本,那么确认我的成本函数不是凸的。
我的代码与我在问题中发布的成本函数略有不同,因为我有额外的输入。作为我的实现的输出,我有针对我的样本的不同权重的成本值,现在我无法将其可视化。