Skip to content

gurobi_standard_genetics

Joshua Fogg edited this page Jul 31, 2024 · 2 revisions
gurobi_standard_genetics(sigma, mu, sires, dams, lam, kappa, dimension, upper_bound, lower_bound, time_limit, model_output, debug)

Solve the non-robust (i.e. standard) optimal contribution selection problem using Gurobi. Consider a breeding cohort whose relationships are modelled some matrix $\Sigma$ with and whose expected breeding values $\boldsymbol\mu$. This function uses quadratic programming the contribution $\mathbf{w}$ which maximises expected breeding value subject to considering the worst case for group co-ancestry under some constraints.

Parameters

  • sigma : ndarray or spmatrix
    Relationship matrix $\Sigma$ for the candidates in the cohort. This can either be a dense NumPy array or a sparse SciPy matrix, but either way must be symmetric and positive definite. If an estimated model is being used then any correction should be done before use here.
  • mu : ndarray
    Vector $\boldsymbol\mu$ of expected breeding values for candidates in the cohort for selection.
  • sires : Any
    An object representing an set of indices for all sires (male candidates) in the cohort. Type is not restricted, so could be a NumPy array, a set, a list, an iterator like range, etc.
  • dams : Any
    An object representing an set of indices for all dams (female candidates) in the cohort. Type is not restricted, so could be a NumPy array, a set, a list, an iterator like range, etc.
  • lam : float
    Controls the balance between risk and return, with lower values giving riskier selections and higher more conservative ones. This can take any real value, but $\lambda<0$ effectively corresponds to rewarding inbreeding so should not be considered.
  • dimension : int
    Number of candidates in the cohort, i.e. the dimension of the problem. While strictly speaking this is evident from the other parameters, it's asked for as a convenience to prevent repeated calculation.
  • upper_bound : ndarray or float, optional
    Upper bound on how much each candidate can contribute. This can be an array of differing bounds for each candidate, or a float which applies to all candidates equally. This value should be such that $0\leq l_i \leq u_i \leq 1$ and the default is, $\mathbf{u} = \mathbf{1}$, enforced by the contributions $\mathbf{w}$ being a vector proportions rather than absolute values.
  • lower_bound : ndarray or float, optional
    Lower bound on how much each candidate can contribute. This can be an array of differing bounds for each candidate, or a float which applies to all candidates equally. This value should be such that $0\leq l_i \leq u_i \leq 1$ and the default is, $\mathbf{l} = \mathbf{0}$, enforced by the contributions $\mathbf{w}$ being a vector proportions rather than absolute values.
  • time_limit : float, optional
    Maximum amount of time in seconds to give Gurobi to solve the problem. Optional, with the default being no time limit.
  • model_output : str, optional
    Name to use if saving the model file to the working directory. If given, the string is used as the file name, '{model_output}.mps'. This is optional, and by default the file isn't saved.
  • debug : bool, optional
    Flag which controls whether Gurobi prints its output to terminal. Default value is False.

Returns

  • ndarray
    Portfolio vector $\mathbf{w}$ which Gurobi has determined is a solution.
  • float
    Value of the objective function for returned solution.

Examples

If a problem had been loaded into Python, then usage of this function might look like

>>> w, obj = robustocs.gurobi_standard_genetics(
...     sigma, mu, sires, dams, lam=0.5, dimension=4)
>>> w
array([7.40340335e-11, 7.40340335e-11, 5.00000000e-01, 5.00000000e-01])
>>> obj
1.8749999998889488

Note that due to differing methods this need not give exactly the same solution as highs_standard_genetics though they should be similar to some tolerance.