MilesCranmer commited on
Commit
d39c0a6
1 Parent(s): 80d7197

Update operators.md

Browse files
Files changed (1) hide show
  1. docs/operators.md +60 -36
docs/operators.md CHANGED
@@ -2,46 +2,60 @@
2
 
3
  ## Pre-defined
4
 
5
- All Base julia operators that take 1 or 2 scalars as input,
6
- and output a scalar as output, are available. A selection
7
- of these and other valid operators are stated below.
 
8
 
9
  **Binary**
10
 
11
- `+`, `-`, `*`, `/`, `^`, `greater`, `mod`, `logical_or`,
12
- `logical_and`
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
  **Unary**
15
 
16
- `neg`,
17
- `square`,
18
- `cube`,
19
- `exp`,
20
- `abs`,
21
- `log`,
22
- `log10`,
23
- `log2`,
24
- `log1p`,
25
- `sqrt`,
26
- `sin`,
27
- `cos`,
28
- `tan`,
29
- `sinh`,
30
- `cosh`,
31
- `tanh`,
32
- `atan`,
33
- `asinh`,
34
- `acosh`,
35
- `atanh_clip` (=atanh((x+1)%2 - 1)),
36
- `erf`,
37
- `erfc`,
38
- `gamma`,
39
- `relu`,
40
- `round`,
41
- `floor`,
42
- `ceil`,
43
- `round`,
44
- `sign`.
 
45
 
46
  ## Custom
47
 
@@ -52,7 +66,11 @@ you can define with by passing it to the `pysr` function, with, e.g.,
52
  PySRRegressor(
53
  ...,
54
  unary_operators=["myfunction(x) = x^2"],
55
- binary_operators=["myotherfunction(x, y) = x^2*y"]
 
 
 
 
56
  )
57
  ```
58
 
@@ -62,7 +80,7 @@ Make sure that it works with
62
  instead of `1.5e3`, if you write any constant numbers, or simply convert a result to `Float64(...)`.
63
 
64
  PySR expects that operators not throw an error for any input value over the entire real line from `-3.4e38` to `+3.4e38`.
65
- Thus, for "invalid" inputs, such as negative numbers to a `sqrt` function, you may simply return a `NaN` of the same type as the input. For example,
66
 
67
  ```julia
68
  my_sqrt(x) = x >= 0 ? sqrt(x) : convert(typeof(x), NaN)
@@ -71,3 +89,9 @@ my_sqrt(x) = x >= 0 ? sqrt(x) : convert(typeof(x), NaN)
71
  would be a valid operator. The genetic algorithm
72
  will preferentially selection expressions which avoid
73
  any invalid values over the training dataset.
 
 
 
 
 
 
 
2
 
3
  ## Pre-defined
4
 
5
+ First, note that pretty much any valid Julia function which
6
+ takes one or two scalars as input, and returns on scalar as output,
7
+ is likely to be a valid operator[^1].
8
+ A selection of these and other valid operators are stated below.
9
 
10
  **Binary**
11
 
12
+ - `+`
13
+ - `-`
14
+ - `*`
15
+ - `/`
16
+ - `^`
17
+ - `cond`
18
+ - Equal to `(x, y) -> x > 0 ? y : 0`
19
+ - `greater`
20
+ - Equal to `(x, y) -> x > y ? 1 : 0`
21
+ - `logical_or`
22
+ - Equal to `(x, y) -> (x > 0 || y > 0) ? 1 : 0`
23
+ - `logical_and`
24
+ - Equal to `(x, y) -> (x > 0 && y > 0) ? 1 : 0`
25
+ - `mod`
26
 
27
  **Unary**
28
 
29
+ - `neg`
30
+ - `square`
31
+ - `cube`
32
+ - `exp`
33
+ - `abs`
34
+ - `log`
35
+ - `log10`
36
+ - `log2`
37
+ - `log1p`
38
+ - `sqrt`
39
+ - `sin`
40
+ - `cos`
41
+ - `tan`
42
+ - `sinh`
43
+ - `cosh`
44
+ - `tanh`
45
+ - `atan`
46
+ - `asinh`
47
+ - `acosh`
48
+ - `atanh_clip`
49
+ - Equal to `atanh(mod(x + 1, 2) - 1)`
50
+ - `erf`
51
+ - `erfc`
52
+ - `gamma`
53
+ - `relu`
54
+ - `round`
55
+ - `floor`
56
+ - `ceil`
57
+ - `round`
58
+ - `sign`
59
 
60
  ## Custom
61
 
 
66
  PySRRegressor(
67
  ...,
68
  unary_operators=["myfunction(x) = x^2"],
69
+ binary_operators=["myotherfunction(x, y) = x^2*y"],
70
+ extra_sympy_mappings={
71
+ "myfunction": lambda x: x**2,
72
+ "myotherfunction": lambda x, y: x**2 * y,
73
+ },
74
  )
75
  ```
76
 
 
80
  instead of `1.5e3`, if you write any constant numbers, or simply convert a result to `Float64(...)`.
81
 
82
  PySR expects that operators not throw an error for any input value over the entire real line from `-3.4e38` to `+3.4e38`.
83
+ Thus, for invalid inputs, such as negative numbers to a `sqrt` function, you may simply return a `NaN` of the same type as the input. For example,
84
 
85
  ```julia
86
  my_sqrt(x) = x >= 0 ? sqrt(x) : convert(typeof(x), NaN)
 
89
  would be a valid operator. The genetic algorithm
90
  will preferentially selection expressions which avoid
91
  any invalid values over the training dataset.
92
+
93
+
94
+ <!-- Footnote for 1: -->
95
+ <!-- (Will say "However, you may need to define a `extra_sympy_mapping`":) -->
96
+
97
+ [^1]: However, you will need to define a sympy equivalent in `extra_sympy_mapping` if you want to use a function not in the above list.