-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFrechet2.m
87 lines (74 loc) · 3.09 KB
/
Frechet2.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
classdef Frechet2 < Frechet
% Frechet2 special case of Frechet distribution with minval = 0
% Same as the ExtrVal2L distribution.
methods(Static)
function Reals = ParmsToReals(Parms,~)
Reals = [NumTrans.GT2Real(eps,Parms(1)), NumTrans.GT2Real(eps,Parms(2))];
end
function Parms = RealsToParms(Reals,~)
Parms = [NumTrans.Real2GT(eps,Reals(1)), NumTrans.Real2GT(eps,Reals(2))];
end
end % methods(Static)
methods
function obj=Frechet2(varargin)
obj=obj@Frechet;
obj.FamilyName = 'Frechet2';
obj.NDistParms = 2;
obj.ParmTypes = 'rr';
obj.DefaultParmCodes = 'rr';
obj.CDFNearlyOne = 0.999999;
obj.minval = 0;
obj.StartParmsMLEfn = @obj.StartParmsMLE;
switch nargin
case 0
case 2
ResetParms(obj,[varargin{1},varargin{2}]);
otherwise
ME = MException('Frechet2:Constructor', ...
'Frechet2 constructor needs 0 or 2 arguments.');
throw(ME);
end
end
function []=ResetParms(obj,newparmvalues)
ClearBeforeResetParmsC(obj);
obj.shape = newparmvalues(1);
obj.scale = newparmvalues(2);
ReInit(obj);
end
function PerturbParms(obj,ParmCodes)
% Perturb parameter values prior to estimation attempts.
newShape = ifelse(ParmCodes(1)=='f', obj.shape, 0.9*obj.shape);
newScale = ifelse(ParmCodes(2)=='f', obj.scale, 0.9*obj.scale);
obj.ResetParms([newShape, newScale]);
end
function []=ReInit(obj)
assert(obj.shape>0,'Frechet2 shape parameter must be > 0.');
assert(obj.scale>0,'Frechet2 scale parameter must be > 0.');
obj.LowerBound = obj.minval+eps;
obj.UpperBound = obj.minval + obj.scale * (-1 / log(obj.maxCDF))^(1/obj.shape);
if obj.UpperBound > obj.maxUpperBound
obj.UpperBound = obj.maxUpperBound;
end
% obj.UpperBound = Frechet.frechicdf(obj.CDFNearlyOne,obj.shape,obj.scale,obj.minval);
obj.Initialized = true;
if (obj.NameBuilding)
BuildMyName(obj);
end
end
function parms = StartParmsMLE(obj,X)
% Based on the following quartile functions from Wikipedia:
% assuming m == 0
% q1 = s * log(4)^(-1/alpha)
% q3 = s * log(4/3)^(-1/alpha)
obs = double(prctile(X,[25 75]));
% Here is the array of functions, all of which are to be zero'ed
F = @(p) [...
( obs(1)/p(2) )^(-p(1)) - log(4); ...
( obs(2)/p(2) )^(-p(1)) - log(4/3) ...
];
starts = mean(X);
x0 = double([3 starts]);
parms = fsolve(F,x0,obj.fsolveoptions);
end
end % methods
end % class Frechet2