# `Tune.Optimizers.TPE`
[🔗](https://github.com/mikehostetler/tune/blob/v0.5.0/lib/tune/optimizers/tpe.ex#L1)

A categorical Tree-structured Parzen Estimator.

Each dimension is a categorical choice `0..n-1`. The first `n_startup`
suggestions are uniform. After that, observations are split into a good
group (the best `min(ceil(gamma * n), 25)` scores, higher is better) and a
bad group. For each dimension independently, smoothed category densities
`l(x)` and `g(x)` are computed with a uniform prior of weight `prior_weight`;
`n_candidates` values are sampled from `l` and the one with the highest
`l(x) / g(x)` is chosen, earliest on ties.

This follows the documented behavior of Optuna's independent categorical TPE
sampler. It does not reproduce Optuna's random number stream, multivariate
mode, or Parzen weighting of older trials.

# `choice`

```elixir
@type choice() :: %{required(String.t()) =&gt; non_neg_integer()}
```

# `t`

```elixir
@type t() :: %Tune.Optimizers.TPE{
  gamma: float(),
  n_candidates: pos_integer(),
  n_startup: non_neg_integer(),
  prior_weight: float(),
  space: %{required(String.t()) =&gt; pos_integer()}
}
```

# `new`

```elixir
@spec new(%{required(String.t()) =&gt; pos_integer()}, keyword()) :: t()
```

Builds a sampler for a space of dimension name to category count.

# `suggest`

```elixir
@spec suggest(t(), [{choice(), number()}], Tune.Search.Program.Context.t()) ::
  {choice(), Tune.Search.Program.Context.t()}
```

Suggests one choice from `{choice, score}` observations.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
