BinarySelectionProtocol#
- class pybrops.breed.prot.sel.BinarySelectionProtocol.BinarySelectionProtocol(ncross, nparent, nmating, nprogeny, nobj, obj_wt=None, obj_trans=None, obj_trans_kwargs=None, nineqcv=None, ineqcv_wt=None, ineqcv_trans=None, ineqcv_trans_kwargs=None, neqcv=None, eqcv_wt=None, eqcv_trans=None, eqcv_trans_kwargs=None, ndset_wt=None, ndset_trans=None, ndset_trans_kwargs=None, rng=None, soalgo=None, moalgo=None, **kwargs)[source]#
Bases:
SelectionProtocol
Semi-abstract class for creating binary selection protocols.
Constructor for the semi-abstract class BinarySelectionProtocol.
- Parameters:
ncross (Integral) – Number of cross configurations to consider.
nparent (Integral) – Number of parents per cross configuration.
nmating (Integral, numpy.ndarray) –
Number of matings per configuration.
If
nmating
isIntegral
, then broadcast to anumpy.ndarray
of shape(ncross,)
.If
nmating
isnumpy.ndarray
, then the array must be of typeIntegral
and of shape(ncross,)
.nprogeny (Integral, numpy.ndarray) –
Number of progeny to derive from each mating event.
If
nprogeny
isIntegral
, then broadcast to anumpy.ndarray
of shape(ncross,)
.If
nprogeny
isnumpy.ndarray
, then the array must be of typeIntegral
and of shape(ncross,)
.nobj (Integral) – Number of optimization objectives when constructing a
SelectionProblem
. This is equivalent to the vector length returned by theobj_trans
function. Must beIntegral
greater than 0.obj_wt (numpy.ndarray, Real, None) –
Objective function weights. Weights from this vector are applied to objective function values via the Hadamard product. If values are
1.0
or-1.0
, this can be used to specify minimizing and maximizing objectives, respectively.If
obj_wt
isnumpy.ndarray
, then the array must be of shape(nobj,)
.If
obj_wt
isReal
, then the value is broadcast to anumpy.ndarray
of shape(nobj,)
.If
obj_wt
isNone
, then the value1.0
is broadcast to anumpy.ndarray
of shape(nobj,)
. This assumes that all objectives are to be minimized.obj_trans (Callable, None) –
A function which transforms values from a latent objective space to the objective space. This transformation function must have the following signature:
def obj_trans( decnvec: numpy.ndarray, latentvec: numpy.ndarray, **kwargs: dict ) -> numpy.ndarray: # do stuff return output
Where:
decnvec
is anumpy.ndarray
containing the decision vector.latentvec
is anumpy.ndarray
containing the latent spaceobjective function values which are to be transformed.
kwargs
is adict
containing additional keyword arguments.
If
obj_trans
isNone
, then default to an identity objective transformation function.obj_trans_kwargs (dict) –
Keyword arguments for the latent space to objective space transformation function.
If obj_trans_kwargs` is
None
, then default to an empty dictionary.nineqcv (Integral, None) –
Number of inequality constraint violation functions. This is equivalent to the vector length returned by the
ineqcv_trans
function. Must beIntegral
greater than or equal to zero.If
nineqcv
isNone
, then set to zero.ineqcv_wt (numpy.ndarray, None) –
Inequality constraint violation function weights. Weights from this vector are applied to inequality constraint violation function values via the Hadamard product. If values are
1.0
or-1.0
, this can be used to specify minimizing and maximizing constraints, respectively.If
ineqcv_wt
isnumpy.ndarray
, then the array must be of shape(nineqcv,)
.If
ineqcv_wt
isReal
, then the value is broadcast to anumpy.ndarray
of shape(nineqcv,)
.If
ineqcv_wt
isNone
, then the value1.0
is broadcast to anumpy.ndarray
of shape(nineqcv,)
. This assumes that all constraints are to be minimized.ineqcv_trans (Callable, None) –
A function which transforms values from a latent objective space to the inequality constraint violation space. This transformation function must have the following signature:
def ineqcv_trans( decnvec: numpy.ndarray, latentvec: numpy.ndarray, **kwargs: dict ) -> numpy.ndarray: # do stuff return output
Where:
decnvec
is anumpy.ndarray
containing the decision vector.latentvec
is anumpy.ndarray
containing the latent spaceobjective function values which are to be transformed.
kwargs
is adict
containing additional keyword arguments.
If
ineqcv_trans
isNone
, then default to a transformation function returning an empty vector.ineqcv_trans_kwargs (dict, None) –
Keyword arguments for the latent space to inequality constraint violation transformation function.
If ineqcv_trans_kwargs` is
None
, then default to an empty dictionary.neqcv (Integral, None) –
Number of equality constraint violations. This is equivalent to the vector length returned by the
eqcv_trans
function. Must beIntegral
greater than or equal to zero.If
neqcv
isNone
, then set to zero.eqcv_wt (numpy.ndarray, None) –
Equality constraint violation function weights. Weights from this vector are applied to equality constraint violation function values via the Hadamard product. If values are
1.0
or-1.0
, this can be used to specify minimizing and maximizing constraints, respectively.If
eqcv_wt
isnumpy.ndarray
, then the array must be of shape(neqcv,)
.If
eqcv_wt
isReal
, then the value is broadcast to anumpy.ndarray
of shape(neqcv,)
.If
eqcv_wt
isNone
, then the value1.0
is broadcast to anumpy.ndarray
of shape(neqcv,)
. This assumes that all constraints are to be minimized.eqcv_trans (Callable, None) –
A function which transforms values from a latent objective space to the equality constraint violation space. This transformation function must have the following signature:
def eqcv_trans( decnvec: numpy.ndarray, latentvec: numpy.ndarray, **kwargs: dict ) -> numpy.ndarray: # do stuff return output
Where:
decnvec
is anumpy.ndarray
containing the decision vector.latentvec
is anumpy.ndarray
containing the latent spaceobjective function values which are to be transformed.
kwargs
is adict
containing additional keyword arguments.
If
eqcv_trans
isNone
, then default to a transformation function returning an empty vector.eqcv_trans_kwargs (dict, None) –
Keyword arguments for the latent space to equality constraint violation transformation function.
If eqcv_trans_kwargs` is
None
, then default to an empty dictionary.ndset_wt (Real, None) –
Nondominated set weight. The weight from this function is applied to outputs from
ndset_trans
. If values are1.0
or-1.0
, this can be used to specify minimizing and maximizing objectives, respectively.If
ndset_wt
isNone
, then it is set to the default value of1.0
. This assumes that the objective is to be minimized.ndset_trans (Callable, None) –
A function which transforms values from the non-dominated set objective space to the single-objective space. This transformation function must have the following signature:
def ndset_trans( mat: numpy.ndarray, **kwargs: dict ) -> numpy.ndarray: # do stuff return output
Where:
mat
is anumpy.ndarray
containing a point coordinate arrayof shape
(npt, nobj)
wherenpt
is the number of points andnobj
is the number of objectives (dimensions). This array contains input points for calculating the distance between a point to the vectorvec_wt
.
kwargs
is adict
containing additional keyword arguments.
If
ndset_trans
isNone
, then default to a transformation function calculating the distance between a weight vector and provided pointsndset_trans_kwargs (dict, None) –
Nondominated set transformation function keyword arguments.
If
ndset_trans_kwargs
isNone
, then default to defaults for the defaultndset_trans
function:ndset_trans_kwargs = { "obj_wt": numpy.repeat(1.0, nobj), "vec_wt": numpy.repeat(1.0, nobj) }
rng (numpy.random.Generator, numpy.random.RandomState, None) –
Random number source.
If
rng
isNone
, default to the global random number generator.soalgo (BinaryOptimizationAlgorithm, None) –
Single-objective optimization algorithm.
If
soalgo
isNone
, then use a default single-objective optimization algorithm.moalgo (BinaryOptimizationAlgorithm, None) –
Multi-objective opimization algorithm.
If
moalgo
isNone
, then use a default multi-objective optimization algorithm.kwargs (dict) – Additional keyword arguments.
Methods
Calculate a Pareto frontier for objectives.
Create an optimization problem definition using provided inputs.
Select individuals for breeding.
Solve the selection problem using a single-objective optimization algorithm.
Attributes
Function which transforms outputs from
latentfn
to equality constraint violation values.Keyword arguments for the latent space to equality constraint violation transformation function.
Equality constraint violation function weights.
Function which transforms outputs from
latentfn
to inequality constraint violation values.Keyword arguments for the latent space to inequality constraint violation transformation function.
Inequality constraint violation function weights.
Multi-objective opimization algorithm.
Number of cross configurations to consider.
Nondominated set transformation function.
Nondominated set transformation function keyword arguments.
Nondominated set weights.
Number of equality constraint violations.
Number of inequality constraint violation functions.
Number of matings per cross configuration.
Number of optimization objectives.
Number of parents per cross configuration.
Number of progeny to derive from each mating event.
Number of selected individuals.
Function which transforms outputs from
latentfn
to objective function values.Keyword arguments for the latent space to objective space transformation function.
Objective function weights.
rng.
Single-objective optimization algorithm.
- property eqcv_trans: Callable[[ndarray, ndarray, dict], ndarray]#
Function which transforms outputs from
latentfn
to equality constraint violation values.
- property eqcv_trans_kwargs: dict#
Keyword arguments for the latent space to equality constraint violation transformation function.
- property eqcv_wt: ndarray#
Equality constraint violation function weights.
- property ineqcv_trans: Callable[[ndarray, ndarray, dict], ndarray]#
Function which transforms outputs from
latentfn
to inequality constraint violation values.
- property ineqcv_trans_kwargs: dict#
Keyword arguments for the latent space to inequality constraint violation transformation function.
- property ineqcv_wt: ndarray#
Inequality constraint violation function weights.
- property moalgo: BinaryOptimizationAlgorithm#
Multi-objective opimization algorithm.
- mosolve(pgmat, gmat, ptdf, bvmat, gpmod, t_cur, t_max, miscout=None, **kwargs)[source]#
Calculate a Pareto frontier for objectives.
- Parameters:
pgmat (PhasedGenotypeMatrix) – Genomes
gmat (GenotypeMatrix) – Genotypes
ptdf (pandas.DataFrame) – Phenotype dataframe
bvmat (BreedingValueMatrix) – Breeding value matrix
gpmod (GenomicModel) – Genomic prediction model
t_cur (int) – Current generation number.
t_max (int) – Maximum (deadline) generation number.
miscout (dict, None) – Pointer to a dictionary for miscellaneous user defined output. If
dict
, write to dict (may overwrite previously defined fields). IfNone
, user defined output is not calculated or stored.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A tuple containing two objects
(frontier, sel_config)
.Where:
frontier
is anumpy.ndarray
of shape(q,v)
containing Pareto frontier points.sel_config
is anumpy.ndarray
of shape(q,k)
containing parent selection decisions for each corresponding point in the Pareto frontier.
Where:
q
is the number of points in the frontier.v
is the number of objectives for the frontier.k
is the number of search space decision variables.
- Return type:
tuple
- property ncross: Integral#
Number of cross configurations to consider.
- property ndset_trans: Callable[[ndarray, dict], ndarray]#
Nondominated set transformation function.
- property ndset_trans_kwargs: dict#
Nondominated set transformation function keyword arguments.
- property ndset_wt: Real#
Nondominated set weights.
- property neqcv: Integral#
Number of equality constraint violations.
- property nineqcv: Integral#
Number of inequality constraint violation functions.
- property nmating: ndarray#
Number of matings per cross configuration.
- property nobj: Integral#
Number of optimization objectives.
- property nparent: Integral#
Number of parents per cross configuration.
- property nprogeny: ndarray#
Number of progeny to derive from each mating event.
- property nselindiv: Integral#
Number of selected individuals.
- property obj_trans: Callable[[ndarray, ndarray, dict], ndarray]#
Function which transforms outputs from
latentfn
to objective function values.
- property obj_trans_kwargs: dict#
Keyword arguments for the latent space to objective space transformation function.
- property obj_wt: ndarray#
Objective function weights.
- abstract problem(pgmat, gmat, ptdf, bvmat, gpmod, t_cur, t_max, **kwargs)[source]#
Create an optimization problem definition using provided inputs.
- Parameters:
pgmat (PhasedGenotypeMatrix) – Genomes
gmat (GenotypeMatrix) – Genotypes
ptdf (pandas.DataFrame) – Phenotype dataframe
bvmat (BreedingValueMatrix) – Breeding value matrix
gpmod (GenomicModel) – Genomic prediction model
t_cur (int) – Current generation number.
t_max (int) – Maximum (deadline) generation number.
kwargs (dict) – Additional keyword arguments.
- Returns:
out – An optimization problem definition.
- Return type:
- property rng: Generator | RandomState#
rng.
- select(pgmat, gmat, ptdf, bvmat, gpmod, t_cur, t_max, miscout=None, **kwargs)[source]#
Select individuals for breeding.
- Parameters:
pgmat (PhasedGenotypeMatrix) – Genomes
gmat (GenotypeMatrix) – Genotypes
ptdf (pandas.DataFrame) – Phenotype dataframe
bvmat (BreedingValueMatrix) – Breeding value matrix
gpmod (GenomicModel) – Genomic prediction model
t_cur (int) – Current generation number.
t_max (int) – Maximum (deadline) generation number.
miscout (dict, None) – Pointer to a dictionary for miscellaneous user defined output. If
dict
, write to dict (may overwrite previously defined fields). IfNone
, user defined output is not calculated or stored.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A selection configuration object, requiring all necessary information to mate individuals.
- Return type:
- property soalgo: BinaryOptimizationAlgorithm#
Single-objective optimization algorithm.
- sosolve(pgmat, gmat, ptdf, bvmat, gpmod, t_cur, t_max, miscout=None, **kwargs)[source]#
Solve the selection problem using a single-objective optimization algorithm.
- Parameters:
pgmat (PhasedGenotypeMatrix) – Genomes
gmat (GenotypeMatrix) – Genotypes
ptdf (pandas.DataFrame) – Phenotype dataframe
bvmat (BreedingValueMatrix) – Breeding value matrix
gpmod (GenomicModel) – Genomic prediction model
t_cur (int) – Current generation number.
t_max (int) – Maximum (deadline) generation number.
miscout (dict, None) – Pointer to a dictionary for miscellaneous user defined output. If
dict
, write to dict (may overwrite previously defined fields). IfNone
, user defined output is not calculated or stored.kwargs (dict) – Additional keyword arguments.
- Returns:
out – A single-objective solution to the posed selection problem.
- Return type: