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
use crate::{prelude::Signal, signal::PointwiseMapSgn, Map};
#[derive(Clone, Copy, Debug, Default)]
pub struct InfClip;
impl Map<f64, f64> for InfClip {
fn eval(&self, x: f64) -> f64 {
x.signum()
}
}
pub type InfClipping<S> = PointwiseMapSgn<S, InfClip>;
impl<S: Signal> InfClipping<S> {
pub fn new(sgn: S) -> Self {
Self::new_pointwise(sgn, InfClip)
}
}
#[derive(Clone, Copy, Debug)]
pub struct Clip {
pub threshold: f64,
}
impl Clip {
pub fn new(threshold: f64) -> Self {
Self { threshold }
}
}
impl Default for Clip {
fn default() -> Self {
Self::new(1.0)
}
}
impl Map<f64, f64> for Clip {
fn eval(&self, x: f64) -> f64 {
x.clamp(-self.threshold, self.threshold) / self.threshold
}
}
pub type Clipping<S> = PointwiseMapSgn<S, Clip>;
impl<S: Signal> Clipping<S> {
pub fn new(sgn: S, threshold: f64) -> Self {
Self::new_pointwise(sgn, Clip::new(threshold))
}
}
#[derive(Clone, Copy, Debug)]
pub struct Atan {
pub shape: f64,
}
impl Atan {
pub fn new(shape: f64) -> Self {
Self { shape }
}
}
impl Default for Atan {
fn default() -> Self {
Self::new(1.0)
}
}
impl Map<f64, f64> for Atan {
fn eval(&self, x: f64) -> f64 {
(self.shape * x).atan() / std::f64::consts::FRAC_PI_2
}
}
pub type Arctangent<S> = PointwiseMapSgn<S, Atan>;
impl<S: Signal> Arctangent<S> {
pub fn new(sgn: S, shape: f64) -> Self {
Self::new_pointwise(sgn, Atan::new(shape))
}
}