gemseo.disciplines.linear_combination module#
Discipline computing a linear combination of its inputs.
- class LinearCombination(input_names, output_name, input_coefficients=mappingproxy({}), offset=0.0, input_size=1, average=False)[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 the input variables.
output_name (str) -- The name of the output variable.
input_coefficients (Mapping[str, float]) --
The coefficients related to the input variables. If empty, use 1 for all the \(d\) input variables when
average
isFalse
. or \(1/d\) whenaverage
isTrue
.By default it is set to {}.
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) --
The size of the inputs.
By default it is set to 1.
average (bool) --
Whether to average the inputs when
input_coefficients
is empty,By default it is set to False.