Description
Some refactoring is needed and we are more or less ready for this changes. I put them all here together, but they can be split later into separate issues.
- Refactor
init
- Decide on algorithms type (or "distance type can be different from
X
") - Document algorithms separately
- Drop extra fields from result.
Below is a short description of these problems.
- Refactor
init
.
Currentlyinit
is redundant, since we haveinit
andinit_k
and some weird logic, which one to choose. Correct solution is to use multiple dispatch, add additional functioncreate_seed
which should accept argumentinit
(and all other necessary arguments). Ifinit
is String orSymbol
it should fall tosmart_init
, ifNothing
then defaultkmeans++
, otherwise return deepcopy of the init.
All of this should happen in kmeans
(before kmeans!
), so duplicated copy is avoided.
- Decide on algorithms type (distance may have different type)
Currently we inferdistance
type from the type of the design matrix. This can be wrong, for example, ifX
eltype
isRGB
orComplex
, then distance can have different type, usuallyFloat64
orFloat32
.
This can be solved by turning all algorithms to parametric, for example
Lloyd{Float64, Float64}
and we can define something like this
struct Foo{T1, T2} end
Foo{T1}() where {T1} = Foo{T1, T1}()
Foo() = Foo{Float64, Float64}()
Foo{Float64}() # Foo{Float64, Float64}
Foo() # Foo{Float64, Float64}
It make it somewhat more verbose, and constraint to the design matrix type, but on the other hand it's more Julia like.
On the other hand, currently we infer everything from the matrices itself and distance type can be kmeans
argument. I think it can work, but it looks weird.
- Better documentation
I think it would be better for users to come to the documentation and see separate page, where all algorithms and their usage is described, especially taking into account the fact that we soon will add stochastic algorithms (coresets and minibatch). It can be organized as follows;
- Full scan algorithms
-- Lloyd
-- Elkan
-- Hamerly
-- Yinyang - Stochastic algortihms
-- Coresets
-- MiniBatch
- Drop extra fields from results.
Currently we have lots of redundant fields in result, which are not used, and I think they shouldn't be added, since they can be always calculated from all current data result. This extra information shouldn't be calculated inside kmeans
, there should be separate set of utility functions, which can be invoked if need arise.