Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add code analyze and fix type inference #68

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: '1.9'
version: '1.10'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
5 changes: 5 additions & 0 deletions analyze/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[deps]
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"

[compat]
JET = "0.9"
5 changes: 5 additions & 0 deletions analyze/analyze.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@echo off

SET BASEPATH=%~dp0

CALL "%JULIA_1105%" --project=%BASEPATH% --load=%BASEPATH%\analyze.jl
20 changes: 20 additions & 0 deletions analyze/analyze.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Pkg
Pkg.instantiate()

using JET

Pkg.activate(dirname(@__DIR__))
Pkg.instantiate()

using UnsupervisedClustering

package_path = dirname(@__DIR__)
module_path = joinpath(package_path, "src/UnsupervisedClustering.jl")

report = report_file(module_path; analyze_from_definitions = true)
println("Report 1")
@show report

report = report_package(UnsupervisedClustering)
println("Report 2")
@show report
5 changes: 5 additions & 0 deletions analyze/analyze.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

BASEPATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

$JULIA_1105 --project=$BASEPATH $BASEPATH/analyze.jl
6 changes: 3 additions & 3 deletions src/ensemble/chain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ ClusteringChain represents a chain of clustering algorithms that are executed se
# Fields
- `algorithms`: the vector of clustering algorithms that will be executed in sequence.
"""
Base.@kwdef struct ClusteringChain <: AbstractAlgorithm
algorithms::AbstractVector{<:AbstractAlgorithm}
Base.@kwdef struct ClusteringChain{T <: AbstractAlgorithm} <: AbstractAlgorithm
algorithms::Vector{T}

function ClusteringChain(algorithms::AbstractAlgorithm...)
function ClusteringChain(algorithms::T...) where T <: AbstractAlgorithm
return new(collect(algorithms))
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/localsearch/gmm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
estimator::CovarianceMatrixEstimator
verbose::Bool = DEFAULT_VERBOSE
rng::AbstractRNG = Random.GLOBAL_RNG
tolerance::Real = DEFAULT_TOLERANCE
max_iterations::Integer = DEFAULT_MAX_ITERATIONS
tolerance::Float64 = DEFAULT_TOLERANCE
max_iterations::Int = DEFAULT_MAX_ITERATIONS
decompose_if_fails::Bool = true
)

Expand All @@ -27,8 +27,8 @@ Base.@kwdef mutable struct GMM <: AbstractAlgorithm
estimator::CovarianceMatrixEstimator
verbose::Bool = DEFAULT_VERBOSE
rng::AbstractRNG = Random.GLOBAL_RNG
tolerance::Real = DEFAULT_TOLERANCE
max_iterations::Integer = DEFAULT_MAX_ITERATIONS
tolerance::Float64 = DEFAULT_TOLERANCE
max_iterations::Int = DEFAULT_MAX_ITERATIONS
decompose_if_fails::Bool = true
end

Expand Down
8 changes: 4 additions & 4 deletions src/localsearch/kmeans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
metric::SemiMetric = SqEuclidean()
verbose::Bool = DEFAULT_VERBOSE
rng::AbstractRNG = Random.GLOBAL_RNG
tolerance::Real = DEFAULT_TOLERANCE
max_iterations::Integer = DEFAULT_MAX_ITERATIONS
tolerance::Float64 = DEFAULT_TOLERANCE
max_iterations::Int = DEFAULT_MAX_ITERATIONS
)

The k-means is a clustering algorithm that aims to partition data into clusters by minimizing the distances between data points and their cluster centroids.
Expand All @@ -28,8 +28,8 @@ Base.@kwdef mutable struct Kmeans <: AbstractAlgorithm
metric::SemiMetric = SqEuclidean()
verbose::Bool = DEFAULT_VERBOSE
rng::AbstractRNG = Random.GLOBAL_RNG
tolerance::Real = DEFAULT_TOLERANCE
max_iterations::Integer = DEFAULT_MAX_ITERATIONS
tolerance::Float64 = DEFAULT_TOLERANCE
max_iterations::Int = DEFAULT_MAX_ITERATIONS
end

@doc """
Expand Down
6 changes: 3 additions & 3 deletions src/localsearch/kmedoids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Kmedoids(
verbose::Bool = DEFAULT_VERBOSE
rng::AbstractRNG = Random.GLOBAL_RNG
tolerance::Real = DEFAULT_TOLERANCE
tolerance::Float64 = DEFAULT_TOLERANCE
max_iterations::Integer = DEFAULT_MAX_ITERATIONS
)

