EmuKit / emukit

A Python-based toolbox of various methods in decision making, uncertainty quantification and statistical emulation: multi-fidelity, experimental design, Bayesian optimisation, Bayesian quadrature, etc.
https://emukit.github.io/emukit/
Apache License 2.0
600 stars 128 forks source link

Support for Generics in Parameter class #297

Open ekalosak opened 4 years ago

ekalosak commented 4 years ago

Parameter[float, int, Decimal, Fraction] or even something like numeric a => Parameter[a] would be extremely helpful for validating model constructions.

apaleyes commented 4 years ago

Interesting idea, but the use isn't entirely clear. Can you give a quick conceptual example of how would you use this GenericParameter?

ekalosak commented 4 years ago
A = TypeVar('A', a, b)
B = Sequence[A]
class BanditParameter(Parameter[B]):
  def __init__(self, name: str,
    subparameters: Sequence[Parameter[A]],  # should be isomorphic to B, ignoring constraints on Parameter[A] domains
    domain: Sequence[B]
  ):
  ...

Effectively to enforce the membership of the elements in the Bandit domain in their respective Parameter[A] domains. The type signature above doesn't nail it exactly, but that's the motivation :)

Also for determining which encodings to use for parameters automatically in constructing models that support different types of parameters e.g. model A can handle categorical inputs natively, model B requires a 1-hot encoding.