Search with unobserved heterogeneity#
Below is documentation for the Matlab code in “full_info_NNE_search” folder at this GitHub repository. The code uses full-info NNE to estimate a search model with unobserved consumer heterogeneity. |
Workflow#
The following shows how to estimate the search model on a real dataset (in data.mat).
>> nne_gen % generate the training examples
>> nne_train % train the neural net and apply it to the data
Description of each file#
search_ht_model.m#
This function codes the search model with unobserved consumer heterogeneity.
[Y, stat] = search_ht_model(rs, par, curve, X, consumer_idx)
Inputs:
rs: a random stream (to control randomness)par: the search model parameter vectorcurve: lookup table for reservation utility, available fromcurve.matX: product attributesconsumer_id: indices of consumers (or search sessions)
Outputs:
Y: dummies indicating searches, purchases, first-search, and last-searchstat: summary statistics
nne_gen.m#
This script generates the training, validation, and test examples.
It uses
search_ht_model.mto simulate the data.It uses Matlab’s built-in bit-to-integer encoding on
Yto save memory, decoded later during training.
nne_train.m#
This script trains a neural net, using the examples from nne_gen.m.
Validation loss is reported. You can use it to choose neural net hyperparameters, such as the numbers of hidden nodes.
After training, it draws parameter recovery plots using the test examples.
After training, it applies the neural net on
data.mat.In the end, it saves the trained neural net to
trained_nne.mat.
learn.m#
This function codes the training loop, and is used by nne_train.m.
This is a custom training loop based on Matlab’s built-in back-propogation and adam algorithms.
[ema_net, train_pred, val_pred, test_pred] = ...
learn(net, opt, nne, train_dataY, train_label, val_dataY, val_label, test_dataY)
Inputs:
net: the initial neural netopt: options including batch size, number of iterations, etc.train_dataY,train_label: training examplesval_dataY,val_label: validation examplestest_dataY: test examples
Outputs:
ema_net: the final trained neural nettrain_pred: predictions for training examplesval_pred: predictions for validation examplestest_pred: predictions for test examples