【发布时间】:2015-11-19 08:10:59
【问题描述】:
我如何检查这个成本函数是凹的还是凸的?我还想知道这是否有一个或多个最小值。
努力;
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
我在上面的代码中尝试做的是获取一个随机权重值作为上述成本函数的输入,然后使用不变的样本计算这些随机输入的成本值,如果我找到多个最小成本,那么这证实了我的成本函数不是凸的。
我的代码与我在问题中发布的成本函数略有不同,因为我有一个额外的输入。作为我的实现的输出,我有针对我的样本的不同权重的成本值,现在我无法将其可视化。
【问题讨论】:
-
请阅读SE policy on homework questions。要点是:如果你没有表现出任何努力,那么它就是题外话,可能会在一个小时内关闭。
-
你好阿德里安,谢谢。首先,这不是家庭作业。我需要建议,因为我相信有不同的方法可以解决这个问题。关于我所做的努力;请看下面的代码;
-
感谢 Adriaan,现在我已经上传了代码。对我尝试做的事情的长篇解释是我一开始没有上传代码的原因。但我希望这会有所帮助!
-
感谢您上传代码。这是一个很好的问题!
-
它对于数学来说可能仍然更可行。SE
标签: matlab cluster-analysis som convex-optimization concave