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

Method normalize

src/pymgrid/utils/space/space.py:327–340  ·  view source on GitHub ↗
(self, val)

Source from the content-addressed store, hash-verified

325 self._norm_spread[self._norm_spread == 0] = 1
326
327 def normalize(self, val):
328 un_low, un_high = self._unnormalized.low, self._unnormalized.high
329
330 self._shape_check(val, 'normalize')
331 val = self._bounds_check(val, un_low, un_high)
332
333 normalized = self._normalized.low + (self._norm_spread / self._unnorm_spread) * (val - un_low)
334
335 try:
336 if not isinstance(val, np.ndarray):
337 return normalized.item()
338 return normalized
339 except (AttributeError, ValueError):
340 return normalized
341
342 def denormalize(self, val):
343 norm_low, norm_high = self._normalized.low, self._normalized.high

Callers 8

sample_actionMethod · 0.45
to_normalizedMethod · 0.45
state_dictMethod · 0.45
convert_actionMethod · 0.45
test_normalizeMethod · 0.45

Calls 3

_bounds_checkMethod · 0.95
_shape_checkMethod · 0.80
itemMethod · 0.80