MilesCranmer commited on
Commit
48b723d
1 Parent(s): 3acde9e

Add test for empty unary_operators list

Browse files
Files changed (1) hide show
  1. test/test.py +13 -4
test/test.py CHANGED
@@ -2,18 +2,27 @@ import numpy as np
2
  from pysr import pysr
3
  X = np.random.randn(100, 5)
4
 
5
- # Test 1
6
  y = X[:, 0]
7
  equations = pysr(X, y,
8
- niterations=100)
9
  print(equations)
10
  assert equations.iloc[-1]['MSE'] < 1e-10
11
 
12
- # Test 2
13
  y = X[:, 0]**2
14
  equations = pysr(X, y,
15
  unary_operators=["square(x) = x^2"], binary_operators=["plus"],
16
- niterations=100)
17
  print(equations)
18
  assert equations.iloc[-1]['MSE'] < 1e-10
19
 
 
 
 
 
 
 
 
 
 
 
2
  from pysr import pysr
3
  X = np.random.randn(100, 5)
4
 
5
+ print("Test 1 - defaults; simple linear relation")
6
  y = X[:, 0]
7
  equations = pysr(X, y,
8
+ niterations=10)
9
  print(equations)
10
  assert equations.iloc[-1]['MSE'] < 1e-10
11
 
12
+ print("Test 2 - test custom operator")
13
  y = X[:, 0]**2
14
  equations = pysr(X, y,
15
  unary_operators=["square(x) = x^2"], binary_operators=["plus"],
16
+ niterations=10)
17
  print(equations)
18
  assert equations.iloc[-1]['MSE'] < 1e-10
19
 
20
+ X = np.random.randn(100, 1)
21
+ y = X[:, 0] + 3.0
22
+ print("Test 3 - empty operator list, and single dimension input")
23
+ equations = pysr(X, y,
24
+ unary_operators=[], binary_operators=["plus"],
25
+ niterations=10)
26
+
27
+ print(equations)
28
+ assert equations.iloc[-1]['MSE'] < 1e-10