Update GeMOSA v4
This commit is contained in:
@@ -20,7 +20,9 @@ class DynamicFunc(MathFunc):
|
||||
|
||||
def noise_call(self, x, timestamp, std):
|
||||
clean_y = self.__call__(x, timestamp)
|
||||
if isinstance(clean_y, np.ndarray):
|
||||
if std is None:
|
||||
noise_y = clean_y
|
||||
elif isinstance(clean_y, np.ndarray):
|
||||
noise_y = clean_y + np.random.normal(scale=std, size=clean_y.shape)
|
||||
else:
|
||||
raise ValueError("Unkonwn type: {:}".format(type(clean_y)))
|
||||
@@ -43,7 +45,7 @@ class LinearDFunc(DynamicFunc):
|
||||
return a * x + b
|
||||
|
||||
def __repr__(self):
|
||||
return "{name}({a} * {x} + {b})".format(
|
||||
return "({a} * {x} + {b})".format(
|
||||
name=self.__class__.__name__,
|
||||
a=self._params[0],
|
||||
b=self._params[1],
|
||||
@@ -69,7 +71,7 @@ class QuadraticDFunc(DynamicFunc):
|
||||
return a * x * x + b * x + c
|
||||
|
||||
def __repr__(self):
|
||||
return "{name}({a} * {x}^2 + {b} * {x} + {c})".format(
|
||||
return "({a} * {x}^2 + {b} * {x} + {c})".format(
|
||||
name=self.__class__.__name__,
|
||||
a=self._params[0],
|
||||
b=self._params[1],
|
||||
@@ -97,6 +99,39 @@ class SinQuadraticDFunc(DynamicFunc):
|
||||
|
||||
def __repr__(self):
|
||||
return "{name}({a} * {x}^2 + {b} * {x} + {c})".format(
|
||||
name="Sin",
|
||||
a=self._params[0],
|
||||
b=self._params[1],
|
||||
c=self._params[2],
|
||||
x=self.xstr,
|
||||
)
|
||||
|
||||
|
||||
class BinaryQuadraticDFunc(DynamicFunc):
|
||||
"""The dynamic quadratic function that outputs f(x) = a * x[0]^2 + b * x[1] + c >= 0.
|
||||
The a, b, and c is a function of timestamp.
|
||||
"""
|
||||
|
||||
def __init__(self, params=None):
|
||||
super(BinaryQuadraticDFunc, self).__init__(3, params)
|
||||
|
||||
def __call__(self, x, timestamp):
|
||||
self.check_valid()
|
||||
a = self._params[0](timestamp)
|
||||
b = self._params[1](timestamp)
|
||||
c = self._params[2](timestamp)
|
||||
convert_fn = lambda x: x[-1] if isinstance(x, (tuple, list)) else x
|
||||
a, b, c = convert_fn(a), convert_fn(b), convert_fn(c)
|
||||
if isinstance(x, np.ndarray) and x.shape[-1] == 2:
|
||||
results = a * x[..., 0] * x[..., 0] + b * x[..., 1] + c
|
||||
return (results >= 0).astype(np.int)
|
||||
else:
|
||||
raise ValueError(
|
||||
"Either the type {:} or the shape is incorrect.".format(type(x))
|
||||
)
|
||||
|
||||
def __repr__(self):
|
||||
return "({a} * {x}[0]^2 + {b} * {x}[1] + {c} >= 0)".format(
|
||||
name=self.__class__.__name__,
|
||||
a=self._params[0],
|
||||
b=self._params[1],
|
||||
|
Reference in New Issue
Block a user