Skip to content

Is it possible to account for the covariance matrix in PySR? #792

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

You must be logged in to vote

Do you mean covariance between rows of y? If this is what you are looking for:

import numpy as np
from pysr import PySRRegressor
from pysr import jl

X = np.random.randn(100, 2)  # Your input data
y = np.random.randn(100)     # Your target values
cov_matrix = # Your covariance matrix

# First compute and register inverse of covariance matrix
inv_cov = np.linalg.inv(cov_matrix)  # Compute inverse in Python

# Important we make it `const` here for performance reasons
jl.seval("x -> @eval const INV_COV_MATRIX = $x")(inv_cov)

loss_function = """
function custom_loss(tree, dataset::Dataset{T,L}, options) where {T,L}
    # Compute predictions
    prediction, completed = eval_tree_array(tree, d…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@zouzaxd
Comment options

Answer selected by zouzaxd
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
2 participants