forked from yetkinyilmaz/tracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformulate.py
89 lines (50 loc) · 1.35 KB
/
formulate.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
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
import pandas as pd
import numpy as np
class Dimension:
Spatial = -3.0
Angular = 0.
Order = 0
Flat = True
class Operation:
def __init__(self, seed = "+"):
self.op = seed
self.a = "x"
self.b = "x"
self.c = ""
def split_b(self, sign = "+"):
self.b = ""
opb = Operation(sign)
return opb
d_a = Dimension()
d_b = Dimension()
d_c = Dimension()
a = ""
b = ""
c = ""
op = ""
class Generator:
def __init__(self, dim = 1, seed = "+"):
op = Operation(seed)
self.ops = [op]
def split(self, sign):
self.ops = self.ops + [self.ops[len(self.ops)-1].split_b(sign)]
def formulate(self):
formula = "p[0]+"
ipar = 1
for o in self.ops:
p = ""
if o.op == "+":
p = "p[" + str(ipar) + "]*"
ipar += 1
formula = formula + o.a + o.op + p + o.b
return formula
def funk(x, y, p = [], formula = "p[0] + ( (p[1]*x) + ( p[2]*(x**2) ) )"):
return eval(formula)
def formulate():
# return "2. * np.cos(np.arctan2(y,x)) / np.sqrt(x**2+y**2)"
return "2. * y*y/x / np.sqrt(x**3+y**2+x**2)"
myops = np.random.choice(["+","*"],2,p=[0.8,0.2])
gen = Generator("+")
for o in myops:
gen.split(o)
print(gen.formulate())