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

Stochastic introspective mini-batch ascent.

Each of `max_steps` steps:

1. takes the next training minibatch of `bsz` rows from a seeded shuffle;
2. runs `num_candidates` trajectories per row, each with a program sampled
   from the pool by a softmax over mean minibatch scores (`temperature`);
3. ranks rows by the gap between their best and worst trajectory scores,
   then by lowest best score, so variable and then weak behavior is
   targeted first;
4. for the top `num_candidates` rows, builds a new candidate from a sampled
   pool program with one strategy, chosen at random:
   * `append_a_demo` adds the best trajectory's final call per predictor as a
     demonstration (keeping at most `max_demos`),
   * `append_a_rule` asks the proposal role to contrast the best and worst
     trajectory and appends the advice to one predictor's instruction;
   the positive trajectory is the row's own best when it succeeded and
   beat its worst; for a weak row with no gap, it is the best successful
   trajectory of another minibatch row that scored higher. A row with no
   such positive is skipped, so failures never become demonstrations;
5. scores new candidates on the same minibatch and adds them to the pool.

Finally the baseline and the `num_final` best pool programs by mean
minibatch score are evaluated on the full validation set; only a complete,
eligible validation result is returned.

Options: `:bsz` (default 4), `:num_candidates` (default 4), `:max_steps`
(default 4), `:max_demos` (default 4), `:temperature` (default 0.2),
`:num_final` (default 3).

Differences from DSPy: trajectory variation comes from sampling pool
programs, not from changing the model temperature; final selection uses
the explicit validation set.

---

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