Skip to content

Commit f2965e4

Browse files
Merge pull request #79 from holgerteichgraeber/32bit
32bit ready
2 parents c8d5944 + a848a39 commit f2965e4

File tree

12 files changed

+88
-87
lines changed

12 files changed

+88
-87
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ keywords = ["clustering", "JuMP", "optimization"]
44
license = "MIT"
55
desc = "julia implementation of using different clustering methods for finding representative periods for the optimization of energy systems"
66
author = ["Holger Teichgraeber"]
7-
version = "0.3.2"
7+
version = "0.3.3"
88

99
[deps]
1010
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"

docs/src/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![](https://img.shields.io/badge/docs-dev-blue.svg)](https://holgerteichgraeber.github.io/ClustForOpt.jl/dev)
55
[![Build Status](https://travis-ci.com/holgerteichgraeber/ClustForOpt.jl.svg?token=HRFemjSxM1NBCsbHGNDG&branch=master)](https://travis-ci.com/holgerteichgraeber/ClustForOpt.jl)
66

7-
[ClustForOpt](https://github.com/holgerteichgraeber/ClustForOpt.jl) is a [julia](https://www.juliaopt.com) implementation of clustering methods for finding representative periods for optimization problems. A utilization in a scalable capacity expansion problem can be found in the package [CEP](https://github.com/YoungFaithful/CEP.jl).
7+
[ClustForOpt](https://github.com/holgerteichgraeber/ClustForOpt.jl) is a [julia](https://www.juliaopt.com) implementation of clustering methods for finding representative periods for optimization problems. A utilization in a scalable capacity expansion problem can be found in the package [CEP](https://github.com/YoungFaithful/CapacityExpansion.jl).
88

99
The package has two main purposes: 1) Provide a simple process of clustering time-series input data, with clustered data output in a generalized type system 2) provide an interface between clustered data and optimization problem.
1010

@@ -33,6 +33,6 @@ Install using:
3333

3434
```julia
3535
]
36-
add https://github.com/holgerteichgraeber/ClustForOpt.jl.git
36+
add ClustForOpt
3737
```
3838
where `]` opens the julia package manager.

examples/workflow_introduction.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ ts_input_data = load_timeseries_data(data_path; T=24, years=[2016])
1414

1515
#= ClustData
1616
How the struct is setup:
17-
ClustData{region::String,K::Int,T::Int,data::Dict{String,Array},weights::Array{Float64},mean::Dict{String,Array},sdv::Dict{String,Array}} <: TSData
17+
ClustData{region::String,K::Int,T::Int,data::Dict{String,Array},weights::Array{AbstractFloat},mean::Dict{String,Array},sdv::Dict{String,Array}} <: TSData
1818
-region: specifies region data belongs to
1919
-K: number of periods
2020
-T: time steps per period

src/clustering/attribute_weighting.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
function attribute_weighting(data::ClustData,attribute_weights::Dict{String,Float64})
2+
function attribute_weighting(data::ClustData,attribute_weights::Dict{String,AbstractFloat})
33
44
apply the different attribute weights based on the dictionary entry for each tech or exact name
55
"""
66
function attribute_weighting(data::ClustData,
7-
attribute_weights::Dict{String,Float64}
7+
attribute_weights::Dict{String,AbstractFloat}
88
)
99
for name in keys(data.data)
1010
tech=split(name,"-")[1]

src/clustering/exact_kmedoids.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
"Holds results of kmedoids run"
44
mutable struct kmedoidsResult
5-
medoids::Array{Float64}
5+
medoids::Array{AbstractFloat}
66
assignments::Array{Int}
7-
totalcost::Float64
7+
totalcost::AbstractFloat
88
end
99

1010

1111
"""
1212
kmedoids_exact(
13-
data::Array{Float64},
13+
data::Array{AbstractFloat},
1414
nclust::Int,
1515
_dist::SemiMetric = SqEuclidean(),
1616
env::Any;
@@ -21,7 +21,7 @@ Performs the exact kmedoids algorithm as in Kotzur et al, 2017
2121
optimizer=Gurobi.Optimizer
2222
"""
2323
function kmedoids_exact(
24-
data::Array{Float64},
24+
data::Array{AbstractFloat},
2525
nclust::Int,
2626
optimizer::DataType;
2727
_dist::SemiMetric = SqEuclidean(),

src/clustering/extreme_vals.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function simple_extr_val_ident(data::ClustData,
6767
end
6868

6969
"""
70-
simple_extr_val_ident(data::Array{Float64};extremum="max",peak_def="absolute")
70+
simple_extr_val_ident(data::Array{AbstractFloat};extremum="max",peak_def="absolute")
7171
identifies a single simple extreme period from the data and returns column index of extreme period
7272
- `data_type`: any attribute from the attributes contained within *data*
7373
- `extremum`: "min" or "max"
@@ -78,7 +78,7 @@ function simple_extr_val_ident(clust_data::ClustData,
7878
data_type::String;
7979
extremum::String="max",
8080
peak_def::String="absolute",
81-
consecutive_periods::Int64=1)
81+
consecutive_periods::Int=1)
8282
data=clust_data.data[data_type]
8383
delta_period=consecutive_periods-1
8484
# set data to be compared
@@ -168,7 +168,7 @@ function extreme_val_output(data::ClustData,
168168
end
169169
weights_ed=[]
170170
#initiate new k-ids-ed that don't represent any original time-period
171-
k_ids_ed=zeros(Int64,size(data.k_ids))
171+
k_ids_ed=zeros(Int,size(data.k_ids))
172172
if rep_mod_method == "feasibility"
173173
weights_ed = zeros(length(unique_extr_val_idcs))
174174
#no representation is done of the original time-period, it's just for feasibility

src/clustering/intraperiod_segmentation.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ function intraperiod_segmentation(data_merged::ClustDataMerged;
2828
end
2929

3030
"""
31-
run_clust_segmentation(period::Array{Float64,2};n_seg::Int=24,iterations::Int=300,norm_scope::String="full")
31+
run_clust_segmentation(period::Array{AbstractFloat,2};n_seg::Int=24,iterations::Int=300,norm_scope::String="full")
3232
!!! Not yet proven implementation of segmentation introduced by Bahl et al. 2018
3333
"""
34-
function run_clust_segmentation(period::Array{Float64,2};
34+
function run_clust_segmentation(period::Array{AbstractFloat,2};
3535
n_seg::Int=24,
3636
iterations::Int=300,
3737
norm_scope::String="full")
3838
norm_period, typely_mean, typely_sdv=z_normalize(period;scope=norm_scope)
3939
#x,weights,clustids,x,iter= run_clust_hierarchical(norm_period,n_seg,iterations)
4040
data=norm_period
41-
clustids=run_clust_hierarchical_partitional(data::Array, n_seg::Int64)
41+
clustids=run_clust_hierarchical_partitional(data::Array, n_seg::Int)
4242
weights = calc_weights(clustids,n_seg)
4343

4444

@@ -48,7 +48,7 @@ function run_clust_segmentation(period::Array{Float64,2};
4848
return centers,weights,clustids,cost,1
4949
end
5050

51-
function get_clustids(ends::Array{Int64,1})
51+
function get_clustids(ends::Array{Int,1})
5252
clustids=collect(1:size(data,2))
5353
j=1
5454
for i in 1:size(data,2)
@@ -61,12 +61,12 @@ function get_clustids(ends::Array{Int64,1})
6161
end
6262

6363
"""
64-
run_clust_hierarchical_partitional(data::Array, n_seg::Int64)
64+
run_clust_hierarchical_partitional(data::Array, n_seg::Int)
6565
!!! Not yet proven
6666
Usees provided data and number of segments to aggregate them together
6767
"""
6868
function run_clust_hierarchical_partitional(data::Array,
69-
n_seg::Int64)
69+
n_seg::Int)
7070
_dist= SqEuclidean()
7171
#Assign each timeperiod it's own cluster
7272
clustids=collect(1:size(data,2))
@@ -99,20 +99,20 @@ function run_clust_hierarchical_partitional(data::Array,
9999
end
100100

101101
"""
102-
merge_clustids!(clustids::Array{Int64,1},index::Int64)
102+
merge_clustids!(clustids::Array{Int,1},index::Int)
103103
Calculate the new clustids by merging the cluster of the index provided with the cluster of index+1
104104
"""
105-
function merge_clustids!(clustids::Array{Int64,1},index::Int64)
105+
function merge_clustids!(clustids::Array{Int,1},index::Int)
106106
clustids[index+1]=clustids[index]
107107
clustids[index+2:end].-=1
108108
end
109109

110110
"""
111-
get_mean_data(data::Array, clustids::Array{Int64,1})
111+
get_mean_data(data::Array, clustids::Array{Int,1})
112112
Calculate mean of data: The number of columns is kept the same, mean is calculated for aggregated columns and the same in all with same clustid
113113
"""
114114
function get_mean_data(data::Array,
115-
clustids::Array{Int64,1})
115+
clustids::Array{Int,1})
116116
mean_data=zeros(size(data))
117117
for i in 1:size(data,2)
118118
mean_data[:,i]=mean(data[:,findall(clustids.==clustids[i])], dims=2)

src/clustering/run_clust.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
"""
3-
run_clust(data::ClustData;norm_op::String="zscore",norm_scope::String="full",method::String="kmeans",representation::String="centroid",n_clust::Int=5,n_init::Int=100,iterations::Int=300,save::String="",attribute_weights::Dict{String,Float64}=Dict{String,Float64}(),get_all_clust_results::Bool=false,kwargs...)
3+
run_clust(data::ClustData;norm_op::String="zscore",norm_scope::String="full",method::String="kmeans",representation::String="centroid",n_clust::Int=5,n_init::Int=100,iterations::Int=300,save::String="",attribute_weights::Dict{String,AbstractFloat}=Dict{String,AbstractFloat}(),get_all_clust_results::Bool=false,kwargs...)
44
norm_op: "zscore", "01"(not implemented yet)
55
norm_scope: "full","sequence","hourly"
66
method: "kmeans","kmedoids","kmedoids_exact","hierarchical"
@@ -15,7 +15,7 @@ function run_clust(data::ClustData;
1515
n_seg::Int=data.T,
1616
n_init::Int=100,
1717
iterations::Int=300,
18-
attribute_weights::Dict{String,Float64}=Dict{String,Float64}(),
18+
attribute_weights::Dict{String,AbstractFloat}=Dict{String,AbstractFloat}(),
1919
save::String="",#QUESTION dead?
2020
get_all_clust_results::Bool=false,
2121
kwargs...
@@ -62,7 +62,7 @@ function run_clust(data_norm_merged::ClustDataMerged;
6262
n_clust::Int=5,
6363
n_init::Int=100,
6464
iterations::Int=300,
65-
orig_k_ids::Array{Int64,1}=Array{Int64,1}(),
65+
orig_k_ids::Array{Int,1}=Array{Int,1}(),
6666
kwargs...)
6767
6868
method: "kmeans","kmedoids","kmedoids_exact","hierarchical"
@@ -75,13 +75,13 @@ function run_clust(data_norm_merged::ClustDataMerged,
7575
n_clust::Int=5,
7676
n_init::Int=100,
7777
iterations::Int=300,
78-
orig_k_ids::Array{Int64,1}=Array{Int64,1}(),
78+
orig_k_ids::Array{Int,1}=Array{Int,1}(),
7979
kwargs...)
8080
# initialize data arrays
81-
centers = Array{Array{Float64},1}(undef,n_init)
81+
centers = Array{Array{AbstractFloat},1}(undef,n_init)
8282
clustids = Array{Array{Int,1},1}(undef,n_init)
83-
weights = Array{Array{Float64},1}(undef,n_init)
84-
cost = Array{Float64,1}(undef,n_init)
83+
weights = Array{Array{AbstractFloat},1}(undef,n_init)
84+
cost = Array{AbstractFloat,1}(undef,n_init)
8585
iter = Array{Int,1}(undef,n_init)
8686

8787
# clustering
@@ -346,7 +346,7 @@ end
346346
Helper function to run run_clust_hierarchical_centroids and run_clust_hierarchical_medoid
347347
"""
348348
function run_clust_hierarchical(
349-
data::Array{Float64,2},
349+
data::Array{AbstractFloat,2},
350350
n_clust::Int,
351351
iterations::Int;
352352
_dist::SemiMetric = SqEuclidean()

src/clustering/shape_based/cluster_gen_dbaclust_parallel.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ writetable(joinpath("outfiles",string("parameters_dtw_",region,".txt")),df)
6464

6565
# Function that can be an input to pmap
6666

67-
@everywhere function dbac_par_sc(n_clust::Int,i::Int,rad_sc::Int,seq::Array{Float64,2},n_init::Int,iterations::Int,inner_iterations::Int) # function to use with pmap to parallelize sc band calculation
67+
@everywhere function dbac_par_sc(n_clust::Int,i::Int,rad_sc::Int,seq::Array{AbstractFloat,2},n_init::Int,iterations::Int,inner_iterations::Int) # function to use with pmap to parallelize sc band calculation
6868

6969
rmin,rmax=sakoe_chiba_band(rad_sc,24)
7070

0 commit comments

Comments
 (0)