sf.apps.train.ExpFeatures¶

class ExpFeatures(features)[source]

Bases: object

Exponential embedding with feature vectors.

Weights of the $$W$$ matrix in the $$WAW$$ parametrization are expressed as an exponential of the inner product between user-specified feature vectors and trainable parameters: $$w_i = \exp(-f^{(i)}\cdot\theta)$$. The Jacobian, which encapsulates the derivatives of the weights with respect to the parameters can be computed straightforwardly as: $$\frac{d w_i}{d\theta_k} = -f^{(i)}_k w_i$$.

Example usage:

>>> features = np.array([[0.1, 0.1, 0.1], [0.2, 0.2, 0.2], [0.3, 0.3, 0.3]])
>>> embedding = ExpFeatures(features)
>>> parameters = np.array([0.1, 0.2, 0.3])
>>> embedding(parameters)
[0.94176453 0.88692044 0.83527021]

Parameters

features (np.array) – Matrix of feature vectors where the i-th row is the i-th feature vector

 jacobian(params) Computes the Jacobian matrix of weights with respect to input parameters $$J_{ ij} = \frac{\partial w_i}{\partial \theta_j}$$. weights(params) Computes weights as a function of input parameters.
jacobian(params)[source]

Computes the Jacobian matrix of weights with respect to input parameters $$J_{ ij} = \frac{\partial w_i}{\partial \theta_j}$$.

Parameters

params (np.array) – trainable parameters

Returns

Jacobian matrix of weights with respect to parameters

Return type

np.array

weights(params)[source]

Computes weights as a function of input parameters.

Parameters

params (np.array) – trainable parameters

Returns

weights

Return type

np.array