MCPcopy
hub / github.com/GPflow/GPflow / Linear

Class Linear

gpflow/functions.py:96–126  ·  view source on GitHub ↗

y_i = A x_i + b

Source from the content-addressed store, hash-verified

94
95
96class Linear(MeanFunction, Function):
97 """
98 y_i = A x_i + b
99 """
100
101 @check_shapes(
102 "A: [broadcast D, broadcast Q]",
103 "b: [broadcast Q]",
104 )
105 def __init__(self, A: TensorType = None, b: TensorType = None) -> None:
106 """
107 A is a matrix which maps each element of X to Y, b is an additive
108 constant.
109 """
110 MeanFunction.__init__(self)
111 A = np.ones((1, 1), dtype=default_float()) if A is None else A
112 b = np.zeros(1, dtype=default_float()) if b is None else b
113 if isinstance(A, Parameter):
114 if len(A._shape) >= 2:
115 self.A = A
116 else:
117 raise ValueError(
118 "Error 'gpflow.funcitons.Linear()' mean function. A has not the correct shape (at least 2d)."
119 )
120 else:
121 self.A = Parameter(np.atleast_2d(A))
122 self.b = Parameter(b)
123
124 @inherit_check_shapes
125 def __call__(self, X: TensorType) -> tf.Tensor:
126 return tf.tensordot(X, self.A, [[-1], [0]]) + self.b
127
128
129class Identity(Linear, Function):

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…