Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/netml/ndm/ae.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, epochs=100, batch_size=32, lr=1e-3,
loss='mse',
dropout_rate=0.2,
l2_regularizer=0.1, validation_size=0.1,
verbose=1, random_state=42, contamination=0.1, hid_dim=16, lat_dim=8):
verbose=1, contamination=0.1, hid_dim=16, lat_dim=8, **kwargs):
"""AutoEncoder

Parameters
Expand Down Expand Up @@ -109,9 +109,7 @@ def __init__(self, epochs=100, batch_size=32, lr=1e-3,
verbose: int (default is 1)
A print level is to control what information should be printed according to the given value.
The higher the value is, the more info is printed.

random_state: int (default is 42)


"""
self.epochs = epochs
self.batch_size = batch_size
Expand All @@ -120,14 +118,18 @@ def __init__(self, epochs=100, batch_size=32, lr=1e-3,
self.l2_regularizer = l2_regularizer
self.validation_size = validation_size
self.verbose = verbose
self.random_state = random_state
self.lr = lr
self.contamination = contamination
self.hid_dim = hid_dim
self.lat_dim = lat_dim

check_parameter(dropout_rate, 0, 1, param_name='dropout_rate', include_left=True)

if "random_state" in kwargs and verbose > 5:
print(
"Warning: 'random_state' passed to AutoEncoder. Use torch.manual_seed() instead."
)

if self.loss == 'mse' or (not self.loss):
self.criterion = nn.MSELoss()

Expand Down
2 changes: 2 additions & 0 deletions src/netml/ndm/gmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ def __init__(self, n_components=1, covariance_type='full', tol=1e-3,
contamination: float (default is 0.1)
It's in range (0,1). A threshold used to decide the normal score (not used).

random_state: int (default is 42)

"""
self.n_components = n_components
self.covariance_type = covariance_type
Expand Down
8 changes: 6 additions & 2 deletions src/netml/ndm/kde.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class KDE(KernelDensity, BaseDetector):

def __init__(self, bandwidth=1.0, algorithm='auto',
kernel='gaussian', metric="euclidean", atol=0, rtol=0, contamination=0.1,
breadth_first=True, leaf_size=40, metric_params=None, random_state=42):
breadth_first=True, leaf_size=40, metric_params=None, verbose=0, **kwargs):
"""Kernel density estimation (KDE)
Parameters
----------
Expand Down Expand Up @@ -63,7 +63,11 @@ def __init__(self, bandwidth=1.0, algorithm='auto',
self.leaf_size = leaf_size
self.metric_params = metric_params
self.contamination = contamination
self.random_state = random_state

if "random_state" in kwargs and verbose > 5:
print(
"Warning: argument 'random_state' passed to KDE has no effect."
)

# run the choose algorithm code so that exceptions will happen here
# we're using clone() in the GenerativeBayes classifier,
Expand Down
11 changes: 6 additions & 5 deletions src/netml/ndm/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class MODEL:

def __init__(self, model=None, *, score_metric='auc', verbose=1, random_state=42):
def __init__(self, model=None, *, score_metric='auc', verbose=1, **kwargs):
"""Train and test a model on a given data.

Parameters
Expand All @@ -28,9 +28,6 @@ def __init__(self, model=None, *, score_metric='auc', verbose=1, random_state=42
a print level is to control what information should be printed according to the given value.
The higher the value is, the more info is printed.

random_state: int
a value is to make your experiments more reproducible.

Returns
-------
a MODEL instance
Expand All @@ -40,10 +37,14 @@ def __init__(self, model=None, *, score_metric='auc', verbose=1, random_state=42
self.model_name = model.name
self.score_metric = score_metric
self.verbose = verbose
self.random_state = random_state
# store all data generated during training and testing the model.
self.history = {}

if "random_state" in kwargs:
self.random_state = kwargs["random_state"]
if verbose > 5:
print("Warning: setting random_state for a model wrapper doesn't affect the underlying predictions.")

@timing
def _train(self, X_train, y_train=None):
"""fit the model on the train set
Expand Down
10 changes: 6 additions & 4 deletions src/netml/ndm/ocsvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OCSVM(OneClassSVM):

def __init__(self, kernel='rbf', degree=3, gamma='scale',
coef0=0.0, tol=1e-3, nu=0.5, shrinking=True, cache_size=200,
verbose=False, max_iter=-1, random_state=100):
verbose=False, max_iter=-1, **kwargs):
"""One Class SVM (OCSVM)

Parameters
Expand Down Expand Up @@ -49,10 +49,13 @@ def __init__(self, kernel='rbf', degree=3, gamma='scale',

verbose: bool (default is False)
Enable verbose output.
"""

random_state: int (default is 42)
if "random_state" in kwargs and verbose > 5:
print(
"Warning: argument 'random_state' passed to OCSVM has no effect."
)

"""
super(OCSVM, self).__init__(
kernel=kernel,
degree=degree,
Expand All @@ -66,7 +69,6 @@ def __init__(self, kernel='rbf', degree=3, gamma='scale',
max_iter=max_iter,
)

self.random_state = random_state
self.verbose = verbose

# override decision_function. because test and grid_search will use decision_function first
Expand Down
7 changes: 4 additions & 3 deletions src/netml/ndm/pca.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class PCA(BaseDetector):

def __init__(self, n_components=None, n_selected_components=None,
contamination=0.1, copy=True, whiten=False, svd_solver='auto',
tol=0.0, iterated_power='auto', random_state=None,
weighted=True, standardization=True):
tol=0.0, iterated_power='auto', random_state=42,
weighted=True, standardization=True, verbose=0):
"""Principal component analysis (PCA)

Parameters
Expand Down Expand Up @@ -48,7 +48,7 @@ def __init__(self, n_components=None, n_selected_components=None,
Number of iterations for the power method computed by
svd_solver == 'randomized'.

random_state : int
random_state: int (default is 42)

weighted : bool, optional (default=True)
If True, the eigenvalues are used in score computation.
Expand All @@ -70,6 +70,7 @@ def __init__(self, n_components=None, n_selected_components=None,
self.weighted = weighted
self.standardization = standardization
self.score_name = "reconstructed" # the way to obtain outlier scores
self.verbose = verbose

self.contamination = contamination

Expand Down