@@ -28,10 +28,10 @@ class RBFSampler(BaseEstimator, TransformerMixin):
28
28
Parameters
29
29
----------
30
30
gamma: float
31
- parameter of RBF kernel: exp(-gamma * x**2 )
31
+ Parameter of RBF kernel: exp(-γ × x² )
32
32
33
33
n_components: int
34
- number of Monte Carlo samples per original feature.
34
+ Number of Monte Carlo samples per original feature.
35
35
Equals the dimensionality of the computed feature space.
36
36
37
37
random_state : {int, RandomState}, optional
@@ -44,7 +44,7 @@ class RBFSampler(BaseEstimator, TransformerMixin):
44
44
Benjamin Recht.
45
45
"""
46
46
47
- def __init__ (self , gamma = 1. , n_components = 100. , random_state = None ):
47
+ def __init__ (self , gamma = 1. , n_components = 100 , random_state = None ):
48
48
self .gamma = gamma
49
49
self .n_components = n_components
50
50
self .random_state = random_state
@@ -94,8 +94,10 @@ def transform(self, X, y=None):
94
94
"""
95
95
X = atleast2d_or_csr (X )
96
96
projection = safe_sparse_dot (X , self .random_weights_ )
97
- return (np .sqrt (2. ) / np .sqrt (self .n_components )
98
- * np .cos (projection + self .random_offset_ ))
97
+ projection += self .random_offset_
98
+ np .cos (projection , projection )
99
+ projection *= np .sqrt (2. ) / np .sqrt (self .n_components )
100
+ return projection
99
101
100
102
101
103
class SkewedChi2Sampler (BaseEstimator , TransformerMixin ):
@@ -176,15 +178,17 @@ def transform(self, X, y=None):
176
178
-------
177
179
X_new: array-like, shape (n_samples, n_components)
178
180
"""
179
- X = array2d (X )
181
+ X = array2d (X , copy = True )
180
182
if (X < 0 ).any ():
181
183
raise ValueError ("X may not contain entries smaller than zero." )
182
184
183
- projection = safe_sparse_dot (np .log (X + self .skewedness ),
184
- self .random_weights_ )
185
-
186
- return (np .sqrt (2. ) / np .sqrt (self .n_components )
187
- * np .cos (projection + self .random_offset_ ))
185
+ X += self .skewedness
186
+ np .log (X , X )
187
+ projection = safe_sparse_dot (X , self .random_weights_ )
188
+ projection += self .random_offset_
189
+ np .cos (projection , projection )
190
+ projection *= np .sqrt (2. ) / np .sqrt (self .n_components )
191
+ return projection
188
192
189
193
190
194
class AdditiveChi2Sampler (BaseEstimator , TransformerMixin ):
0 commit comments