repo
stringlengths
2
99
file
stringlengths
13
225
code
stringlengths
0
18.3M
file_length
int64
0
18.3M
avg_line_length
float64
0
1.36M
max_line_length
int64
0
4.26M
extension_type
stringclasses
1 value
alibi-detect
alibi-detect-master/alibi_detect/models/tensorflow/tests/test_gmm_tf.py
import numpy as np from alibi_detect.models.tensorflow.gmm import gmm_energy, gmm_params N, K, D = 10, 5, 1 z = np.random.rand(N, D).astype(np.float32) gamma = np.random.rand(N, K).astype(np.float32) def test_gmm_params_energy(): phi, mu, cov, L, log_det_cov = gmm_params(z, gamma) assert phi.numpy().shape[0]...
893
37.869565
91
py
alibi-detect
alibi-detect-master/alibi_detect/models/tensorflow/tests/test_autoencoder_tf.py
import numpy as np import pytest import tensorflow as tf from tensorflow.keras.layers import Dense, InputLayer from alibi_detect.models.tensorflow.autoencoder import AE, AEGMM, VAE, VAEGMM, Seq2Seq, EncoderLSTM, DecoderLSTM from alibi_detect.models.tensorflow.losses import loss_aegmm, loss_vaegmm from alibi_detect.mode...
4,397
31.338235
112
py
alibi-detect
alibi-detect-master/alibi_detect/models/tensorflow/tests/test_losses_tf.py
import pytest import numpy as np import tensorflow as tf from alibi_detect.models.tensorflow.losses import elbo, loss_adv_ae, loss_aegmm, loss_vaegmm, loss_distillation N, K, D, F = 10, 5, 1, 3 x = np.random.rand(N, F).astype(np.float32) y = np.random.rand(N, F).astype(np.float32) sim = 1. cov_diag = tf.ones(x.shape[1...
2,563
34.123288
111
py
alibi-detect
alibi-detect-master/alibi_detect/models/tensorflow/tests/test_trainer_tf.py
from functools import partial from itertools import product import numpy as np import pytest import tensorflow as tf from tensorflow.keras.losses import categorical_crossentropy from alibi_detect.models.tensorflow.trainer import trainer from alibi_detect.utils.tensorflow.data import TFDataset N, F = 100, 2 x = np.rand...
1,795
34.215686
95
py
alibi-detect
alibi-detect-master/alibi_detect/saving/loading.py
import logging import os from functools import partial from importlib import import_module from pathlib import Path from typing import Any, Callable, Optional, Union, Type, TYPE_CHECKING import dill import numpy as np import toml from transformers import AutoTokenizer from alibi_detect.saving.registry import registry...
18,954
31.624785
120
py
alibi-detect
alibi-detect-master/alibi_detect/saving/schemas.py
""" Pydantic models used by :func:`~alibi_detect.utils.validate.validate_config` to validate configuration dictionaries. The `resolved` kwarg of :func:`~alibi_detect.utils.validate.validate_config` determines whether the *unresolved* or *resolved* pydantic models are used: - The *unresolved* models expect any artefact...
52,612
39.193277
120
py
alibi-detect
alibi-detect-master/alibi_detect/saving/validators.py
import sys from typing import Any, Generic, Optional, Type, TypeVar, Union, List import numpy as np from numpy.lib import NumpyVersion from pydantic.fields import ModelField from alibi_detect.utils.frameworks import has_tensorflow, has_pytorch, has_keops, Framework if has_tensorflow: import tensorflow as tf if ha...
3,113
35.635294
118
py
alibi-detect
alibi-detect-master/alibi_detect/saving/registry.py
""" This registry allows Python objects to be registered and accessed by their string reference later on. The primary usage is to register objects so that they can be specified in a `config.toml` file. A number of Alibi Detect functions are also pre-registered in the registry for convenience. See the `Registering artef...
3,373
41.708861
144
py
alibi-detect
alibi-detect-master/alibi_detect/saving/validate.py
import warnings from alibi_detect.saving.schemas import ( DETECTOR_CONFIGS, DETECTOR_CONFIGS_RESOLVED) from alibi_detect.version import __version__ def validate_config(cfg: dict, resolved: bool = False) -> dict: """ Validates a detector config dict by passing the dict to the detector's pydantic model sch...
2,144
36.631579
114
py
alibi-detect
alibi-detect-master/alibi_detect/saving/saving.py
import logging import os import shutil import warnings from functools import partial from pathlib import Path from typing import Callable, Optional, Tuple, Union, Any, Dict, TYPE_CHECKING import dill import numpy as np import toml from transformers import PreTrainedTokenizerBase from alibi_detect.saving._typing import...
19,169
34.369004
116
py
alibi-detect
alibi-detect-master/alibi_detect/saving/__init__.py
from alibi_detect.saving.validate import validate_config from alibi_detect.saving.loading import load_detector, read_config, resolve_config from alibi_detect.saving.registry import registry from alibi_detect.saving.saving import save_detector, write_config __all__ = [ "save_detector", "write_config", "load...
413
26.6
82
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_typing.py
"""Typing constructs for saving and loading functionality List of detectors that are valid for saving and loading either via the legacy methods or the new config driven functionality""" VALID_DETECTORS = [ 'AdversarialAE', 'ChiSquareDrift', 'ClassifierDrift', 'IForest', 'KSDrift', 'LLR', '...
951
23.410256
110
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_sklearn/loading.py
import os from pathlib import Path from typing import Union import joblib from sklearn.base import BaseEstimator def load_model(filepath: Union[str, os.PathLike], ) -> BaseEstimator: """ Load scikit-learn (or xgboost) model. Models are assumed to be a subclass of :class:`~sklearn.base.BaseEsti...
706
25.185185
118
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_sklearn/saving.py
import logging import os from pathlib import Path from typing import Union import joblib from sklearn.base import BaseEstimator from alibi_detect.utils.frameworks import Framework logger = logging.getLogger(__name__) def save_model_config(model: BaseEstimator, base_path: Path, ...
2,235
30.942857
120
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_sklearn/__init__.py
from alibi_detect.saving._sklearn.saving import save_model_config as save_model_config_sk from alibi_detect.saving._sklearn.loading import load_model as load_model_sk __all__ = [ "save_model_config_sk", "load_model_sk" ]
230
27.875
89
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_sklearn/tests/test_saving_sk.py
from pytest_cases import param_fixture, parametrize, parametrize_with_cases from alibi_detect.saving.tests.datasets import ContinuousData from alibi_detect.saving.tests.models import classifier_model, xgb_classifier_model from alibi_detect.saving.loading import _load_model_config from alibi_detect.saving.saving impor...
1,295
38.272727
96
py
alibi-detect
alibi-detect-master/alibi_detect/saving/tests/conftest.py
import pytest @pytest.fixture def seed(pytestconfig): """ Returns the random seed set by pytest-randomly. """ return pytestconfig.getoption("randomly_seed")
175
16.6
51
py
alibi-detect
alibi-detect-master/alibi_detect/saving/tests/datasets.py
import numpy as np import pytest from alibi_testing.data import get_movie_sentiment_data from pytest_cases import parametrize from requests import RequestException # Note: If any of below cases become large, see https://smarie.github.io/python-pytest-cases/#c-caching-cases FLOAT = np.float32 INT = np.int32 # Group d...
2,799
37.888889
120
py
alibi-detect
alibi-detect-master/alibi_detect/saving/tests/models.py
from functools import partial from importlib import import_module import numpy as np import tensorflow as tf import torch import torch.nn as nn from sklearn.ensemble import RandomForestClassifier from xgboost import XGBClassifier from requests.exceptions import HTTPError import pytest from pytest_cases import fixtur...
12,456
39.313916
114
py
alibi-detect
alibi-detect-master/alibi_detect/saving/tests/__init__.py
0
0
0
py
alibi-detect
alibi-detect-master/alibi_detect/saving/tests/test_saving.py
# type: ignore """ Tests for saving/loading of detectors via config.toml files. Internal functions such as save_kernel/load_kernel_config etc are also tested. """ from functools import partial import os from pathlib import Path from typing import Callable import sklearn.base import toml import dill import numpy as np...
56,177
40.065789
119
py
alibi-detect
alibi-detect-master/alibi_detect/saving/tests/test_validate.py
import numpy as np import pytest from pydantic import ValidationError from alibi_detect.saving import validate_config from alibi_detect.saving.schemas import KernelConfig from alibi_detect.saving.saving import X_REF_FILENAME from alibi_detect.version import __version__ from copy import deepcopy import tensorflow as t...
3,998
32.889831
95
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_pytorch/loading.py
import logging import os from importlib import import_module from pathlib import Path from typing import Callable, Optional, Union, Type import dill import torch import torch.nn as nn from alibi_detect.cd.pytorch import UAE, HiddenOutput from alibi_detect.cd.pytorch.preprocess import _Encoder from alibi_detect.models...
4,175
27.8
115
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_pytorch/conversions.py
import torch def get_pt_dtype(dtype_str: str): """Returns pytorch datatype specified by string.""" return getattr(torch, dtype_str)
143
17
55
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_pytorch/saving.py
import os import logging from pathlib import Path from typing import Any, Callable, Dict, Optional, Tuple, Union import dill # dispatch table setting not done here as done in top-level saving.py file import torch import torch.nn as nn from alibi_detect.cd.pytorch import UAE, HiddenOutput from alibi_detect.models.pyt...
4,430
32.568182
109
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_pytorch/__init__.py
from alibi_detect.utils.missing_optional_dependency import import_optional load_kernel_config_pt, load_embedding_pt, load_model_pt, load_optimizer_pt, \ prep_model_and_emb_pt = import_optional( 'alibi_detect.saving._pytorch.loading', names=['load_kernel_config', 'load_embedding', ...
836
26
77
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_pytorch/tests/test_saving_pt.py
from pytest_cases import param_fixture, parametrize, parametrize_with_cases from alibi_detect.saving.tests.datasets import ContinuousData from alibi_detect.saving.tests.models import encoder_model from alibi_detect.cd.pytorch import HiddenOutput as HiddenOutput_pt from alibi_detect.saving.loading import _load_model_c...
2,131
38.481481
115
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_keops/loading.py
from typing import Callable from alibi_detect.utils.keops.kernels import DeepKernel def load_kernel_config(cfg: dict) -> Callable: """ Loads a kernel from a kernel config dict. Parameters ---------- cfg A kernel config dict. (see pydantic schema's). Returns ------- The kernel...
1,118
28.447368
115
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_keops/__init__.py
from alibi_detect.utils.missing_optional_dependency import import_optional load_kernel_config_ke = import_optional( 'alibi_detect.saving._keops.loading', names=['load_kernel_config']) __all__ = [ "load_kernel_config_ke", ]
245
23.6
74
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_tensorflow/loading.py
import logging import os from importlib import import_module import warnings from functools import partial from pathlib import Path from typing import Callable, Dict, List, Optional, Tuple, Union, Type import dill import tensorflow as tf from tensorflow_probability.python.distributions.distribution import \ Distri...
35,509
33.34236
120
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_tensorflow/conversions.py
import tensorflow as tf def get_tf_dtype(dtype_str: str): """Returns tensorflow datatype specified by string.""" return getattr(tf, dtype_str)
154
18.375
58
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_tensorflow/saving.py
import logging import os from functools import partial from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Tuple, Union import dill # dispatch table setting not done here as done in top-level saving.py file import tensorflow as tf from tensorflow.keras.layers import Input, InputLayer # B...
34,567
34.237513
114
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_tensorflow/__init__.py
from alibi_detect.utils.missing_optional_dependency import import_optional load_detector_legacy, load_kernel_config_tf, load_embedding_tf, load_model_tf, load_optimizer_tf, \ prep_model_and_emb_tf = import_optional( 'alibi_detect.saving._tensorflow.loading', names=['load_detector_legacy', ...
1,091
30.2
99
py
alibi-detect
alibi-detect-master/alibi_detect/saving/_tensorflow/tests/test_saving_tf.py
from pytest_cases import param_fixture, parametrize, parametrize_with_cases import pytest from alibi_detect.saving.tests.datasets import ContinuousData from alibi_detect.saving.tests.models import encoder_model from alibi_detect.cd.tensorflow import HiddenOutput as HiddenOutput_tf from alibi_detect.saving.loading imp...
5,554
37.846154
112
py
alibi-detect
alibi-detect-master/alibi_detect/tests/test_datasets.py
import numpy as np import pandas as pd import pytest from requests import RequestException from urllib.error import URLError from alibi_detect.datasets import fetch_kdd, fetch_ecg, corruption_types_cifar10c, fetch_cifar10c, \ fetch_attack, fetch_nab, get_list_nab from alibi_detect.utils.data import Bunch # KDD cup...
5,278
37.816176
113
py
alibi-detect
alibi-detect-master/alibi_detect/tests/test_dep_management.py
""" Test optional dependencies. These tests import all the named objects from the public API of alibi-detect and test that they throw the correct errors if the relevant optional dependencies are not installed. If these tests fail, it is likely that: 1. The optional dependency relation hasn't been added to the test scr...
14,221
43.72327
120
py
alibi-detect
alibi-detect-master/alibi_detect/tests/conftest.py
import pytest def pytest_addoption(parser): parser.addoption("--opt-dep", action="store") @pytest.fixture(scope='session') def opt_dep(request): """Optional dependency fixture. Tests that use this fixture must be run with the --opt-dep option via terminal. If not they will skip. This fixture is used...
621
31.736842
119
py
alibi-detect
alibi-detect-master/alibi_detect/tests/__init__.py
0
0
0
py
alibi-detect
alibi-detect-master/alibi_detect/cd/chisquare.py
import numpy as np from scipy.stats import chi2_contingency from typing import Callable, Dict, List, Optional, Tuple, Union from alibi_detect.cd.base import BaseUnivariateDrift from alibi_detect.utils.warnings import deprecated_alias class ChiSquareDrift(BaseUnivariateDrift): @deprecated_alias(preprocess_x_ref='p...
7,025
49.913043
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/base.py
import logging from abc import abstractmethod from typing import Callable, Dict, List, Optional, Tuple, Union, Any import numpy as np from alibi_detect.base import BaseDetector, concept_drift_dict, DriftConfigMixin from alibi_detect.cd.utils import get_input_shape, update_reference from alibi_detect.utils.frameworks i...
52,690
41.94295
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/learned_kernel.py
import numpy as np from typing import Callable, Dict, Optional, Union from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, has_keops, BackendValidator, Framework from alibi_detect.utils.warnings import deprecated_alias from alibi_detect.base import DriftConfigMixin if has_pytorch: from torch.util...
9,166
45.532995
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/_domain_clf.py
from abc import ABC, abstractmethod from typing import Callable import numpy as np from sklearn.svm import SVC from sklearn.calibration import CalibratedClassifierCV class _DomainClf(ABC): """ Base class for domain classifiers used in :py:class:`~alibi_detect.cd.ContextAwareDrift`.The `SVCDomainClf` is cu...
3,611
33.730769
114
py
alibi-detect
alibi-detect-master/alibi_detect/cd/mmd.py
import logging import numpy as np from typing import Callable, Dict, Optional, Union, Tuple from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, has_keops, BackendValidator, Framework from alibi_detect.utils.warnings import deprecated_alias from alibi_detect.base import DriftConfigMixin if has_pytorc...
6,795
41.475
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/cvm_online.py
import numpy as np from typing import Any, Callable, List, Optional, Union from alibi_detect.base import DriftConfigMixin from alibi_detect.cd.base_online import BaseUniDriftOnline from alibi_detect.utils.misc import quantile import numba as nb from tqdm import tqdm import warnings class CVMDriftOnline(BaseUniDriftOn...
14,378
44.792994
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/fet.py
import numpy as np from typing import Callable, Dict, Tuple, Optional, Union from alibi_detect.cd.base import BaseUnivariateDrift from scipy.stats import fisher_exact class FETDrift(BaseUnivariateDrift): def __init__( self, x_ref: Union[np.ndarray, list], p_val: float = .05, ...
5,594
45.239669
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/base_online.py
import logging import warnings from abc import abstractmethod from typing import Any, Callable, Dict, List, Optional, Union, Tuple, TYPE_CHECKING import numpy as np from alibi_detect.base import BaseDetector, concept_drift_dict from alibi_detect.cd.utils import get_input_shape from alibi_detect.utils.state import Stat...
17,889
37.308351
120
py
alibi-detect
alibi-detect-master/alibi_detect/cd/cvm.py
import numpy as np from typing import Callable, Dict, Tuple, Optional, Union from alibi_detect.cd.base import BaseUnivariateDrift try: from scipy.stats import cramervonmises_2samp except ImportError: cramervonmises_2samp = None class CVMDrift(BaseUnivariateDrift): def __init__( self, ...
4,372
42.73
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/utils.py
import logging import random from typing import Callable, Dict, Optional, Tuple, Union import numpy as np from alibi_detect.utils.sampling import reservoir_sampling from alibi_detect.utils.frameworks import Framework logger = logging.getLogger(__name__) def update_reference(X_ref: np.ndarray, X...
4,341
34.300813
108
py
alibi-detect
alibi-detect-master/alibi_detect/cd/classifier.py
import numpy as np from typing import Callable, Dict, Optional, Union from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, \ BackendValidator, Framework from alibi_detect.base import DriftConfigMixin from sklearn.base import ClassifierMixin from alibi_detect.cd.sklearn.classifier import Classifi...
11,053
50.175926
117
py
alibi-detect
alibi-detect-master/alibi_detect/cd/lsdd_online.py
import os import numpy as np from typing import Any, Callable, Dict, Optional, Union from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, BackendValidator, Framework from alibi_detect.base import DriftConfigMixin if has_pytorch: from alibi_detect.cd.pytorch.lsdd_online import LSDDDriftOnlineTorch ...
7,617
38.677083
118
py
alibi-detect
alibi-detect-master/alibi_detect/cd/spot_the_diff.py
import numpy as np from typing import Callable, Dict, Optional, Union from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, BackendValidator, Framework from alibi_detect.base import DriftConfigMixin if has_pytorch: from alibi_detect.cd.pytorch.spot_the_diff import SpotTheDiffDriftTorch from al...
9,141
47.62766
118
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tabular.py
import numpy as np from scipy.stats import chi2_contingency, ks_2samp from typing import Callable, Dict, List, Optional, Tuple, Union from alibi_detect.cd.base import BaseUnivariateDrift from alibi_detect.utils.warnings import deprecated_alias import warnings class TabularDrift(BaseUnivariateDrift): @deprecated_a...
8,308
51.923567
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/mmd_online.py
import os import numpy as np from typing import Any, Callable, Dict, Optional, Union from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, BackendValidator, Framework from alibi_detect.base import DriftConfigMixin if has_pytorch: from alibi_detect.cd.pytorch.mmd_online import MMDDriftOnlineTorch ...
7,411
37.604167
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/model_uncertainty.py
import logging import numpy as np from typing import Callable, Dict, Optional, Union from functools import partial from alibi_detect.cd.ks import KSDrift from alibi_detect.cd.chisquare import ChiSquareDrift from alibi_detect.cd.preprocess import classifier_uncertainty, regressor_uncertainty from alibi_detect.cd.utils i...
14,152
43.646688
120
py
alibi-detect
alibi-detect-master/alibi_detect/cd/context_aware.py
import logging import numpy as np from typing import Callable, Dict, Optional, Union, Tuple from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, BackendValidator, Framework from alibi_detect.utils.warnings import deprecated_alias from alibi_detect.base import DriftConfigMixin if has_pytorch: from...
7,323
42.082353
116
py
alibi-detect
alibi-detect-master/alibi_detect/cd/__init__.py
from .chisquare import ChiSquareDrift from .classifier import ClassifierDrift from .ks import KSDrift from .learned_kernel import LearnedKernelDrift from .lsdd import LSDDDrift from .lsdd_online import LSDDDriftOnline from .spot_the_diff import SpotTheDiffDrift from .mmd import MMDDrift from .mmd_online import MMDDrift...
1,007
26.243243
84
py
alibi-detect
alibi-detect-master/alibi_detect/cd/ks.py
import numpy as np from scipy.stats import ks_2samp from typing import Callable, Dict, Optional, Tuple, Union from alibi_detect.cd.base import BaseUnivariateDrift from alibi_detect.utils.warnings import deprecated_alias class KSDrift(BaseUnivariateDrift): @deprecated_alias(preprocess_x_ref='preprocess_at_init') ...
4,384
41.572816
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/lsdd.py
import numpy as np from typing import Callable, Dict, Optional, Union, Tuple from alibi_detect.utils.frameworks import has_pytorch, has_tensorflow, BackendValidator, Framework from alibi_detect.utils.warnings import deprecated_alias from alibi_detect.base import DriftConfigMixin if has_pytorch: from alibi_detect.c...
6,658
41.96129
118
py
alibi-detect
alibi-detect-master/alibi_detect/cd/preprocess.py
import numpy as np from scipy.special import softmax from scipy.stats import entropy from typing import Callable, Union def classifier_uncertainty( x: Union[np.ndarray, list], model_fn: Callable, preds_type: str = 'probs', uncertainty_type: str = 'entropy', margin_width: float = 0.1, ) -> np.ndarr...
3,470
35.15625
118
py
alibi-detect
alibi-detect-master/alibi_detect/cd/fet_online.py
from tqdm import tqdm import numpy as np from typing import Any, Callable, List, Optional, Union from alibi_detect.base import DriftConfigMixin from alibi_detect.cd.base_online import BaseUniDriftOnline from alibi_detect.utils.misc import quantile from scipy.stats import hypergeom import numba as nb import warnings c...
15,054
45.180982
118
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_ks.py
from functools import partial from itertools import product import numpy as np import pytest import tensorflow as tf from tensorflow.keras.layers import Dense, Input, InputLayer from typing import Callable from alibi_detect.cd import KSDrift from alibi_detect.cd.tensorflow.preprocess import HiddenOutput, UAE, preproces...
4,062
37.330189
96
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_cvm_online.py
import numpy as np import pytest from alibi_detect.cd import CVMDriftOnline from alibi_detect.utils._random import fixed_seed n, n_test = 200, 500 n_bootstraps = 1000 ert = 50 np.random.seed(0) window_sizes = [[10], [10, 20]] batch_size = [None, int(n_bootstraps/4)] n_features = [1, 3] @pytest.mark.parametrize('win...
4,225
35.747826
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_lsdd.py
import numpy as np import pytest from alibi_detect.cd import LSDDDrift from alibi_detect.cd.pytorch.lsdd import LSDDDriftTorch from alibi_detect.cd.tensorflow.lsdd import LSDDDriftTF n, n_features = 100, 5 tests_lsdddrift = ['tensorflow', 'pytorch', 'PyToRcH', 'mxnet'] n_tests = len(tests_lsdddrift) @pytest.fixture...
931
26.411765
81
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/conftest.py
import pytest @pytest.fixture def seed(pytestconfig): """ Returns the random seed set by pytest-randomly. """ return pytestconfig.getoption("randomly_seed")
175
16.6
51
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_spot_the_diff.py
import numpy as np import pytest import tensorflow as tf from tensorflow.keras.layers import Dense import torch import torch.nn as nn from alibi_detect.cd import SpotTheDiffDrift from alibi_detect.cd.pytorch.spot_the_diff import SpotTheDiffDriftTorch from alibi_detect.cd.tensorflow.spot_the_diff import SpotTheDiffDrift...
2,129
28.178082
94
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_tabular.py
from itertools import product import numpy as np import pytest from alibi_detect.cd import TabularDrift n = 750 n_categories, n_features = 5, 6 n_cat = [0, 2, n_features] categories_per_feature = [None, int, list] correction = ['bonferroni', 'fdr'] update_x_ref = [{'last': 1000}, {'reservoir_sampling': 1000}] preproc...
2,931
39.722222
107
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_mmd_online.py
import numpy as np import pytest from alibi_detect.cd import MMDDriftOnline from alibi_detect.cd.pytorch.mmd_online import MMDDriftOnlineTorch from alibi_detect.cd.tensorflow.mmd_online import MMDDriftOnlineTF n, n_features = 100, 5 tests_mmddriftonline = ['tensorflow', 'pytorch', 'PyToRcH', 'mxnet'] n_tests = len(te...
1,353
27.808511
98
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_lsdd_online.py
import numpy as np import pytest from alibi_detect.cd import LSDDDriftOnline from alibi_detect.cd.pytorch.lsdd_online import LSDDDriftOnlineTorch from alibi_detect.cd.tensorflow.lsdd_online import LSDDDriftOnlineTF n, n_features = 100, 5 tests_lsdddriftonline = ['tensorflow', 'pytorch', 'PyToRcH', 'mxnet'] n_tests = ...
1,331
27.956522
99
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_fet_online.py
import numpy as np import pytest from functools import partial from alibi_detect.cd import FETDriftOnline from alibi_detect.utils._random import fixed_seed n = 250 n_inits, n_reps = 3, 100 n_bootstraps = 1000 ert = 150 window_sizes = [40] alternatives = ['less', 'greater'] n_features = [1, 3] @pytest.mark.parametri...
4,578
35.927419
120
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_chisquare.py
from itertools import product import numpy as np import pytest from alibi_detect.cd import ChiSquareDrift n_categories, n_features, n_tiles = 5, 6, 20 x_ref = np.tile(np.array([np.arange(n_categories)] * n_features).T, (n_tiles, 1)) np.random.shuffle(x_ref) categories_per_feature = [ None, {f: n_categories fo...
2,417
36.78125
86
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_mmd.py
import numpy as np import pytest from alibi_detect.cd import MMDDrift from alibi_detect.cd.pytorch.mmd import MMDDriftTorch from alibi_detect.cd.tensorflow.mmd import MMDDriftTF from alibi_detect.utils.frameworks import has_keops if has_keops: from alibi_detect.cd.keops.mmd import MMDDriftKeops n, n_features = 100...
1,185
29.410256
80
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_learned_kernel.py
import numpy as np import pytest import tensorflow as tf from tensorflow.keras.layers import Dense import torch import torch.nn as nn from alibi_detect.cd import LearnedKernelDrift from alibi_detect.cd.pytorch.learned_kernel import LearnedKernelDriftTorch from alibi_detect.cd.tensorflow.learned_kernel import LearnedKer...
2,811
29.901099
94
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_cvm.py
import numpy as np import pytest import scipy from packaging import version if version.parse(scipy.__version__) >= version.parse('1.7.0'): from alibi_detect.cd import CVMDrift n, n_test = 500, 200 np.random.seed(0) n_features = [2] # TODO - test 1D case once BaseUnivariateDrift updated tests_cvmdrift = list(n_fe...
1,377
31.046512
102
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_classifier.py
import numpy as np import pytest import tensorflow as tf from tensorflow.keras.layers import Dense, Input import torch import torch.nn as nn from alibi_detect.cd import ClassifierDrift from alibi_detect.cd.pytorch.classifier import ClassifierDriftTorch from alibi_detect.cd.tensorflow.classifier import ClassifierDriftTF...
2,093
28.492958
80
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_preprocess.py
from itertools import product import numpy as np import pytest import torch.nn as nn import torch from sklearn.linear_model import LogisticRegression from alibi_detect.cd.preprocess import classifier_uncertainty, regressor_uncertainty n, n_features = 100, 10 shape = (n_features,) X_train = np.random.rand(n * n_feature...
2,067
29.411765
85
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_fet.py
import numpy as np import pytest from alibi_detect.cd import FETDrift from itertools import product n, n_test = 500, 200 np.random.seed(0) alternative = ['less', 'greater', 'two-sided'] n_features = [2] # TODO - test 1D case once BaseUnivariateDrift updated tests_fetdrift = list(product(alternative, n_features)) n_t...
1,966
33.508772
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_contextmmd.py
import numpy as np import pytest from alibi_detect.cd import ContextMMDDrift from alibi_detect.cd.pytorch.context_aware import ContextMMDDriftTorch from alibi_detect.cd.tensorflow.context_aware import ContextMMDDriftTF n, n_features = 100, 5 tests_context_mmddrift = ['tensorflow', 'pytorch', 'PyToRcH', 'mxnet'] n_tes...
1,099
30.428571
88
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_model_uncertainty.py
import numpy as np import pytest from functools import partial from itertools import product import scipy import tensorflow as tf from tensorflow.keras.layers import Dense, Input, Softmax, Dropout import torch import torch.nn as nn from typing import Union from alibi_detect.cd import ClassifierUncertaintyDrift, Regress...
6,110
31.163158
114
py
alibi-detect
alibi-detect-master/alibi_detect/cd/tests/test_utils.py
from itertools import product import numpy as np import pytest from alibi_detect.cd.utils import update_reference n = [3, 50] n_features = [1, 10] update_method = [ None, 'last', 'reservoir_sampling' ] tests_update = list(product(n, n_features, update_method)) n_tests_update = len(tests_update) @pytest.f...
1,134
29.675676
85
py
alibi-detect
alibi-detect-master/alibi_detect/cd/keops/learned_kernel.py
from copy import deepcopy from functools import partial from tqdm import tqdm import numpy as np from pykeops.torch import LazyTensor import torch import torch.nn as nn from torch.utils.data import DataLoader from typing import Callable, Dict, List, Optional, Union, Tuple from alibi_detect.cd.base import BaseLearnedKer...
16,939
48.244186
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/keops/mmd.py
import logging import numpy as np from pykeops.torch import LazyTensor import torch from typing import Callable, Dict, List, Optional, Tuple, Union from alibi_detect.cd.base import BaseMMDDrift from alibi_detect.utils.keops.kernels import GaussianRBF from alibi_detect.utils.pytorch import get_device from alibi_detect.u...
8,642
45.972826
120
py
alibi-detect
alibi-detect-master/alibi_detect/cd/keops/__init__.py
0
0
0
py
alibi-detect
alibi-detect-master/alibi_detect/cd/keops/tests/test_mmd_keops.py
from functools import partial from itertools import product import numpy as np import pytest import torch import torch.nn as nn from typing import Callable, List from alibi_detect.utils.frameworks import has_keops from alibi_detect.utils.pytorch import GaussianRBF, mmd2_from_kernel_matrix from alibi_detect.cd.pytorch.p...
4,726
38.066116
110
py
alibi-detect
alibi-detect-master/alibi_detect/cd/keops/tests/test_learned_kernel_keops.py
from itertools import product import numpy as np import pytest import torch import torch.nn as nn from typing import Callable, Optional, Union from alibi_detect.utils.frameworks import has_keops from alibi_detect.utils.pytorch import GaussianRBF as GaussianRBFTorch from alibi_detect.utils.pytorch import mmd2_from_kerne...
4,968
36.931298
103
py
alibi-detect
alibi-detect-master/alibi_detect/cd/sklearn/classifier.py
import logging import numpy as np from functools import partial from typing import Callable, Dict, Optional, Tuple, Union from sklearn.base import clone, ClassifierMixin from sklearn.calibration import CalibratedClassifierCV from sklearn.exceptions import NotFittedError from sklearn.ensemble import RandomForestClassifi...
15,607
49.186495
117
py
alibi-detect
alibi-detect-master/alibi_detect/cd/sklearn/__init__.py
0
0
0
py
alibi-detect
alibi-detect-master/alibi_detect/cd/sklearn/tests/test_classifier_sklearn.py
import pytest import numpy as np from typing import Union from alibi_detect.cd.sklearn.classifier import ClassifierDriftSklearn from sklearn.svm import SVC from sklearn.svm import LinearSVC from sklearn.tree import DecisionTreeClassifier from sklearn.linear_model import LogisticRegression from sklearn.ensemble import ...
17,137
43.630208
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/learned_kernel.py
from copy import deepcopy from functools import partial from tqdm import tqdm import numpy as np import torch import torch.nn as nn from torch.utils.data import DataLoader from typing import Callable, Dict, Optional, Union, Tuple from alibi_detect.cd.base import BaseLearnedKernelDrift from alibi_detect.utils.pytorch im...
12,289
46.451737
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/mmd.py
import logging import numpy as np import torch from typing import Callable, Dict, Optional, Tuple, Union from alibi_detect.cd.base import BaseMMDDrift from alibi_detect.utils.pytorch import get_device from alibi_detect.utils.pytorch.distance import mmd2_from_kernel_matrix from alibi_detect.utils.pytorch.kernels import ...
6,868
46.372414
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/utils.py
from torch import nn from typing import Callable def activate_train_mode_for_dropout_layers(model: Callable) -> Callable: model.eval() # type: ignore n_dropout_layers = 0 for module in model.modules(): # type: ignore if isinstance(module, nn.Dropout): module.train() n_dr...
444
25.176471
72
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/classifier.py
from copy import deepcopy from functools import partial import numpy as np import torch import torch.nn as nn from torch.utils.data import DataLoader from scipy.special import softmax from typing import Callable, Dict, Optional, Union, Tuple from alibi_detect.cd.base import BaseClassifierDrift from alibi_detect.models....
10,365
46.990741
115
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/lsdd_online.py
from tqdm import tqdm import numpy as np import torch from typing import Any, Callable, Optional, Union from alibi_detect.cd.base_online import BaseMultiDriftOnline from alibi_detect.utils.pytorch import get_device from alibi_detect.utils.pytorch import GaussianRBF, permed_lsdds, quantile from alibi_detect.utils.framew...
11,629
47.057851
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/spot_the_diff.py
import logging import numpy as np import torch import torch.nn as nn from torch.utils.data import DataLoader from typing import Callable, Dict, Optional, Union from alibi_detect.cd.pytorch.classifier import ClassifierDriftTorch from alibi_detect.utils.pytorch.data import TorchDataset from alibi_detect.utils.pytorch imp...
11,086
46.995671
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/mmd_online.py
from tqdm import tqdm import numpy as np import torch from typing import Any, Callable, Optional, Union from alibi_detect.cd.base_online import BaseMultiDriftOnline from alibi_detect.utils.pytorch import get_device from alibi_detect.utils.pytorch.kernels import GaussianRBF from alibi_detect.utils.pytorch import zero_di...
10,720
45.816594
119
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/context_aware.py
import logging import numpy as np import torch from typing import Callable, Dict, Optional, Tuple, Union from alibi_detect.cd.base import BaseContextMMDDrift from alibi_detect.utils.pytorch import get_device from alibi_detect.utils.pytorch.kernels import GaussianRBF from alibi_detect.utils.warnings import deprecated_al...
13,224
46.232143
120
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/__init__.py
from alibi_detect.utils.missing_optional_dependency import import_optional UAE, HiddenOutput, preprocess_drift = import_optional( 'alibi_detect.cd.pytorch.preprocess', names=['UAE', 'HiddenOutput', 'preprocess_drift']) __all__ = [ "UAE", "HiddenOutput", "preprocess_drift" ]
297
23.833333
74
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/lsdd.py
import numpy as np import torch from typing import Callable, Dict, Optional, Tuple, Union from alibi_detect.cd.base import BaseLSDDDrift from alibi_detect.utils.pytorch import get_device from alibi_detect.utils.pytorch.kernels import GaussianRBF from alibi_detect.utils.pytorch.distance import permed_lsdds from alibi_de...
8,982
49.466292
118
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/preprocess.py
from typing import Callable, Dict, Optional, Type, Union import numpy as np import torch import torch.nn as nn from alibi_detect.utils.pytorch.prediction import (predict_batch, predict_batch_transformer) class _Encoder(nn.Module): def __init__( self,...
4,599
36.398374
111
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/tests/test_mmd_pt.py
from functools import partial from itertools import product import numpy as np import pytest import torch import torch.nn as nn from typing import Callable, List from alibi_detect.cd.pytorch.mmd import MMDDriftTorch from alibi_detect.cd.pytorch.preprocess import HiddenOutput, preprocess_drift n, n_hidden, n_classes = ...
3,494
34.30303
96
py
alibi-detect
alibi-detect-master/alibi_detect/cd/pytorch/tests/test_learned_kernel_pt.py
from itertools import product import numpy as np import pytest import torch import torch.nn as nn from typing import Union from alibi_detect.cd.pytorch.learned_kernel import LearnedKernelDriftTorch n = 100 class MyKernel(nn.Module): def __init__(self, n_features: int): super().__init__() self.den...
2,264
26.621951
92
py