Home

Awesome

<!-- prettier-ignore-start --> <div align="center">

SymbolicRegression.jl searches for symbolic expressions which optimize a particular objective.

https://github.com/MilesCranmer/SymbolicRegression.jl/assets/7593028/f5b68f1f-9830-497f-a197-6ae332c94ee0

Latest releaseDocumentationForumsPaper
versionDevDiscussionsPaper
Build statusCoverage
CICoverage Status

Check out PySR for a Python frontend. Cite this software

</div> <!-- prettier-ignore-end -->

Contents:

Quickstart

Install in Julia with:

using Pkg
Pkg.add("SymbolicRegression")

MLJ Interface

The easiest way to use SymbolicRegression.jl is with MLJ. Let's see an example:

import SymbolicRegression: SRRegressor
import MLJ: machine, fit!, predict, report

# Dataset with two named features:
X = (a = rand(500), b = rand(500))

# and one target:
y = @. 2 * cos(X.a * 23.5) - X.b ^ 2

# with some noise:
y = y .+ randn(500) .* 1e-3

model = SRRegressor(
    niterations=50,
    binary_operators=[+, -, *],
    unary_operators=[cos],
)

Now, let's create and train this model on our data:

mach = machine(model, X, y)

fit!(mach)

You will notice that expressions are printed using the column names of our table. If, instead of a table-like object, a simple array is passed (e.g., X=randn(100, 2)), x1, ..., xn will be used for variable names.

Let's look at the expressions discovered:

report(mach)

Finally, we can make predictions with the expressions on new data:

predict(mach, X)

This will make predictions using the expression selected by model.selection_method, which by default is a mix of accuracy and complexity.

You can override this selection and select an equation from the Pareto front manually with:

predict(mach, (data=X, idx=2))

where here we choose to evaluate the second equation.

For fitting multiple outputs, one can use MultitargetSRRegressor (and pass an array of indices to idx in predict for selecting specific equations). For a full list of options available to each regressor, see the API page.

Low-Level Interface

The heart of SymbolicRegression.jl is the equation_search function. This takes a 2D array and attempts to model a 1D array using analytic functional forms. Note: unlike the MLJ interface, this assumes column-major input of shape [features, rows].

import SymbolicRegression: Options, equation_search

X = randn(2, 100)
y = 2 * cos.(X[2, :]) + X[1, :] .^ 2 .- 2

options = Options(
    binary_operators=[+, *, /, -],
    unary_operators=[cos, exp],
    populations=20
)

hall_of_fame = equation_search(
    X, y, niterations=40, options=options,
    parallelism=:multithreading
)

You can view the resultant equations in the dominating Pareto front (best expression seen at each complexity) with:

import SymbolicRegression: calculate_pareto_frontier

dominating = calculate_pareto_frontier(hall_of_fame)

This is a vector of PopMember type - which contains the expression along with the score. We can get the expressions with:

trees = [member.tree for member in dominating]

Each of these equations is an Expression{T} type for some constant type T (like Float32).

These expression objects are callable โ€“ you can simply pass in data:

tree = trees[end]
output = tree(X)

Constructing expressions

Expressions are represented under-the-hood as the Node type which is developed in the DynamicExpressions.jl package. The Expression type wraps this and includes metadata about operators and variable names.

You can manipulate and construct expressions directly. For example:

using SymbolicRegression: Options, Expression, Node

options = Options(;
    binary_operators=[+, -, *, /], unary_operators=[cos, exp, sin]
)
operators = options.operators
variable_names = ["x1", "x2", "x3"]
x1, x2, x3 = [Expression(Node(Float64; feature=i); operators, variable_names) for i=1:3]

tree = cos(x1 - 3.2 * x2) - x1 * x1

This tree has Float64 constants, so the type of the entire tree will be promoted to Node{Float64}.

We can convert all constants (recursively) to Float32:

float32_tree = convert(Expression{Float32}, tree)

We can then evaluate this tree on a dataset:

X = rand(Float32, 3, 100)

tree(X)

This callable format is the easy-to-use version which will automatically set all values to NaN if there were any Inf or NaN during evaluation. You can call the raw evaluation method with eval_tree_array:

