Skip to content

Commit

Permalink
ENH: re-order some supply-side calculations for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgortmaker committed Dec 31, 2021
1 parent 7c19170 commit 9257704
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions pyblp/markets/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -1279,15 +1279,14 @@ def compute_eta_by_theta_jacobian(self, xi_jacobian: Array) -> Tuple[Array, List
)
np.einsum('jkk->jk', capital_delta_tensor)[...] -= np.squeeze(capital_lamda_diagonal_tensor, axis=2)

# compute the product of the tensor and eta
capital_delta_tensor_times_eta = np.c_[np.squeeze(capital_delta_tensor @ eta)]
# contribute the contribution of xi to the jacobian
eta_jacobian = -capital_delta_inverse @ np.squeeze(capital_delta_tensor @ eta, axis=2).T @ xi_jacobian

# compute derivatives of X1 and X2 with respect to prices
X1_derivatives = self.compute_X1_derivatives('prices')
X2_derivatives = self.compute_X2_derivatives('prices')

# fill the Jacobian of eta with respect to theta parameter-by-parameter
eta_jacobian = np.zeros((self.J, self.parameters.P), options.dtype)
# add each parameter's additional contraction
for p, parameter in enumerate(self.parameters.unfixed):
# compute the tangent with respect to the parameter of derivatives of aggregate inclusive values
probabilities_tangent, conditionals_tangent = self.compute_probabilities_by_parameter_tangent(
Expand All @@ -1310,10 +1309,8 @@ def compute_eta_by_theta_jacobian(self, xi_jacobian: Array) -> Tuple[Array, List
)
np.einsum('jj->j', capital_delta_tangent)[...] -= capital_lamda_diagonal_tangent

# extract the tangent of xi with respect to the parameter and compute the associated tangent of eta
eta_jacobian[:, [p]] = -capital_delta_inverse @ (
capital_delta_tangent @ eta + capital_delta_tensor_times_eta.T @ xi_jacobian[:, [p]]
)
# subtract this parameter's contribution
eta_jacobian[:, [p]] -= capital_delta_inverse @ capital_delta_tangent @ eta

return eta_jacobian, errors

Expand Down

0 comments on commit 9257704

Please sign in to comment.