Skip to content
Snippets Groups Projects
Commit c40e57bb authored by Laura Christine Kühle's avatar Laura Christine Kühle
Browse files

Added 'randomize()' and 'is_smooth()'for functions used for training data.

parent c8bc8a2a
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,12 @@ class InitialCondition(object):
def get_name(self):
return self.__class__.__name__
def is_smooth(self):
return True
def randomize(self):
pass
def calculate(self, x):
while x < self._left_bound:
x = x + self._interval_len
......@@ -37,6 +43,10 @@ class Sine(InitialCondition):
# Unpack necessary configurations
self._factor = config.pop('factor', 2)
def randomize(self):
config = {'factor': 2}
self._reset(config)
def _get_point(self, x):
return np.sin(self._factor * np.pi * x)
......@@ -52,6 +62,9 @@ class Box(InitialCondition):
else:
return 0
def is_smooth(self):
return False
class FourPeakWave(InitialCondition):
def _reset(self, config):
......@@ -64,6 +77,9 @@ class FourPeakWave(InitialCondition):
self._a = 0.5
self._z = -0.7
def is_smooth(self):
return False
def _get_point(self, x):
if (x >= -0.8) & (x <= -0.6):
return 1/6 * (self._gaussian_function(x, self._z-self._delta)
......@@ -93,6 +109,11 @@ class Linear(InitialCondition):
# Unpack necessary configurations
self._factor = config.pop('factor', 1)
def randomize(self):
a = np.random.uniform(low=-100, high=100)
config = {'factor': a}
self._reset(config)
def _get_point(self, x):
return self._factor * x
......@@ -104,6 +125,14 @@ class LinearAbsolut(InitialCondition):
# Unpack necessary configurations
self._factor = config.pop('factor', 1)
def is_smooth(self):
return False
def randomize(self):
a = np.random.uniform(low=-100, high=100)
config = {'factor': a}
self._reset(config)
def _get_point(self, x):
return self._factor * abs(x)
......@@ -119,3 +148,77 @@ class DiscontinuousConstant(InitialCondition):
def _get_point(self, x):
return self._left_factor * (x <= self._x0) + self._right_factor * (x > self._x0)
class Polynomial(InitialCondition):
def _reset(self, config):
super()._reset(config)
# Unpack necessary configurations
self._factor = config.pop('factor', 1)
self._exponential = config.pop('exponential', 2)
def randomize(self):
a = np.random.uniform(low=-100, high=100)
k = np.random.randint(2, high=6)
config = {'factor': a, 'exponential': k}
self._reset(config)
def _get_point(self, x):
return self._factor * (x ** self._exponential)
class Continuous(InitialCondition):
def _reset(self, config):
super()._reset(config)
# Unpack necessary configurations
self._factor = config.pop('factor', 1)
def randomize(self):
a = np.random.uniform(low=-100, high=100)
config = {'factor': a}
self._reset(config)
def _get_point(self, x):
return self._factor
class HeavisideOneSided(InitialCondition):
def _reset(self, config):
super()._reset(config)
# Unpack necessary configurations
self._factor = config.pop('factor', -1)
def is_smooth(self):
return False
def randomize(self):
a = np.random.choice([-1, 1])
config = {'factor': a}
self._reset(config)
def _get_point(self, x):
return self._factor - 2 * self._factor * np.heaviside(x, 0)
class HeavisideTwoSided(InitialCondition):
def _reset(self, config):
super()._reset(config)
# Unpack necessary configurations
self._left_factor = config.pop('left_factor', 1)
self._right_factor = config.pop('right_factor', 2)
def is_smooth(self):
return False
def randomize(self):
a = np.random.choice([-1, 1])
b = np.random.choice([-1, 1])
config = {'left_factor': a, 'right_factor': b}
self._reset(config)
def _get_point(self, x):
return self._left_factor - self._left_factor * np.heaviside(x, 0) - self._right_factor * np.heaviside(x, 0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment