> ## Documentation Index
> Fetch the complete documentation index at: https://doc.blueapi.ir/llms.txt
> Use this file to discover all available pages before exploring further.

# Mutation Operators for Merge Genome Evolution

> Specification for mutation operators in EMEP, including alpha jitter, per-layer perturbation, strategy switch, and density adjustment with rate scheduling.

Mutation operators introduce variation into merge genomes during the EMEP evolutionary loop. Each operator targets a specific genome field and applies a bounded perturbation. This page specifies the available operators, their mechanics, rate scheduling, and validation constraints.

## Mutation Flowchart

```mermaid theme={null}
flowchart TD
    START([START]) --> INPUT[Input Genome]
    INPUT --> RATE{Mutation Rate Check}
    RATE -->|Skip| OUTPUT1[Return Unchanged]
    RATE -->|Apply| SELECT[Select Operator]
    SELECT --> OP1[Alpha Jitter]
    SELECT --> OP2[Per-Layer Perturbation]
    SELECT --> OP3[Strategy Switch]
    SELECT --> OP4[Density Adjustment]
    OP1 --> VALIDATE[Validate Genome]
    OP2 --> VALIDATE
    OP3 --> VALIDATE
    OP4 --> VALIDATE
    VALIDATE -->|Valid| OUTPUT2[Return Mutated Genome]
    VALIDATE -->|Invalid| RETRY{Retry Limit?}
    RETRY -->|Below| SELECT
    RETRY -->|Exceeded| OUTPUT1
    OUTPUT1 --> END([END])
    OUTPUT2 --> END
```

## Alpha Jitter

Perturbs global alpha coefficients by adding Gaussian noise. The noise scale is proportional to the current alpha value to preserve relative weighting.

```text theme={null}
alpha_i' = alpha_i + N(0, sigma * alpha_i)
alpha_i' = clip(alpha_i', 0, 1)
alpha' = normalize(alpha')
```

Sigma is configurable, default 0.1. After perturbation, coefficients are re-normalized to sum to 1.0. If any coefficient falls below a minimum threshold (default 0.01), it is set to zero and the remainder re-normalized.

## Per-Layer Perturbation

Applies alpha jitter independently to each layer range defined in `per_layer_alpha`. This allows the genome to evolve heterogeneous blending across the model depth. The same Gaussian noise model applies per layer range.

If `per_layer_alpha` is absent, the operator has a configurable probability of creating it by copying global alpha into layer-specific ranges.

## Strategy Switch

Replaces the merge method with another supported strategy. The switch is random but weighted by historical success rates. Methods with higher average fitness in the current experiment receive higher switch probability.

Supported transitions:

| From            | To              | Notes                                                |
| --------------- | --------------- | ---------------------------------------------------- |
| TIES            | DARE            | Both use density, transition preserves density value |
| DARE            | TIES            | Density value remains valid                          |
| SLERP           | Task Arithmetic | Alpha becomes task vector scaling                    |
| Task Arithmetic | SLERP           | Task vectors discarded, alpha restored               |
| Any             | Franken-Merge   | Requires layer routing initialization                |

## Density Adjustment

Modifies the density parameter for TIES (Yadav et al. 2023) and DARE (Yu et al. 2023) merges. Adjustment is multiplicative:

```text theme={null}
density' = density * (1 + N(0, sigma_density))
density' = clip(density', min_density, 1.0)
```

Default sigma\_density is 0.15. Minimum density is 0.2. Values below 0.2 are rejected as too sparse for stable merges.

## Rate and Schedule

The base mutation rate is 0.1 per gene. EMEP supports two schedules:

**Static**: fixed rate for all generations **Adaptive**: rate increases when diversity falls, decreases when diversity is high

```text theme={null}
rate_adaptive = base_rate * (1 + (diversity_target - diversity_current) / diversity_target)
rate_adaptive = clip(rate_adaptive, 0.05, 0.5)
```

## Retry Logic

Invalid mutations are retried up to 3 times with the same operator. If all retries fail, the genome is returned unchanged. Invalid states include:

* Alpha coefficients that do not sum to 1.0 after normalization
* Density outside valid range
* Strategy switch to incompatible parent configuration
* Layer routing with gaps or overlaps

## Validation

Every mutated genome passes through the same validation rules as manually created genomes. See [Genome](/evolution/genome) for the full validation specification.

<Warning>
  High mutation rates combined with small population sizes can destabilize the search. If more than 30% of mutations produce invalid genomes, the engine logs a warning and suggests reducing mutation rate or expanding the search space.
</Warning>