output, did_succeed = eval_tree_array(tree, X)

where did_succeed explicitly declares whether the evaluation was successful.

Exporting to SymbolicUtils.jl

We can view the equations in the dominating Pareto frontier with:

dominating = calculate_pareto_frontier(hall_of_fame)

We can convert the best equation to SymbolicUtils.jl with the following function:

import SymbolicRegression: node_to_symbolic

eqn = node_to_symbolic(dominating[end].tree)
println(simplify(eqn*5 + 3))

We can also print out the full pareto frontier like so:

import SymbolicRegression: compute_complexity, string_tree

println("Complexity\tMSE\tEquation")

for member in dominating
    complexity = compute_complexity(member, options)
    loss = member.loss
    string = string_tree(member.tree, options)

    println("$(complexity)\t$(loss)\t$(string)")
end

Contributors โœจ

We are eager to welcome new contributors! If you have an idea for a new feature, don't hesitate to share it on the issues page or forums.

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> <!-- prettier-ignore-start --> <!-- markdownlint-disable --> <table> <tbody> <tr> <td align="center" valign="top" width="12.5%"><a href="https://www.linkedin.com/in/markkittisopikul/"><img src="https://avatars.githubusercontent.com/u/8062771?v=4?s=50" width="50px;" alt="Mark Kittisopikul"/><br /><sub><b>Mark Kittisopikul</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=mkitti" title="Code">๐Ÿ’ป</a> <a href="#ideas-mkitti" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#infra-mkitti" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="#platform-mkitti" title="Packaging/porting to new platform">๐Ÿ“ฆ</a> <a href="#promotion-mkitti" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Amkitti" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#tool-mkitti" title="Tools">๐Ÿ”ง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=mkitti" title="Tests">โš ๏ธ</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/tttc3"><img src="https://avatars.githubusercontent.com/u/97948946?v=4?s=50" width="50px;" alt="T Coxon"/><br /><sub><b>T Coxon</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3Atttc3" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=tttc3" title="Code">๐Ÿ’ป</a> <a href="#plugin-tttc3" title="Plugin/utility libraries">๐Ÿ”Œ</a> <a href="#ideas-tttc3" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#infra-tttc3" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="#maintenance-tttc3" title="Maintenance">๐Ÿšง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Atttc3" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#tool-tttc3" title="Tools">๐Ÿ”ง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=tttc3" title="Tests">โš ๏ธ</a> <a href="#userTesting-tttc3" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/DhananjayAshok"><img src="https://avatars.githubusercontent.com/u/46792537?v=4?s=50" width="50px;" alt="Dhananjay Ashok"/><br /><sub><b>Dhananjay Ashok</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=DhananjayAshok" title="Code">๐Ÿ’ป</a> <a href="#example-DhananjayAshok" title="Examples.">๐ŸŒ</a> <a href="#ideas-DhananjayAshok" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#maintenance-DhananjayAshok" title="Maintenance">๐Ÿšง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=DhananjayAshok" title="Tests">โš ๏ธ</a></td> <td align="center" valign="top" width="12.5%"><a href="https://gitlab.com/johanbluecreek"><img src="https://avatars.githubusercontent.com/u/852554?v=4?s=50" width="50px;" alt="Johan Blรฅbรคck"/><br /><sub><b>Johan Blรฅbรคck</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3Ajohanbluecreek" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=johanbluecreek" title="Code">๐Ÿ’ป</a> <a href="#ideas-johanbluecreek" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#maintenance-johanbluecreek" title="Maintenance">๐Ÿšง</a> <a href="#promotion-johanbluecreek" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Ajohanbluecreek" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=johanbluecreek" title="Tests">โš ๏ธ</a> <a href="#userTesting-johanbluecreek" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://mathopt.de/people/martensen/index.php"><img src="https://avatars.githubusercontent.com/u/20998300?v=4?s=50" width="50px;" alt="JuliusMartensen"/><br /><sub><b>JuliusMartensen</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3AAlCap23" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=AlCap23" title="Code">๐Ÿ’ป</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=AlCap23" title="Documentation">๐Ÿ“–</a> <a href="#plugin-AlCap23" title="Plugin/utility libraries">๐Ÿ”Œ</a> <a href="#ideas-AlCap23" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#infra-AlCap23" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="#maintenance-AlCap23" title="Maintenance">๐Ÿšง</a> <a href="#platform-AlCap23" title="Packaging/porting to new platform">๐Ÿ“ฆ</a> <a href="#promotion-AlCap23" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3AAlCap23" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#tool-AlCap23" title="Tools">๐Ÿ”ง</a> <a href="#userTesting-AlCap23" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/ngam"><img src="https://avatars.githubusercontent.com/u/67342040?v=4?s=50" width="50px;" alt="ngam"/><br /><sub><b>ngam</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=ngam" title="Code">๐Ÿ’ป</a> <a href="#infra-ngam" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="#platform-ngam" title="Packaging/porting to new platform">๐Ÿ“ฆ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Angam" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#tool-ngam" title="Tools">๐Ÿ”ง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=ngam" title="Tests">โš ๏ธ</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/kazewong"><img src="https://avatars.githubusercontent.com/u/8803931?v=4?s=50" width="50px;" alt="Kaze Wong"/><br /><sub><b>Kaze Wong</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3Akazewong" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=kazewong" title="Code">๐Ÿ’ป</a> <a href="#ideas-kazewong" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#infra-kazewong" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="#maintenance-kazewong" title="Maintenance">๐Ÿšง</a> <a href="#promotion-kazewong" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Akazewong" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#research-kazewong" title="Research">๐Ÿ”ฌ</a> <a href="#userTesting-kazewong" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/ChrisRackauckas"><img src="https://avatars.githubusercontent.com/u/1814174?v=4?s=50" width="50px;" alt="Christopher Rackauckas"/><br /><sub><b>Christopher Rackauckas</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3AChrisRackauckas" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=ChrisRackauckas" title="Code">๐Ÿ’ป</a> <a href="#plugin-ChrisRackauckas" title="Plugin/utility libraries">๐Ÿ”Œ</a> <a href="#ideas-ChrisRackauckas" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#infra-ChrisRackauckas" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="#promotion-ChrisRackauckas" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3AChrisRackauckas" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#research-ChrisRackauckas" title="Research">๐Ÿ”ฌ</a> <a href="#tool-ChrisRackauckas" title="Tools">๐Ÿ”ง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=ChrisRackauckas" title="Tests">โš ๏ธ</a> <a href="#userTesting-ChrisRackauckas" title="User Testing">๐Ÿ““</a></td> </tr> <tr> <td align="center" valign="top" width="12.5%"><a href="https://kidger.site/"><img src="https://avatars.githubusercontent.com/u/33688385?v=4?s=50" width="50px;" alt="Patrick Kidger"/><br /><sub><b>Patrick Kidger</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3Apatrick-kidger" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=patrick-kidger" title="Code">๐Ÿ’ป</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=patrick-kidger" title="Documentation">๐Ÿ“–</a> <a href="#plugin-patrick-kidger" title="Plugin/utility libraries">๐Ÿ”Œ</a> <a href="#ideas-patrick-kidger" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#maintenance-patrick-kidger" title="Maintenance">๐Ÿšง</a> <a href="#promotion-patrick-kidger" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Apatrick-kidger" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#research-patrick-kidger" title="Research">๐Ÿ”ฌ</a> <a href="#tool-patrick-kidger" title="Tools">๐Ÿ”ง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=patrick-kidger" title="Tests">โš ๏ธ</a> <a href="#userTesting-patrick-kidger" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/OkonSamuel"><img src="https://avatars.githubusercontent.com/u/39421418?v=4?s=50" width="50px;" alt="Okon Samuel"/><br /><sub><b>Okon Samuel</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3AOkonSamuel" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=OkonSamuel" title="Code">๐Ÿ’ป</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=OkonSamuel" title="Documentation">๐Ÿ“–</a> <a href="#maintenance-OkonSamuel" title="Maintenance">๐Ÿšง</a> <a href="#ideas-OkonSamuel" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#infra-OkonSamuel" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3AOkonSamuel" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=OkonSamuel" title="Tests">โš ๏ธ</a> <a href="#userTesting-OkonSamuel" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/w2ll2am"><img src="https://avatars.githubusercontent.com/u/16038228?v=4?s=50" width="50px;" alt="William Booth-Clibborn"/><br /><sub><b>William Booth-Clibborn</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=w2ll2am" title="Code">๐Ÿ’ป</a> <a href="#example-w2ll2am" title="Examples.">๐ŸŒ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=w2ll2am" title="Documentation">๐Ÿ“–</a> <a href="#userTesting-w2ll2am" title="User Testing">๐Ÿ““</a> <a href="#maintenance-w2ll2am" title="Maintenance">๐Ÿšง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Aw2ll2am" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#tool-w2ll2am" title="Tools">๐Ÿ”ง</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=w2ll2am" title="Tests">โš ๏ธ</a></td> <td align="center" valign="top" width="12.5%"><a href="https://pablo-lemos.github.io/"><img src="https://avatars.githubusercontent.com/u/38078898?v=4?s=50" width="50px;" alt="Pablo Lemos"/><br /><sub><b>Pablo Lemos</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3APablo-Lemos" title="Bug reports">๐Ÿ›</a> <a href="#ideas-Pablo-Lemos" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#promotion-Pablo-Lemos" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3APablo-Lemos" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#research-Pablo-Lemos" title="Research">๐Ÿ”ฌ</a> <a href="#userTesting-Pablo-Lemos" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/Moelf"><img src="https://avatars.githubusercontent.com/u/5306213?v=4?s=50" width="50px;" alt="Jerry Ling"/><br /><sub><b>Jerry Ling</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3AMoelf" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=Moelf" title="Code">๐Ÿ’ป</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=Moelf" title="Documentation">๐Ÿ“–</a> <a href="#example-Moelf" title="Examples.">๐ŸŒ</a> <a href="#ideas-Moelf" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#promotion-Moelf" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3AMoelf" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#userTesting-Moelf" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/CharFox1"><img src="https://avatars.githubusercontent.com/u/35052672?v=4?s=50" width="50px;" alt="Charles Fox"/><br /><sub><b>Charles Fox</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3ACharFox1" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=CharFox1" title="Code">๐Ÿ’ป</a> <a href="#ideas-CharFox1" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#maintenance-CharFox1" title="Maintenance">๐Ÿšง</a> <a href="#promotion-CharFox1" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3ACharFox1" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#research-CharFox1" title="Research">๐Ÿ”ฌ</a> <a href="#userTesting-CharFox1" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/johannbrehmer"><img src="https://avatars.githubusercontent.com/u/17068560?v=4?s=50" width="50px;" alt="Johann Brehmer"/><br /><sub><b>Johann Brehmer</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=johannbrehmer" title="Code">๐Ÿ’ป</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=johannbrehmer" title="Documentation">๐Ÿ“–</a> <a href="#ideas-johannbrehmer" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#promotion-johannbrehmer" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Ajohannbrehmer" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#research-johannbrehmer" title="Research">๐Ÿ”ฌ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=johannbrehmer" title="Tests">โš ๏ธ</a> <a href="#userTesting-johannbrehmer" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="http://www.cosmicmar.com/"><img src="https://avatars.githubusercontent.com/u/1510968?v=4?s=50" width="50px;" alt="Marius Millea"/><br /><sub><b>Marius Millea</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=marius311" title="Code">๐Ÿ’ป</a> <a href="#ideas-marius311" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#promotion-marius311" title="Promotion">๐Ÿ“ฃ</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Amarius311" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#userTesting-marius311" title="User Testing">๐Ÿ““</a></td> </tr> <tr> <td align="center" valign="top" width="12.5%"><a href="https://gitlab.com/cobac"><img src="https://avatars.githubusercontent.com/u/27872944?v=4?s=50" width="50px;" alt="Coba"/><br /><sub><b>Coba</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3Acobac" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=cobac" title="Code">๐Ÿ’ป</a> <a href="#ideas-cobac" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Acobac" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#userTesting-cobac" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/pitmonticone"><img src="https://avatars.githubusercontent.com/u/38562595?v=4?s=50" width="50px;" alt="Pietro Monticone"/><br /><sub><b>Pietro Monticone</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3Apitmonticone" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=pitmonticone" title="Documentation">๐Ÿ“–</a> <a href="#ideas-pitmonticone" title="Ideas, planning, and feedback.">๐Ÿ’ก</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/sheevy"><img src="https://avatars.githubusercontent.com/u/1525683?v=4?s=50" width="50px;" alt="Mateusz Kubica"/><br /><sub><b>Mateusz Kubica</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=sheevy" title="Documentation">๐Ÿ“–</a> <a href="#ideas-sheevy" title="Ideas, planning, and feedback.">๐Ÿ’ก</a></td> <td align="center" valign="top" width="12.5%"><a href="https://jaywadekar.github.io/"><img src="https://avatars.githubusercontent.com/u/5493388?v=4?s=50" width="50px;" alt="Jay Wadekar"/><br /><sub><b>Jay Wadekar</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3AJayWadekar" title="Bug reports">๐Ÿ›</a> <a href="#ideas-JayWadekar" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#promotion-JayWadekar" title="Promotion">๐Ÿ“ฃ</a> <a href="#research-JayWadekar" title="Research">๐Ÿ”ฌ</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/ablaom"><img src="https://avatars.githubusercontent.com/u/30517088?v=4?s=50" width="50px;" alt="Anthony Blaom, PhD"/><br /><sub><b>Anthony Blaom, PhD</b></sub></a><br /><a href="#infra-ablaom" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a> <a href="#ideas-ablaom" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Aablaom" title="Reviewed Pull Requests">๐Ÿ‘€</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/Jgmedina95"><img src="https://avatars.githubusercontent.com/u/97254349?v=4?s=50" width="50px;" alt="Jgmedina95"/><br /><sub><b>Jgmedina95</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3AJgmedina95" title="Bug reports">๐Ÿ›</a> <a href="#ideas-Jgmedina95" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3AJgmedina95" title="Reviewed Pull Requests">๐Ÿ‘€</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/mcabbott"><img src="https://avatars.githubusercontent.com/u/32575566?v=4?s=50" width="50px;" alt="Michael Abbott"/><br /><sub><b>Michael Abbott</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=mcabbott" title="Code">๐Ÿ’ป</a> <a href="#ideas-mcabbott" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Amcabbott" title="Reviewed Pull Requests">๐Ÿ‘€</a> <a href="#tool-mcabbott" title="Tools">๐Ÿ”ง</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/oscardssmith"><img src="https://avatars.githubusercontent.com/u/11729272?v=4?s=50" width="50px;" alt="Oscar Smith"/><br /><sub><b>Oscar Smith</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=oscardssmith" title="Code">๐Ÿ’ป</a> <a href="#ideas-oscardssmith" title="Ideas, planning, and feedback.">๐Ÿ’ก</a></td> </tr> <tr> <td align="center" valign="top" width="12.5%"><a href="https://ericphanson.com/"><img src="https://avatars.githubusercontent.com/u/5846501?v=4?s=50" width="50px;" alt="Eric Hanson"/><br /><sub><b>Eric Hanson</b></sub></a><br /><a href="#ideas-ericphanson" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#promotion-ericphanson" title="Promotion">๐Ÿ“ฃ</a> <a href="#userTesting-ericphanson" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/henriquebecker91"><img src="https://avatars.githubusercontent.com/u/14113435?v=4?s=50" width="50px;" alt="Henrique Becker"/><br /><sub><b>Henrique Becker</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=henriquebecker91" title="Code">๐Ÿ’ป</a> <a href="#ideas-henriquebecker91" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/pulls?q=is%3Apr+reviewed-by%3Ahenriquebecker91" title="Reviewed Pull Requests">๐Ÿ‘€</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/qwertyjl"><img src="https://avatars.githubusercontent.com/u/110912592?v=4?s=50" width="50px;" alt="qwertyjl"/><br /><sub><b>qwertyjl</b></sub></a><br /><a href="https://github.com/MilesCranmer/SymbolicRegression.jl/issues?q=author%3Aqwertyjl" title="Bug reports">๐Ÿ›</a> <a href="https://github.com/MilesCranmer/SymbolicRegression.jl/commits?author=qwertyjl" title="Documentation">๐Ÿ“–</a> <a href="#ideas-qwertyjl" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#userTesting-qwertyjl" title="User Testing">๐Ÿ““</a></td> <td align="center" valign="top" width="12.5%"><a href="https://huijzer.xyz/"><img src="https://avatars.githubusercontent.com/u/20724914?v=4?s=50" width="50px;" alt="Rik Huijzer"/><br /><sub><b>Rik Huijzer</b></sub></a><br /><a href="#ideas-rikhuijzer" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#infra-rikhuijzer" title="Infrastructure (Hosting, Build-Tools, etc)">๐Ÿš‡</a></td> <td align="center" valign="top" width="12.5%"><a href="https://github.com/GCaptainNemo"><img src="https://avatars.githubusercontent.com/u/43086239?v=4?s=50" width="50px;" alt="Hongyu Wang"/><br /><sub><b>Hongyu Wang</b></sub></a><br /><a href="#ideas-GCaptainNemo" title="Ideas, planning, and feedback.">๐Ÿ’ก</a> <a href="#promotion-GCaptainNemo" title="Promotion">๐Ÿ“ฃ</a> <a href="#research-GCaptainNemo" title="Research">๐Ÿ”ฌ</a></td> <td align="center" valign="top" width="12.5%"><a href="https://sauravmaheshkar.github.io/"><img src="https://avatars.githubusercontent.com/u/61241031?v=4?s=50" width="50px;" alt="Saurav Maheshkar"/><br /><sub><b>Saurav Maheshkar</b></sub></a><br /><a href="#tool-SauravMaheshkar" title="Tools">๐Ÿ”ง</a></td> </tr> </tbody> </table> <!-- markdownlint-restore --> <!-- prettier-ignore-end --> <!-- ALL-CONTRIBUTORS-LIST:END -->

