.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/latent/read_or_estimate.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_latent_read_or_estimate.py: Read of estimate ================ Function to estimate the parameters, or read them from a file, if available. :author: Michel Bierlaire, EPFL :date: Sat Dec 9 17:20:49 2023 .. GENERATED FROM PYTHON SOURCE LINES 11-40 .. code-block:: default import logging from typing import Optional from biogeme.biogeme import BIOGEME from biogeme.results import bioResults import biogeme.exceptions as excep logger = logging.getLogger(__name__) def read_or_estimate( the_biogeme: BIOGEME, directory: Optional[str] = '.' ) -> bioResults: """ Function to estimate the parameters, or read them from a file, if available. :param the_biogeme: Biogeme object. :param directory: directory where the pickle file is supposed to be. :return: estimation results. """ try: filename = f'{directory}/{the_biogeme.modelName}.pickle' logger.info('Results are read from the file {filename}.') results = bioResults(pickleFile=filename) except excep.FileNotFoundError: logger.info('Parameters are estimated.') results = the_biogeme.estimate() return results .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.000 seconds) .. _sphx_glr_download_auto_examples_latent_read_or_estimate.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: read_or_estimate.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: read_or_estimate.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_