Skip to content

Commit

Permalink
Add medoids information to the results (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
datejada authored Oct 11, 2024
1 parent 2922f4a commit 1ea0fc3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,14 @@ function find_auxiliary_data(clustering_data::AbstractDataFrame)
period_duration = maximum(clustering_data.timestep)
last_period_duration =
maximum(clustering_data[clustering_data.period .== n_periods, :timestep])
medoids = nothing

return AuxiliaryClusteringData(
key_columns,
period_duration,
last_period_duration,
n_periods,
medoids,
)
end

Expand Down Expand Up @@ -483,6 +485,7 @@ function find_representative_periods(
# Reinterpret the results
rp_matrix = clustering_matrix[:, kmedoids_result.medoids]
assignments = kmedoids_result.assignments
aux.medoids = kmedoids_result.medoids
else
throw(ArgumentError("Clustering method is not supported"))
end
Expand All @@ -507,6 +510,9 @@ function find_representative_periods(
rp = n_rp,
key_columns = aux.key_columns,
)
if method :k_medoids
append!(aux.medoids, n_complete_periods + 1)
end
end

return ClusteringResult(rp_df, weight_matrix, clustering_matrix, rp_matrix, aux)
Expand Down
4 changes: 3 additions & 1 deletion src/structures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ mutable struct AuxiliaryClusteringData
period_duration::Int
last_period_duration::Int
n_periods::Int
medoids::Union{Vector{Int}, Nothing}

function AuxiliaryClusteringData(
key_columns,
period_duration,
last_period_duration,
n_periods,
medoids,
)
return new(key_columns, period_duration, last_period_duration, n_periods)
return new(key_columns, period_duration, last_period_duration, n_periods, medoids)
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/test-cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
end
end

@testset "Data valudation" begin
@testset "Data validation" begin
@testset "Make sure that when the columns are right validation works and the key columns are found" begin
@test begin
df =
Expand Down

0 comments on commit 1ea0fc3

Please sign in to comment.