# Symmetry
{class}`~baybe.symmetries.base.Symmetry` is a concept tied to the structure of the searchspace.
It is thus closely related to a {class}`~baybe.constraints.base.Constraint`, but has a
different purpose in BayBE:
- **Constraint**: Excludes parts of the searchspace from recommendation. If a problem
shows invariance, you can use constraints to exclude redundant regions from the search.
- **Symmetry**: Influences the way the problem is modeled, for example by applying
symmetry-aware data augmentation. This can be applied independently of constraints.
For an example of the influence of constraints and/or data augmentation via symmetries
on the optimization of a permutation invariant function,
[see here](/examples/Symmetries/permutation).
## Definitions
The following table summarizes available symmetries in BayBE:
| Symmetry | Functional Definition | Corresponding Constraint |
|:-----------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------|
| {class}`~baybe.symmetries.permutation.PermutationSymmetry` | $f(x,y) = f(y,x)$ | {class}`~baybe.constraints.discrete.DiscretePermutationInvarianceConstraint` | |
|
| {class}`~baybe.symmetries.dependency.DependencySymmetry` | $f(x,y) = \begin{cases}g(x,y) & \text{if }c(x) \\h(x) & \text{otherwise}\end{cases}$
where $c(x)$ is a condition that is either true or false | {class}`~baybe.constraints.discrete.DiscreteDependenciesConstraint` |
| {class}`~baybe.symmetries.mirror.MirrorSymmetry` | $f(x,y) = f(-x,y)$ | No constraint is available. Instead, the number range for that parameter can simply be restricted. |
## Data Augmentation
This can be a powerful tool to improve the modeling process. Data augmentation
essentially changes the data that the model is fitted on by adding more points. The
augmented points are constructed such that they represent a symmetric point compared
with their original, which always corresponds to a different transformation depending
on which symmetry is responsible.
If the surrogate model receives such augmented points, it can learn the symmetry. This
has the advantage that it can improve predictions for unseen points and is fully
model-agnostic. Downsides are increased training time and potential computational
challenges arising from a fit on substantially more points. Data augmentation is
controlled by assigning symmetries to the
{attr}`~baybe.recommenders.pure.bayesian.base.BayesianRecommender.symmetries`
attribute of the recommender.
Below we illustrate the effect of data augmentation for the different symmetries
supported by BayBE:

## Invariant Kernels
Some machine learning models can be constructed with architectures that automatically
respect a symmetry, i.e. applying the model to an augmented point always produces the
same output as the original point by construction.
For Gaussian processes, this can be achieved by applying special kernels.
```{admonition} Not Implemented Yet
:class: warning
Ideally, invariant kernels will be applied automatically when a corresponding symmetry has been
configured for the surrogate model GP. This feature is not implemented yet.
```