tsam 2.1.0__py3-none-any.whl → 2.3.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tsam/periodAggregation.py CHANGED
@@ -1,141 +1,141 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- import numpy as np
4
- from tsam.representations import representations
5
-
6
-
7
- def aggregatePeriods(
8
- candidates,
9
- n_clusters=8,
10
- n_iter=100,
11
- clusterMethod="k_means",
12
- solver="cbc",
13
- representationMethod=None,
14
- representationDict=None,
15
- distributionPeriodWise=True,
16
- timeStepsPerPeriod=None,
17
- ):
18
- """
19
- Clusters the data based on one of the cluster methods:
20
- 'averaging', 'k_means', 'exact k_medoid' or 'hierarchical'
21
-
22
- :param candidates: Dissimilarity matrix where each row represents a candidate. required
23
- :type candidates: np.ndarray
24
-
25
- :param n_clusters: Number of aggregated cluster. optional (default: 8)
26
- :type n_clusters: integer
27
-
28
- :param n_iter: Only required for the number of starts of the k-mean algorithm. optional (default: 10)
29
- :type n_iter: integer
30
-
31
- :param clusterMethod: Chosen clustering algorithm. Possible values are
32
- 'averaging','k_means','exact k_medoid' or 'hierarchical'. optional (default: 'k_means')
33
- :type clusterMethod: string
34
- """
35
-
36
- # cluster the data
37
- if clusterMethod == "averaging":
38
- n_sets = len(candidates)
39
- if n_sets % n_clusters == 0:
40
- cluster_size = int(n_sets / n_clusters)
41
- clusterOrder = [
42
- [n_cluster] * cluster_size for n_cluster in range(n_clusters)
43
- ]
44
- else:
45
- cluster_size = int(n_sets / n_clusters)
46
- clusterOrder = [
47
- [n_cluster] * cluster_size for n_cluster in range(n_clusters)
48
- ]
49
- clusterOrder.append(
50
- [n_clusters - 1] * int(n_sets - cluster_size * n_clusters)
51
- )
52
- clusterOrder = np.hstack(np.array(clusterOrder))
53
- clusterCenters, clusterCenterIndices = representations(
54
- candidates,
55
- clusterOrder,
56
- default="meanRepresentation",
57
- representationMethod=representationMethod,
58
- representationDict=representationDict,
59
- distributionPeriodWise=distributionPeriodWise,
60
- timeStepsPerPeriod=timeStepsPerPeriod,
61
- )
62
-
63
- if clusterMethod == "k_means":
64
- from sklearn.cluster import KMeans
65
-
66
- k_means = KMeans(n_clusters=n_clusters, max_iter=1000, n_init=n_iter, tol=1e-4)
67
-
68
- clusterOrder = k_means.fit_predict(candidates)
69
- # get with own mean representation to avoid numerical trouble caused by sklearn
70
- clusterCenters, clusterCenterIndices = representations(
71
- candidates,
72
- clusterOrder,
73
- default="meanRepresentation",
74
- representationMethod=representationMethod,
75
- representationDict=representationDict,
76
- distributionPeriodWise=distributionPeriodWise,
77
- timeStepsPerPeriod=timeStepsPerPeriod,
78
- )
79
-
80
- if clusterMethod == "k_medoids":
81
- from tsam.utils.k_medoids_exact import KMedoids
82
-
83
- k_medoid = KMedoids(n_clusters=n_clusters, solver=solver)
84
-
85
- clusterOrder = k_medoid.fit_predict(candidates)
86
- clusterCenters, clusterCenterIndices = representations(
87
- candidates,
88
- clusterOrder,
89
- default="medoidRepresentation",
90
- representationMethod=representationMethod,
91
- representationDict=representationDict,
92
- distributionPeriodWise=distributionPeriodWise,
93
- timeStepsPerPeriod=timeStepsPerPeriod,
94
- )
95
-
96
- if clusterMethod == "k_maxoids":
97
- from tsam.utils.k_maxoids import KMaxoids
98
-
99
- k_maxoid = KMaxoids(n_clusters=n_clusters, solver=solver)
100
-
101
- clusterOrder = k_maxoid.fit_predict(candidates)
102
- clusterCenters, clusterCenterIndices = representations(
103
- candidates,
104
- clusterOrder,
105
- default="maxoidRepresentation",
106
- representationMethod=representationMethod,
107
- representationDict=representationDict,
108
- distributionPeriodWise=distributionPeriodWise,
109
- timeStepsPerPeriod=timeStepsPerPeriod,
110
- )
111
-
112
- if clusterMethod == "hierarchical" or clusterMethod == "adjacent_periods":
113
- if n_clusters == 1:
114
- clusterOrder = np.asarray([0] * len(candidates))
115
- else:
116
- from sklearn.cluster import AgglomerativeClustering
117
-
118
- if clusterMethod == "hierarchical":
119
- clustering = AgglomerativeClustering(
120
- n_clusters=n_clusters, linkage="ward"
121
- )
122
- elif clusterMethod == "adjacent_periods":
123
- adjacencyMatrix = np.eye(len(candidates), k=1) + np.eye(
124
- len(candidates), k=-1
125
- )
126
- clustering = AgglomerativeClustering(
127
- n_clusters=n_clusters, linkage="ward", connectivity=adjacencyMatrix
128
- )
129
- clusterOrder = clustering.fit_predict(candidates)
130
- # represent hierarchical aggregation with medoid
131
- clusterCenters, clusterCenterIndices = representations(
132
- candidates,
133
- clusterOrder,
134
- default="medoidRepresentation",
135
- representationMethod=representationMethod,
136
- representationDict=representationDict,
137
- distributionPeriodWise=distributionPeriodWise,
138
- timeStepsPerPeriod=timeStepsPerPeriod,
139
- )
140
-
141
- return clusterCenters, clusterCenterIndices, clusterOrder
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import numpy as np
4
+ from tsam.representations import representations
5
+
6
+
7
+ def aggregatePeriods(
8
+ candidates,
9
+ n_clusters=8,
10
+ n_iter=100,
11
+ clusterMethod="k_means",
12
+ solver="highs",
13
+ representationMethod=None,
14
+ representationDict=None,
15
+ distributionPeriodWise=True,
16
+ timeStepsPerPeriod=None,
17
+ ):
18
+ """
19
+ Clusters the data based on one of the cluster methods:
20
+ 'averaging', 'k_means', 'exact k_medoid' or 'hierarchical'
21
+
22
+ :param candidates: Dissimilarity matrix where each row represents a candidate. required
23
+ :type candidates: np.ndarray
24
+
25
+ :param n_clusters: Number of aggregated cluster. optional (default: 8)
26
+ :type n_clusters: integer
27
+
28
+ :param n_iter: Only required for the number of starts of the k-mean algorithm. optional (default: 10)
29
+ :type n_iter: integer
30
+
31
+ :param clusterMethod: Chosen clustering algorithm. Possible values are
32
+ 'averaging','k_means','exact k_medoid' or 'hierarchical'. optional (default: 'k_means')
33
+ :type clusterMethod: string
34
+ """
35
+
36
+ # cluster the data
37
+ if clusterMethod == "averaging":
38
+ n_sets = len(candidates)
39
+ if n_sets % n_clusters == 0:
40
+ cluster_size = int(n_sets / n_clusters)
41
+ clusterOrder = [
42
+ [n_cluster] * cluster_size for n_cluster in range(n_clusters)
43
+ ]
44
+ else:
45
+ cluster_size = int(n_sets / n_clusters)
46
+ clusterOrder = [
47
+ [n_cluster] * cluster_size for n_cluster in range(n_clusters)
48
+ ]
49
+ clusterOrder.append(
50
+ [n_clusters - 1] * int(n_sets - cluster_size * n_clusters)
51
+ )
52
+ clusterOrder = np.hstack(np.array(clusterOrder, dtype=object))
53
+ clusterCenters, clusterCenterIndices = representations(
54
+ candidates,
55
+ clusterOrder,
56
+ default="meanRepresentation",
57
+ representationMethod=representationMethod,
58
+ representationDict=representationDict,
59
+ distributionPeriodWise=distributionPeriodWise,
60
+ timeStepsPerPeriod=timeStepsPerPeriod,
61
+ )
62
+
63
+ if clusterMethod == "k_means":
64
+ from sklearn.cluster import KMeans
65
+
66
+ k_means = KMeans(n_clusters=n_clusters, max_iter=1000, n_init=n_iter, tol=1e-4)
67
+
68
+ clusterOrder = k_means.fit_predict(candidates)
69
+ # get with own mean representation to avoid numerical trouble caused by sklearn
70
+ clusterCenters, clusterCenterIndices = representations(
71
+ candidates,
72
+ clusterOrder,
73
+ default="meanRepresentation",
74
+ representationMethod=representationMethod,
75
+ representationDict=representationDict,
76
+ distributionPeriodWise=distributionPeriodWise,
77
+ timeStepsPerPeriod=timeStepsPerPeriod,
78
+ )
79
+
80
+ if clusterMethod == "k_medoids":
81
+ from tsam.utils.k_medoids_exact import KMedoids
82
+
83
+ k_medoid = KMedoids(n_clusters=n_clusters, solver=solver)
84
+
85
+ clusterOrder = k_medoid.fit_predict(candidates)
86
+ clusterCenters, clusterCenterIndices = representations(
87
+ candidates,
88
+ clusterOrder,
89
+ default="medoidRepresentation",
90
+ representationMethod=representationMethod,
91
+ representationDict=representationDict,
92
+ distributionPeriodWise=distributionPeriodWise,
93
+ timeStepsPerPeriod=timeStepsPerPeriod,
94
+ )
95
+
96
+ if clusterMethod == "k_maxoids":
97
+ from tsam.utils.k_maxoids import KMaxoids
98
+
99
+ k_maxoid = KMaxoids(n_clusters=n_clusters)
100
+
101
+ clusterOrder = k_maxoid.fit_predict(candidates)
102
+ clusterCenters, clusterCenterIndices = representations(
103
+ candidates,
104
+ clusterOrder,
105
+ default="maxoidRepresentation",
106
+ representationMethod=representationMethod,
107
+ representationDict=representationDict,
108
+ distributionPeriodWise=distributionPeriodWise,
109
+ timeStepsPerPeriod=timeStepsPerPeriod,
110
+ )
111
+
112
+ if clusterMethod == "hierarchical" or clusterMethod == "adjacent_periods":
113
+ if n_clusters == 1:
114
+ clusterOrder = np.asarray([0] * len(candidates))
115
+ else:
116
+ from sklearn.cluster import AgglomerativeClustering
117
+
118
+ if clusterMethod == "hierarchical":
119
+ clustering = AgglomerativeClustering(
120
+ n_clusters=n_clusters, linkage="ward"
121
+ )
122
+ elif clusterMethod == "adjacent_periods":
123
+ adjacencyMatrix = np.eye(len(candidates), k=1) + np.eye(
124
+ len(candidates), k=-1
125
+ )
126
+ clustering = AgglomerativeClustering(
127
+ n_clusters=n_clusters, linkage="ward", connectivity=adjacencyMatrix
128
+ )
129
+ clusterOrder = clustering.fit_predict(candidates)
130
+ # represent hierarchical aggregation with medoid
131
+ clusterCenters, clusterCenterIndices = representations(
132
+ candidates,
133
+ clusterOrder,
134
+ default="medoidRepresentation",
135
+ representationMethod=representationMethod,
136
+ representationDict=representationDict,
137
+ distributionPeriodWise=distributionPeriodWise,
138
+ timeStepsPerPeriod=timeStepsPerPeriod,
139
+ )
140
+
141
+ return clusterCenters, clusterCenterIndices, clusterOrder
tsam/representations.py CHANGED
@@ -1,167 +1,167 @@
1
- # -*- coding: utf-8 -*-
2
-
3
- import numpy as np
4
- from sklearn.metrics.pairwise import euclidean_distances
5
- from tsam.utils.durationRepresentation import durationRepresentation
6
-
7
-
8
- def representations(
9
- candidates,
10
- clusterOrder,
11
- default,
12
- representationMethod=None,
13
- representationDict=None,
14
- distributionPeriodWise=True,
15
- timeStepsPerPeriod=None,
16
- ):
17
- clusterCenterIndices = None
18
- if representationMethod is None:
19
- representationMethod = default
20
- if representationMethod == "meanRepresentation":
21
- clusterCenters = meanRepresentation(candidates, clusterOrder)
22
- elif representationMethod == "medoidRepresentation":
23
- clusterCenters, clusterCenterIndices = medoidRepresentation(
24
- candidates, clusterOrder
25
- )
26
- elif representationMethod == "maxoidRepresentation":
27
- clusterCenters, clusterCenterIndices = maxoidRepresentation(
28
- candidates, clusterOrder
29
- )
30
- elif representationMethod == "minmaxmeanRepresentation":
31
- clusterCenters = minmaxmeanRepresentation(
32
- candidates, clusterOrder, representationDict, timeStepsPerPeriod
33
- )
34
- elif representationMethod == "durationRepresentation" or representationMethod == "distributionRepresentation":
35
- clusterCenters = durationRepresentation(
36
- candidates, clusterOrder, distributionPeriodWise, timeStepsPerPeriod, representMinMax=False,
37
- )
38
- elif representationMethod == "distributionAndMinMaxRepresentation":
39
- clusterCenters = durationRepresentation(
40
- candidates, clusterOrder, distributionPeriodWise, timeStepsPerPeriod, representMinMax=True,
41
- )
42
- else:
43
- raise ValueError("Chosen 'representationMethod' does not exist.")
44
-
45
- return clusterCenters, clusterCenterIndices
46
-
47
-
48
- def maxoidRepresentation(candidates, clusterOrder):
49
- """
50
- Represents the candidates of a given cluster group (clusterOrder)
51
- by its medoid, measured with the euclidean distance.
52
-
53
- :param candidates: Dissimilarity matrix where each row represents a candidate. required
54
- :type candidates: np.ndarray
55
-
56
- :param clusterOrder: Integer array where the index refers to the candidate and the
57
- Integer entry to the group. required
58
- :type clusterOrder: np.array
59
- """
60
- # set cluster member that is farthest away from the points of the other clusters as maxoid
61
- clusterCenters = []
62
- clusterCenterIndices = []
63
- for clusterNum in np.unique(clusterOrder):
64
- indice = np.where(clusterOrder == clusterNum)
65
- innerDistMatrix = euclidean_distances(candidates, candidates[indice])
66
- mindistIdx = np.argmax(innerDistMatrix.sum(axis=0))
67
- clusterCenters.append(candidates[indice][mindistIdx])
68
- clusterCenterIndices.append(indice[0][mindistIdx])
69
-
70
- return clusterCenters, clusterCenterIndices
71
-
72
-
73
- def medoidRepresentation(candidates, clusterOrder):
74
- """
75
- Represents the candidates of a given cluster group (clusterOrder)
76
- by its medoid, measured with the euclidean distance.
77
-
78
- :param candidates: Dissimilarity matrix where each row represents a candidate. required
79
- :type candidates: np.ndarray
80
-
81
- :param clusterOrder: Integer array where the index refers to the candidate and the
82
- Integer entry to the group. required
83
- :type clusterOrder: np.array
84
- """
85
- # set cluster center as medoid
86
- clusterCenters = []
87
- clusterCenterIndices = []
88
- for clusterNum in np.unique(clusterOrder):
89
- indice = np.where(clusterOrder == clusterNum)
90
- innerDistMatrix = euclidean_distances(candidates[indice])
91
- mindistIdx = np.argmin(innerDistMatrix.sum(axis=0))
92
- clusterCenters.append(candidates[indice][mindistIdx])
93
- clusterCenterIndices.append(indice[0][mindistIdx])
94
-
95
- return clusterCenters, clusterCenterIndices
96
-
97
-
98
- def meanRepresentation(candidates, clusterOrder):
99
- """
100
- Represents the candidates of a given cluster group (clusterOrder)
101
- by its mean.
102
-
103
- :param candidates: Dissimilarity matrix where each row represents a candidate. required
104
- :type candidates: np.ndarray
105
-
106
- :param clusterOrder: Integer array where the index refers to the candidate and the
107
- Integer entry to the group. required
108
- :type clusterOrder: np.array
109
- """
110
- # set cluster centers as means of the group candidates
111
- clusterCenters = []
112
- for clusterNum in np.unique(clusterOrder):
113
- indice = np.where(clusterOrder == clusterNum)
114
- currentMean = candidates[indice].mean(axis=0)
115
- clusterCenters.append(currentMean)
116
- return clusterCenters
117
-
118
-
119
- def minmaxmeanRepresentation(
120
- candidates, clusterOrder, representationDict, timeStepsPerPeriod
121
- ):
122
- """
123
- Represents the candidates of a given cluster group (clusterOrder)
124
- by either the minimum, the maximum or the mean values of each time step for
125
- all periods in that cluster depending on the command for each attribute.
126
-
127
- :param candidates: Dissimilarity matrix where each row represents a candidate. required
128
- :type candidates: np.ndarray
129
-
130
- :param clusterOrder: Integer array where the index refers to the candidate and the
131
- Integer entry to the group. required
132
- :type clusterOrder: np.array
133
-
134
- :param representationDict: A dictionary which defines for each attribute whether the typical
135
- period should be represented by the minimum or maximum values within each cluster.
136
- optional (default: None)
137
- :type representationDict: dictionary
138
-
139
- :param timeStepsPerPeriod: The number of discrete timesteps which describe one period. required
140
- :type timeStepsPerPeriod: integer
141
- """
142
- # set cluster center depending of the representationDict
143
- clusterCenters = []
144
- for clusterNum in np.unique(clusterOrder):
145
- indice = np.where(clusterOrder == clusterNum)
146
- currentClusterCenter = np.zeros(len(representationDict) * timeStepsPerPeriod)
147
- for attributeNum in range(len(representationDict)):
148
- startIdx = attributeNum * timeStepsPerPeriod
149
- endIdx = (attributeNum + 1) * timeStepsPerPeriod
150
- if list(representationDict.values())[attributeNum] == "min":
151
- currentClusterCenter[startIdx:endIdx] = candidates[
152
- indice, startIdx:endIdx
153
- ].min(axis=1)
154
- elif list(representationDict.values())[attributeNum] == "max":
155
- currentClusterCenter[startIdx:endIdx] = candidates[
156
- indice, startIdx:endIdx
157
- ].max(axis=1)
158
- elif list(representationDict.values())[attributeNum] == "mean":
159
- currentClusterCenter[startIdx:endIdx] = candidates[
160
- indice, startIdx:endIdx
161
- ].mean(axis=1)
162
- else:
163
- raise ValueError(
164
- 'At least one value in the representationDict is neither "min", "max" nor "mean".'
165
- )
166
- clusterCenters.append(currentClusterCenter)
167
- return clusterCenters
1
+ # -*- coding: utf-8 -*-
2
+
3
+ import numpy as np
4
+ from sklearn.metrics.pairwise import euclidean_distances
5
+ from tsam.utils.durationRepresentation import durationRepresentation
6
+
7
+
8
+ def representations(
9
+ candidates,
10
+ clusterOrder,
11
+ default,
12
+ representationMethod=None,
13
+ representationDict=None,
14
+ distributionPeriodWise=True,
15
+ timeStepsPerPeriod=None,
16
+ ):
17
+ clusterCenterIndices = None
18
+ if representationMethod is None:
19
+ representationMethod = default
20
+ if representationMethod == "meanRepresentation":
21
+ clusterCenters = meanRepresentation(candidates, clusterOrder)
22
+ elif representationMethod == "medoidRepresentation":
23
+ clusterCenters, clusterCenterIndices = medoidRepresentation(
24
+ candidates, clusterOrder
25
+ )
26
+ elif representationMethod == "maxoidRepresentation":
27
+ clusterCenters, clusterCenterIndices = maxoidRepresentation(
28
+ candidates, clusterOrder
29
+ )
30
+ elif representationMethod == "minmaxmeanRepresentation":
31
+ clusterCenters = minmaxmeanRepresentation(
32
+ candidates, clusterOrder, representationDict, timeStepsPerPeriod
33
+ )
34
+ elif representationMethod == "durationRepresentation" or representationMethod == "distributionRepresentation":
35
+ clusterCenters = durationRepresentation(
36
+ candidates, clusterOrder, distributionPeriodWise, timeStepsPerPeriod, representMinMax=False,
37
+ )
38
+ elif representationMethod == "distributionAndMinMaxRepresentation":
39
+ clusterCenters = durationRepresentation(
40
+ candidates, clusterOrder, distributionPeriodWise, timeStepsPerPeriod, representMinMax=True,
41
+ )
42
+ else:
43
+ raise ValueError("Chosen 'representationMethod' does not exist.")
44
+
45
+ return clusterCenters, clusterCenterIndices
46
+
47
+
48
+ def maxoidRepresentation(candidates, clusterOrder):
49
+ """
50
+ Represents the candidates of a given cluster group (clusterOrder)
51
+ by its medoid, measured with the euclidean distance.
52
+
53
+ :param candidates: Dissimilarity matrix where each row represents a candidate. required
54
+ :type candidates: np.ndarray
55
+
56
+ :param clusterOrder: Integer array where the index refers to the candidate and the
57
+ Integer entry to the group. required
58
+ :type clusterOrder: np.array
59
+ """
60
+ # set cluster member that is farthest away from the points of the other clusters as maxoid
61
+ clusterCenters = []
62
+ clusterCenterIndices = []
63
+ for clusterNum in np.unique(clusterOrder):
64
+ indice = np.where(clusterOrder == clusterNum)
65
+ innerDistMatrix = euclidean_distances(candidates, candidates[indice])
66
+ mindistIdx = np.argmax(innerDistMatrix.sum(axis=0))
67
+ clusterCenters.append(candidates[indice][mindistIdx])
68
+ clusterCenterIndices.append(indice[0][mindistIdx])
69
+
70
+ return clusterCenters, clusterCenterIndices
71
+
72
+
73
+ def medoidRepresentation(candidates, clusterOrder):
74
+ """
75
+ Represents the candidates of a given cluster group (clusterOrder)
76
+ by its medoid, measured with the euclidean distance.
77
+
78
+ :param candidates: Dissimilarity matrix where each row represents a candidate. required
79
+ :type candidates: np.ndarray
80
+
81
+ :param clusterOrder: Integer array where the index refers to the candidate and the
82
+ Integer entry to the group. required
83
+ :type clusterOrder: np.array
84
+ """
85
+ # set cluster center as medoid
86
+ clusterCenters = []
87
+ clusterCenterIndices = []
88
+ for clusterNum in np.unique(clusterOrder):
89
+ indice = np.where(clusterOrder == clusterNum)
90
+ innerDistMatrix = euclidean_distances(candidates[indice])
91
+ mindistIdx = np.argmin(innerDistMatrix.sum(axis=0))
92
+ clusterCenters.append(candidates[indice][mindistIdx])
93
+ clusterCenterIndices.append(indice[0][mindistIdx])
94
+
95
+ return clusterCenters, clusterCenterIndices
96
+
97
+
98
+ def meanRepresentation(candidates, clusterOrder):
99
+ """
100
+ Represents the candidates of a given cluster group (clusterOrder)
101
+ by its mean.
102
+
103
+ :param candidates: Dissimilarity matrix where each row represents a candidate. required
104
+ :type candidates: np.ndarray
105
+
106
+ :param clusterOrder: Integer array where the index refers to the candidate and the
107
+ Integer entry to the group. required
108
+ :type clusterOrder: np.array
109
+ """
110
+ # set cluster centers as means of the group candidates
111
+ clusterCenters = []
112
+ for clusterNum in np.unique(clusterOrder):
113
+ indice = np.where(clusterOrder == clusterNum)
114
+ currentMean = candidates[indice].mean(axis=0)
115
+ clusterCenters.append(currentMean)
116
+ return clusterCenters
117
+
118
+
119
+ def minmaxmeanRepresentation(
120
+ candidates, clusterOrder, representationDict, timeStepsPerPeriod
121
+ ):
122
+ """
123
+ Represents the candidates of a given cluster group (clusterOrder)
124
+ by either the minimum, the maximum or the mean values of each time step for
125
+ all periods in that cluster depending on the command for each attribute.
126
+
127
+ :param candidates: Dissimilarity matrix where each row represents a candidate. required
128
+ :type candidates: np.ndarray
129
+
130
+ :param clusterOrder: Integer array where the index refers to the candidate and the
131
+ Integer entry to the group. required
132
+ :type clusterOrder: np.array
133
+
134
+ :param representationDict: A dictionary which defines for each attribute whether the typical
135
+ period should be represented by the minimum or maximum values within each cluster.
136
+ optional (default: None)
137
+ :type representationDict: dictionary
138
+
139
+ :param timeStepsPerPeriod: The number of discrete timesteps which describe one period. required
140
+ :type timeStepsPerPeriod: integer
141
+ """
142
+ # set cluster center depending of the representationDict
143
+ clusterCenters = []
144
+ for clusterNum in np.unique(clusterOrder):
145
+ indice = np.where(clusterOrder == clusterNum)
146
+ currentClusterCenter = np.zeros(len(representationDict) * timeStepsPerPeriod)
147
+ for attributeNum in range(len(representationDict)):
148
+ startIdx = attributeNum * timeStepsPerPeriod
149
+ endIdx = (attributeNum + 1) * timeStepsPerPeriod
150
+ if list(representationDict.values())[attributeNum] == "min":
151
+ currentClusterCenter[startIdx:endIdx] = candidates[
152
+ indice, startIdx:endIdx
153
+ ].min(axis=1)
154
+ elif list(representationDict.values())[attributeNum] == "max":
155
+ currentClusterCenter[startIdx:endIdx] = candidates[
156
+ indice, startIdx:endIdx
157
+ ].max(axis=1)
158
+ elif list(representationDict.values())[attributeNum] == "mean":
159
+ currentClusterCenter[startIdx:endIdx] = candidates[
160
+ indice, startIdx:endIdx
161
+ ].mean(axis=1)
162
+ else:
163
+ raise ValueError(
164
+ 'At least one value in the representationDict is neither "min", "max" nor "mean".'
165
+ )
166
+ clusterCenters.append(currentClusterCenter)
167
+ return clusterCenters