1 core.vectors.LinearCombination
core.vectors.LinearCombination(coefficients, vector)Linear combination of vector elements with constant coefficients.
Represents: c[0]x[0] + c[1]x[1] + … + c[n-1]*x[n-1]
This enables efficient numpy integration: coefficients @ vector.
1.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| coefficients | np.ndarray | NumPy array of constant coefficients. | required |
| vector | VectorVariable | VectorExpression | VectorVariable or VectorExpression to combine. | required |
1.2 Example
import numpy as np returns = np.array([0.12, 0.08, 0.10]) weights = VectorVariable(“w”, 3) portfolio_return = LinearCombination(returns, weights) portfolio_return.evaluate({“w[0]”: 0.5, “w[1]”: 0.3, “w[2]”: 0.2}) 0.084
1.3 Methods
| Name | Description |
|---|---|
| evaluate | Evaluate the linear combination given variable values. |
| get_variables | Return all variables this expression depends on. |
| jacobian_row | Return Jacobian row in O(n) - coefficients are the gradients. |
1.3.1 evaluate
core.vectors.LinearCombination.evaluate(values)Evaluate the linear combination given variable values.
1.3.2 get_variables
core.vectors.LinearCombination.get_variables()Return all variables this expression depends on.
1.3.3 jacobian_row
core.vectors.LinearCombination.jacobian_row(variables)Return Jacobian row in O(n) - coefficients are the gradients.
For LinearCombination(c, x), gradient is c[i] for x[i], 0 otherwise. This is O(n) but avoids n separate gradient() calls.
1.3.3.1 Returns
| Name | Type | Description |
|---|---|---|
| list[Expression] | None | List of Constant expressions, or None if optimization not applicable. |