Spaces:
Sleeping
Sleeping
Update examples.md
Browse files- docs/examples.md +10 -13
docs/examples.md
CHANGED
|
@@ -180,13 +180,13 @@ as its search backend. This is a pure Julia package, and so can interface easily
|
|
| 180 |
Julia package.
|
| 181 |
For some tasks, it may be necessary to load such a package.
|
| 182 |
|
| 183 |
-
For example, let's
|
| 184 |
|
| 185 |
$$ y = p_{3x + 1} - 5, $$
|
| 186 |
|
| 187 |
where $p_i$ is the $i$th prime number, and $x$ is the input feature.
|
| 188 |
|
| 189 |
-
Let's see if we can discover this
|
| 190 |
the [Primes.jl](https://github.com/JuliaMath/Primes.jl) package.
|
| 191 |
|
| 192 |
First, let's manually initialize the Julia backend
|
|
@@ -212,14 +212,11 @@ Pkg.add("Primes")
|
|
| 212 |
This imports the Julia package manager, and uses it to install
|
| 213 |
`Primes.jl`. Now let's import `Primes.jl`:
|
| 214 |
|
| 215 |
-
Now, let's import it
|
| 216 |
-
|
| 217 |
```python
|
| 218 |
jl.eval("import Primes")
|
| 219 |
```
|
| 220 |
|
| 221 |
-
Now,
|
| 222 |
-
to PySR later on.
|
| 223 |
|
| 224 |
```python
|
| 225 |
jl.eval("""
|
|
@@ -233,20 +230,20 @@ end
|
|
| 233 |
""")
|
| 234 |
```
|
| 235 |
|
| 236 |
-
We have created a
|
| 237 |
-
|
| 238 |
If out-of-bounds, it returns `NaN`.
|
| 239 |
-
If in-bounds, it rounds it to the nearest integer,
|
|
|
|
| 240 |
|
| 241 |
-
|
| 242 |
-
Since we are using PyJulia, we can
|
| 243 |
-
to our custom Julia operator:
|
| 244 |
|
| 245 |
```python
|
| 246 |
primes = {i: jl.p(i*1.0) for i in range(1, 999)}
|
| 247 |
```
|
| 248 |
|
| 249 |
-
|
| 250 |
|
| 251 |
```python
|
| 252 |
import numpy as np
|
|
|
|
| 180 |
Julia package.
|
| 181 |
For some tasks, it may be necessary to load such a package.
|
| 182 |
|
| 183 |
+
For example, let's say we wish to discovery the following relationship:
|
| 184 |
|
| 185 |
$$ y = p_{3x + 1} - 5, $$
|
| 186 |
|
| 187 |
where $p_i$ is the $i$th prime number, and $x$ is the input feature.
|
| 188 |
|
| 189 |
+
Let's see if we can discover this using
|
| 190 |
the [Primes.jl](https://github.com/JuliaMath/Primes.jl) package.
|
| 191 |
|
| 192 |
First, let's manually initialize the Julia backend
|
|
|
|
| 212 |
This imports the Julia package manager, and uses it to install
|
| 213 |
`Primes.jl`. Now let's import `Primes.jl`:
|
| 214 |
|
|
|
|
|
|
|
| 215 |
```python
|
| 216 |
jl.eval("import Primes")
|
| 217 |
```
|
| 218 |
|
| 219 |
+
Now, we define a custom operator:
|
|
|
|
| 220 |
|
| 221 |
```python
|
| 222 |
jl.eval("""
|
|
|
|
| 230 |
""")
|
| 231 |
```
|
| 232 |
|
| 233 |
+
We have created a a function `p`, which takes an arbitrary number as input.
|
| 234 |
+
`p` first checks whether the input is between 0.5 and 1000.
|
| 235 |
If out-of-bounds, it returns `NaN`.
|
| 236 |
+
If in-bounds, it rounds it to the nearest integer, compures the corresponding prime number, and then
|
| 237 |
+
converts it to the same type as input.
|
| 238 |
|
| 239 |
+
Next, let's generate a list of primes for our test dataset.
|
| 240 |
+
Since we are using PyJulia, we can just call `p` directly to do this:
|
|
|
|
| 241 |
|
| 242 |
```python
|
| 243 |
primes = {i: jl.p(i*1.0) for i in range(1, 999)}
|
| 244 |
```
|
| 245 |
|
| 246 |
+
Next, let's use this list of primes to create a dataset of $x, y$ pairs:
|
| 247 |
|
| 248 |
```python
|
| 249 |
import numpy as np
|