Symbolic regression
Symbolic Regression
helpers
auc_from_scores_labels
def auc_from_scores_labels(
scores, labels
):
Call self as a function.
compare_theta_corr
def compare_theta_corr(
theta, X, C, method:str='pearson', use_upper:bool=True
):
Call self as a function.
spearman_rho
def spearman_rho(
a, b
):
Call self as a function.
cosine_sim
def cosine_sim(
a, b, eps:float=1e-12
):
Call self as a function.
pearson_between_vectors
def pearson_between_vectors(
a, b, eps:float=1e-12
):
Call self as a function.
flatten_upper
def flatten_upper(
mat
):
Call self as a function.
empirical_corr_matrix
def empirical_corr_matrix(
X, centered:bool=True
):
Call self as a function.
curved_edge
def curved_edge(
ax, x1, y1, x2, y2, curvature:float=0.2, plot_kwargs:VAR_KEYWORD
):
Draw a curved (quadratic Bézier) edge between (x1,y1) and (x2,y2). curvature > 0 bends left, curvature < 0 bends right.
loss_SR3
def loss_SR3(
alpha, model, dataset, vk, G, L1_reg, options
):
loss used for 2BC with SR3
derivative_loss_alpha_multi_vk
def derivative_loss_alpha_multi_vk(
tree, X, options, vk, G
):
loss projecting and aligning the gradiant Args: dy: (S, N) gradients of tree w.r.t inputs vk: (S, N, m) projector vectors per sample (m projectors) G: (S, m) target projected gradients per sample Returns MSE between normalized projected dy and normalized G (averaged over m).
loss_SR2
def loss_SR2(
alpha, model, dataset, G, L1_reg, options
):
loss used for the 2BC witb SR2
derivative_loss_alpha_multi
def derivative_loss_alpha_multi(
tree, X, options, G
):
loss aligning the gradiant
loss_SR1
def loss_SR1(
alpha, model, X, Y, L1_reg, options
):
loss used for the 2BC witb SR1
class_loss
def class_loss(
tree, X, options, Y
):
classification loss used for the 2BC witb SR1
TwoBodyModel
def TwoBodyModel(
pairs, key, add_constant:bool=False
):
Initialize self. See help(type(self)) for accurate signature.
FFNN_theta_to_mu
def FFNN_theta_to_mu(
hidden_dim:int, num_layers:int, parent:Union=<flax.linen.module._Sentinel object at 0x7f9be9751700>,
name:Optional=None
)->None:
simple feed forward net from theta to mu1
SR class
SymbolicRegression
def SymbolicRegression(
dataset:Dataset, cluster_idx_in:Array, objective:str, type_of_vk:Optional=None,
cluster_idx_out:Optional=None, # only needed for SR1 if not specified, full/in
search_space:str='2_body_correlator', # ansatz or genetic
add_constant:bool=False, shift_data:bool=True, VAE_model:Optional=None, # needed for SR2,3
VAE_params:Optional=None, # needed for SR2,3
mu_cluster:Optional=None, # needed for SR2,3
idx_mu_cluster:Optional=None, # needed for SR2,3
):
Wrapper with the SR methods to be used on top of the representation learned by the cpVAE for quantum
Args:
dataset: Dataset object
cluster_idx_in: coord. specifying the location of the cluster we analyse in parameter (theta) space
objective: SR1, SR2 or SR3
cluster_idx_out: coord. specifying the location of the cluster we analyse in parameter (theta) space (only used in SR1)
search_space: 2_body_correlator or genetic
add_constant: if True, add a constant term to the model
shift_data: if the symbolic function takes direcly the dataset.data or if {0,1}->{-1,1} before
for SR2,3 also need:
VAE_model: the VAE model
VAE_params: its params
mu_cluster: the value of the latent variable accrooss theta space where the cluster appear (for now, only one mu)
idx_mu_cluster: index of the latent variable where the cluster appear (for now, only one)