gemseo.disciplines.linear_combination module#
Discipline computing a linear combination of its inputs.
- class LinearCombination(input_names, output_name, input_coefficients=None, offset=0.0, input_size=None)[source]#
Bases:
Discipline
Discipline computing a linear combination of its inputs.
The user can specify the coefficients related to the variables as well as the offset.
E.g., a discipline computing the output \(y\) from \(d\) inputs \(x_1,\ldots,x_d\) with the function \(f(x_1,\ldots,x_d)=a_0+\sum_{i=1}^d a_i x_i\).
When the offset \(a_0\) is equal to 0 and the coefficients \(a_1,\ldots,a_d\) are equal to 1, the discipline simply sums the inputs.
Notes
By default, the
LinearCombination
simply sums the inputs.Examples
>>> discipline = LinearCombination(["alpha", "beta", "gamma"], "delta", input_coefficients={"alpha": 1.,"beta": 2.,"gamma": 3.}) >>> input_data = {"alpha": array([1.0]), "beta": array([1.0]), "gamma": array([1.0])} >>> discipline.execute(input_data) >>> delta = discipline.io.data["delta"] # delta = array([6.])
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
input_names (Iterable[str]) -- The names of input variables.
output_name (str) -- The name of the output variable.
input_coefficients (dict[str, float] | None) -- The coefficients related to the input variables. If
None
, use 1 for all the input variables.offset (float) --
The output value when all the input variables are equal to zero.
By default it is set to 0.0.
input_size (int | None) -- The size of the inputs. If
None
, the default inputs are initialized with size 1 arrays.