Expand All @@ -19,8 +19,8 @@ The k-medoids is a variation of k-means clustering algorithm that uses actual da
Base.@kwdef mutable struct Kmedoids <: AbstractAlgorithm
verbose::Bool = DEFAULT_VERBOSE
rng::AbstractRNG = Random.GLOBAL_RNG
tolerance::Real = DEFAULT_TOLERANCE
max_iterations::Integer = DEFAULT_MAX_ITERATIONS
tolerance::Float64 = DEFAULT_TOLERANCE
max_iterations::Int = DEFAULT_MAX_ITERATIONS
end

@doc """
Expand Down
6 changes: 3 additions & 3 deletions src/metaheuristic/generation.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
mutable struct Generation
population::AbstractVector{<:AbstractResult}
empty::Set{Integer}
mutable struct Generation{T <: AbstractResult}
population::Vector{T}
empty::Set{Int}

function Generation()
return new(Vector{AbstractResult}(), Set{Int}())
Expand Down
16 changes: 8 additions & 8 deletions src/metaheuristic/geneticalgorithm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
GeneticAlgorithm(
local_search::AbstractAlgorithm
verbose::Bool = DEFAULT_VERBOSE
max_iterations::Integer = 200
max_iterations_without_improvement::Integer = 150
π_min::Integer = 40
π_max::Integer = 50
max_iterations::Int = 200
max_iterations_without_improvement::Int = 150
π_min::Int = 40
π_max::Int = 50
)

GeneticAlgorithm represents a clustering algorithm that utilizes a genetic algorithm approach to optimize cluster assignments. It combines evolutionary computation and local search elements to find high-quality clustering solutions.
Expand All @@ -23,10 +23,10 @@ GeneticAlgorithm represents a clustering algorithm that utilizes a genetic algor
Base.@kwdef struct GeneticAlgorithm <: AbstractAlgorithm
local_search::AbstractAlgorithm
verbose::Bool = DEFAULT_VERBOSE
max_iterations::Integer = 200
max_iterations_without_improvement::Integer = 150
π_min::Integer = 40
π_max::Integer = 50
max_iterations::Int = 200
max_iterations_without_improvement::Int = 150
π_min::Int = 40
π_max::Int = 50
end

@doc """
Expand Down
4 changes: 2 additions & 2 deletions src/metaheuristic/multistart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
MultiStart(
local_search::AbstractAlgorithm
verbose::Bool = DEFAULT_VERBOSE
max_iterations::Integer = 200
max_iterations::Int = 200
)

The MultiStart approach repeatedly applies a clustering algorithm to generate multiple solutions with different initial points and selects the best solution.
Expand All @@ -15,7 +15,7 @@ The MultiStart approach repeatedly applies a clustering algorithm to generate mu
Base.@kwdef struct MultiStart <: AbstractAlgorithm
local_search::AbstractAlgorithm
verbose::Bool = DEFAULT_VERBOSE
max_iterations::Integer = 200
max_iterations::Int = 200
end

@doc """
Expand Down
8 changes: 4 additions & 4 deletions src/metaheuristic/randomswap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
RandomSwap(
local_search::AbstractAlgorithm
verbose::Bool = DEFAULT_VERBOSE
max_iterations::Integer = 200
max_iterations_without_improvement::Integer = 150
max_iterations::Int = 200
max_iterations_without_improvement::Int = 150
)

RandomSwap is a meta-heuristic approach used for clustering problems. It follows an iterative process that combines local optimization with perturbation to explore the search space effectively. A local optimization algorithm is applied at each iteration to converge toward a local optimum. Then, a perturbation operator generates a new starting point and continues the search.
Expand All @@ -22,8 +22,8 @@ RandomSwap is a meta-heuristic approach used for clustering problems. It follows
Base.@kwdef struct RandomSwap <: AbstractAlgorithm
local_search::AbstractAlgorithm
verbose::Bool = DEFAULT_VERBOSE
max_iterations::Integer = 200
max_iterations_without_improvement::Integer = 150
max_iterations::Int = 200
max_iterations_without_improvement::Int = 150
end

@doc """
Expand Down
4 changes: 2 additions & 2 deletions test/gmmsk.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Base.@kwdef mutable struct GMMSK <: UnsupervisedClustering.AbstractAlgorithm
verbose::Bool = false
rng::AbstractRNG = Random.GLOBAL_RNG
tolerance::Real = 1e-3
max_iterations::Integer = 1000
tolerance::Float64 = 1e-3
max_iterations::Int = 1000
end

function seed!(algorithm::GMMSK, seed::Integer)
Expand Down
Loading