# Symbolic regression


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

# Symbolic Regression

## helpers

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L250"
target="_blank" style="float:right; font-size:smaller">source</a>

### auc_from_scores_labels

``` python

def auc_from_scores_labels(
    scores, labels
):

```

*Call self as a function.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L231"
target="_blank" style="float:right; font-size:smaller">source</a>

### compare_theta_corr

``` python

def compare_theta_corr(
    theta, X, C, method:str='pearson', use_upper:bool=True
):

```

*Call self as a function.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L218"
target="_blank" style="float:right; font-size:smaller">source</a>

### spearman_rho

``` python

def spearman_rho(
    a, b
):

```

*Call self as a function.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L213"
target="_blank" style="float:right; font-size:smaller">source</a>

### cosine_sim

``` python

def cosine_sim(
    a, b, eps:float=1e-12
):

```

*Call self as a function.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L203"
target="_blank" style="float:right; font-size:smaller">source</a>

### pearson_between_vectors

``` python

def pearson_between_vectors(
    a, b, eps:float=1e-12
):

```

*Call self as a function.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L198"
target="_blank" style="float:right; font-size:smaller">source</a>

### flatten_upper

``` python

def flatten_upper(
    mat
):

```

*Call self as a function.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L187"
target="_blank" style="float:right; font-size:smaller">source</a>

### empirical_corr_matrix

``` python

def empirical_corr_matrix(
    X, centered:bool=True
):

```

*Call self as a function.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L162"
target="_blank" style="float:right; font-size:smaller">source</a>

### curved_edge

``` python

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.

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L155"
target="_blank" style="float:right; font-size:smaller">source</a>

### loss_SR3

``` python

def loss_SR3(
    alpha, model, dataset, vk, G, L1_reg, options
):

```

*loss used for 2BC with SR3*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L115"
target="_blank" style="float:right; font-size:smaller">source</a>

### derivative_loss_alpha_multi_vk

``` python

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).

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L106"
target="_blank" style="float:right; font-size:smaller">source</a>

### loss_SR2

``` python

def loss_SR2(
    alpha, model, dataset, G, L1_reg, options
):

```

*loss used for the 2BC witb SR2*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L96"
target="_blank" style="float:right; font-size:smaller">source</a>

### derivative_loss_alpha_multi

``` python

def derivative_loss_alpha_multi(
    tree, X, options, G
):

```

*loss aligning the gradiant*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L89"
target="_blank" style="float:right; font-size:smaller">source</a>

### loss_SR1

``` python

def loss_SR1(
    alpha, model, X, Y, L1_reg, options
):

```

*loss used for the 2BC witb SR1*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L77"
target="_blank" style="float:right; font-size:smaller">source</a>

### class_loss

``` python

def class_loss(
    tree, X, options, Y
):

```

*classification loss used for the 2BC witb SR1*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L42"
target="_blank" style="float:right; font-size:smaller">source</a>

### TwoBodyModel

``` python

def TwoBodyModel(
    pairs, key, add_constant:bool=False
):

```

*Initialize self. See help(type(self)) for accurate signature.*

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L26"
target="_blank" style="float:right; font-size:smaller">source</a>

### FFNN_theta_to_mu

``` python

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

------------------------------------------------------------------------

<a
href="https://github.com/qic-ibk/qdisc/blob/main/qdisc/sr/core.py#L265"
target="_blank" style="float:right; font-size:smaller">source</a>

### SymbolicRegression

``` python

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)
