From fbf36ffb845269419f84ad0f5430aa094de26d63 Mon Sep 17 00:00:00 2001 From: tylerjthomas9 Date: Tue, 7 Feb 2023 16:58:59 -0700 Subject: [PATCH 1/5] PythonCall.jl support --- .github/workflows/CI.yml | 26 ++++---------------------- .gitignore | 2 ++ CondaPkg.toml | 2 ++ Project.toml | 8 ++++---- src/OutlierDetectionPython.jl | 6 ++++++ src/models.jl | 8 ++++++-- src/utils.jl | 13 ++++++------- 7 files changed, 30 insertions(+), 35 deletions(-) create mode 100644 CondaPkg.toml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 25bdba4..d5f4231 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -10,9 +10,9 @@ jobs: fail-fast: false matrix: version: - - '1.5' - '1.6' - '1' + - 'nightly' os: - ubuntu-latest - windows-latest @@ -20,33 +20,15 @@ jobs: arch: - x64 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - with: - python-version: 3.9 - - name: python dependencies - run: | - python -m pip install --upgrade pip - pip install pyod + - uses: actions/checkout@v3 - uses: julia-actions/setup-julia@v1 with: version: ${{ matrix.version }} arch: ${{ matrix.arch }} - - uses: actions/cache@v1 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v1 # https://github.com/julia-actions/cache - uses: julia-actions/julia-buildpkg@v1 - env: - PYTHON: python - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - uses: codecov/codecov-action@v2 with: - file: lcov.info + files: lcov.info diff --git a/.gitignore b/.gitignore index 0f84bed..a69651f 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ *.jl.cov *.jl.mem /Manifest.toml + +.CondaPkg/* \ No newline at end of file diff --git a/CondaPkg.toml b/CondaPkg.toml new file mode 100644 index 0000000..65e5585 --- /dev/null +++ b/CondaPkg.toml @@ -0,0 +1,2 @@ +[deps] +pyod = "=1" diff --git a/Project.toml b/Project.toml index def564d..daa66c7 100644 --- a/Project.toml +++ b/Project.toml @@ -1,16 +1,16 @@ name = "OutlierDetectionPython" uuid = "2449c660-d36c-460e-a68b-92ab3c865b3e" authors = ["David Muhr and contributors"] -version = "0.1.2" +version = "0.2.0" [deps] OutlierDetectionInterface = "1722ece6-f894-4ffc-b6be-6ca1174e2011" -PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0" +PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d" [compat] OutlierDetectionInterface = "0.1" -PyCall = "1.92" -julia = "1" +PythonCall = "0.9" +julia = "1.6" [extras] OutlierDetectionTest = "66620973-d34b-445b-a614-4040704cad69" diff --git a/src/OutlierDetectionPython.jl b/src/OutlierDetectionPython.jl index 3691f7e..10c15fc 100644 --- a/src/OutlierDetectionPython.jl +++ b/src/OutlierDetectionPython.jl @@ -1,6 +1,12 @@ module OutlierDetectionPython using OutlierDetectionInterface const OD = OutlierDetectionInterface + using PythonCall + const numpy = PythonCall.pynew() + + function __init__() + PythonCall.pycopy!(numpy, pyimport("numpy")) + end include("utils.jl") include("models.jl") diff --git a/src/models.jl b/src/models.jl index d9d9a41..58f18f1 100644 --- a/src/models.jl +++ b/src/models.jl @@ -215,22 +215,26 @@ end """ SODDetector(n_neighbors = 5, ref_set = 10, - alpha = 0.8) + alpha = 0.8, + contamination = 0.1) $(make_docs_link("sod")) """ @pymodel mutable struct SODDetector <: UnsupervisedDetector n_neighbors::Integer = 20::(_ > 0) ref_set::Integer = 10::(_ > 0) alpha::Real = 0.8::(0 < _ < 1) + contamination::Real = 0.1::(0 < _ < 0.5) end """ SOSDetector(perplexity = 4.5, metric = "minkowski", - eps = 1e-5) + eps = 1e-5, + contamination = 0.1) $(make_docs_link("sos")) """ @pymodel mutable struct SOSDetector <: UnsupervisedDetector perplexity::Real = 4.5::(_ > 0) metric::String = "minkowski"::(_ in ("cityblock", "cosine", "euclidean", "l1", "l2", "manhatten", "braycurtis", "canberra", "chebyshev", "correlation", "dice", "hamming", "jaccard", "kulsinski", "mahalanobis", "matching", "minkowski", "rogerstanimoto", "russellrao", "seuclidean", "sokalmichener", "sokalsneath", "sqeuclidean", "yule")) eps::Real = 1e-5::(_ > 0) + contamination::Real = 0.1::(0 < _ < 0.5) end diff --git a/src/utils.jl b/src/utils.jl index aab6dae..a97e66b 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -1,7 +1,6 @@ -using PyCall:PyObject, PyReverseDims, pyimport_conda struct PyModel <: DetectorModel - pyobject::PyObject + pyobject::Py end # lazily import a python model @@ -10,7 +9,7 @@ pyod_import(name::String) = () -> begin module_name = lowercase(raw_name) # names are not consistently uppercased model_name = raw_name == "IForest" ? raw_name : uppercase(raw_name) - getproperty(pyimport_conda("pyod.models.$(module_name)", "pyod", "conda-forge"), model_name) + getproperty(pyimport("pyod.models.$(module_name)"), model_name) end pyod_import(name::Symbol) = pyod_import(String(name)) @@ -22,12 +21,12 @@ function pyod_fit(modelname, params) pymodelname = String(modelname) quote function OD.fit(model::$modelname, X::Data; verbosity)::Fit - Xt = PyReverseDims(X) # from column-major to row-major + Xt = numpy.array(PermutedDimsArray(X, (2,1))) # from column-major to row-major # load the underlying python model with key-word arguments detector = pyod_import($pymodelname)()($((Expr(:kw, p, :(model.$p)) for p in params)...)) detector.fit(Xt) # the underlying python model is out model - return PyModel(detector), detector.decision_scores_ + return PyModel(detector), pyconvert(Array, detector.decision_scores_) end end end @@ -36,9 +35,9 @@ end function pyod_score(modelname) quote function OD.transform(_::$modelname, model::DetectorModel, X::Data)::Scores - Xt = PyReverseDims(X) # change from column-major to row-major + Xt = numpy.array(PermutedDimsArray(X, (2,1))) # from column-major to row-major scores_test = model.pyobject.decision_function(Xt) - return scores_test + return pyconvert(Vector, scores_test) end end end From 3934f72e5bdc837a6c5a8416fb2dd6fe9ad25b7d Mon Sep 17 00:00:00 2001 From: tylerjthomas9 Date: Tue, 7 Feb 2023 17:21:48 -0700 Subject: [PATCH 2/5] expand `contamination` support --- src/models.jl | 68 +++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 19 deletions(-) diff --git a/src/models.jl b/src/models.jl index 58f18f1..a7c32a6 100644 --- a/src/models.jl +++ b/src/models.jl @@ -1,10 +1,12 @@ """ ABODDetector(n_neighbors = 5, - method = "fast") + method = "fast", + contamination = 0.1) $(make_docs_link("abod")) """ @pymodel mutable struct ABODDetector <: UnsupervisedDetector n_neighbors::Integer = 5::(_ > 0) method::String = "fast"::(_ in ("default", "fast")) + contamination::Real = 0.1::(0 < _ < 0.5) end """ CBLOFDetector(n_clusters = 8, @@ -12,7 +14,8 @@ end beta = 5, use_weights = false, random_state = nothing, - n_jobs = 1) + n_jobs = 1, + contamination = 0.1) $(make_docs_link("cblof")) """ @pymodel mutable struct CBLOFDetector <: UnsupervisedDetector @@ -22,41 +25,50 @@ $(make_docs_link("cblof")) use_weights::Bool = false random_state::Union{Nothing,Integer} = nothing n_jobs::Integer = 1::(_ >= -1) + contamination::Real = 0.1::(0 < _ < 0.5) end """ COFDetector(n_neighbors = 5, - method="fast") + method="fast", + contamination = 0.1) $(make_docs_link("cof")) """ @pymodel mutable struct COFDetector <: UnsupervisedDetector - n_neighbors::Integer = 5::(_ > 0) + n_neighbors::Integer = 20::(_ > 0) method::String = "fast"::(_ in ("fast", "memory")) + contamination::Real = 0.1::(0 < _ < 0.5) end -""" COPODDetector() +""" COPODDetector(n_jobs = 1, + contamination = 0.1) $(make_docs_link("copod")) """ -@pymodel mutable struct COPODDetector <: UnsupervisedDetector end +@pymodel mutable struct COPODDetector <: UnsupervisedDetector + n_jobs::Integer = 1::(_ >= -1) + contamination::Real = 0.1::(0 < _ < 0.5) +end """ HBOSDetector(n_bins = 10, alpha = 0.1, - tol = 0.5) + tol = 0.5, + contamination = 0.1) $(make_docs_link("hbos")) """ @pymodel mutable struct HBOSDetector <: UnsupervisedDetector n_bins::Integer = 10::(_ > 1) alpha::Real = 0.1::(0 < _ < 1) tol::Real = 0.5::(0 < _ < 1) + contamination::Real = 0.1::(0 < _ < 0.5) end """ IForestDetector(n_estimators = 100, max_samples = "auto", max_features = 1.0 bootstrap = false, - behaviour = "new", random_state = nothing, verbose = 0, - n_jobs = 1) + n_jobs = 1, + contamination = 0.1) $(make_docs_link("iforest")) """ @pymodel mutable struct IForestDetector <: UnsupervisedDetector @@ -64,10 +76,10 @@ $(make_docs_link("iforest")) max_samples::Union{String,Real} = "auto" max_features::Real = 1.0 bootstrap::Bool = false - behaviour::String = "new" random_state::Union{Nothing,Integer} = nothing verbose::Integer = 0::(0 <= _ <= 2) n_jobs::Integer = 1::(_ >= -1) + contamination::Real = 0.1::(0 < _ < 0.5) end """ KNNDetector(n_neighbors = 5, @@ -78,7 +90,8 @@ end metric = "minkowski", p = 2, metric_params = nothing, - n_jobs = 1) + n_jobs = 1, + contamination = 0.1) $(make_docs_link("knn")) """ @pymodel mutable struct KNNDetector <: UnsupervisedDetector @@ -91,26 +104,31 @@ $(make_docs_link("knn")) p::Union{Nothing,Integer} = 2 metric_params::Union{Nothing,Any} = nothing n_jobs::Integer = 1::(_ >= -1) + contamination::Real = 0.1::(0 < _ < 0.5) end """ LMDDDetector(n_iter = 50, dis_measure = "aad", - random_state = nothing) + random_state = nothing, + contamination = 0.1) $(make_docs_link("lmdd")) """ @pymodel mutable struct LMDDDetector <: UnsupervisedDetector n_iter::Integer = 50::(_ > 0) dis_measure::String = "aad"::(_ in ("aad", "var", "iqr")) random_state::Union{Nothing,Integer} = nothing + contamination::Real = 0.1::(0 < _ < 0.5) end """ LODADetector(n_bins = 10, - n_random_cuts = 100) + n_random_cuts = 100, + contamination = 0.1) $(make_docs_link("loda")) """ @pymodel mutable struct LODADetector <: UnsupervisedDetector n_bins::Integer = 10::(_ > 1) n_random_cuts::Integer = 100::(_ > 0) + contamination::Real = 0.1::(0 < _ < 0.5) end """ LOFDetector(n_neighbors = 5, @@ -120,7 +138,8 @@ end p = 2, metric_params = nothing, n_jobs = 1, - novelty = true) + novelty = true, + contamination = 0.1) $(make_docs_link("lof")) """ @pymodel mutable struct LOFDetector <: UnsupervisedDetector @@ -132,21 +151,25 @@ $(make_docs_link("lof")) metric_params::Union{Nothing,Any} = nothing n_jobs::Integer = 1::(_ >= -1) novelty::Bool = true + contamination::Real = 0.1::(0 < _ < 0.5) end """ LOCIDetector(alpha = 0.5, - k = 3) + k = 3, + contamination = 0.1) $(make_docs_link("loci")) """ @pymodel mutable struct LOCIDetector <: UnsupervisedDetector alpha::Real = 0.5::(0 < _ < 1) k::Real = 3::(_ > 0) + contamination::Real = 0.1::(0 < _ < 0.5) end """ MCDDetector(store_precision = true, assume_centered = false, support_fraction = nothing, - random_state = nothing) + random_state = nothing, + contamination = 0.1) $(make_docs_link("mcd")) """ @pymodel mutable struct MCDDetector <: UnsupervisedDetector @@ -154,6 +177,7 @@ $(make_docs_link("mcd")) assume_centered::Bool = false support_fraction::Union{Nothing,Real} = nothing random_state::Union{Nothing,Integer} = nothing + contamination::Real = 0.1::(0 < _ < 0.5) end """ OCSVMDetector(kernel = "rbf", @@ -165,7 +189,8 @@ end shrinking = true, cache_size = 200, verbose = false, - max_iter = -1) + max_iter = -1, + contamination = 0.1) $(make_docs_link("ocsvm")) """ @pymodel mutable struct OCSVMDetector <: UnsupervisedDetector @@ -179,6 +204,7 @@ $(make_docs_link("ocsvm")) cache_size::Integer = 200::(_ > 0) verbose::Bool = false max_iter::Integer = -1 + contamination::Real = 0.1::(0 < _ < 0.5) end """ PCADetector(n_components = nothing, @@ -190,7 +216,8 @@ end iterated_power = "auto", standardization = true, weighted = true, - random_state = nothing) + random_state = nothing, + contamination = 0.1) $(make_docs_link("pca")) """ @pymodel mutable struct PCADetector <: UnsupervisedDetector @@ -204,13 +231,16 @@ $(make_docs_link("pca")) standardization::Bool = true weighted::Bool = true random_state::Union{Nothing,Integer} = nothing + contamination::Real = 0.1::(0 < _ < 0.5) end -""" RODDetector(parallel_execution = false) +""" RODDetector(parallel_execution = false, + contamination = 0.1) $(make_docs_link("rod")) """ @pymodel mutable struct RODDetector <: UnsupervisedDetector parallel_execution::Bool = false + contamination::Real = 0.1::(0 < _ < 0.5) end """ SODDetector(n_neighbors = 5, From 6c89a7c263c8342df9fa81d767395978b1e5c51b Mon Sep 17 00:00:00 2001 From: Tyler Thomas <36181311+tylerjthomas9@users.noreply.github.com> Date: Wed, 8 Feb 2023 09:50:00 -0700 Subject: [PATCH 3/5] Prevent numba import causing segfault on mac --- CondaPkg.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CondaPkg.toml b/CondaPkg.toml index 65e5585..f49cd0a 100644 --- a/CondaPkg.toml +++ b/CondaPkg.toml @@ -1,2 +1,5 @@ [deps] pyod = "=1" + +[deps.llvmlite] +channel = "numba" From 0c4f625843692a1e21058c631fe8db66b31638be Mon Sep 17 00:00:00 2001 From: tylerjthomas9 Date: Thu, 9 Feb 2023 09:02:01 -0700 Subject: [PATCH 4/5] remove `contamination` --- src/models.jl | 68 +++++++++++++-------------------------------------- 1 file changed, 17 insertions(+), 51 deletions(-) diff --git a/src/models.jl b/src/models.jl index a7c32a6..cfd61cd 100644 --- a/src/models.jl +++ b/src/models.jl @@ -1,12 +1,10 @@ """ ABODDetector(n_neighbors = 5, - method = "fast", - contamination = 0.1) + method = "fast") $(make_docs_link("abod")) """ @pymodel mutable struct ABODDetector <: UnsupervisedDetector n_neighbors::Integer = 5::(_ > 0) method::String = "fast"::(_ in ("default", "fast")) - contamination::Real = 0.1::(0 < _ < 0.5) end """ CBLOFDetector(n_clusters = 8, @@ -14,8 +12,7 @@ end beta = 5, use_weights = false, random_state = nothing, - n_jobs = 1, - contamination = 0.1) + n_jobs = 1) $(make_docs_link("cblof")) """ @pymodel mutable struct CBLOFDetector <: UnsupervisedDetector @@ -25,40 +22,33 @@ $(make_docs_link("cblof")) use_weights::Bool = false random_state::Union{Nothing,Integer} = nothing n_jobs::Integer = 1::(_ >= -1) - contamination::Real = 0.1::(0 < _ < 0.5) end """ COFDetector(n_neighbors = 5, - method="fast", - contamination = 0.1) + method="fast") $(make_docs_link("cof")) """ @pymodel mutable struct COFDetector <: UnsupervisedDetector n_neighbors::Integer = 20::(_ > 0) method::String = "fast"::(_ in ("fast", "memory")) - contamination::Real = 0.1::(0 < _ < 0.5) end -""" COPODDetector(n_jobs = 1, - contamination = 0.1) +""" COPODDetector(n_jobs = 1) $(make_docs_link("copod")) """ @pymodel mutable struct COPODDetector <: UnsupervisedDetector n_jobs::Integer = 1::(_ >= -1) - contamination::Real = 0.1::(0 < _ < 0.5) end """ HBOSDetector(n_bins = 10, alpha = 0.1, - tol = 0.5, - contamination = 0.1) + tol = 0.5) $(make_docs_link("hbos")) """ @pymodel mutable struct HBOSDetector <: UnsupervisedDetector n_bins::Integer = 10::(_ > 1) alpha::Real = 0.1::(0 < _ < 1) tol::Real = 0.5::(0 < _ < 1) - contamination::Real = 0.1::(0 < _ < 0.5) end """ IForestDetector(n_estimators = 100, @@ -67,8 +57,7 @@ end bootstrap = false, random_state = nothing, verbose = 0, - n_jobs = 1, - contamination = 0.1) + n_jobs = 1) $(make_docs_link("iforest")) """ @pymodel mutable struct IForestDetector <: UnsupervisedDetector @@ -79,7 +68,6 @@ $(make_docs_link("iforest")) random_state::Union{Nothing,Integer} = nothing verbose::Integer = 0::(0 <= _ <= 2) n_jobs::Integer = 1::(_ >= -1) - contamination::Real = 0.1::(0 < _ < 0.5) end """ KNNDetector(n_neighbors = 5, @@ -90,8 +78,7 @@ end metric = "minkowski", p = 2, metric_params = nothing, - n_jobs = 1, - contamination = 0.1) + n_jobs = 1) $(make_docs_link("knn")) """ @pymodel mutable struct KNNDetector <: UnsupervisedDetector @@ -104,31 +91,26 @@ $(make_docs_link("knn")) p::Union{Nothing,Integer} = 2 metric_params::Union{Nothing,Any} = nothing n_jobs::Integer = 1::(_ >= -1) - contamination::Real = 0.1::(0 < _ < 0.5) end """ LMDDDetector(n_iter = 50, dis_measure = "aad", - random_state = nothing, - contamination = 0.1) + random_state = nothing) $(make_docs_link("lmdd")) """ @pymodel mutable struct LMDDDetector <: UnsupervisedDetector n_iter::Integer = 50::(_ > 0) dis_measure::String = "aad"::(_ in ("aad", "var", "iqr")) random_state::Union{Nothing,Integer} = nothing - contamination::Real = 0.1::(0 < _ < 0.5) end """ LODADetector(n_bins = 10, - n_random_cuts = 100, - contamination = 0.1) + n_random_cuts = 100) $(make_docs_link("loda")) """ @pymodel mutable struct LODADetector <: UnsupervisedDetector n_bins::Integer = 10::(_ > 1) n_random_cuts::Integer = 100::(_ > 0) - contamination::Real = 0.1::(0 < _ < 0.5) end """ LOFDetector(n_neighbors = 5, @@ -138,8 +120,7 @@ end p = 2, metric_params = nothing, n_jobs = 1, - novelty = true, - contamination = 0.1) + novelty = true) $(make_docs_link("lof")) """ @pymodel mutable struct LOFDetector <: UnsupervisedDetector @@ -151,25 +132,21 @@ $(make_docs_link("lof")) metric_params::Union{Nothing,Any} = nothing n_jobs::Integer = 1::(_ >= -1) novelty::Bool = true - contamination::Real = 0.1::(0 < _ < 0.5) end """ LOCIDetector(alpha = 0.5, - k = 3, - contamination = 0.1) + k = 3) $(make_docs_link("loci")) """ @pymodel mutable struct LOCIDetector <: UnsupervisedDetector alpha::Real = 0.5::(0 < _ < 1) k::Real = 3::(_ > 0) - contamination::Real = 0.1::(0 < _ < 0.5) end """ MCDDetector(store_precision = true, assume_centered = false, support_fraction = nothing, - random_state = nothing, - contamination = 0.1) + random_state = nothing) $(make_docs_link("mcd")) """ @pymodel mutable struct MCDDetector <: UnsupervisedDetector @@ -177,7 +154,6 @@ $(make_docs_link("mcd")) assume_centered::Bool = false support_fraction::Union{Nothing,Real} = nothing random_state::Union{Nothing,Integer} = nothing - contamination::Real = 0.1::(0 < _ < 0.5) end """ OCSVMDetector(kernel = "rbf", @@ -189,8 +165,7 @@ end shrinking = true, cache_size = 200, verbose = false, - max_iter = -1, - contamination = 0.1) + max_iter = -1) $(make_docs_link("ocsvm")) """ @pymodel mutable struct OCSVMDetector <: UnsupervisedDetector @@ -204,7 +179,6 @@ $(make_docs_link("ocsvm")) cache_size::Integer = 200::(_ > 0) verbose::Bool = false max_iter::Integer = -1 - contamination::Real = 0.1::(0 < _ < 0.5) end """ PCADetector(n_components = nothing, @@ -216,8 +190,7 @@ end iterated_power = "auto", standardization = true, weighted = true, - random_state = nothing, - contamination = 0.1) + random_state = nothing) $(make_docs_link("pca")) """ @pymodel mutable struct PCADetector <: UnsupervisedDetector @@ -231,40 +204,33 @@ $(make_docs_link("pca")) standardization::Bool = true weighted::Bool = true random_state::Union{Nothing,Integer} = nothing - contamination::Real = 0.1::(0 < _ < 0.5) end -""" RODDetector(parallel_execution = false, - contamination = 0.1) +""" RODDetector(parallel_execution = false) $(make_docs_link("rod")) """ @pymodel mutable struct RODDetector <: UnsupervisedDetector parallel_execution::Bool = false - contamination::Real = 0.1::(0 < _ < 0.5) end """ SODDetector(n_neighbors = 5, ref_set = 10, - alpha = 0.8, - contamination = 0.1) + alpha = 0.8) $(make_docs_link("sod")) """ @pymodel mutable struct SODDetector <: UnsupervisedDetector n_neighbors::Integer = 20::(_ > 0) ref_set::Integer = 10::(_ > 0) alpha::Real = 0.8::(0 < _ < 1) - contamination::Real = 0.1::(0 < _ < 0.5) end """ SOSDetector(perplexity = 4.5, metric = "minkowski", - eps = 1e-5, - contamination = 0.1) + eps = 1e-5) $(make_docs_link("sos")) """ @pymodel mutable struct SOSDetector <: UnsupervisedDetector perplexity::Real = 4.5::(_ > 0) metric::String = "minkowski"::(_ in ("cityblock", "cosine", "euclidean", "l1", "l2", "manhatten", "braycurtis", "canberra", "chebyshev", "correlation", "dice", "hamming", "jaccard", "kulsinski", "mahalanobis", "matching", "minkowski", "rogerstanimoto", "russellrao", "seuclidean", "sokalmichener", "sokalsneath", "sqeuclidean", "yule")) eps::Real = 1e-5::(_ > 0) - contamination::Real = 0.1::(0 < _ < 0.5) end From d8ea34522fe060095ca6d84ac16efe2bd08e5aaa Mon Sep 17 00:00:00 2001 From: David Muhr Date: Fri, 24 Mar 2023 15:51:31 +0100 Subject: [PATCH 5/5] add some models --- src/models.jl | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/models.jl b/src/models.jl index cfd61cd..8d65751 100644 --- a/src/models.jl +++ b/src/models.jl @@ -33,6 +33,15 @@ $(make_docs_link("cof")) method::String = "fast"::(_ in ("fast", "memory")) end +""" CDDetector(whitening = true, + rule_of_thumb = false) +$(make_docs_link("cd")) +""" +@pymodel mutable struct CDDetector <: UnsupervisedDetector + whitening::Bool = true + rule_of_thumb::Bool = false +end + """ COPODDetector(n_jobs = 1) $(make_docs_link("copod")) """ @@ -40,6 +49,39 @@ $(make_docs_link("copod")) n_jobs::Integer = 1::(_ >= -1) end +""" ECODDetector(n_jobs = 1) +$(make_docs_link("ecod")) +""" +@pymodel mutable struct ECODDetector <: UnsupervisedDetector + n_jobs = 1 +end + +""" GMMDetector(n_components=1, + covariance_type="full", + tol=0.001, + reg_covar=1e-06, + max_iter=100, + n_init=1, + init_params="kmeans", + weights_init=None, + means_init=None, + precisions_init=None, + random_state=None, + warm_start=False) +$(make_docs_link("gmm")) +""" +@pymodel mutable struct GMMDetector <: UnsupervisedDetector + n_components::Integer = 1::(_ > 0) + covariance_type::String = "full"::(_ in ("full", "tied", "diag", "spherical")) + tol::Real = 0.001::(_ > 0) + reg_covar::Real = 1e-06::(_ >= 0) + max_iter::Integer = 100::(_ > 0) + n_init::Integer = 1::(_ > 0) + init_params::String = "kmeans"::(_ in ("kemans", "random")) + random_state::Union{Nothing,Integer} = nothing + warm_start::Bool = false +end + """ HBOSDetector(n_bins = 10, alpha = 0.1, tol = 0.5) @@ -70,6 +112,32 @@ $(make_docs_link("iforest")) n_jobs::Integer = 1::(_ >= -1) end +""" INNEDetector(n_estimators=200, + max_samples="auto", + random_state=None) +$(make_docs_link("inne")) +""" +@pymodel mutable struct INNEDetector <: UnsupervisedDetector + n_estimators::Integer = 200::(_ > 0) + max_samples::Union{Integer,Real,String} = "auto" + random_state::Union{Nothing,Integer} = nothing +end + +""" KDEDetector(bandwidth=1.0, + algorithm="auto", + leaf_size=30, + metric="minkowski", + metric_params=None) +$(make_docs_link("kde")) +""" +@pymodel mutable struct KDEDetector <: UnsupervisedDetector + bandwidth::Real = 1.0::(_ > 0) + algorithm::String = "auto"::(_ in ("auto", "ball_tree", "kd_tree", "brute")) + leaf_size::Integer = 30::(_ > 0) + metric::String = "minkowski"::(_ in ("cityblock", "cosine", "euclidean", "l1", "l2", "manhatten", "braycurtis", "canberra", "chebyshev", "correlation", "dice", "hamming", "jaccard", "kulsinski", "mahalanobis", "matching", "minkowski", "rogerstanimoto", "russellrao", "seuclidean", "sokalmichener", "sokalsneath", "sqeuclidean", "yule")) + metric_params::Union{Nothing,Any} = nothing +end + """ KNNDetector(n_neighbors = 5, method = "largest", radius = 1.0,