Skip to content

Commit

Permalink
make it easier to manually pick weights based on cluster numbers in p…
Browse files Browse the repository at this point in the history
…aper, also to extract load profiles of individual simulated sessions
  • Loading branch information
SiobhanPowell committed May 20, 2022
1 parent 5fa9e77 commit e357aab
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
23 changes: 22 additions & 1 deletion HowToExtractIndividualSessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
config = SPEEChGeneralConfiguration(model)
scenario = Scenarios('BaseCase')
config.change_pg(new_weights = scenario.new_weights)
config.change_pg(new_weights = {7:0.2, 10:0.2})#scenario.new_weights)
config.change_pg(new_weights = {7:0.2, 10:0.2}, dend=True) # If you are making your own weights, use "dend=True"


# Run a version of "config.run_all":
Expand All @@ -53,3 +53,24 @@
for key in individual_session_parameters_all.keys():
if individual_session_parameters_all[key] is not None:
individual_session_parameters_all[key].to_csv('IndividualSessionsOutputData/'+key+'.csv')


# Extract the individual load profiles, not just the session parameters
categories = ['Home', 'MUD', 'Work', 'Other Slow', 'Other Fast']
total_load_profiles = {}
for segment in categories:
if individual_session_parameters_all[segment] is not None:
individual_session_parameters_all[segment] = individual_session_parameters_all[segment].reset_index(drop=True)
n_segment = len(individual_session_parameters_all[segment])

individual_profiles = {} # collect the individual load profiles
for index_value in np.arange(0, n_segment): # calculate for each session
tmp1, tmp2 = model.end_times_and_load(individual_session_parameters_all[segment].loc[index_value, 'Start'].reshape(1,), individual_session_parameters_all[segment].loc[index_value, 'Energy'].reshape(1,), individual_session_parameters_all[segment].loc[index_value, 'Rate'].reshape(1,))
individual_profiles[index_value] = tmp2
individual_profiles = pd.DataFrame(individual_profiles)
individual_profiles.to_csv('IndividualSessionsOutputData/'+segment+'_individual_load_profiles.csv', index=None) # save the individual load profiles in the same folder
total_load_profiles[segment] = individual_profiles.sum(axis=1)

total_load_profiles = pd.DataFrame(total_load_profiles)
total_load_profiles['Total'] = total_load_profiles.loc[:, categories].sum(axis=1) # calculate the total load profile as the sum of all sessions in all segments
total_load_profiles.to_csv('IndividualSessionsOutputData/total_load_profiles.csv', index=None) # save the total load profile
5 changes: 3 additions & 2 deletions SimpleExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
# Demonstration of changing group weights and behaviour weights:
model = SPEECh(data)
config = SPEEChGeneralConfiguration(model)
config.change_pg(new_weights={0: 0.5, 1: 0.5}) # Adjust distribution over driver groups so that 0 and 1 have each 50%
config.change_pg(new_weights={3: 0.5, 4: 0.5}, dend=True) # Adjust distribution over driver groups so that 0 and 1 have each 50%
# Note counting of groups starts at 0 and ends at 15 (subtract 1 from the numbering in the paper)
# (^ down-weights the others to 0 accordingly)

# Could also uncomment these two lines to use a pre-set weighting:
Expand All @@ -41,7 +42,7 @@
config.groups()
# Give weights 40% and 60% to behaviors 0 and 1 in the group 1 workplace segment:
# (down-weights the others to 0 accordingly)
config.change_ps_zg(1, 'Work', 'weekday', {0: 0.4, 1: 0.6})
config.change_ps_zg(3, 'Work', 'weekday', {0: 0.4, 1: 0.6})
config.run_all(weekday=weekday_option)
plots = Plotting(model, config)
plots.total(save_str='simple_example_plot_adjusted.png')
8 changes: 7 additions & 1 deletion speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def change_ps_zg(self, g, cat, weekday, new_weights):

self.group_configs[g].segment_gmms[weekday][cat] = gmm

def change_pg(self, new_weights, new_col='pg'):
def change_pg(self, new_weights, new_col='pg', dend=False):
"""Change the distribution over driver groups, P(g).
Parameters:
Expand All @@ -273,6 +273,12 @@ def change_pg(self, new_weights, new_col='pg'):
The input need only specify new weights for a subset of the components;
the remaining weight will be distributed among the remaining components proportionately.
"""

if dend: # If inputs are given using cluster numbers from the dendrogram
new_weights_old = copy.deepcopy(new_weights)
new_weights = {}
for key, val in new_weights_old.items():
new_weights[self.speech.data.cluster_reorder_dendtoac[key]] = val

self.speech.pg[new_col] = self.speech.pg['pg'].copy()
all_inds = np.arange(0, self.speech.data.ng)
Expand Down

0 comments on commit e357aab

Please sign in to comment.