forked from lawrennd/optimi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsigmoidTransform.m
39 lines (34 loc) · 1012 Bytes
/
sigmoidTransform.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function y = sigmoidTransform(x, transform)
% SIGMOIDTRANSFORM Constrains a parameter to be between 0 and 1.
% FORMAT
% DESC contains commands to constrain parameters to be between 0
% and 1 via the sigmoid function.
% ARG x : input argument.
% ARG y : return argument.
% ARG transform : type of transform, 'atox' maps a value into
% the transformed space (i.e. makes it between 0 and 1). 'xtoa' maps the
% parameter back from transformed space to the original
% space. 'gradfact' gives the factor needed to correct gradients
% with respect to the transformed parameter.
%
% SEEALSO : negLogLogitTransform, expTransform
%
% COPYRIGHT : Neil D. Lawrence, 2004, 2005, 2006, 2007
% OPTIMI
limVal = 36;
y = zeros(size(x));
switch transform
case 'atox'
index = find(x<-limVal);
y(index) = eps;
x(index) = NaN;
index = find(x<limVal);
y(index) = sigmoid(x(index));
x(index) = NaN;
index = find(~isnan(x));
y(index) = 1-eps;
case 'xtoa'
y = invSigmoid(x);
case 'gradfact'
y = x.*(1-x);
end