-
Notifications
You must be signed in to change notification settings - Fork 745
Expand file tree
/
Copy pathnoises.py
More file actions
87 lines (70 loc) · 3.04 KB
/
noises.py
File metadata and controls
87 lines (70 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Copyright 2018 The dm_control Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Meta-variations that modify original values by a specified variation."""
from dm_control.composer.variation import base
from dm_control.composer.variation import variation_values
class Additive(base.Variation):
"""A variation that adds to an existing value.
This variation takes a value generated by another variation and adds it to an
existing value. In cumulative mode, the generated value is added to the
current value being varied. In non-cumulative mode, the generated value is
added to a fixed initial value.
"""
def __init__(self, variation, cumulative=False):
self._variation = variation
self._cumulative = cumulative
def __call__(self, initial_value=None, current_value=None, random_state=None):
base_value = current_value if self._cumulative else initial_value
return base_value + (
variation_values.evaluate(self._variation, initial_value, current_value,
random_state))
def __eq__(self, other):
if not isinstance(other, Additive):
return False
return (
self._variation == other._variation
and self._cumulative == other._cumulative
)
def __repr__(self):
return (
f"Additive(variation={self._variation}, cumulative={self._cumulative})"
)
class Multiplicative(base.Variation):
"""A variation that multiplies to an existing value.
This variation takes a value generated by another variation and multiplies it
to an existing value. In cumulative mode, the generated value is multiplied to
the current value being varied. In non-cumulative mode, the generated value is
multiplied to a fixed initial value.
"""
def __init__(self, variation, cumulative=False):
self._variation = variation
self._cumulative = cumulative
def __call__(self, initial_value=None, current_value=None, random_state=None):
base_value = current_value if self._cumulative else initial_value
return base_value * (
variation_values.evaluate(self._variation, initial_value, current_value,
random_state))
def __eq__(self, other):
if not isinstance(other, Multiplicative):
return False
return (
self._variation == other._variation
and self._cumulative == other._cumulative
)
def __repr__(self):
return (
f"Multiplicative(variation={self._variation}, "
f"cumulative={self._cumulative})"
)