easyiec.core.Box#

class easyiec.core.Box(lower, upper, names=None, kinds=None, log=None, categories=None, units=None)[source]#

Bases: object

Axis-aligned box \([\mathbf l,\mathbf u]\) with typed, named genes.

Parameters:
lower, upperarray_like of shape (d,)

Bounds in natural units; upper > lower elementwise.

namessequence of str, optional

Gene names (default x0, x1, ...). Used in plots, prompts and exports.

kindssequence of {“real”, “int”, “cat”}, optional

Gene types; "cat" genes take values 0, ..., n_cat-1 decoded by flooring a real in [0, n_cat).

logsequence of bool, optional

Logarithmic scaling between the bounds (requires positive bounds).

categoriesdict, optional

{gene index: list of labels} for categorical genes.

unitssequence of str, optional

Physical units shown in descriptions.

Examples

>>> b = Box([0, 1e-2], [1, 10], names=["mix", "gain"], log=[False, True])
>>> z = b.normalize([0.5, 0.1]); [round(float(v), 4) for v in z]
[0.5, 0.3333]
>>> [round(float(v), 4) for v in b.denormalize(z)]
[0.5, 0.1]
clip(x)[source]#

Clip to the bounds.

decode(x)[source]#

Genome → {name: value} with integer/categorical genes resolved.

denormalize(z)[source]#

Map unit-cube points to natural units (clipped to the box).

describe(x)[source]#

One line per gene with name, value and range (used in LLM prompts).

property dim#

Number of genes \(d\).

label(i, value)[source]#

Human-readable value of gene i (category label, rounded number + unit).

normalize(x)[source]#

Map natural-unit genomes to the unit cube (works row-wise on 2-D input).

sample(rng, n=None)[source]#

Uniform samples in the unit cube mapped to natural units.