To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / _FullBNT / BNT / CPDs / @softmax_CPD / maximize_params.m @ 8:b5b38998ef3b
History | View | Annotate | Download (1.56 KB)
| 1 |
function CPD = maximize_params(CPD, temp) |
|---|---|
| 2 |
% MAXIMIZE_PARAMS Set the params of a CPD to their ML values (dsoftmax) using IRLS |
| 3 |
% CPD = maximize_params(CPD, temperature) |
| 4 |
% temperature parameter is ignored |
| 5 |
|
| 6 |
% Written by Pierpaolo Brutti |
| 7 |
|
| 8 |
if ~adjustable_CPD(CPD), return; end |
| 9 |
options = foptions; |
| 10 |
|
| 11 |
if CPD.verbose |
| 12 |
options(1) = 1; |
| 13 |
else |
| 14 |
options(1) = -1; |
| 15 |
end |
| 16 |
%options(1) = CPD.verbose; |
| 17 |
|
| 18 |
options(2) = CPD.wthresh; |
| 19 |
options(3) = CPD.llthresh; |
| 20 |
options(5) = CPD.approx_hess; |
| 21 |
options(14) = CPD.max_iter; |
| 22 |
|
| 23 |
dpsize = size(CPD.self_vals,3); |
| 24 |
for i=1:dpsize, |
| 25 |
mask=find(CPD.eso_weights(:,:,i)>0); % for adapting the parameters we use only positive weighted example |
| 26 |
if ~isempty(mask), |
| 27 |
if ~isempty(CPD.dps_as_cps.ndx), |
| 28 |
puredp_map = find_equiv_posns(CPD.dpndx, union(CPD.dpndx, CPD.dps_as_cps.ndx)); % find the glm structure |
| 29 |
subs = ind2subv(CPD.sizes(union(CPD.dpndx, CPD.dps_as_cps.ndx)),i); % that corrisponds to the |
| 30 |
active_glm = max([1,subv2ind(CPD.sizes(CPD.dpndx), subs(puredp_map))]); % i-th 'fictitious' example |
| 31 |
|
| 32 |
CPD.glim{active_glm} = netopt_weighted(CPD.glim{active_glm}, options, CPD.parent_vals(mask',:,i),...
|
| 33 |
CPD.self_vals(mask',:,i), CPD.eso_weights(mask',:,i), 'scg'); |
| 34 |
else |
| 35 |
alfa = 0.4; if CPD.solo, alfa = 1; end % learning step = 1 <=> self is all alone in the net |
| 36 |
CPD.glim{i} = glmtrain_weighted(CPD.glim{i}, options, CPD.parent_vals(mask',:),...
|
| 37 |
CPD.self_vals(mask',:,i), CPD.eso_weights(mask',:,i), alfa); |
| 38 |
end |
| 39 |
end |
| 40 |
mask=[]; |
| 41 |
end |