Skip to content

Commit

Permalink
TST: remove KM replication of fake cereal problem for simplicity
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffgortmaker committed May 2, 2018
1 parent 5c3c3b1 commit 981aaa1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,29 +179,26 @@ def nevo_problem():
return Problem(product_data, np.recfromcsv(NEVO_AGENTS_LOCATION))


@pytest.fixture(params=[pytest.param('blp_problem', id="BLP"), pytest.param('nevo_problem', id="Nevo")])
@pytest.fixture
def knittel_metaxoglou_2014(request):
"""Load initial parameter values and estimates from replication code for Knittel and Metaxoglou (2014).
The replication code was modified to output one Matlab data file for each dataset (BLP automobile data and Nevo's
cereal data), each containing the results of one round of Knitro optimization and post-estimation calculations. The
replication code was kept mostly intact, but was modified slightly in the following ways:
The replication code was modified to output a Matlab data file for the automobile dataset, which contains the
results of one round of Knitro optimization and post-estimation calculations. The replication code was kept mostly
intact, but was modified slightly in the following ways:
- Tolerance parameters, Knitro optimization parameters, and starting values for sigma were all configured.
- A bug in the code's computation of the BLP instruments was fixed. When creating a vector of "other" and
"rival" sums, the code did not specify a dimension over which to sum, which created problems with one-
dimensional vectors. A dimension of 1 was added to both sum commands.
- For the Nevo data, the constant column and the column of prices were swapped in X2. Parameter matrices were
changed accordingly. For example, before elasticities were computed, the order of coefficients was changed to
reflect the new position of prices.
- Delta was initialized as the solution to the Logit model.
- After estimation, the objective was called again at the optimal parameters to re-load globals at the optimal
parameter values.
- Before being saved to a Matlab data file, matrices were renamed and reshaped.
"""
problem = request.getfixturevalue(request.param)
return scipy.io.loadmat(str(TEST_DATA_PATH / 'knittel_metaxoglou_2014' / request.param), {'problem': problem})
problem = request.getfixturevalue('blp_problem')
return scipy.io.loadmat(str(TEST_DATA_PATH / 'knittel_metaxoglou_2014.mat'), {'problem': problem})


@pytest.fixture(params=[pytest.param(p, id=p.name) for p in Path(TEST_DATA_PATH / 'nwspgr').iterdir()])
Expand Down
Binary file added tests/data/knittel_metaxoglou_2014.mat
Binary file not shown.
Binary file removed tests/data/knittel_metaxoglou_2014/blp_problem.mat
Binary file not shown.
Binary file removed tests/data/knittel_metaxoglou_2014/nevo_problem.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/test_blp.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def test_knittel_metaxoglou_2014(knittel_metaxoglou_2014):
knittel_metaxoglou_2014.get('initial_sigma'),
knittel_metaxoglou_2014.get('initial_pi'),
optimization=Optimization('knitro', {'opttol': 1e-8, 'xtol': 1e-8}),
iteration=Iteration('simple', {'tol': 1e-13}),
iteration=Iteration('simple', {'tol': 1e-12, 'iterations': 100000, 'norm': lambda x: np.abs(x).max()}),
steps=1
)

Expand Down

0 comments on commit 981aaa1

Please sign in to comment.