Skip to content

Commit

Permalink
improves support for new database abstractions
Browse files Browse the repository at this point in the history
  • Loading branch information
sadit committed May 2, 2022
1 parent 9efca5b commit f085fd8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KNearestCenters"
uuid = "4dca28ae-43b8-11eb-1f5e-d55054101997"
authors = ["Eric S. Tellez"]
version = "0.6.2"
version = "0.7.0"

[deps]
CategoricalArrays = "324d7699-5711-5eae-9e2f-1d82baa6b597"
Expand All @@ -17,7 +17,7 @@ StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
CategoricalArrays = "0.8, 0.9, 0.10"
KCenters = "0.5.0"
KCenters = "0.6"
MLDataUtils = "0.5"
Parameters = "0.12"
SearchModels = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion src/knc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ end
Creates a Knc classifier using the given configuration and data.
"""
function Knc(config::KncConfig, X, y::CategoricalArray; verbose=true)
function Knc(config::KncConfig, X::AbstractDatabase, y::CategoricalArray; verbose=true)
# computes a set of #labels centers using labels for clustering
D = kcenters(config.kernel.dist, X, y, config.centerselection)
@assert length(levels(y)) == length(D.centers)
Expand Down
13 changes: 6 additions & 7 deletions src/kncproto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ end
Creates a KncProto classifier using the given configuration and data.
"""
function KncProto(config::KncProtoConfig, X, y::CategoricalArray; verbose=true)
function KncProto(config::KncProtoConfig, X::AbstractDatabase, y::CategoricalArray; verbose=true)
config.ncenters == 0 && error("invalid ncenter $ncenters; ncenters <= -2 or 2 <= ncenters; please use plain Knc otherwise")
X = convert(AbstractDatabase, X)
if config.ncenters > 0
# computes a set of ncenters for all dataset
verbose && println(stderr, "KncProto> clustering data without knowing labels", config)
Expand All @@ -144,7 +143,7 @@ function KncProto(config::KncProtoConfig, X, y::CategoricalArray; verbose=true)
ncenters = abs(config.ncenters)
verbose && println(stderr, "KncProto> clustering data with label division", config)
nclasses = length(levels(y))
centers = VectorDatabase(eltype(X))
centers = eltype(X)[]
dmax = Float32[]
class_map = Int32[]
nclasses = length(levels(y))
Expand All @@ -170,19 +169,19 @@ function KncProto(config::KncProtoConfig, X, y::CategoricalArray; verbose=true)
end
end

KncProto(config, centers, dmax, class_map, convert(Int32, nclasses), KnnResult(1))
KncProto(config, VectorDatabase(centers), dmax, class_map, convert(Int32, nclasses), KnnResult(1))
end
end

function KncProto(
config::KncProtoConfig,
input_clusters::ClusteringData,
train_X,
train_X::AbstractDatabase,
train_y::CategoricalArray;
verbose=false
)
train_X = convert(AbstractDatabase, train_X)
centers = VectorDatabase(eltype(train_X)) # clusters
centers = eltype(train_X)[] # clusters
classes = Int32[] # class mapping between clusters and classes
dmax = Float32[]
ncenters = length(input_clusters.centers)
Expand Down Expand Up @@ -243,7 +242,7 @@ function KncProto(
end

verbose && println(stderr, "finished with $(length(centers)) centers; started with $(length(input_clusters.centers))")
KncProto(config, centers, dmax, classes, convert(Int32, nclasses), KnnResult(1))
KncProto(config, VectorDatabase(centers), dmax, classes, convert(Int32, nclasses), KnnResult(1))
end

"""
Expand Down
4 changes: 2 additions & 2 deletions test/loaddata.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file is a part of KNearestCenters.jl

using Test
using Test, SimilaritySearch

function loadiris()
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data"
Expand All @@ -19,7 +19,7 @@ function loadiris()
push!(y, arr[end])
end

X, y
VectorDatabase(X), y
end


Expand Down

2 comments on commit f085fd8

@sadit
Copy link
Owner Author

@sadit sadit commented on f085fd8 May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/59522

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.7.0 -m "<description of version>" f085fd84ae458b911938c3c97bfec2455a295a98
git push origin v0.7.0

Please sign in to comment.