MCPcopy Create free account
hub / github.com/ahalev/python-microgrid / to_normalized

Method to_normalized

src/pymgrid/microgrid/microgrid.py:409–430  ·  view source on GitHub ↗

Normalize an action or observation. Parameters ---------- data_dict : dict[str, list[int]] Action or observation to normalize. Dictionary keys are names of the modules while dictionary values are lists containing an action corresponding to al

(self, data_dict, act=False, obs=False)

Source from the content-addressed store, hash-verified

407 if module_list[0].action_space.shape[0]}
408
409 def to_normalized(self, data_dict, act=False, obs=False):
410 """
411 Normalize an action or observation.
412
413 Parameters
414 ----------
415 data_dict : dict[str, list[int]]
416 Action or observation to normalize. Dictionary keys are names of the modules while dictionary values
417 are lists containing an action corresponding to all modules with that name.
418 act : bool, default False
419 Set to True if you are normalizing an action.
420 obs : bool, default False
421 Set to True if you are normalizing an observation.
422
423 Returns
424 -------
425 dict[str, list[float]]
426 Normalized action.
427 """
428 assert act + obs == 1, 'One of act or obs must be True but not both.'
429 return {module_name: [module.to_normalized(value, act=act, obs=obs) for module, value in zip(module_list, data_dict[module_name])]
430 for module_name, module_list in self._modules.iterdict() if module_name in data_dict}
431
432 def from_normalized(self, data_dict, act=False, obs=False):
433 """

Callers 3

test_stepMethod · 0.45
test_stepMethod · 0.45
test_stepMethod · 0.45

Calls 1

iterdictMethod · 0.80

Tested by 3

test_stepMethod · 0.36
test_stepMethod · 0.36
test_stepMethod · 0.36