-
Notifications
You must be signed in to change notification settings - Fork 0
/
RainTyping.m
71 lines (53 loc) · 1.95 KB
/
RainTyping.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
function[V_RainTypes,my_GMModel,nb_clusters]=RainTyping(V_p0,V_k,V_teta,M_PCs,nb_clusters)
V_RainTypes=zeros(size(V_p0));
inds_dry=(V_k==-1);
inds_wet=(V_k>0);
V_p0(inds_dry)=[];
V_k(inds_dry)=[];
V_teta(inds_dry)=[];
M_PCs(inds_dry,:)=[];
V_p0(V_p0<0.01)=0.01;
V_p0(V_p0>0.99)=0.99;
V_k(V_k<0.01)=0.01;
V_teta(V_teta<0.01)=0.01;
M_PCs=M_PCs(:,1:3);%only 3 first PCs
nb_PCs=size(M_PCs,2);
M_rainpatterns=[norminv(V_p0);log(V_k);log(V_teta);M_PCs'];
if nb_clusters==0
max_clusters=25;%#ToSet
min_clusters=10;
nb_iter=3;
figure(10)
clf
%EM classification based on M_rainpatterns
M_BIC=[];
options = statset('MaxIter',10000,'TolFun',1e-15);
V_nb_clusters=min_clusters:max_clusters;
M_BIC=NaN(length(V_nb_clusters),nb_iter);
for iter=1:nb_iter
for j=min_clusters:max_clusters
j
GMModel = fitgmdist(M_rainpatterns',j,'Options',options,'CovarianceType','diagonal','RegularizationValue',0.1);
M_BIC(j-min_clusters+1,iter)=GMModel.BIC;
end
end
hold on
plot(V_nb_clusters,M_BIC,'c-')
hold on
plot(V_nb_clusters,mean(M_BIC,2),'b-')
[~,nb_clusters]=min(mean(M_BIC,2));
nb_clusters=nb_clusters+min_clusters-1;
%---
options = statset('MaxIter',1e6,'TolFun',1e-20);
my_GMModel = fitgmdist(M_rainpatterns',nb_clusters,'Options',options,'CovarianceType','diagonal','RegularizationValue',0.1);
[V_RainTypes_tmp,~,~] = cluster(my_GMModel,M_rainpatterns');
V_RainTypes(inds_wet)=V_RainTypes_tmp;
else
display('before cluster')
options = statset('MaxIter',1e4,'TolFun',1e-20);
my_GMModel = fitgmdist(M_rainpatterns',nb_clusters,'Options',options,'CovarianceType','diagonal','RegularizationValue',0.1);
display('after cluster')
[V_RainTypes_tmp,~,~] = cluster(my_GMModel,M_rainpatterns');
V_RainTypes(inds_wet)=V_RainTypes_tmp;
end
end