The algorithm smooths functions preserving local peaks. To distinguish peaks from noise it needs noise standard deviation
Project description
Confidence Based Smoothing
The algorithm smooths functions preserving local peaks. To distinguish peaks from noise it needs noise standard deviation.
Installation
pip install --upgrade confsmooth
Usage
import os, shutil, statsmodels
import matplotlib.pyplot as plt
import numpy as np
from statsmodels.nonparametric.kernel_regression import KernelReg
from confsmooth import confsmooth
from scipy.signal import savgol_filter
x = np.linspace(-2,2,500)
real_noise_level = 0.002
y = 1 - np.power(np.abs(x)+0.01,0.01) + np.random.normal(0, real_noise_level, len(x))
# estimate noise standard deviation
savgol = savgol_filter(y,21,1)
noise_level = np.std(y - savgol)
print('Estimated noise level =', noise_level, 'Real noise level =', real_noise_level)
smoothed_conf = confsmooth(y, noise_level, confidence=0.995, deg=2)
kr = KernelReg(endog=y, exog=x, var_type='c', bw=[0.1])
smoothed_kr, _ = kr.fit(x)
fig,ax = plt.subplots()
ax.plot(x, y, label='initial')
ax.plot(x, savgol, label='savgol')
ax.plot(x, smoothed_kr, label='Kernel regr')
ax.plot(x, smoothed_conf, label='confsmooth')
ax.legend()
plt.show()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file confsmooth-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: confsmooth-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01c15ee4a5834f9a7e7dbcf42a46ac84381c0cef5f79a05e9c5ea24469d3adba |
|
MD5 | b30ea6a628f97d1746cbb70ffc97f20e |
|
BLAKE2b-256 | 0f447d24523e1fd39c64cbf385182c79d57451743e975d00003d9306cfeb8f5b |