Package: searchlogit
Quick startThe following example uses the basesearchlogitto estimate a mixed logit model for choices of electricity supplier (See the data here). The parameters are:X: 2-D array of input data (in long format) with choice situations as rows, and variables as columnsy: 1-D array of choices (in long format)varnames: List of variable names that matches the number and order of the columns inXalts:  1-D array of alternative indexes or an alternatives listids:  1-D array of the ids of the choice situationspanels: 1-D array of ids for panel formationrandvars: dictionary of variables and their mixing distributions ("n"normal,"ln"lognormal,"t"triangular,"u"uniform,"tn"truncated normal)transvars: List of variables to apply the specified transformationtransformation: String specifying the transformation to be applied (default is the Box-Cox transformation)correlation: Either a list of variables names that are correlated or a boolean to set all randvars as correlatedThe current version ofsearchlogitonly supports input data in long format.# Read data from CSV fileimportpandasaspddf=pd.read_csv("https://raw.githubusercontent.com/arteagac/xlogit/master/examples/data/electricity_long.csv")# reverse sign for randvars with a lognormal distributiondf['tod']=-df['tod']df['seas']=-df['seas']X=df[varnames]y=df['choice']# Fit the model with xlogitfromsearchlogitimportMixedLogitmodel=MixedLogit()model.fit(X,y,varnames,alts=df['alt'],ids=df['chid'],panels=df['id'],randvars={'cl':'n','loc':'n','wk':'u','tod':'ln','seas':'n'},correlation=['loc','wk','tod','seas'],transvars=['cl'],n_draws=600)model.summary()Optimization terminated successfully.
        Current function value: 3942.930393
        Iterations: 66
        Function evaluations: 77
        Gradient evaluations: 77
Estimation time= 51.5 seconds
Frequencies of alternatives: observed choice
[0.22576177 0.26246537 0.23684211 0.26939058]
Frequencies of alternatives: predicted choice
[0.22930773 0.26222102 0.22989339 0.2730377 ]
---------------------------------------------------------------------------
Coefficient              Estimate      Std.Err.         z-val         P>|z|
---------------------------------------------------------------------------
pf                  -0.8844627763  0.0295175526 -29.9639603432             0 ***
loc                  2.2458727521  0.1032222566 21.7576405168             0 ***
wk                   0.2276055259  0.0685607922  3.3197621949      0.000901 ***
tod                  2.1355682749  0.0376005793 56.7961535512             0 ***
seas                 8.7966341596  0.2824599096 31.1429475855             0 ***
chol.loc.loc         1.3698552163  0.1301206261 10.5275793490             0 ***
chol.wk.loc          0.5137795414  0.0664560103  7.7311222681      1.07e-14 ***
chol.wk.wk          -0.5269078200  0.0465699165 -11.3143389438             0 ***
chol.tod.loc        -0.0092950782  0.0277084890 -0.3354595849         0.737
chol.tod.wk          0.0694307288  0.0316747405  2.1919904546        0.0284 *
chol.tod.tod         0.3998943075  0.0283441100 14.1085504981             0 ***
chol.seas.loc        0.2636579056  0.1466998262  1.7972611991        0.0723 .
chol.seas.wk        -0.0387176619  0.1862974259 -0.2078271435         0.835
chol.seas.tod        1.0931383738  0.1523794076  7.1737933030      7.29e-13 ***
chol.seas.seas      -2.9951794692  0.1818545992 -16.4701881742             0 ***
cl                  -0.1571373624  0.0234064621 -6.7134179193       1.9e-11 ***
sd.cl                0.2767984154  0.0345402217  8.0137996096      1.11e-15 ***
lambda.cl            1.1525365710  0.1287181869  1.1850428803         0.236
---------------------------------------------------------------------------
Significance:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Log-Likelihood= -3942.930
AIC= 7921.861
BIC= 7991.861Quick installInstallsearchlogitusingpipas follows:pipinstallsearchlogitHintTo enable GPU processing, you must install theCuPy Python library.  Whensearchlogitdetects that CuPy is properly installed, it switches to GPU processing without any additional setup. If you use Google Colab, CuPy is usually installed by default.No GPU? No problemsearchlogitcan also be used without a GPU. However, if you need to speed up your model estimation, there are several low cost and even free options to access cloud GPU resources. For instance:Google Colaboffers free GPU resources for learning purposes with no setup required, as the service can be accessed using a web browser. Using searchlogit in Google Colab is very easy as it runs out of the box without needing to install CUDA or CuPy, which are installed by default.For examples of xlogit running in Google Colabsee this link.TheGoogle Cloud platformoffers GPU processing starting at $0.45 USD per hour for a NVIDIA Tesla K80 GPU with 4,992 CUDA cores.Amazon Sagemakeroffers virtual machine instances with the same TESLA K80 GPU at less than $1 USD per hour.Benchmarksearchlogitextendsxlogit. As shown in the plots below,xlogitis significantly faster than existing estimation packages. Also,xlogitprovides convenient scaling when the number of random draws increases. These results were obtained using a modest and low-cost NVIDIA GTX 1060 graphics card. More sophisticated graphics cards are expected to provide even faster estimation times. For additional details about this benchmark and for replication instructions checkhttps://xlogit.readthedocs.io/en/latest/benchmark.html.NotesThe current version allows estimation of:Mixed Logit with several types of mixing distributions (normal, lognormal, triangular, uniform, and truncated normal)Mixed Logit with panel dataMixed Logit with unbalanced panel dataMixed Logit with Halton drawsMixed Logit with correlated random variablesMixed Logit with Box-Cox transformed fixed and random variablesMultinomial Logit models with Box-Cox transformed fixed and random variablesConditional logit modelsLatent class logit modelsLatent class mixed logit modelsWeighed regression for all of the logit-based modelsHandling of unbalanced availability of choice alternatives for all of the supported modelsPost-estimation tools for prediction and specification testingInclusion of sample weights for all of the supported modelsContactIf you have any questions, ideas to improvesearchlogit, or want to report a bug, just open anew issue in xlogit’s GitHub repository.CitingsearchlogitPlease citesearchlogitas follows:Beeramoole, P. B., Alexander, P., Kelly, R., Arteaga, C.,. (2022). Searchlogit [Computer software].https://pypi.org/project/searchlogit/Or using BibTex as follows:@misc{searchlogit,
    author = {Beeramoole, P and Paz, A and Kelly, R and Arteaga, C},
    title = "{Searchlogit [Computer software]},
    url = {https://pypi.org/project/searchlogit/},
    year = {2022}
}