Building Nodes and Weights for Integration Example¶
import pyblp pyblp.__version__
In this example, we’ll build nodes and weights for integration over agent choice probabilities according to a Integration configuration. We’ll construct a sparse grid of nodes and weights according to a level-5 Gauss-Hermite quadrature rule.
integration = pyblp.Integration('grid', 5) integration
Configured to construct nodes and weights in a sparse grid according to the level-5 Gauss-Hermite rule.
Usually, this configuration should be passed directly to Problem, which will create a sparse grid of dimension \(K_2\), the number of nonlinear product characteristics. Alternatively, we can build the sparse grid ourselves and pass the constructed agent data to Problem, possibly after modifying the nodes and weights. If we want to allow agents to have heterogeneous tastes over 2 product characteristics, we’ll need a grid of dimension 2.
agent_data = pyblp.build_integration(integration, 2) agent_data.nodes.shape
If we wanted to construct nodes and weights for each market, we could call build_integration once for each market, add a column of market IDs, and stack the arrays.