forked from bakerjw/NGAW2_correlations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetInterIntraEventResiduals.m
146 lines (124 loc) · 5.03 KB
/
GetInterIntraEventResiduals.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
function Out=GetInterIntraEventResiduals(input)
%This class is used to get observed ground motion residuals and
%seperate out into inter and intra event terms. There is also the potential
%to consider spatial correlation (but not implemented as a Aug 2012)
%in the inter and intra event terms
%Input variables:
%input - a structure with the following elements
% .imObservations - the Im values of the observed ground motions
% .imMedian - the predicted median ground motion
% .totalSigma - the predicted total standard deviation
% .interSigma - the inter-event sigma
% .intraSigma - the intra-event sigma
% .eventIds - the event ID numbers
%Output variables:
%Out - a structure with the following elements
% Out.totalResiduals
% Out.totalResidualsNormalized
% Out.interEventResiduals
% Out.interEventResidualsNormalized
% Out.intraEventResiduals
% Out.intraEventResidualsNormalized
% Out.eventData = eventData - a structure which contains the number
% of different earthquakes, "numEq", the unique "EqId", the number
% of Gm per Eq, "eventNumGms", and the inter-event sigma "interSigma"
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%make local copies of the structured variables
imObservations = input.imObservations;
eventIds = input.eventIds;
median = input.imMedian;
totalSigma = input.totalSigma;
interSigma = input.interSigma;
intraSigma = input.intraSigma;
numObs=length(imObservations);
%now begin the computations
%get the total residuals
totalResiduals = (log(imObservations) - log(median));
totalResidualsNormalized = totalResiduals./totalSigma;
%now get the conditional covariance matrix
condCovMatrix = diag(intraSigma.^2);
%set the event data
eventData = setEventData(input);
%now get the inter intra residuals
numEqs = eventData.numEqs;
eta=zeros(numEqs,1);
for i=1:numEqs
eventNumGms=eventData.eventNumGms(i);
interEventSigma = eventData.interSigma(i);
indexmin=sum(eventData.eventNumGms(1:i-1))+1;
indexmax=sum(eventData.eventNumGms(1:i));
Ccsub=zeros(indexmax-indexmin+1,indexmax-indexmin+1);
Ccsub(:,:)=condCovMatrix(indexmin:indexmax,indexmin:indexmax);
totalResidSub=zeros(indexmax-indexmin+1,1);
totalResidSub=totalResiduals(indexmin:indexmax,1);
%get the inter-event residual, eta_i
oneN = ones(eventNumGms,1);
eta(i,1) = (oneN'*(Ccsub\totalResidSub))/(1/interEventSigma^2 + oneN'*(Ccsub\oneN)); %note C\ is same as inv(C)
end
%now assign the inter-event term to the eventData structure
eventData.interEventResiduals=eta;
eventData.interEventResidualNormalized=eta./eventData.interSigma;
%now need to assign the inter-event residuals to the individual
%ground motions and get the intra-event residual
for i=1:numObs
%get the EqId of the ground motion
gmEqId=eventIds(i);
%now find the inter-event residual for this earthquake Id
for j=1:numEqs
eqId=eventData.eventId(j);
if gmEqId==eqId
%now set inter-event residual
interEventResiduals(i,1)=eventData.interEventResiduals(j);
end
end
end
%normalize all the interEvent Residuals
interEventResidualsNormalized=interEventResiduals./interSigma;
%now get the intra-event residual
intraEventResiduals = totalResiduals - interEventResiduals;
%normalize all the intraEvent Residuals
intraEventResidualsNormalized=intraEventResiduals./intraSigma;
%store
Out.totalResiduals = totalResiduals;
Out.totalResidualsNormalized = totalResidualsNormalized;
Out.interEventResiduals = interEventResiduals;
Out.interEventResidualsNormalized = interEventResidualsNormalized;
Out.intraEventResiduals = intraEventResiduals;
Out.intraEventResidualsNormalized = intraEventResidualsNormalized;
Out.eventData = eventData;
%end of function
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function eventData = setEventData(input)
eventIds=input.eventIds;
nObs=length(input.imObservations);
numEq=0; %initialise
eventData.eventId=0;
eventData.eventNumGms=0;
for i=1:nObs
foundEqId=0;
for k=1:numEq
if eventData.eventId(k)==eventIds(i);
eventData.eventNumGms(k)=eventData.eventNumGms(k)+1; %number of events
foundEqId=1;
break
end
end
if foundEqId==0
numEq=numEq+1;
eventData.eventId(numEq)=eventIds(i);
eventData.eventNumGms(numEq)=1; %number of events
end
end
eventData.numEqs=numEq;
GmId=0;
for i=1:numEq
%get the last ground motion which is for this earthquake
GmId=GmId+eventData.eventNumGms(i);
interEventSigma=input.interSigma(GmId);
eventData.interSigma(i,1)=interEventSigma;
end
return;
%end of function
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%