Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/francescoalemanno/kisssmoothing.jl
Easily smooth your data in Julia
https://github.com/francescoalemanno/kisssmoothing.jl
filtering interpolation julia kernel-smoothing rbf-network smoothing
Last synced: about 2 months ago
JSON representation
Easily smooth your data in Julia
- Host: GitHub
- URL: https://github.com/francescoalemanno/kisssmoothing.jl
- Owner: francescoalemanno
- License: other
- Created: 2022-03-16T16:42:32.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-05T20:25:59.000Z (over 1 year ago)
- Last Synced: 2024-08-09T07:54:15.243Z (5 months ago)
- Topics: filtering, interpolation, julia, kernel-smoothing, rbf-network, smoothing
- Language: Julia
- Homepage:
- Size: 679 KB
- Stars: 23
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# KissSmoothing.jl
This package implements a denoising procedure, a Radial Basis Function estimation procedure and a Natural Cubic Splines estimation procedure.## Denoising
denoise(V::Array; factor=1.0, rtol=1e-12, dims=ndims(V), verbose = false)
smooth data in `V` according to:
`V` : data to smooth
`factor` : smoothing intensity
`rtol` : relative tolerance on how precise the smoothing intensity is determined
`dims` : array dimension being smoothed
`verbose` : enables some printing of internal info
returns a tuple (S,N) where:
`S` : is the smoothed data
`N` : is the extracted noise
in particular `S + N` reconstructs the original data `V`.
### Example
```julia
begin
using KissSmoothing, Statistics, LinearAlgebra
using PyPlot
figure(figsize=(5,4))
for (i,s) in enumerate(2 .^ LinRange(-1.5,1.5,4))
# generating a simple sinusoidal signal
X = LinRange(0, pi, 1000)
Y = sin.(X.^2)
# generate it's noise corrupted version
TN = std(Y).*randn(length(X))./7 .*s
raw_S = Y .+ TN
# using this package function to extract signal S and noise N
S, N = denoise(raw_S)
subplot(2, 2, i)
plot(X,raw_S, color="gray",lw=0.8, label="Y noisy")
plot(X,Y,color="red",label="Y true")
plot(X,S,color="blue", ls ="dashed",label="Y smoothed")
xlabel("X")
ylabel("Y")
i==1 && legend()
end
tight_layout()
savefig("test.png")
end
```
![test.png](test.png "Plot of 1D signal smoothing")### Multidimensional example
```julia
using KissSmoothing, Statistics, LinearAlgebra
using PyPlot
figure(figsize=(5,4))
for (i,s) in enumerate(2 .^ LinRange(-1.5,1.5,4))
# generating a simple circle dataset
X = LinRange(0,10pi,1000)
Y = sin.(X) .+ randn(length(X))./7 .*s
Z = cos.(X) .+ randn(length(X))./7 .*s
M = [Y Z]
O = [sin.(X) cos.(X)]
# using this package function to extract signal S and noise N
S, N = denoise(M, dims=1)subplot(2,2,i)
scatter(M[:,1],M[:,2], color="gray",s=2,label="noisy")
plot(S[:,1],S[:,2], color="red",lw=1.5,label="smoothed")
plot(O[:,1],O[:,2], color="blue",lw=1.0,label="true")
i==1 && legend()
xlabel("X")
ylabel("Y")
end
tight_layout()
savefig("test_multi.png")
```
![test_multi.png](test_multi.png "Plot of multidim smoothing")## RBF Estimation
fit_rbf(xv::Array, yv::Array, cp::Array)
fit thin-plate radial basis function according to:
`xv` : array NxP, N number of training points, P number of input variables
`yv` : array NxQ, N number of training points, Q number of output variables
`cp` : array KxP, K number of control points, P number of input variables
returns a callable RBF object.
### Example
```julia
using PyPlot, KissSmoothing
t = LinRange(0,2pi,1000)
ty = sin.(t)
y = ty .+ randn(length(t)) .*0.05
fn = fit_rbf(t,y,LinRange(0,2pi,20))
scatter(t, y, color="gray",s=2,label="noisy")
plot(t, fn(t), color="red",lw=1.5,label="rbf estimate")
plot(t,ty, color="blue",lw=1.0,label="true")
xlabel("X")
ylabel("Y")
legend()
tight_layout()
savefig("rbf.png")
```
![rbf.png](rbf.png "Plot of rbf estimation")## NSplines Estimation
fit_nspline(xv::Vector, yv::Vector, cp::Vector)
fit natural cubic splines basis function according to:
`xv` : array N, N number of training points
`yv` : array N, N number of training points
`cp` : array K, K number of control points
returns a callable function.
### Example
```julia
using PyPlot, KissSmoothing
t = LinRange(0,pi,1000)
ty = sin.(t.^2)
y = ty .+ randn(length(t)) .*0.05
fn = fit_nspline(t,y,LinRange(0,2pi,20))
scatter(t, y, color="gray",s=2,label="noisy")
plot(t, fn.(t), color="red",lw=1.5,label="nspline estimate")
plot(t,ty, color="blue",lw=1.0,label="true")
xlabel("X")
ylabel("Y")
legend()
tight_layout()
savefig("nspline.png")
```
![nspline.png](nspline.png "Plot of NSpline estimation")## Sine Series Estimation
fit_sine_series(X::Vector,Y::Vector, basis_elements::Integer; lambda = 0.0, order=3)
fit Y ~ 1 + X + Σ sin(.) by minimising Σ (Y - f(x))^2 + lambda * ∫(Δ^order F)^2
`X` : array N, N number of training points.
`Y` : array N, N number of training points.
`basis_elements` : number of sine terms.
Keyword arguments:
`lambda` : intensity of regularization.
`order` : derivative to regularise.returns a callable function.
### Example
```julia
using PyPlot, KissSmoothing
fg(x) = sin(x^2) + x
x = collect(LinRange(0,pi,250))
xc = identity.(x)
filter!(x->(x-1)^2>0.1, x)
filter!(x->(x-2)^2>0.1, x)
y = fg.(x) .+ randn(length(x)) .*0.05
fn = fit_sine_seris(x,y,20, lambda = 0.00001)
scatter(x, y, color="gray",s=2,label="noisy")
plot(xc, fn.(xc), color="red",lw=1.,label="fit")
plot(xc,fg.(xc), color="blue",lw=0.7,label="true")
xlabel("X")
ylabel("Y")
legend()
tight_layout()
savefig("sine_fit.png")
```
![sine_fit.png](sine_fit.png "Plot of FFT Spline estimation")## Least Squares Denoising
lsq_denoise(S::AbstractVector{<:Real}; order::Integer=3, strength::Real = NaN)
denoise a sequence S by penalising its order-th finite differences in a least squares regression
`S` : sequence.
Keyword arguments:
`order` : finite differencing order.
`strength` : intensity of penalisation on the derivative, if unspecified it is auto-determined.return the filtered sequence.
### Example
```julia
using PyPlot, KissSmoothing
fg(x) = sin(x^2) + x
x = collect(LinRange(0,pi,150))
y = fg.(x) .+ randn(length(x)) .*0.1
plot(y, color="red",lw=1.,label="noisy seq")
plot(lsq_denoise(y,order=2), color="blue",lw=1.,label="filtered")
xlabel("X")
ylabel("Y")
legend()
tight_layout()
savefig("lsq_denoise.png")
```
![lsq_denoise.png](lsq_denoise.png "Plot of LSQ Denoising")