-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathestimateCoefficients.m
170 lines (130 loc) · 7.5 KB
/
estimateCoefficients.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
147
148
149
150
151
152
153
154
155
156
157
158
159
function estimateCoefficients(sample, n,sampBforWindow)
global DensityVars;
% For the first iteration of the online density estimator, the coefficients
% are usually set to zeros.
% Check to see if the sample is outside the domain. If the sample is
% outside the domain, don't count it.
inRange = checkRange(sample, DensityVars.DensityDomain);
if( ~inRange )
return
end % if( ~checkRange(sample(k), DensityVars.DensityDomain) )
% Upper and lower values of wavelet basis support.
lowerSupp = min(DensityVars.WaveSupport);
upperSupp = max(DensityVars.WaveSupport);
% Scaling coefficients only.
scalCoeff = DensityVars.Coefficients{1,1};
% Corresponding coefficients and translates for the scaling function with
% current sample.
[ correspCoeff,...
relevantKs,...
lowerKIndex,...
upperKIndex] = findRelevantCoefficients(sample,...
lowerSupp,...
upperSupp,...
DensityVars.StartLevel,...
scalCoeff,...
DensityVars.ScalTranslates);
% Perform interpolation across each translate and sample.
x = 2^DensityVars.StartLevel*sample - relevantKs;
phiHere = getPhiAt(x);
% Updating relevant coefficients.
% If agingFlag == 2 then updating using the window method is performed.
if (DensityVars.AgingFlag == 2)
% Update corresponding coefficients with addition as default.
updCoeffAdd = correspCoeff + 2^(DensityVars.StartLevel / 2)*(phiHere / DensityVars.WindowSize);
scalCoeff(lowerKIndex:upperKIndex) = updCoeffAdd;
% Check to see if n > windowSize. If n > windowSize then begin
% discounting the sampleBeforeWindow's corresponding
% coefficients.
if (n > DensityVars.WindowSize)
% Corresponding coefficients and translates for the scaling function
% the sampleBeforeWindow.
[corrCoefSampBfWin,...
relKsSampBfWin,...
lowKIndSampBfWin,...
uppKIndSampBfWin] = findRelevantCoefficients(sampBforWindow,...
lowerSupp,...
upperSupp,...
DensityVars.StartLevel,...
scalCoeff,...
DensityVars.ScalTranslates);
% Perform interpolation across each translate and sample for sampleBforWindow.
xSampBfWin = 2^DensityVars.StartLevel*sampBforWindow - relKsSampBfWin;
phiHereSampBfWin = getPhiAt(xSampBfWin);
updCoeffSubtr = corrCoefSampBfWin - 2^(DensityVars.StartLevel / 2)*(phiHereSampBfWin / DensityVars.WindowSize);
scalCoeff(lowKIndSampBfWin : uppKIndSampBfWin) = updCoeffSubtr;
DensityVars.Coefficients{1,1} = scalCoeff;
else
scalCoeff(lowerKIndex : upperKIndex) = updCoeffAdd;
DensityVars.Coefficients{1,1} = scalCoeff;
end % if (n > windowSize)
else
updCoeff = (n / (n + 1))*correspCoeff + (1 / (n + 1))*2^(DensityVars.StartLevel / 2)*phiHere;
allCoeffUpd = (n / (n + 1))*scalCoeff;
allCoeffUpd(lowerKIndex : upperKIndex) = updCoeff;
DensityVars.Coefficients{1,1} = allCoeffUpd;
end % (agingFlag == 2)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% WAVELETS.
if (DensityVars.WaveletFlag == 1)
for j = DensityVars.StartLevel : DensityVars.StopLevel
% Translates for resolution j.
transOfResJ = DensityVars.WaveTranslates{((j - DensityVars.StartLevel) + 1),1};
% Current j coefficients.
coeffIndVal = ((j - DensityVars.StartLevel) + 2) ; % Only wavelet coefficients
currWaveCoeff = DensityVars.Coefficients{coeffIndVal,1};
% Corresponding coefficients and translates for the wavelet function with
% current sample.
[corresCoeffWavCurrSamp,...
relKsWavCurrSamp,...
lowKIndexWavCurrSamp,...
uppKIndexWavCurrSamp] = findRelevantCoefficients(sample,...
lowerSupp,...
upperSupp,...
j,...
currWaveCoeff,...
transOfResJ);
% Perform interpolation with the psi wavelet for the current sample.
xWavCurrSamp = 2^j*sample - relKsWavCurrSamp;
psiHereWavCurrSamp = getPsiAt( xWavCurrSamp );
% If agingFlag == 2 then updating using the window method is performed.
if (DensityVars.AgingFlag == 2)
% Update corresponding wavelet coefficients with addition as default.
updWavCoeffAddCurrSamp = corresCoeffWavCurrSamp + 2^(j / 2)*(psiHereWavCurrSamp / DensityVars.WindowSize);
currWaveCoeff(lowKIndexWavCurrSamp:uppKIndexWavCurrSamp) = updWavCoeffAddCurrSamp;
% Check to see if n > windowSize. If n > windowSize then begin
% discounting the sampleBeforeWindow's corresponding
% coefficients.
if (n > DensityVars.WindowSize)
% Corresponding coefficients and translates for the wavelet function
% the sampleBeforeWindow.
[corrCoefWavSampBfWin,...
relKsWavSampBfWin,...
lowKIndWavSampBfWin,...
uppKIndWavSampBfWin] = findRelevantCoefficients(sampBforWindow,...
lowerSupp,...
upperSupp,...
j,...
currWaveCoeff,...
transOfResJ);
% Perform interpolation across each translate and sample for sampleBforWindow.
xWavSampBfWin = 2^j*sampBforWindow - relKsWavSampBfWin;
psiHereWavSampBfWin = getPsiAt(xWavSampBfWin);
% Subtraction portion for the sample before window.
updWavCoeffSubtr = corrCoefWavSampBfWin - 2^(j / 2)*(psiHereWavSampBfWin / DensityVars.WindowSize);
currWaveCoeff(lowKIndWavSampBfWin:uppKIndWavSampBfWin) = updWavCoeffSubtr;
DensityVars.Coefficients{coeffIndVal,1} = currWaveCoeff;
else
currWaveCoeff(lowKIndexWavCurrSamp : uppKIndexWavCurrSamp) = updWavCoeffAddCurrSamp;
DensityVars.Coefficients{coeffIndVal,1} = currWaveCoeff;
end % if (n > windowSize)
else
% Update the relevant coefficients.
updWaveCoeff = (n / (n + 1))*corresCoeffWavCurrSamp + (1 / (n + 1))*2^(j / 2)*psiHereWavCurrSamp;
currWaveCoeff = (n / (n + 1))*currWaveCoeff;
currWaveCoeff(lowKIndexWavCurrSamp : uppKIndexWavCurrSamp) = updWaveCoeff;
DensityVars.Coefficients{coeffIndVal,1} = currWaveCoeff;
end % if (agingFlag == 2)
end % for j = startLevel : stopLevel
end % if (waveletFlag == 1)
end % estimateCoefficients()