-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"level" parameter in waveletSmooth function #9
Comments
@danizil the waveletSmooth function in the subrepos/models/wavelet directory is from DeepLearning_Financial, a previous attempt to replicate the results of the paper: (https://github.com/mlpanda/DeepLearning_Financial) I am currently using a modified implementation of that formula, seen here: |
level is 2 as defined in the original paper; as for the axis, I am still looking into how that specific step is tied to the next level of the model (the stacked autoencoder stage). I am fairly confident that my implementation is on the right track axis wise, but I am not infallible. I do recall the feature set being seemingly incorrectly oriented when using Related/relevant: |
Hi @timothyyu
def waveletSmooth(x, wavelet="db4", level=1, DecLvl=2):
# calculate the wavelet coefficients
# danny: coeffs is (DecLvl + 1) arrays: one approximation coefficients (cA) array (lowest frequencies)
# and then DecLvl number of detail coefficients (cD)
coeffs = pywt.wavedec(x.T, wavelet, mode="per", level=DecLvl)
# calculate a threshold
# danny: mad is median deviation (not standard deviation)
sigma = mad(coeffs[-level]) #danny: should be shape 2X19. this is the original but i turned it off
#danny: option 2 - scale each cD by its own median
# sigma = np.array([mad(i) for i in coeffs[1:]])
# changing this threshold also changes the behavior,
# but I have not played with this very much
# danny: uthresh is universal threshold - a formula appearing in articles (haven't gone into it)
uthresh = sigma * np.sqrt(2 * np.log(len(x)))
# danny: we take [1:] because these are the detail coefficients and we denoise them
coeffs[1:] = (pywt.threshold(coeffs[1:][i], value=uthresh[i], mode="soft") for i in range(len(coeffs[1:])))
# reconstruct the signal using the thresholded coefficients
y = pywt.waverec(coeffs, wavelet, mode="per")
return y``` |
related closed issue (duplicate): |
@danizil make sure the wavelet type in your code is I am still looking into/examining the level median application/decomposition (#1) + the axis orientation (#2); one of main issues I'm running into is that the authors of the model were not very specific when it comes to particular aspects of the implementation of their model (see #6 and #7 for relevant discussion regarding that). Basically beyond a certain point, the highest academic judgement/practice should be used to fill in the gaps in the implementation of the model + correction of errors. |
Axis decomposition check started; see 707dfb5: |
will have to double check but i believe i was correct initially with
The authors of the original paper were not explicitly clear or detailed for this aspect of the model - will also have to take a closer look at/reevaluate the autoencoder stage in how it is supposed to work on the transformed data (19X DecLvl+1) before LSTM input |
Hi Timothy.
In reviewing your code I ran into issues using the waveletSmooth function (in the directory subrepos/models/wavelet). I think it might be the difference in our pywt versions, but the function was doing the wavelet decomposition along the features axis and not separately for each feature along its time series.
After fixing it, I noticed that the "level" parameter was only in charge of thresholding
the detail coefficients using the "level" detail coefficient's median.
I'm hardly a wavelet expert, and have learned it only now for this algorithm, but I changed your code to threshold coefficients according to their level's median, because that was done in all denoising sources I have seen.
Could you explain your consideration in choosing one level for all cD thresholding?
cheers!
Danny
The text was updated successfully, but these errors were encountered: