Skip to content

Commit fcd71e8

Browse files
committed
Update
1 parent 6847601 commit fcd71e8

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

tests/test_ode-strogatz.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def test_d_glider1():
230230

231231
assert(len(model.bestExpressions) == 1)
232232
assert(sr.expr_eq(sympy.expand(model.bestExpressions[0][0]), sympy.sympify("-0.05*x**2-sin(y)")))
233-
"""
233+
234234
def test_d_glider2():
235235
label, x, y = file_data("https://raw.githubusercontent.com/lacava/ode-strogatz/master/d_glider2.txt")
236236

@@ -245,13 +245,14 @@ def test_d_glider2():
245245

246246
plt.ion()
247247

248+
"""
248249
model = sr.SR(niterations = 3,
249250
verbose = False,
250251
unary_operators = {"cos": (sympy.cos, np.cos)},
251252
binary_operators = {"/": (operator.truediv, operator.truediv),
252253
"+": (operator.add, operator.add)},
253254
discrete_param_values = ["(-1, 1)"],
254-
operator_depth = {"cos": 1, "/": 1, "+": 1},
255+
operator_depth = {"cos": 1, "/": 1, "+": 2},
255256
#callback = callback,
256257
#monothread = True,
257258
maxcomplexity = 20,
@@ -261,7 +262,27 @@ def test_d_glider2():
261262
262263
assert(len(model.bestExpressions) == 1)
263264
assert(sr.expr_eq(sympy.expand(model.bestExpressions[0][0]), sympy.sympify("x - cos(y)/x")))
264-
"""
265+
"""
266+
267+
#It works with change of variable
268+
cy = np.cos(y)
269+
sy = np.sin(y)
270+
271+
model = sr.SR(niterations = 3,
272+
verbose = False,
273+
binary_operators = {"/": (operator.truediv, operator.truediv),
274+
"+": (operator.add, operator.add)},
275+
operator_depth = {"/": 1, "+": 2},
276+
#callback = callback,
277+
#monothread = True,
278+
maxcomplexity = 20,
279+
foundBreak = True)
280+
281+
model.fit([x, cy, sy], label, ["x", "cy", "sy"])
282+
283+
assert(len(model.bestExpressions) == 1)
284+
assert(sr.expr_eq(sympy.expand(model.bestExpressions[0][0]), sympy.expand(sympy.simplify(sympy.sympify("x - cy/x")))))
285+
265286
def test_d_lv1():
266287
label, x, y = file_data("https://raw.githubusercontent.com/lacava/ode-strogatz/master/d_lv1.txt")
267288

@@ -402,13 +423,14 @@ def test_d_shearflow1():
402423
discrete_param_values = ["(-1, 1)"],
403424
#callback = callback,
404425
#monothread = True,
426+
#It works with change of variable
405427
foundBreak = True)
406428

407429
model.fit([x, y], label, ["x", "y"])
408430

409431
assert(len(model.bestExpressions) == 1)
410432
assert(sr.expr_eq(sympy.expand(model.bestExpressions[0][0]), sympy.expand(sympy.simplify(sympy.sympify("cot(y)*cos(x)")))))
411-
"""
433+
412434
def test_d_shearflow2():
413435
label, x, y = file_data("https://raw.githubusercontent.com/lacava/ode-strogatz/master/d_shearflow2.txt")
414436

@@ -423,6 +445,7 @@ def test_d_shearflow2():
423445

424446
plt.ion()
425447

448+
"""
426449
model = sr.SR(niterations = 3,
427450
verbose = False,
428451
unary_operators = {"sin": (sympy.sin, np.sin),
@@ -439,7 +462,28 @@ def test_d_shearflow2():
439462
440463
assert(len(model.bestExpressions) == 1)
441464
assert(sr.expr_eq(sympy.expand(model.bestExpressions[0][0]), sympy.expand(sympy.simplify(sympy.sympify("(cos(y)**2+0.1*sin(y)**2)*sin(x)")))))
442-
"""
465+
"""
466+
467+
#It works with change of variable
468+
cx = np.cos(x)
469+
sx = np.sin(x)
470+
cy = np.cos(y)
471+
sy = np.sin(y)
472+
473+
model = sr.SR(niterations = 3,
474+
verbose = False,
475+
binary_operators = {"*": (operator.mul, operator.mul),
476+
"+": (operator.add, operator.add)},
477+
operator_depth = {"*": 2, "+": 2},
478+
discrete_param_values = ["(0, 1)", 0.1],
479+
#callback = callback,
480+
#monothread = True,
481+
foundBreak = True)
482+
483+
model.fit([cx, sx, cy, sy], label, ["cx", "sx", "cy", "sy"])
484+
485+
assert(len(model.bestExpressions) == 1)
486+
assert(sr.expr_eq(sympy.expand(model.bestExpressions[0][0]), sympy.expand(sympy.simplify(sympy.sympify("(cy**2+0.1*sy**2)*sx")))))
443487

444488
def test_d_vdp1():
445489
label, x, y = file_data("https://raw.githubusercontent.com/lacava/ode-strogatz/master/d_vdp1.txt")

0 commit comments

Comments
 (0)