> For the complete documentation index, see [llms.txt](https://finch-1.gitbook.io/version0.0.1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://finch-1.gitbook.io/version0.0.1/layers/float-array-layers.md).

# Float Array Layers

### FloatPool

`FloatPool` generates individuals with float genes within specified ranges.

```python
pool = FloatPool(ranges=[[0, 1], [-1, 1]], length=3, fitness_function=fitness_func)
```

* `ranges`: List of \[min, max] for each gene
* `length`: Number of genes per individual
* `fitness_function`: Evaluates individual fitness
* `device`: 'cpu' or 'gpu' (default: 'cpu')

Generates individuals with random float values within the specified ranges.

### ParentBlendFloat

`ParentBlendFloat` performs blend crossover between parents.

```python
blend_layer = ParentBlendFloat(selection_function=select_func, families=5, children=2, alpha=0.5)
```

* `selection_function`: Selects parents
* `families`: Number of families to create
* `children`: Children per family
* `alpha`: Blending factor (default: 0.5)
* `device`: 'cpu' or 'gpu' (default: 'cpu')

For each gene:

```
child_gene = parent1_gene + gamma * (parent2_gene - parent1_gene)
where gamma = uniform(-alpha, 1 + alpha)
```

### ParentSimulatedBinaryFloat

`ParentSimulatedBinaryFloat` simulates binary crossover for float genes.

```python
sbx_layer = ParentSimulatedBinaryFloat(selection_function=select_func, families=5, children=2, eta=1.0)
```

* `selection_function`: Selects parents
* `families`: Number of families to create
* `children`: Children per family
* `eta`: Distribution index (default: 1.0)
* `device`: 'cpu' or 'gpu' (default: 'cpu')

For each gene:

```
beta = (2u)^(1/(eta+1))         if u <= 0.5
beta = (1/(2(1-u)))^(1/(eta+1)) if u > 0.5
where u is a random number in [0, 1]

child1_gene = 0.5 * ((1 + beta) * parent1_gene + (1 - beta) * parent2_gene)
child2_gene = 0.5 * ((1 - beta) * parent1_gene + (1 + beta) * parent2_gene)
```

### ParentArithmeticFloat

`ParentArithmeticFloat` creates children by weighted averaging of parents' genes.

```python
arithmetic_layer = ParentArithmeticFloat(selection_function=select_func, families=5, children=2, alpha='uniform')
```

* `selection_function`: Selects parents
* `families`: Number of families to create
* `children`: Children per family
* `alpha`: Mixing ratio (default: 'uniform')
* `device`: 'cpu' or 'gpu' (default: 'cpu')

For each gene:

```
child_gene = alpha * parent1_gene + (1 - alpha) * parent2_gene
where alpha is either fixed or random per child if 'uniform'
```

### GaussianMutation

`GaussianMutation` applies Gaussian noise to genes.

```python
gaussian_mutation = GaussianMutation(mutation_rate=0.1, sigma=0.1, selection_function=select_func)
```

* `mutation_rate`: Probability of mutating each gene
* `sigma`: Standard deviation of Gaussian noise
* `selection_function`: Selects individuals for mutation
* `device`: 'cpu' or 'gpu' (default: 'cpu')
* `overpowered`: If True, only applies beneficial mutations (default: False)

For each gene, with probability `mutation_rate`:

```
gene = gene + normal(0, sigma)
```

### UniformMutation

`UniformMutation` replaces genes with uniform random values.

```python
uniform_mutation = UniformMutation(mutation_rate=0.1, lower_bound=-1, upper_bound=1, selection_function=select_func)
```

* `mutation_rate`: Probability of mutating each gene
* `lower_bound`: Minimum value for mutation
* `upper_bound`: Maximum value for mutation
* `selection_function`: Selects individuals for mutation
* `device`: 'cpu' or 'gpu' (default: 'cpu')
* `overpowered`: If True, only applies beneficial mutations (default: False)

For each gene, with probability `mutation_rate`:

```
gene = uniform(lower_bound, upper_bound)
```

### PolynomialMutation

`PolynomialMutation` applies polynomial mutation to genes.

```python
polynomial_mutation = PolynomialMutation(mutation_rate=0.1, eta=20, bounds=[[-1, 1], [-1, 1]], selection_function=select_func)
```

* `mutation_rate`: Probability of mutating each gene
* `eta`: Distribution index
* `bounds`: List of \[min, max] for each gene
* `selection_function`: Selects individuals for mutation
* `device`: 'cpu' or 'gpu' (default: 'cpu')
* `overpowered`: If True, only applies beneficial mutations (default: False)

For each gene, with probability `mutation_rate`:

```
delta = (2u)^(1/(eta+1)) - 1        if u < 0.5
delta = 1 - (2(1-u))^(1/(eta+1))    if u >= 0.5
where u is a random number in [0, 1]

gene = gene + delta * (upper_bound - lower_bound)
gene = clip(gene, lower_bound, upper_bound)
```

### InsertionDeletionMutationFloat

`InsertionDeletionMutationFloat` moves a random gene to a new position.

```python
insertion_deletion_mutation = InsertionDeletionMutationFloat(selection_function=select_func)
```

* `selection_function`: Selects individuals for mutation
* `device`: 'cpu' or 'gpu' (default: 'cpu')
* `overpowered`: If True, only applies beneficial mutations (default: False)

Process:

1. Select a random gene
2. Remove it from its current position
3. Insert it at a new random position

### Example Usage

```python
from Finch.generic import Environment
from Finch.layers.float_arrays import FloatPool, ParentBlendFloat, GaussianMutation
from Finch.layers.universal_layers import Populate, SortByFitness, CapPopulation
from Finch.selectors import TournamentSelection

def fitness_function(individual):
    return sum(individual.item)

pool = FloatPool(ranges=[[0, 1], [0, 1], [0, 1]], length=3, fitness_function=fitness_function)
layers = [
    Populate(population=100, gene_pool=pool),
    ParentBlendFloat(selection_function=TournamentSelection(percent_to_select=0.1).select, families=10, children=2),
    GaussianMutation(mutation_rate=0.1, sigma=0.1, selection_function=TournamentSelection(percent_to_select=0.2).select),
    SortByFitness(),
    CapPopulation(max_population=100)
]

env = Environment(layers=layers)
env.compile()
env.evolve(generations=100)
```

This setup creates and evolves a population of 100 individuals, each with 3 genes, using blend crossover and Gaussian mutation.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://finch-1.gitbook.io/version0.0.1/layers/float-array-layers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