Code structure

SymbolicRegression.jl is organized roughly as follows. Rounded rectangles indicate objects, and rectangles indicate functions.

(if you can't see this diagram being rendered, try pasting it into mermaid-js.github.io/mermaid-live-editor)

flowchart TB
    op([Options])
    d([Dataset])
    op --> ES
    d --> ES
    subgraph ES[equation_search]
        direction TB
        IP[sr_spawner]
        IP --> p1
        IP --> p2
        subgraph p1[Thread 1]
            direction LR
            pop1([Population])
            pop1 --> src[s_r_cycle]
            src --> opt[optimize_and_simplify_population]
            opt --> pop1
        end
        subgraph p2[Thread 2]
            direction LR
            pop2([Population])
            pop2 --> src2[s_r_cycle]
            src2 --> opt2[optimize_and_simplify_population]
            opt2 --> pop2
        end
        pop1 --> hof
        pop2 --> hof
        hof([HallOfFame])
        hof --> migration
        pop1 <-.-> migration
        pop2 <-.-> migration
        migration[migrate!]
    end
    ES --> output([HallOfFame])

The HallOfFame objects store the expressions with the lowest loss seen at each complexity.

The dependency structure of the code itself is as follows:

stateDiagram-v2
    AdaptiveParsimony --> Mutate
    AdaptiveParsimony --> Population
    AdaptiveParsimony --> RegularizedEvolution
    AdaptiveParsimony --> SearchUtils
    AdaptiveParsimony --> SingleIteration
    AdaptiveParsimony --> SymbolicRegression
    CheckConstraints --> Mutate
    CheckConstraints --> SymbolicRegression
    Complexity --> CheckConstraints
    Complexity --> HallOfFame
    Complexity --> LossFunctions
    Complexity --> MLJInterface
    Complexity --> Mutate
    Complexity --> PopMember
    Complexity --> Population
    Complexity --> SearchUtils
    Complexity --> SingleIteration
    Complexity --> SymbolicRegression
    ConstantOptimization --> ExpressionBuilder
    ConstantOptimization --> Mutate
    ConstantOptimization --> SingleIteration
    Core --> AdaptiveParsimony
    Core --> CheckConstraints
    Core --> Complexity
    Core --> ConstantOptimization
    Core --> DimensionalAnalysis
    Core --> ExpressionBuilder
    Core --> ExpressionBuilder
    Core --> HallOfFame
    Core --> InterfaceDynamicExpressions
    Core --> LossFunctions
    Core --> MLJInterface
    Core --> Migration
    Core --> Mutate
    Core --> MutationFunctions
    Core --> PopMember
    Core --> Population
    Core --> Recorder
    Core --> RegularizedEvolution
    Core --> SearchUtils
    Core --> SingleIteration
    Core --> SymbolicRegression
    Dataset --> Core
    DimensionalAnalysis --> LossFunctions
    ExpressionBuilder --> SymbolicRegression
    HallOfFame --> ExpressionBuilder
    HallOfFame --> MLJInterface
    HallOfFame --> SearchUtils
    HallOfFame --> SingleIteration
    HallOfFame --> SymbolicRegression
    HallOfFame --> deprecates
    InterfaceDynamicExpressions --> ExpressionBuilder
    InterfaceDynamicExpressions --> HallOfFame
    InterfaceDynamicExpressions --> LossFunctions
    InterfaceDynamicExpressions --> SymbolicRegression
    InterfaceDynamicQuantities --> Dataset
    InterfaceDynamicQuantities --> MLJInterface
    LossFunctions --> ConstantOptimization
    LossFunctions --> ExpressionBuilder
    LossFunctions --> ExpressionBuilder
    LossFunctions --> Mutate
    LossFunctions --> PopMember
    LossFunctions --> Population
    LossFunctions --> SingleIteration
    LossFunctions --> SymbolicRegression
    MLJInterface --> SymbolicRegression
    Migration --> SymbolicRegression
    Mutate --> RegularizedEvolution
    MutationFunctions --> ExpressionBuilder
    MutationFunctions --> Mutate
    MutationFunctions --> Population
    MutationFunctions --> SymbolicRegression
    MutationFunctions --> deprecates
    MutationWeights --> Core
    MutationWeights --> Options
    MutationWeights --> OptionsStruct
    Operators --> Core
    Operators --> Options
    Options --> Core
    OptionsStruct --> Core
    OptionsStruct --> Options
    OptionsStruct --> Options
    PopMember --> ConstantOptimization
    PopMember --> ExpressionBuilder
    PopMember --> HallOfFame
    PopMember --> Migration
    PopMember --> Mutate
    PopMember --> Population
    PopMember --> SearchUtils
    PopMember --> SingleIteration
    PopMember --> SymbolicRegression
    Population --> ExpressionBuilder
    Population --> Migration
    Population --> RegularizedEvolution
    Population --> SearchUtils
    Population --> SingleIteration
    Population --> SymbolicRegression
    ProgramConstants --> Core
    ProgramConstants --> Dataset
    ProgramConstants --> Operators
    ProgressBars --> SearchUtils
    ProgressBars --> SymbolicRegression
    Recorder --> Mutate
    Recorder --> RegularizedEvolution
    Recorder --> SingleIteration
    Recorder --> SymbolicRegression
    RegularizedEvolution --> SingleIteration
    SearchUtils --> SymbolicRegression
    SingleIteration --> SymbolicRegression
    Utils --> ConstantOptimization
    Utils --> Dataset
    Utils --> DimensionalAnalysis
    Utils --> HallOfFame
    Utils --> InterfaceDynamicExpressions
    Utils --> MLJInterface
    Utils --> Migration
    Utils --> Operators
    Utils --> Options
    Utils --> PopMember
    Utils --> Population
    Utils --> RegularizedEvolution
    Utils --> SearchUtils
    Utils --> SingleIteration
    Utils --> SymbolicRegression

Bash command to generate dependency structure from src directory (requires vim-stream):

echo 'stateDiagram-v2'
IFS=$'\n'
for f in *.jl; do
    for line in $(cat $f | grep -e 'import \.\.' -e 'import \.' -e 'using \.' -e 'using \.\.'); do
        echo $(echo $line | vims -s 'dwf:d$' -t '%s/^\.*//g' '%s/Module//g') $(basename "$f" .jl);
    done;
done | vims -l 'f a--> ' | sort

Search options

See https://astroautomata.com/SymbolicRegression.jl/stable/api/#Options