From 85d16f81a93bdde2287e39dc61df9dc6ddb108a5 Mon Sep 17 00:00:00 2001 From: Niru Maheswaranathan Date: Mon, 7 Sep 2015 02:20:54 -0500 Subject: [PATCH] Adds soft rectification function --- jetpack/signals.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/jetpack/signals.py b/jetpack/signals.py index 65124b8..1a9298c 100644 --- a/jetpack/signals.py +++ b/jetpack/signals.py @@ -10,7 +10,7 @@ import numpy as np from scipy.ndimage.filters import gaussian_filter1d -__all__ = ['peakdet', 'smooth', 'norms', 'sfthr', 'sq', 'arr'] +__all__ = ['peakdet', 'smooth', 'norms', 'sfthr', 'sfrct', 'sq', 'arr'] def peakdet(v, delta, x=None): @@ -182,6 +182,30 @@ def sfthr(x, threshold): return np.sign(x) * np.maximum(np.abs(x) - threshold, 0) +def sfrct(x, threshold): + """ + Soft rectification function + + y = log(1 + exp(x - threshold)) + + Parameters + ---------- + x : array_like + The input array to the soft thresholding function + + threshold : float + The threshold of the function + + Returns + ------- + y : array_like + The output of the soft thresholding function + + """ + + return np.log1p(np.exp(x - threshold)) + + def sq(x): """ Reshape vector to a square image