@@ -16,15 +16,15 @@ def _linear_superposition(alphas, vecs, shape):
16
16
Parameters
17
17
----------
18
18
alphas
19
- Coefficients of the superposition
19
+ Coefficients of the superposition.
20
20
vecs
21
- Tensors of the superposition
21
+ Tensors of the superposition.
22
22
shape
23
- Shape of each tensor
23
+ Shape of each tensor.
24
24
25
25
Returns
26
26
-------
27
- Linear tensor superposition
27
+ Linear tensor superposition.
28
28
"""
29
29
input_str = string .ascii_lowercase [2 : 2 + len (shape )]
30
30
einstr = 'a,ba{}->b{}' .format (input_str , input_str )
@@ -39,19 +39,19 @@ def _calculate_global_linearity(predict_fn: Callable, input_shape: Tuple, X_samp
39
39
Parameters
40
40
----------
41
41
predict_fn
42
- Model prediction function
42
+ Model prediction function.
43
43
input_shape
44
- Shape of the input
44
+ Shape of the input.
45
45
X_samples
46
- Array of feature vectors in the linear superposition
46
+ Array of feature vectors in the linear superposition.
47
47
model_type
48
- 'classifier' or 'regressor'
48
+ Supported values: `` 'classifier'`` | `` 'regressor'``.
49
49
alphas
50
- Array of coefficients in the linear superposition
50
+ Array of coefficients in the linear superposition.
51
51
52
52
Returns
53
53
-------
54
- Linearity score
54
+ Linearity score.
55
55
56
56
"""
57
57
ss = X_samples .shape [:2 ] # X_samples shape=(nb_instances, nb_samples, nb_features)
@@ -105,27 +105,27 @@ def _calculate_global_linearity(predict_fn: Callable, input_shape: Tuple, X_samp
105
105
106
106
def _calculate_pairwise_linearity (predict_fn : Callable , x : np .ndarray , input_shape : Tuple , X_samples : np .ndarray ,
107
107
model_type : str , alphas : np .ndarray ) -> np .ndarray :
108
- """Calculates the norm of the difference between the output of a linear superposition of a test vector x and
109
- vectors in X_samples and the linear superposition of the outputs, averaged over all the vectors in X_samples.
108
+ """Calculates the norm of the difference between the output of a linear superposition of a test vector `x` and
109
+ vectors in ` X_samples` and the linear superposition of the outputs, averaged over all the vectors in ` X_samples` .
110
110
111
111
Parameters
112
112
----------
113
113
predict_fn
114
- Model prediction function
114
+ Model prediction function.
115
115
x
116
- Test instance for which to calculate the linearity measure
116
+ Test instance for which to calculate the linearity measure.
117
117
input_shape
118
- Shape of the input
118
+ Shape of the input.
119
119
X_samples
120
- Array of feature vectors in the linear superposition
120
+ Array of feature vectors in the linear superposition.
121
121
model_type
122
- 'classifier' or 'regressor'
122
+ Supported values: `` 'classifier'`` | `` 'regressor'``.
123
123
alphas
124
- Array of coefficients in the linear superposition
124
+ Array of coefficients in the linear superposition.
125
125
126
126
Returns
127
127
-------
128
- Linearity score
128
+ Linearity score.
129
129
130
130
"""
131
131
ss = X_samples .shape [:2 ] # X_samples shape=(nb_instances, nb_samples, nb_features)
@@ -190,15 +190,15 @@ def _sample_knn(x: np.ndarray, X_train: np.ndarray, nb_samples: int = 10) -> np.
190
190
Parameters
191
191
----------
192
192
x
193
- Central instance for sampling
193
+ Central instance for sampling.
194
194
X_train
195
195
Training set.
196
196
nb_samples
197
197
Number of samples to generate.
198
198
199
199
Returns
200
200
-------
201
- Sampled vectors
201
+ Sampled vectors.
202
202
203
203
"""
204
204
x = x .reshape (x .shape [0 ], - 1 )
@@ -221,23 +221,23 @@ def _sample_knn(x: np.ndarray, X_train: np.ndarray, nb_samples: int = 10) -> np.
221
221
222
222
def _sample_grid (x : np .ndarray , feature_range : np .ndarray , epsilon : float = 0.04 ,
223
223
nb_samples : int = 10 , res : int = 100 ) -> np .ndarray :
224
- """Samples data points uniformly from an interval centered at x and with size epsilon * Delta ,
225
- with delta = f_max - f_min the features ranges.
224
+ """Samples data points uniformly from an interval centered at `x` and with size ` epsilon * delta` ,
225
+ with ` delta = f_max - f_min` the features ranges.
226
226
227
227
Parameters
228
228
----------
229
229
x
230
230
Instance of interest.
231
231
feature_range
232
- Array with min and max values for each feature
232
+ Array with min and max values for each feature.
233
233
epsilon
234
234
Size of the sampling region around central instance as percentage of features range.
235
235
nb_samples
236
236
Number of samples to generate.
237
237
238
238
Returns
239
239
-------
240
- Sampled vectors
240
+ Sampled vectors.
241
241
242
242
"""
243
243
nb_instances = x .shape [0 ]
@@ -271,7 +271,7 @@ def _linearity_measure(predict_fn: Callable,
271
271
alphas : Optional [np .ndarray ] = None ,
272
272
model_type : str = 'classifier' ,
273
273
agg : str = 'global' ) -> np .ndarray :
274
- """Calculate the linearity measure of the model around an instance of interest x .
274
+ """Calculate the linearity measure of the model around an instance of interest `x` .
275
275
276
276
Parameters
277
277
----------
@@ -284,7 +284,7 @@ def _linearity_measure(predict_fn: Callable,
284
284
feature_range
285
285
Array with min and max values for each feature.
286
286
method
287
- Method for sampling. Supported values 'knn' or 'grid'.
287
+ Method for sampling. Supported values: `` 'knn'`` | `` 'grid'`` .
288
288
epsilon
289
289
Size of the sampling region around the central instance as a percentage of feature range.
290
290
nb_samples
@@ -294,13 +294,13 @@ def _linearity_measure(predict_fn: Callable,
294
294
alphas
295
295
Array of coefficients in the superposition.
296
296
model_type
297
- Type of task. Supported values are 'regressor' or 'classifier'.
297
+ Type of task. Supported values: `` 'regressor'`` | `` 'classifier'`` .
298
298
agg
299
- Aggregation method. Supported values are 'global' or 'pairwise'.
299
+ Aggregation method. Supported values: `` 'global'`` | `` 'pairwise'`` .
300
300
301
301
Returns
302
302
-------
303
- Linearity score
303
+ Linearity score.
304
304
305
305
"""
306
306
input_shape = x .shape [1 :]
@@ -339,11 +339,11 @@ def _infer_feature_range(X_train: np.ndarray) -> np.ndarray:
339
339
Parameters
340
340
----------
341
341
X_train
342
- Training set
342
+ Training set.
343
343
344
344
Returns
345
345
-------
346
- Feature range
346
+ Feature range.
347
347
"""
348
348
X_train = X_train .reshape (X_train .shape [0 ], - 1 )
349
349
return np .vstack ((X_train .min (axis = 0 ), X_train .max (axis = 0 ))).T
@@ -365,7 +365,7 @@ def __init__(self,
365
365
Parameters
366
366
----------
367
367
method
368
- Method for sampling. Supported methods are 'knn' or 'grid'.
368
+ Method for sampling. Supported methods: `` 'knn'`` | `` 'grid'`` .
369
369
epsilon
370
370
Size of the sampling region around the central instance as a percentage of the features range.
371
371
nb_samples
@@ -375,9 +375,9 @@ def __init__(self,
375
375
alphas
376
376
Coefficients in the superposition.
377
377
agg
378
- Aggregation method. Supported values are 'global' or 'pairwise'.
378
+ Aggregation method. Supported values: `` 'global'`` | `` 'pairwise'`` .
379
379
model_type
380
- Type of task. Supported values are 'regressor' or 'classifier'.
380
+ Type of task. Supported values: `` 'regressor'`` | `` 'classifier'`` .
381
381
"""
382
382
self .method = method
383
383
self .epsilon = epsilon
@@ -395,11 +395,8 @@ def fit(self, X_train: np.ndarray) -> None:
395
395
Parameters
396
396
----------
397
397
X_train
398
- Training set
398
+ Training set.
399
399
400
- Returns
401
- -------
402
- None
403
400
"""
404
401
self .X_train = X_train
405
402
self .feature_range = _infer_feature_range (X_train )
@@ -412,13 +409,13 @@ def score(self, predict_fn: Callable, x: np.ndarray) -> np.ndarray:
412
409
Parameters
413
410
----------
414
411
predict_fn
415
- Prediction function
412
+ Prediction function.
416
413
x
417
- Instance of interest
414
+ Instance of interest.
418
415
419
416
Returns
420
417
-------
421
- Linearity measure
418
+ Linearity measure.
422
419
423
420
"""
424
421
input_shape = x .shape [1 :]
@@ -466,7 +463,7 @@ def linearity_measure(predict_fn: Callable,
466
463
feature_range
467
464
Array with min and max values for each feature.
468
465
method
469
- Method for sampling. Supported values 'knn' or 'grid'.
466
+ Method for sampling. Supported values: `` 'knn'`` | `` 'grid'`` .
470
467
X_train
471
468
Training set.
472
469
epsilon
@@ -478,13 +475,13 @@ def linearity_measure(predict_fn: Callable,
478
475
alphas
479
476
Coefficients in the superposition.
480
477
agg
481
- Aggregation method. Supported values 'global' or 'pairwise'.
478
+ Aggregation method. Supported values: `` 'global'`` | `` 'pairwise'`` .
482
479
model_type
483
- Type of task. Supported values 'regressor' or 'classifier'.
480
+ Type of task. Supported values: `` 'regressor'`` | `` 'classifier'`` .
484
481
485
482
Returns
486
483
-------
487
- Linearity measure
484
+ Linearity measure.
488
485
489
486
"""
490
487
if method == 'knn' :
0 commit comments