Skip to content

Commit

Permalink
Renamed AutoEncoderMLJ to AutoEncoder and started isolating MLJ model…
Browse files Browse the repository at this point in the history
…s in their own submodule
  • Loading branch information
sylvaticus committed Jan 9, 2024
1 parent 38074a9 commit df11d62
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 173 deletions.
4 changes: 3 additions & 1 deletion src/BetaML.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ include("Clustering/Clustering.jl") # Clustering (hard) algorithms
include("GMM/GMM.jl") # GMM-based learners (clustering, fitter, regression)
include("Imputation/Imputation.jl") # (Missing) imputation algorithms
include("Utils/Utils_extra.jl") # Utility functions that depend on some BetaML functionality. Set them here to avoid recursive dependence
include("Bmlj/Bmlj.jl") # MLJ Interface module

# "Merging" of the modules...
@force using .Api
Expand All @@ -50,6 +51,7 @@ include("Utils/Utils_extra.jl") # Utility functions that depend on some Beta
@reexport using .GMM
@force using .Imputation
@reexport using .Imputation
import .Bmlj # some MLJ models have the same name as BetaML models, set them in a separate interface submodule

# ------------------------------------------------------------------------------
#MLJ interface...
Expand All @@ -58,7 +60,7 @@ const MLJ_TREES_MODELS = (DecisionTreeClassifier, DecisionTreeRegressor, Ra
const MLJ_CLUSTERING_MODELS = (KMeans, KMedoids, GaussianMixtureClusterer)
const MLJ_IMPUTERS_MODELS = (SimpleImputer, GaussianMixtureImputer, RandomForestImputer,GeneralImputer) # these are the name of the MLJ models, not the BetaML ones...
const MLJ_NN_MODELS = (NeuralNetworkRegressor,MultitargetNeuralNetworkRegressor, NeuralNetworkClassifier)
const MLJ_OTHER_MODELS = (GaussianMixtureRegressor,MultitargetGaussianMixtureRegressor,AutoEncoderMLJ)
const MLJ_OTHER_MODELS = (GaussianMixtureRegressor,MultitargetGaussianMixtureRegressor,Bmlj.AutoEncoder)
const MLJ_INTERFACED_MODELS = (MLJ_PERCEPTRON_MODELS..., MLJ_TREES_MODELS..., MLJ_CLUSTERING_MODELS..., MLJ_IMPUTERS_MODELS..., MLJ_NN_MODELS..., MLJ_OTHER_MODELS...)


Expand Down
160 changes: 0 additions & 160 deletions src/Utils/Utils_MLJ.jl

This file was deleted.

3 changes: 0 additions & 3 deletions src/Utils/Utils_extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,6 @@ function inverse_predict(m::AutoEncoder,X)
end
return xtemp|> makematrix
end

include("Utils_MLJ.jl") # Utility functions that depend on some BetaML functionality. Set them here to avoid recursive dependence

end


Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLDatasets = "eb30cadb-4394-5ae3-aed4-317e484a6458"
MLJBase = "a7f614a8-145f-11e9-1d2a-a57a1082229d"
MLJTestInterface = "72560011-54dd-4dc2-94f3-c5de45b75ecd"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
Pipe = "b98c9c47-44ae-5843-9183-064241ee97a0"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Expand Down
31 changes: 22 additions & 9 deletions test/Utils_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -726,15 +726,28 @@ s2 = silhouette(pd,[1,1,2,2])
# NEW TEST
println("Testing MLJ interface for Utils....")
import MLJBase
const Mlj = MLJBase

X, y = Mlj.@load_iris
model = AutoEncoderMLJ(outdims=2,rng=copy(TESTRNG))
ae = Mlj.machine(model, X)
Mlj.fit!(ae)
X_latent = Mlj.transform(ae, X)
X_recovered = Mlj.inverse_transform(ae,X_latent)
@test relative_mean_error(Mlj.matrix(X),X_recovered) < 0.05
const MLJ = MLJBase

X, y = MLJ.@load_iris
model = BetaML.Bmlj.AutoEncoder(outdims=2,rng=copy(TESTRNG))
ae = MLJ.machine(model, X)
MLJ.fit!(ae)
X_latent = MLJ.transform(ae, X)
X_recovered = MLJ.inverse_transform(ae,X_latent)
@test relative_mean_error(MLJ.matrix(X),X_recovered) < 0.05

import MLJTestInterface

@testset "generic mlj interface test" begin
fails, summary = MLJTestInterface.test(
[BetaML.Bmlj.AutoEncoder,],
MLJTestInterface.make_regression()[1];
mod=@__MODULE__,
verbosity=0, # bump to debug
throw=false, # set to true to debug
)
@test isempty(fails)
end

#=
using Random, StableRNGs
Expand Down

0 comments on commit df11d62

Please sign in to comment.