Download the Jupyter Notebook for this section: build_integration.ipynb

Building Nodes and Weights for Integration Example

[1]:
import pyblp

pyblp.__version__
[1]:
'0.8.0'

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.

[2]:
integration = pyblp.Integration('grid', 5)
integration
[2]:
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.

[3]:
agent_data = pyblp.build_integration(integration, 2)
agent_data.nodes.shape
[3]:
(53, 2)
[4]:
agent_data.weights.shape
[4]:
(53, 1)

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.