-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.py
47 lines (40 loc) · 1.22 KB
/
functions.py
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
import numpy as np
from numpy import random, sin, cos, tan, sqrt, exp, log, abs, floor, ceil
from math import log, pi
points = 20
class Function:
def __init__(self, func, x_dom, y_test, label):
self.func = func
self.x_dom = x_dom
self.y_test = y_test
self.label = label
def __call__(self, x):
return self.func(x)
class Sphere(Function):
def __init__(self):
x_dom = np.arange(-5.0, 5.01, 10.0/points)
label = "Sphere"
def func(x):
return x**2
y_test = np.fromiter(map(func, list(x_dom)), dtype=np.float32)
super().__init__(func, x_dom, y_test, label)
class Sine(Function):
def __init__(self):
x_dom = np.arange(-2*pi, 2*pi, 4*pi/points)
label = "Sine"
def func(x):
return np.sin(x)
y_test = np.fromiter(map(func, list(x_dom)), dtype=np.float32)
super().__init__(func, x_dom, y_test, label)
class SquareRoot(Function):
def __init__(self):
x_dom = np.arange(0, 10.1, 10/points)
label = "SquareRoot"
def func(x):
return np.sqrt(x)
y_test = np.fromiter(map(func, list(x_dom)), dtype=np.float32)
super().__init__(func, x_dom, y_test, label)
class Collection():
def __init__(self):
self.func_list = [Sphere(), Sine(), SquareRoot()]
self.name_list = [f.label for f in self.func_list]