tsam 2.3.7__py3-none-any.whl → 2.3.9__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/utils/durationRepresentation.py +41 -38
- {tsam-2.3.7.dist-info → tsam-2.3.9.dist-info}/METADATA +1 -1
- {tsam-2.3.7.dist-info → tsam-2.3.9.dist-info}/RECORD +6 -6
- {tsam-2.3.7.dist-info → tsam-2.3.9.dist-info}/WHEEL +0 -0
- {tsam-2.3.7.dist-info → tsam-2.3.9.dist-info}/licenses/LICENSE.txt +0 -0
- {tsam-2.3.7.dist-info → tsam-2.3.9.dist-info}/top_level.txt +0 -0
|
@@ -31,10 +31,11 @@ def durationRepresentation(
|
|
|
31
31
|
# make pd.DataFrame each row represents a candidate, and the columns are defined by two levels: the attributes and
|
|
32
32
|
# the time steps inside the candidates.
|
|
33
33
|
columnTuples = []
|
|
34
|
-
|
|
34
|
+
num_attributes = int(candidates.shape[1] / timeStepsPerPeriod)
|
|
35
|
+
for i in range(num_attributes):
|
|
35
36
|
for j in range(timeStepsPerPeriod):
|
|
36
37
|
columnTuples.append((i, j))
|
|
37
|
-
|
|
38
|
+
candidates_df = pd.DataFrame(
|
|
38
39
|
candidates, columns=pd.MultiIndex.from_tuples(columnTuples)
|
|
39
40
|
)
|
|
40
41
|
|
|
@@ -43,54 +44,56 @@ def durationRepresentation(
|
|
|
43
44
|
# inner-cluster variance is smaller and the variance across the typical periods' mean values is higher
|
|
44
45
|
if distributionPeriodWise:
|
|
45
46
|
clusterCenters = []
|
|
47
|
+
|
|
46
48
|
for clusterNum in np.unique(clusterOrder):
|
|
47
|
-
indice = np.where(clusterOrder == clusterNum)
|
|
48
|
-
noCandidates = len(indice
|
|
49
|
-
clean_index = []
|
|
50
|
-
|
|
51
|
-
clusterCenter = []
|
|
52
|
-
# get a clean index depending on the size
|
|
53
|
-
for y in candidates.columns.levels[1]:
|
|
54
|
-
for x in range(noCandidates):
|
|
55
|
-
clean_index.append((x, y))
|
|
56
|
-
for a in candidates.columns.levels[0]:
|
|
57
|
-
# get all the values of a certain attribute and cluster
|
|
58
|
-
candidateValues = candidates.loc[indice[0], a]
|
|
59
|
-
# sort all values
|
|
60
|
-
sortedAttr = candidateValues.stack(
|
|
61
|
-
future_stack=True,
|
|
62
|
-
).sort_values()
|
|
63
|
-
# reindex and arrange such that every sorted segment gets represented by its mean
|
|
64
|
-
sortedAttr.index = pd.MultiIndex.from_tuples(clean_index)
|
|
65
|
-
representationValues = sortedAttr.unstack(level=0).mean(axis=1)
|
|
66
|
-
# respect max and min of the attributes
|
|
67
|
-
if representMinMax:
|
|
68
|
-
representationValues.loc[0] = sortedAttr.values[0]
|
|
69
|
-
representationValues.loc[representationValues.index[-1]] = (
|
|
70
|
-
sortedAttr.values[-1]
|
|
71
|
-
)
|
|
49
|
+
indice = np.where(clusterOrder == clusterNum)[0]
|
|
50
|
+
noCandidates = len(indice)
|
|
72
51
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
52
|
+
# Skip empty clusters
|
|
53
|
+
if len(indice) == 0:
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
# This list will hold the representative values for each attribute
|
|
57
|
+
clusterCenter_parts = []
|
|
78
58
|
|
|
79
|
-
|
|
80
|
-
clusterCenter = np.append(clusterCenter, representationValues.values)
|
|
59
|
+
for a in candidates_df.columns.levels[0]:
|
|
81
60
|
|
|
82
|
-
|
|
61
|
+
candidateValues_np = candidates_df.loc[indice, a].values
|
|
62
|
+
|
|
63
|
+
# flatten the 2D array (candidates, timesteps) into a 1D array and sort it.
|
|
64
|
+
sorted_flat_values = np.sort(candidateValues_np.flatten())
|
|
65
|
+
|
|
66
|
+
# reshape the sorted values and calculate the mean for each representative time step.
|
|
67
|
+
representationValues_np = sorted_flat_values.reshape(timeStepsPerPeriod, noCandidates).mean(axis=1)
|
|
68
|
+
|
|
69
|
+
# respect max and min of the attributes
|
|
70
|
+
if representMinMax:
|
|
71
|
+
representationValues_np[0] = sorted_flat_values[0]
|
|
72
|
+
representationValues_np[-1] = sorted_flat_values[-1]
|
|
73
|
+
|
|
74
|
+
# get the order of the representation values such that euclidean distance
|
|
75
|
+
# to the candidates' mean profile is minimized.
|
|
76
|
+
mean_profile_order = np.argsort(candidateValues_np.mean(axis=0))
|
|
77
|
+
|
|
78
|
+
# Create an empty array to place the results in the correct order
|
|
79
|
+
final_representation_for_attr = np.empty_like(representationValues_np)
|
|
80
|
+
final_representation_for_attr[mean_profile_order] = representationValues_np
|
|
81
|
+
|
|
82
|
+
# add to cluster center
|
|
83
|
+
clusterCenter_parts.append(final_representation_for_attr)
|
|
83
84
|
|
|
85
|
+
clusterCenters.append(np.concatenate(clusterCenter_parts))
|
|
86
|
+
|
|
84
87
|
else:
|
|
85
88
|
clusterCentersList = []
|
|
86
|
-
for a in
|
|
89
|
+
for a in candidates_df.columns.levels[0]:
|
|
87
90
|
meanVals = []
|
|
88
91
|
clusterLengths = []
|
|
89
92
|
for clusterNum in np.unique(clusterOrder):
|
|
90
93
|
indice = np.where(clusterOrder == clusterNum)
|
|
91
94
|
noCandidates = len(indice[0])
|
|
92
95
|
# get all the values of a certain attribute and cluster
|
|
93
|
-
candidateValues =
|
|
96
|
+
candidateValues = candidates_df.loc[indice[0], a]
|
|
94
97
|
# calculate centroid of each cluster and append to list
|
|
95
98
|
meanVals.append(candidateValues.mean())
|
|
96
99
|
# make a list of weights of each cluster for each time step within the period
|
|
@@ -113,7 +116,7 @@ def durationRepresentation(
|
|
|
113
116
|
order = meansAndWeightsSorted.index
|
|
114
117
|
# sort all values of the original time series
|
|
115
118
|
sortedAttr = (
|
|
116
|
-
|
|
119
|
+
candidates_df.loc[:, a]
|
|
117
120
|
.stack(
|
|
118
121
|
future_stack=True,
|
|
119
122
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tsam
|
|
3
|
-
Version: 2.3.
|
|
3
|
+
Version: 2.3.9
|
|
4
4
|
Summary: Time series aggregation module (tsam) to create typical periods
|
|
5
5
|
Author-email: Leander Kotzur <leander.kotzur@googlemail.com>, Maximilian Hoffmann <maximilian.hoffmann@julumni.fz-juelich.de>
|
|
6
6
|
Maintainer-email: Julian Belina <j.belina@fz-juelich.de>
|
|
@@ -4,13 +4,13 @@ tsam/periodAggregation.py,sha256=h9CC06jBLNyyaFTMRynGUMN87fOH3NdSEug6EcTsKGA,547
|
|
|
4
4
|
tsam/representations.py,sha256=2NL1wanBhGreCeJ8jh0aNdIx05YXEyyMJmMAVFS5-T4,7133
|
|
5
5
|
tsam/timeseriesaggregation.py,sha256=UdsjsP8RAwmdBHq0wJwB2HfUai538NYRQkK31TR9dBM,57125
|
|
6
6
|
tsam/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
-
tsam/utils/durationRepresentation.py,sha256=
|
|
7
|
+
tsam/utils/durationRepresentation.py,sha256=mPUmK1Q_0gIQ0GBl-NQK4seXLfX02AsrDAU2UolrwJM,9796
|
|
8
8
|
tsam/utils/k_maxoids.py,sha256=0PyaHQMA8vtV_SuQOZ0qdcGFK46aUvOiMSQofjGkjBQ,4415
|
|
9
9
|
tsam/utils/k_medoids_contiguity.py,sha256=xSN9xT61oc2CPxYERhugR9hDkVCb2o8POvAiLLgrey8,5925
|
|
10
10
|
tsam/utils/k_medoids_exact.py,sha256=CW6BLQV2eTYtMxDmo97-6hY1HljxcvkPVrL4DQPN5IQ,7178
|
|
11
11
|
tsam/utils/segmentation.py,sha256=y8TPv1KEqf6ByOz7TRywm3WC9ZPhGiWvhwAcQbFibt4,6132
|
|
12
|
-
tsam-2.3.
|
|
13
|
-
tsam-2.3.
|
|
14
|
-
tsam-2.3.
|
|
15
|
-
tsam-2.3.
|
|
16
|
-
tsam-2.3.
|
|
12
|
+
tsam-2.3.9.dist-info/licenses/LICENSE.txt,sha256=XEzEzumoCmdJzcp5gKT6UOtKrkH-SiGpxVbIfihkNK4,1224
|
|
13
|
+
tsam-2.3.9.dist-info/METADATA,sha256=rFczPzsNRAGeYOqnhvswQrNeurdHI4P9FzaUbniQMUs,15412
|
|
14
|
+
tsam-2.3.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
15
|
+
tsam-2.3.9.dist-info/top_level.txt,sha256=MFI15PnPuMv8F1hTAOXbjGu41z-l6dJbnK69WlIQNcM,5
|
|
16
|
+
tsam-2.3.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|