MilesCranmer commited on
Commit
3ae1f0b
1 Parent(s): c751ff8

More docs on custom operators

Browse files
Files changed (1) hide show
  1. docs/operators.md +14 -7
docs/operators.md CHANGED
@@ -2,8 +2,8 @@
2
 
3
  ## Pre-defined
4
 
5
- All Base julia operators that take 1 or 2 float32 as input,
6
- and output a float32 as output, are available. A selection
7
  of these and other valid operators are stated below.
8
 
9
  **Binary**
@@ -58,9 +58,16 @@ you can define with by passing it to the `pysr` function, with, e.g.,
58
 
59
 
60
  Make sure that it works with
61
- `Float32` as a datatype. That means you need to write `1.5f3`
62
- instead of `1.5e3`, if you write any constant numbers.
63
 
64
- Your operator should work with the entire real line (you can use
65
- abs(x) for operators requiring positive input - see `log_abs`); otherwise
66
- the search code will experience domain errors.
 
 
 
 
 
 
 
 
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**
 
58
 
59
 
60
  Make sure that it works with
61
+ `Float32` as a datatype (for default precision, or `Float64` if you set `precision=64`). That means you need to write `1.5f3`
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)
69
+ ```
70
+
71
+ would be a valid operator. The genetic algorithm
72
+ will preferentially selection expressions which avoid
73
+ any invalid values over the training dataset.