tsam 2.3.8__tar.gz → 2.3.9__tar.gz

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.
Files changed (56) hide show
  1. {tsam-2.3.8/src/tsam.egg-info → tsam-2.3.9}/PKG-INFO +1 -1
  2. {tsam-2.3.8 → tsam-2.3.9}/pyproject.toml +1 -1
  3. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/utils/durationRepresentation.py +44 -52
  4. {tsam-2.3.8 → tsam-2.3.9/src/tsam.egg-info}/PKG-INFO +1 -1
  5. {tsam-2.3.8 → tsam-2.3.9}/LICENSE.txt +0 -0
  6. {tsam-2.3.8 → tsam-2.3.9}/MANIFEST.in +0 -0
  7. {tsam-2.3.8 → tsam-2.3.9}/README.md +0 -0
  8. {tsam-2.3.8 → tsam-2.3.9}/examples/results/paretoOptimalAggregation.csv +0 -0
  9. {tsam-2.3.8 → tsam-2.3.9}/examples/results/preprocessed_wind.csv +0 -0
  10. {tsam-2.3.8 → tsam-2.3.9}/examples/results/testperiods_hierarchical.csv +0 -0
  11. {tsam-2.3.8 → tsam-2.3.9}/examples/results/testperiods_kmeans.csv +0 -0
  12. {tsam-2.3.8 → tsam-2.3.9}/examples/results/testperiods_kmedoids.csv +0 -0
  13. {tsam-2.3.8 → tsam-2.3.9}/examples/results/testperiods_predefClusterOrder.csv +0 -0
  14. {tsam-2.3.8 → tsam-2.3.9}/examples/results/testperiods_predefClusterOrderAndClusterCenters.csv +0 -0
  15. {tsam-2.3.8 → tsam-2.3.9}/examples/results/testperiods_segmentation.csv +0 -0
  16. {tsam-2.3.8 → tsam-2.3.9}/examples/testdata.csv +0 -0
  17. {tsam-2.3.8 → tsam-2.3.9}/requirements.txt +0 -0
  18. {tsam-2.3.8 → tsam-2.3.9}/requirements.yml +0 -0
  19. {tsam-2.3.8 → tsam-2.3.9}/requirements_dev.txt +0 -0
  20. {tsam-2.3.8 → tsam-2.3.9}/setup.cfg +0 -0
  21. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/__init__.py +0 -0
  22. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/hyperparametertuning.py +0 -0
  23. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/periodAggregation.py +0 -0
  24. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/representations.py +0 -0
  25. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/timeseriesaggregation.py +0 -0
  26. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/utils/__init__.py +0 -0
  27. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/utils/k_maxoids.py +0 -0
  28. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/utils/k_medoids_contiguity.py +0 -0
  29. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/utils/k_medoids_exact.py +0 -0
  30. {tsam-2.3.8 → tsam-2.3.9}/src/tsam/utils/segmentation.py +0 -0
  31. {tsam-2.3.8 → tsam-2.3.9}/src/tsam.egg-info/SOURCES.txt +0 -0
  32. {tsam-2.3.8 → tsam-2.3.9}/src/tsam.egg-info/dependency_links.txt +0 -0
  33. {tsam-2.3.8 → tsam-2.3.9}/src/tsam.egg-info/requires.txt +0 -0
  34. {tsam-2.3.8 → tsam-2.3.9}/src/tsam.egg-info/top_level.txt +0 -0
  35. {tsam-2.3.8 → tsam-2.3.9}/test/test_accuracyIndicators.py +0 -0
  36. {tsam-2.3.8 → tsam-2.3.9}/test/test_adjacent_periods.py +0 -0
  37. {tsam-2.3.8 → tsam-2.3.9}/test/test_aggregate_hiearchical.py +0 -0
  38. {tsam-2.3.8 → tsam-2.3.9}/test/test_assert_raises.py +0 -0
  39. {tsam-2.3.8 → tsam-2.3.9}/test/test_averaging.py +0 -0
  40. {tsam-2.3.8 → tsam-2.3.9}/test/test_cluster_order.py +0 -0
  41. {tsam-2.3.8 → tsam-2.3.9}/test/test_durationCurve.py +0 -0
  42. {tsam-2.3.8 → tsam-2.3.9}/test/test_durationRepresentation.py +0 -0
  43. {tsam-2.3.8 → tsam-2.3.9}/test/test_extremePeriods.py +0 -0
  44. {tsam-2.3.8 → tsam-2.3.9}/test/test_hierarchical.py +0 -0
  45. {tsam-2.3.8 → tsam-2.3.9}/test/test_hypertuneAggregation.py +0 -0
  46. {tsam-2.3.8 → tsam-2.3.9}/test/test_k_maxoids.py +0 -0
  47. {tsam-2.3.8 → tsam-2.3.9}/test/test_k_medoids.py +0 -0
  48. {tsam-2.3.8 → tsam-2.3.9}/test/test_k_medoids_contiguity.py +0 -0
  49. {tsam-2.3.8 → tsam-2.3.9}/test/test_minmaxRepresentation.py +0 -0
  50. {tsam-2.3.8 → tsam-2.3.9}/test/test_preprocess.py +0 -0
  51. {tsam-2.3.8 → tsam-2.3.9}/test/test_properties.py +0 -0
  52. {tsam-2.3.8 → tsam-2.3.9}/test/test_samemean.py +0 -0
  53. {tsam-2.3.8 → tsam-2.3.9}/test/test_segmentation.py +0 -0
  54. {tsam-2.3.8 → tsam-2.3.9}/test/test_subhourlyResolution.py +0 -0
  55. {tsam-2.3.8 → tsam-2.3.9}/test/test_subhourly_periods.py +0 -0
  56. {tsam-2.3.8 → tsam-2.3.9}/test/test_weightingFactors.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tsam
