forked from milleratotago/Cupid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDemoEstManyStarts.m
43 lines (38 loc) · 1.75 KB
/
DemoEstManyStarts.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
40
41
oneDist = Normal(0,1);
data = oneDist.Random(1000,1);
[mean(data), std(data,1)]
disp('Example of basic ML estimation')
EstFn = @oneDist.EstML;
fnParms = {data};
% mu sigma
starting_points = [-0.1, 0.9; ...
0.1, 1.1];
[s,EndingVals,fval,exitflag,output,allstarts]= EstManyStarts(oneDist,EstFn,fnParms,starting_points);
s
disp('Example of MLcensored estimation')
Bounds = [-2, 2]; % define truncation bounds
truncData = data(data>=Bounds(1) & data<=Bounds(2)); % censor the data
nsTooExtreme = [sum(data<Bounds(1)), sum(data>Bounds(2))] % count too-small and too-large observations
EstFn = @oneDist.EstMLcensored;
fnParms = [{truncData}, {Bounds}, {nsTooExtreme}];
% mu sigma
starting_points = [-0.1, 0.9; ...
0.1, 1.1; ...
0.0, 1.0];
[s,EndingVals,fval,exitflag,output]= EstManyStarts(oneDist,EstFn,fnParms,starting_points);
s
disp('Example of MLcensored estimation with sigma constrained')
% For this example, suppose we want to consider only parameter combinations
% with sigma exactly 0.9, 1.0, or 1.1, and we want the best of those.
Bounds = [-2, 2]; % define truncation bounds
truncData = data(data>=Bounds(1) & data<=Bounds(2)); % censor the data
nsTooExtreme = [sum(data<Bounds(1)), sum(data>Bounds(2))] % count too-small and too-large observations
EstFn = @oneDist.EstMLcensored;
parmCodes = 'rf'; % indicate that sigma is constrained
fnParms = [{truncData}, {Bounds}, {nsTooExtreme}, parmCodes]; % pass optional parmCodes parameter
% mu sigma
starting_points = [ 0.0, 0.9; ...
0.0, 1.0; ...
0.0, 1.1];
[s,EndingVals,fval,exitflag,output]= EstManyStarts(oneDist,EstFn,fnParms,starting_points);
s