forked from pejminister/Pejtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pej_Bound_to.m
39 lines (25 loc) · 896 Bytes
/
Pej_Bound_to.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
% This function bouds the value in X between 0 and 1 while preserving their
% ranks. If Tol = .01 then it keeps everything between for example .01 and .99 as they are and uses a
% nonlinear transformation to squeez in the rest of the values between
% 0-.01 or .99-1
function Y = Pej_Bound_to(X, Lowerbound, UpperBound, Tol)
if nargin==1
Lowerbound = 0;
UpperBound = 1;
disp('Bounding to (0,1)')
end
if nargin < 4
Tol = .01 * abs(UpperBound-Lowerbound); % this is the length of the area that will be used for nonlinear transformation
disp('Pej_Bound_to: Nonlinear widths set to 1% of the data range.')
end
Lb = Lowerbound + Tol; % lower bound
Ub = UpperBound - Tol; % upper bound
Fl = X<Lb;
Fu = X>Ub;
Y = X;
Y(Fl) = Lb + Tol*transform(X(Fl)-Tol);
Y(Fu) = Ub + Tol*transform(X(Fu)-Tol);
end
function t = transform(d)
t = Pej_Transform_logistic(d)-.5;
end