3
- Version: 2.3.8
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>
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
 
6
6
  [project]
7
7
  name = "tsam"
8
- version = "2.3.8"
8
+ version = "2.3.9"
9
9
  description = "Time series aggregation module (tsam) to create typical periods"
10
10
  authors = [
11
11
  { name = "Leander Kotzur", email = "leander.kotzur@googlemail.com" },
@@ -28,69 +28,61 @@ def durationRepresentation(
28
28
  :type representMinMax: bool
29
29
  """
30
30
 
31
- # Convert candidates to numpy array at the beginning if it's a DataFrame
32
- if isinstance(candidates, pd.DataFrame):
33
- candidates_array = candidates.values
34
- else:
35
- candidates_array = candidates
36
-
37
- # Create a pandas DataFrame only when necessary
38
- columnTuples = [(i, j) for i in range(int(candidates_array.shape[1] / timeStepsPerPeriod))
39
- for j in range(timeStepsPerPeriod)]
40
-
31
+ # make pd.DataFrame each row represents a candidate, and the columns are defined by two levels: the attributes and
32
+ # the time steps inside the candidates.
33
+ columnTuples = []
34
+ num_attributes = int(candidates.shape[1] / timeStepsPerPeriod)
35
+ for i in range(num_attributes):
36
+ for j in range(timeStepsPerPeriod):
37
+ columnTuples.append((i, j))
41
38
  candidates_df = pd.DataFrame(
42
- candidates_array, columns=pd.MultiIndex.from_tuples(columnTuples)
39
+ candidates, columns=pd.MultiIndex.from_tuples(columnTuples)
43
40
  )
44
-
41
+
42
+ # There are two options for the duration representation. Either, the distribution of each cluster is preserved
43
+ # (periodWise = True) or the distribution of the total time series is preserved only. In the latter case, the
44
+ # inner-cluster variance is smaller and the variance across the typical periods' mean values is higher
45
45
  if distributionPeriodWise:
46
46
  clusterCenters = []
47
- unique_clusters = np.unique(clusterOrder)
48
-
49
- for clusterNum in unique_clusters:
47
+
48
+ for clusterNum in np.unique(clusterOrder):
50
49
  indice = np.where(clusterOrder == clusterNum)[0]
51
50
  noCandidates = len(indice)
51
+
52
+ # Skip empty clusters
53
+ if len(indice) == 0:
54
+ continue
52
55
 
53
- # Pre-allocate the full cluster center array
54
- cluster_values_count = noCandidates * timeStepsPerPeriod * len(candidates_df.columns.levels[0])
55
- clusterCenter = np.zeros(cluster_values_count)
56
- current_idx = 0
57
-
56
+ # This list will hold the representative values for each attribute
57
+ clusterCenter_parts = []
58
+
58
59
  for a in candidates_df.columns.levels[0]:
59
- # Get values using numpy indexing when possible
60
- candidateValues = candidates_df.loc[indice, a].values
61
-
62
- # Reshape to more easily work with numpy
63
- candidateValues_reshaped = candidateValues.reshape(-1)
64
-
65
- # Sort values using numpy
66
- sorted_values = np.sort(candidateValues_reshaped)
67
-
68
- # Calculate representative values directly
69
- values_per_timestep = noCandidates
70
- representation_values = np.zeros(timeStepsPerPeriod)
71
-
72
- for t in range(timeStepsPerPeriod):
73
- start_idx = t * values_per_timestep
74
- end_idx = start_idx + values_per_timestep
75
- representation_values[t] = np.mean(sorted_values[start_idx:end_idx])
76
-
77
- # Handle min/max representation if needed
60
+
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
78
70
  if representMinMax:
79
- representation_values[0] = sorted_values[0]
80
- representation_values[-1] = sorted_values[-1]
81
-
82
- # Re-order values based on the mean of candidate values
83
- mean_values = np.mean(candidateValues, axis=0)
84
- order_indices = np.argsort(mean_values)
85
-
86
- # Reorder representation values
87
- representation_values_ordered = representation_values[order_indices]
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))
88
77
 
89
- # Add to cluster center
90
- clusterCenter[current_idx:current_idx+len(representation_values)] = representation_values_ordered
91
- current_idx += len(representation_values)
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
92
81
 
93
- clusterCenters.append(clusterCenter[:current_idx]) # Trim if we didn't use the whole pre-allocation
82
+ # add to cluster center
83
+ clusterCenter_parts.append(final_representation_for_attr)
84
+
85
+ clusterCenters.append(np.concatenate(clusterCenter_parts))
94
86
 
95
87
  else:
96
88
  clusterCentersList = []
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tsam
3
- Version: 2.3.8
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>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes