Skip to content

Can PySR handle recursive functions? #540

Answered by MilesCranmer
jabogithub asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @jabogithub,

Really interesting question! I spent some time on this out of interest and managed to get it to work. This lets you rediscover the Mandelbrot set recursive relation from random samples of the Mandelbrot set.

First, here's a Julia version:
using SymbolicRegression
using MLJBase: machine, fit!, predict
using Random: Random

# Mandelbrot set
function in_mandelbrot(c; max_iteration = 1000)
    z = zero(c)
    iteration = 0
    while abs(z) <= 2.0 && iteration < max_iteration
        z = z^2 + c
        iteration += 1
    end
    return (abs(z) <= 2.0 && iteration == max_iteration)
end

"""
    my_loss(tree, dataset, options)

Custom loss function for sets defined by recursi…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by MilesCranmer
Comment options

You must be logged in to vote
3 replies
@jbdatascience
Comment options

@MilesCranmer
Comment options

@jbdatascience
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
PySR PySR-related discussion SymbolicRegression.jl SymbolicRegression.jl-related discussion
3 participants