diff --git a/cmdstanpy/_version.py b/cmdstanpy/_version.py index 182815cd..5a0419af 100644 --- a/cmdstanpy/_version.py +++ b/cmdstanpy/_version.py @@ -1,3 +1,3 @@ """PyPi Version""" -__version__ = '1.0.8' +__version__ = '1.1.0rc1' diff --git a/docs/_modules/cmdstanpy/cmdstan_args.html b/docs/_modules/cmdstanpy/cmdstan_args.html index 218fc744..181c99ad 100644 --- a/docs/_modules/cmdstanpy/cmdstan_args.html +++ b/docs/_modules/cmdstanpy/cmdstan_args.html @@ -5,7 +5,7 @@ - cmdstanpy.cmdstan_args — CmdStanPy 1.0.8 documentation + cmdstanpy.cmdstan_args — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ @@ -192,7 +192,7 @@

Source code for cmdstanpy.cmdstan_args

 
 
 class Method(Enum):
-    """Supported CmdStan method names."""
+    """Supported CmdStan method names."""
 
     SAMPLE = auto()
     OPTIMIZE = auto()
@@ -204,7 +204,7 @@ 

Source code for cmdstanpy.cmdstan_args

 
 
 
[docs]class SamplerArgs: - """Arguments for the NUTS adaptive sampler.""" + """Arguments for the NUTS adaptive sampler.""" def __init__( self, @@ -224,7 +224,7 @@

Source code for cmdstanpy.cmdstan_args

         adapt_step_size: Optional[int] = None,
         fixed_param: bool = False,
     ) -> None:
-        """Initialize object."""
+        """Initialize object."""
         self.iter_warmup = iter_warmup
         self.iter_sampling = iter_sampling
         self.save_warmup = save_warmup
@@ -243,7 +243,7 @@ 

Source code for cmdstanpy.cmdstan_args

         self.diagnostic_file = None
 
 
[docs] def validate(self, chains: Optional[int]) -> None: - """ + """ Check arguments correctness and consistency. * adaptation and warmup args are consistent @@ -497,7 +497,7 @@

Source code for cmdstanpy.cmdstan_args

             )
[docs] def compose(self, idx: int, cmd: List[str]) -> List[str]: - """ + """ Compose CmdStan command for method-specific non-default arguments. """ cmd.append('method=sample') @@ -547,7 +547,7 @@

Source code for cmdstanpy.cmdstan_args

 
 
 
[docs]class OptimizeArgs: - """Container for arguments for the optimizer.""" + """Container for arguments for the optimizer.""" OPTIMIZE_ALGOS = {'BFGS', 'bfgs', 'LBFGS', 'lbfgs', 'Newton', 'newton'} @@ -580,7 +580,7 @@

Source code for cmdstanpy.cmdstan_args

 
[docs] def validate( self, chains: Optional[int] = None # pylint: disable=unused-argument ) -> None: - """ + """ Check arguments correctness and consistency. """ if self.algorithm and self.algorithm not in self.OPTIMIZE_ALGOS: @@ -678,7 +678,7 @@

Source code for cmdstanpy.cmdstan_args

 
     # pylint: disable=unused-argument
 
[docs] def compose(self, idx: int, cmd: List[str]) -> List[str]: - """compose command string for CmdStan for non-default arg values.""" + """compose command string for CmdStan for non-default arg values.""" cmd.append('method=optimize') if self.algorithm: cmd.append('algorithm={}'.format(self.algorithm.lower())) @@ -705,16 +705,16 @@

Source code for cmdstanpy.cmdstan_args

 
 
 class GenerateQuantitiesArgs:
-    """Arguments needed for generate_quantities method."""
+    """Arguments needed for generate_quantities method."""
 
     def __init__(self, csv_files: List[str]) -> None:
-        """Initialize object."""
+        """Initialize object."""
         self.sample_csv_files = csv_files
 
     def validate(
         self, chains: Optional[int] = None  # pylint: disable=unused-argument
     ) -> None:
-        """
+        """
         Check arguments correctness and consistency.
 
         * check that sample csv files exist
@@ -726,7 +726,7 @@ 

Source code for cmdstanpy.cmdstan_args

                 )
 
     def compose(self, idx: int, cmd: List[str]) -> List[str]:
-        """
+        """
         Compose CmdStan command for method-specific non-default arguments.
         """
         cmd.append('method=generate_quantities')
@@ -735,7 +735,7 @@ 

Source code for cmdstanpy.cmdstan_args

 
 
 
[docs]class VariationalArgs: - """Arguments needed for variational method.""" + """Arguments needed for variational method.""" VARIATIONAL_ALGOS = {'meanfield', 'fullrank'} @@ -766,7 +766,7 @@

Source code for cmdstanpy.cmdstan_args

 
[docs] def validate( self, chains: Optional[int] = None # pylint: disable=unused-argument ) -> None: - """ + """ Check arguments correctness and consistency. """ if ( @@ -833,7 +833,7 @@

Source code for cmdstanpy.cmdstan_args

 
     # pylint: disable=unused-argument
 
[docs] def compose(self, idx: int, cmd: List[str]) -> List[str]: - """ + """ Compose CmdStan command for method-specific non-default arguments. """ cmd.append('method=variational') @@ -864,7 +864,7 @@

Source code for cmdstanpy.cmdstan_args

 
 
 
[docs]class CmdStanArgs: - """ + """ Container for CmdStan command line arguments. Consists of arguments common to all methods and and an object which contains the method-specific arguments. @@ -887,7 +887,7 @@

Source code for cmdstanpy.cmdstan_args

         save_profile: bool = False,
         refresh: Optional[int] = None,
     ) -> None:
-        """Initialize object."""
+        """Initialize object."""
         self.model_name = model_name
         self.model_exe = model_exe
         self.chain_ids = chain_ids
@@ -912,7 +912,7 @@ 

Source code for cmdstanpy.cmdstan_args

         self.validate()
 
 
[docs] def validate(self) -> None: - """ + """ Check arguments correctness and consistency. * input files must exist @@ -1067,7 +1067,7 @@

Source code for cmdstanpy.cmdstan_args

         profile_file: Optional[str] = None,
         num_chains: Optional[int] = None
     ) -> List[str]:
-        """
+        """
         Compose CmdStan command for non-default arguments.
         """
         cmd: List[str] = []
diff --git a/docs/_modules/cmdstanpy/compiler_opts.html b/docs/_modules/cmdstanpy/compiler_opts.html
index a2d8fb30..7b5cc3b6 100644
--- a/docs/_modules/cmdstanpy/compiler_opts.html
+++ b/docs/_modules/cmdstanpy/compiler_opts.html
@@ -5,7 +5,7 @@
   
     
     
-    cmdstanpy.compiler_opts — CmdStanPy 1.0.8 documentation
+    cmdstanpy.compiler_opts — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -56,7 +56,7 @@
   
 
@@ -221,7 +221,7 @@ 

Source code for cmdstanpy.compiler_opts

 
 
 
[docs]class CompilerOptions: - """ + """ User-specified flags for stanc and C++ compiler. Attributes: @@ -237,7 +237,7 @@

Source code for cmdstanpy.compiler_opts

         cpp_options: Optional[Dict[str, Any]] = None,
         user_header: OptionalPath = None,
     ) -> None:
-        """Initialize object."""
+        """Initialize object."""
         self._stanc_options = stanc_options if stanc_options is not None else {}
         self._cpp_options = cpp_options if cpp_options is not None else {}
         self._user_header = str(user_header) if user_header is not None else ''
@@ -248,7 +248,7 @@ 

Source code for cmdstanpy.compiler_opts

         )
 
     def __eq__(self, other: Any) -> bool:
-        """Overrides the default implementation"""
+        """Overrides the default implementation"""
         if self.is_empty() and other is None:  # equiv w/r/t compiler
             return True
         if not isinstance(other, CompilerOptions):
@@ -260,7 +260,7 @@ 

Source code for cmdstanpy.compiler_opts

         )
 
 
[docs] def is_empty(self) -> bool: - """True if no options specified.""" + """True if no options specified.""" return ( self._stanc_options == {} and self._cpp_options == {} @@ -269,21 +269,21 @@

Source code for cmdstanpy.compiler_opts

 
     @property
     def stanc_options(self) -> Dict[str, Union[bool, int, str]]:
-        """Stanc compiler options."""
+        """Stanc compiler options."""
         return self._stanc_options
 
     @property
     def cpp_options(self) -> Dict[str, Union[bool, int]]:
-        """C++ compiler options."""
+        """C++ compiler options."""
         return self._cpp_options
 
     @property
     def user_header(self) -> str:
-        """user header."""
+        """user header."""
         return self._user_header
 
 
[docs] def validate(self) -> None: - """ + """ Check compiler args. Raise ValueError if invalid options are found. """ @@ -292,7 +292,7 @@

Source code for cmdstanpy.compiler_opts

         self.validate_user_header()
[docs] def validate_stanc_opts(self) -> None: - """ + """ Check stanc compiler args and consistency between stanc and C++ options. Raise ValueError if bad config is found. """ @@ -365,7 +365,7 @@

Source code for cmdstanpy.compiler_opts

             ]
[docs] def validate_cpp_opts(self) -> None: - """ + """ Check cpp compiler args. Raise ValueError if bad config is found. """ @@ -382,7 +382,7 @@

Source code for cmdstanpy.compiler_opts

                     )
[docs] def validate_user_header(self) -> None: - """ + """ User header exists. Raise ValueError if bad config is found. """ @@ -420,7 +420,7 @@

Source code for cmdstanpy.compiler_opts

             self._cpp_options['USER_HEADER'] = self._user_header
[docs] def add(self, new_opts: "CompilerOptions") -> None: # noqa: disable=Q000 - """Adds options to existing set of compiler options.""" + """Adds options to existing set of compiler options.""" if new_opts.stanc_options is not None: if self._stanc_options is None: self._stanc_options = new_opts.stanc_options @@ -437,7 +437,7 @@

Source code for cmdstanpy.compiler_opts

             self._user_header = new_opts._user_header
[docs] def add_include_path(self, path: str) -> None: - """Adds include path to existing set of compiler options.""" + """Adds include path to existing set of compiler options.""" path = os.path.abspath(os.path.expanduser(path)) if 'include-paths' not in self._stanc_options: self._stanc_options['include-paths'] = [path] @@ -465,7 +465,7 @@

Source code for cmdstanpy.compiler_opts

         return opts
 
 
[docs] def compose(self) -> List[str]: - """Format makefile options as list of strings.""" + """Format makefile options as list of strings.""" opts = ['STANCFLAGS+=' + flag for flag in self.compose_stanc()] if self._cpp_options is not None and len(self._cpp_options) > 0: for key, val in self._cpp_options.items(): diff --git a/docs/_modules/cmdstanpy/model.html b/docs/_modules/cmdstanpy/model.html index 23884cdb..b968325a 100644 --- a/docs/_modules/cmdstanpy/model.html +++ b/docs/_modules/cmdstanpy/model.html @@ -5,7 +5,7 @@ - cmdstanpy.model — CmdStanPy 1.0.8 documentation + cmdstanpy.model — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ @@ -177,6 +177,7 @@

Source code for cmdstanpy.model

 import shutil
 import subprocess
 import sys
+import tempfile
 import threading
 from collections import OrderedDict
 from concurrent.futures import ThreadPoolExecutor
@@ -184,11 +185,27 @@ 

Source code for cmdstanpy.model

 from io import StringIO
 from multiprocessing import cpu_count
 from pathlib import Path
-from typing import Any, Callable, Dict, Iterable, List, Mapping, Optional, Union
+from typing import (
+    Any,
+    Callable,
+    Dict,
+    Iterable,
+    List,
+    Mapping,
+    Optional,
+    TypeVar,
+    Union,
+)
 
+import pandas as pd
 from tqdm.auto import tqdm
 
-from cmdstanpy import _CMDSTAN_REFRESH, _CMDSTAN_SAMPLING, _CMDSTAN_WARMUP
+from cmdstanpy import (
+    _CMDSTAN_REFRESH,
+    _CMDSTAN_SAMPLING,
+    _CMDSTAN_WARMUP,
+    _TMPDIR,
+)
 from cmdstanpy.cmdstan_args import (
     CmdStanArgs,
     GenerateQuantitiesArgs,
@@ -220,13 +237,14 @@ 

Source code for cmdstanpy.model

 from . import progress as progbar
 
 OptionalPath = Union[str, os.PathLike, None]
+Fit = TypeVar('Fit', CmdStanMCMC, CmdStanMLE, CmdStanVB)
 
 
 
[docs]class CmdStanModel: # overview, omitted from doc comment in order to improve Sphinx docs. # A CmdStanModel object encapsulates the Stan program and provides # methods for compilation and inference. - """ + """ The constructor method allows model instantiation given either the Stan program source file or the compiled executable, or both. By default, the constructor will compile the Stan program on instantiation @@ -271,7 +289,7 @@

Source code for cmdstanpy.model

         cpp_options: Optional[Dict[str, Any]] = None,
         user_header: OptionalPath = None,
     ) -> None:
-        """
+        """
         Initialize object given constructor args.
 
         :param model_name: Model name, used for output file names.
@@ -338,9 +356,14 @@ 

Source code for cmdstanpy.model

             if not cmdstan_version_before(
                 2, 27
             ):  # unknown end of version range
-                model_info = self.src_info()
-                if 'parameters' in model_info:
-                    self._fixed_param |= len(model_info['parameters']) == 0
+                try:
+                    model_info = self.src_info()
+                    if 'parameters' in model_info:
+                        self._fixed_param |= len(model_info['parameters']) == 0
+                except ValueError as e:
+                    if compile:
+                        raise
+                    get_logger().debug(e)
 
         if exe_file is not None:
             self._exe_file = os.path.realpath(os.path.expanduser(exe_file))
@@ -390,7 +413,7 @@ 

Source code for cmdstanpy.model

 
     @property
     def name(self) -> str:
-        """
+        """
         Model name used in output filename templates. Default is basename
         of Stan program or exe file, unless specified in call to constructor
         via argument ``model_name``.
@@ -399,16 +422,16 @@ 

Source code for cmdstanpy.model

 
     @property
     def stan_file(self) -> OptionalPath:
-        """Full path to Stan program file."""
+        """Full path to Stan program file."""
         return self._stan_file
 
     @property
     def exe_file(self) -> OptionalPath:
-        """Full path to Stan exe file."""
+        """Full path to Stan exe file."""
         return self._exe_file
 
 
[docs] def exe_info(self) -> Dict[str, str]: - """ + """ Run model with option 'info'. Parse output statements, which all have form 'key = value' into a Dict. If exe file compiled with CmdStan < 2.27, option 'info' isn't @@ -432,38 +455,28 @@

Source code for cmdstanpy.model

             return result
[docs] def src_info(self) -> Dict[str, Any]: - """ + """ Run stanc with option '--info'. If stanc is older than 2.27 or if the stan file cannot be found, returns an empty dictionary. """ - result: Dict[str, Any] = {} - if self.stan_file is None: - return result - try: - cmd = ( - [os.path.join(cmdstan_path(), 'bin', 'stanc' + EXTENSION)] - # handle include-paths, allow-undefined etc - + self._compiler_options.compose_stanc() - + [ - '--info', - str(self.stan_file), - ] - ) - proc = subprocess.run( - cmd, capture_output=True, text=True, check=True + if self.stan_file is None or cmdstan_version_before(2, 27): + return {} + cmd = ( + [os.path.join(cmdstan_path(), 'bin', 'stanc' + EXTENSION)] + # handle include-paths, allow-undefined etc + + self._compiler_options.compose_stanc() + + ['--info', str(self.stan_file)] + ) + proc = subprocess.run(cmd, capture_output=True, text=True, check=False) + if proc.returncode: + raise ValueError( + f"Failed to get source info for Stan model " + f"'{self._stan_file}'. Console:\n{proc.stderr}" ) - result = json.loads(proc.stdout) - return result - except ( - ValueError, - RuntimeError, - OSError, - subprocess.CalledProcessError, - ) as e: - get_logger().debug(e) - return result
+ result: Dict[str, Any] = json.loads(proc.stdout) + return result
[docs] def format( self, @@ -473,7 +486,7 @@

Source code for cmdstanpy.model

         *,
         backup: bool = True,
     ) -> None:
-        """
+        """
         Run stanc's auto-formatter on the model code. Either saves directly
         back to the file or prints for inspection
 
@@ -559,21 +572,21 @@ 

Source code for cmdstanpy.model

 
     @property
     def stanc_options(self) -> Dict[str, Union[bool, int, str]]:
-        """Options to stanc compilers."""
+        """Options to stanc compilers."""
         return self._compiler_options._stanc_options
 
     @property
     def cpp_options(self) -> Dict[str, Union[bool, int]]:
-        """Options to C++ compilers."""
+        """Options to C++ compilers."""
         return self._compiler_options._cpp_options
 
     @property
     def user_header(self) -> str:
-        """The user header file if it exists, otherwise empty"""
+        """The user header file if it exists, otherwise empty"""
         return self._compiler_options._user_header
 
 
[docs] def code(self) -> Optional[str]: - """Return Stan program as a string.""" + """Return Stan program as a string.""" if not self._stan_file: raise RuntimeError('Please specify source file') @@ -595,7 +608,7 @@

Source code for cmdstanpy.model

         user_header: OptionalPath = None,
         override_options: bool = False,
     ) -> None:
-        """
+        """
         Compile the given Stan program file.  Translates the Stan code to
         C++, then calls the C++ compiler.
 
@@ -745,7 +758,7 @@ 

Source code for cmdstanpy.model

         time_fmt: str = "%Y%m%d%H%M%S",
         timeout: Optional[float] = None,
     ) -> CmdStanMLE:
-        """
+        """
         Run the specified CmdStan optimize algorithm to produce a
         penalized maximum likelihood estimate of the model parameters.
 
@@ -932,7 +945,7 @@ 

Source code for cmdstanpy.model

         *,
         force_one_process_per_chain: Optional[bool] = None,
     ) -> CmdStanMCMC:
-        """
+        """
         Run or more chains of the NUTS-HMC sampler to produce a set of draws
         from the posterior distribution of a model conditioned on some data.
 
@@ -1369,7 +1382,7 @@ 

Source code for cmdstanpy.model

 
[docs] def generate_quantities( self, data: Union[Mapping[str, Any], str, os.PathLike, None] = None, - mcmc_sample: Union[CmdStanMCMC, List[str], None] = None, + previous_fit: Union[Fit, List[str], None] = None, seed: Optional[int] = None, gq_output_dir: OptionalPath = None, sig_figs: Optional[int] = None, @@ -1377,14 +1390,18 @@

Source code for cmdstanpy.model

         refresh: Optional[int] = None,
         time_fmt: str = "%Y%m%d%H%M%S",
         timeout: Optional[float] = None,
-    ) -> CmdStanGQ:
-        """
+        *,
+        mcmc_sample: Union[CmdStanMCMC, List[str], None] = None,
+    ) -> CmdStanGQ[Fit]:
+        """
         Run CmdStan's generate_quantities method which runs the generated
         quantities block of a model given an existing sample.
 
-        This function takes a :class:`CmdStanMCMC` object and the dataset used
-        to generate that sample and calls to the CmdStan ``generate_quantities``
-        method to generate additional quantities of interest.
+        This function takes one of the Stan fit objects
+        :class:`CmdStanMCMC`, :class:`CmdStanMLE`, or :class:`CmdStanVB`
+        and the data required for the model and calls to the CmdStan
+        ``generate_quantities`` method to generate additional quantities of
+        interest.
 
         The :class:`CmdStanGQ` object records the command, the return code,
         and the paths to the generate method output CSV and console files.
@@ -1403,9 +1420,10 @@ 

Source code for cmdstanpy.model

             either as a dictionary with entries matching the data variables,
             or as the path of a data file in JSON or Rdump format.
 
-        :param mcmc_sample: Can be either a :class:`CmdStanMCMC` object returned
-            by the :meth:`sample` method or a list of stan-csv files generated
-            by fitting the model to the data using any Stan interface.
+        :param previous_fit: Can be either a :class:`CmdStanMCMC`,
+            :class:`CmdStanMLE`, or :class:`CmdStanVB` or a list of
+            stan-csv files generated by fitting the model to the data
+            using any Stan interface.
 
         :param seed: The seed for random number generator. Must be an integer
             between 0 and 2^32 - 1. If unspecified,
@@ -1439,39 +1457,64 @@ 

Source code for cmdstanpy.model

 
         :return: CmdStanGQ object
         """
-        if isinstance(mcmc_sample, CmdStanMCMC):
-            mcmc_fit = mcmc_sample
-            sample_csv_files = mcmc_sample.runset.csv_files
-        elif isinstance(mcmc_sample, list):
-            if len(mcmc_sample) < 1:
+        if mcmc_sample is not None:
+            if previous_fit:
+                raise ValueError(
+                    "Cannot supply both 'previous_fit' and "
+                    "deprecated argument 'mcmc_sample'"
+                )
+            get_logger().warning(
+                "Argument name `mcmc_sample` is deprecated, please "
+                "rename to `previous_fit`."
+            )
+
+            previous_fit = mcmc_sample  # type: ignore
+
+        if isinstance(previous_fit, (CmdStanMCMC, CmdStanMLE, CmdStanVB)):
+            fit_object = previous_fit
+            fit_csv_files = previous_fit.runset.csv_files
+        elif isinstance(previous_fit, list):
+            if len(previous_fit) < 1:
                 raise ValueError(
                     'Expecting list of Stan CSV files, found empty list'
                 )
             try:
-                sample_csv_files = mcmc_sample
-                sample_fit = from_csv(sample_csv_files)
-                mcmc_fit = sample_fit  # type: ignore
+                fit_csv_files = previous_fit
+                fit_object = from_csv(fit_csv_files)  # type: ignore
             except ValueError as e:
                 raise ValueError(
                     'Invalid sample from Stan CSV files, error:\n\t{}\n\t'
                     ' while processing files\n\t{}'.format(
-                        repr(e), '\n\t'.join(mcmc_sample)
+                        repr(e), '\n\t'.join(previous_fit)
                     )
                 ) from e
         else:
             raise ValueError(
-                'MCMC sample must be either CmdStanMCMC object'
-                ' or list of paths to sample Stan CSV files.'
-            )
-        chains = mcmc_fit.chains
-        chain_ids = mcmc_fit.chain_ids
-        if mcmc_fit.metadata.cmdstan_config['save_warmup']:
-            get_logger().warning(
-                'Sample contains saved warmup draws which will be used '
-                'to generate additional quantities of interest.'
+                'Previous fit must be either CmdStanPy fit object'
+                ' or list of paths to Stan CSV files.'
             )
+        if isinstance(fit_object, CmdStanMCMC):
+            chains = fit_object.chains
+            chain_ids = fit_object.chain_ids
+            if fit_object._save_warmup:
+                get_logger().warning(
+                    'Sample contains saved warmup draws which will be used '
+                    'to generate additional quantities of interest.'
+                )
+        elif isinstance(fit_object, CmdStanMLE):
+            chains = 1
+            chain_ids = [1]
+            if fit_object._save_iterations:
+                get_logger().warning(
+                    'MLE contains saved iterations which will be used '
+                    'to generate additional quantities of interest.'
+                )
+        else:  # isinstance(fit_object, CmdStanVB)
+            chains = 1
+            chain_ids = [1]
+
         generate_quantities_args = GenerateQuantitiesArgs(
-            csv_files=sample_csv_files
+            csv_files=fit_csv_files
         )
         generate_quantities_args.validate(chains)
         with MaybeDictToFilePath(data, None) as (_data, _inits):
@@ -1512,7 +1555,7 @@ 

Source code for cmdstanpy.model

                     + ' output is unclear!'
                 )
                 raise RuntimeError(msg)
-            quantities = CmdStanGQ(runset=runset, mcmc_sample=mcmc_fit)
+            quantities = CmdStanGQ(runset=runset, previous_fit=fit_object)
         return quantities
[docs] def variational( @@ -1540,7 +1583,7 @@

Source code for cmdstanpy.model

         time_fmt: str = "%Y%m%d%H%M%S",
         timeout: Optional[float] = None,
     ) -> CmdStanVB:
-        """
+        """
         Run CmdStan's variational inference algorithm to approximate
         the posterior distribution of the model conditioned on the data.
 
@@ -1717,6 +1760,73 @@ 

Source code for cmdstanpy.model

         vb = CmdStanVB(runset)
         return vb
+
[docs] def log_prob( + self, + params: Union[Dict[str, Any], str, os.PathLike], + data: Union[Mapping[str, Any], str, os.PathLike, None] = None, + ) -> pd.DataFrame: + """ + Calculate the log probability and gradient at the given parameter + values. + + .. note:: This function is **NOT** an efficient way to evaluate the log + density of the model. It should be used for diagnostics ONLY. + Please, do not use this for other purposes such as testing new + sampling algorithms! + + :param params: Values for all parameters in the model, specified + either as a dictionary with entries matching the parameter + variables, or as the path of a data file in JSON or Rdump format. + + These should be given on the constrained (natural) scale. + + :param data: Values for all data variables in the model, specified + either as a dictionary with entries matching the data variables, + or as the path of a data file in JSON or Rdump format. + + :return: A pandas.DataFrame containing columns "lp_" and additional + columns for the gradient values. These gradients will be for the + unconstrained parameters of the model. + """ + + if cmdstan_version_before(2, 31, self.exe_info()): + raise ValueError( + "Method 'log_prob' not available for CmdStan versions " + "before 2.31" + ) + with MaybeDictToFilePath(data, params) as (_data, _params): + cmd = [ + str(self.exe_file), + "log_prob", + f"constrained_params={_params}", + ] + if _data is not None: + cmd += ["data", f"file={_data}"] + + output_dir = tempfile.mkdtemp(prefix=self.name, dir=_TMPDIR) + + output = os.path.join(output_dir, "output.csv") + cmd += ["output", f"file={output}"] + + get_logger().debug("Cmd: %s", str(cmd)) + + proc = subprocess.run( + cmd, capture_output=True, check=False, text=True + ) + if proc.returncode: + get_logger().error( + "'log_prob' command failed!\nstdout:%s\nstderr:%s", + proc.stdout, + proc.stderr, + ) + raise RuntimeError( + "Method 'log_prob' failed with return code " + + str(proc.returncode) + ) + + result = pd.read_csv(output, comment="#") + return result
+ def _run_cmdstan( self, runset: RunSet, @@ -1726,7 +1836,7 @@

Source code for cmdstanpy.model

         progress_hook: Optional[Callable[[str, int], None]] = None,
         timeout: Optional[float] = None,
     ) -> None:
-        """
+        """
         Helper function which encapsulates call to CmdStan.
         Uses subprocess POpen object to run the process.
         Records stdout, stderr messages, and process returncode.
@@ -1825,7 +1935,7 @@ 

Source code for cmdstanpy.model

         chain_ids: List[int],
         total: int,
     ) -> Optional[Callable[[str, int], None]]:
-        """
+        """
         Sets up tqdm callback for CmdStan sampler console msgs.
         CmdStan progress messages start with "Iteration", for single chain
         process, "Chain [id] Iteration" for multi-chain processing.
diff --git a/docs/_modules/cmdstanpy/stanfit.html b/docs/_modules/cmdstanpy/stanfit.html
index dc541799..d0231d45 100644
--- a/docs/_modules/cmdstanpy/stanfit.html
+++ b/docs/_modules/cmdstanpy/stanfit.html
@@ -5,7 +5,7 @@
   
     
     
-    cmdstanpy.stanfit — CmdStanPy 1.0.8 documentation
+    cmdstanpy.stanfit — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -56,7 +56,7 @@
   
 
@@ -202,7 +202,7 @@ 

Source code for cmdstanpy.stanfit

     path: Union[str, List[str], os.PathLike, None] = None,
     method: Optional[str] = None,
 ) -> Union[CmdStanMCMC, CmdStanMLE, CmdStanVB, None]:
-    """
+    """
     Instantiate a CmdStan object from a the Stan CSV files from a CmdStan run.
     CSV files are specified from either a list of Stan CSV files or a single
     filepath which can be either a directory name, a Stan CSV filename, or
diff --git a/docs/_modules/cmdstanpy/stanfit/gq.html b/docs/_modules/cmdstanpy/stanfit/gq.html
index 5de8cfdf..d4f3c4c4 100644
--- a/docs/_modules/cmdstanpy/stanfit/gq.html
+++ b/docs/_modules/cmdstanpy/stanfit/gq.html
@@ -5,7 +5,7 @@
   
     
     
-    cmdstanpy.stanfit.gq — CmdStanPy 1.0.8 documentation
+    cmdstanpy.stanfit.gq — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -56,7 +56,7 @@
   
 
@@ -176,12 +176,16 @@ 

Source code for cmdstanpy.stanfit.gq

 from typing import (
     Any,
     Dict,
+    Generic,
     Hashable,
     List,
     MutableMapping,
+    NoReturn,
     Optional,
     Tuple,
+    TypeVar,
     Union,
+    overload,
 )
 
 import numpy as np
@@ -194,6 +198,7 @@ 

Source code for cmdstanpy.stanfit.gq

 except ImportError:
     XARRAY_INSTALLED = False
 
+
 from cmdstanpy.cmdstan_args import Method
 from cmdstanpy.utils import (
     BaseType,
@@ -205,11 +210,15 @@ 

Source code for cmdstanpy.stanfit.gq

 
 from .mcmc import CmdStanMCMC
 from .metadata import InferenceMetadata
+from .mle import CmdStanMLE
 from .runset import RunSet
+from .vb import CmdStanVB
+
+Fit = TypeVar('Fit', CmdStanMCMC, CmdStanMLE, CmdStanVB)
 
 
-
[docs]class CmdStanGQ: - """ +
[docs]class CmdStanGQ(Generic[Fit]): + """ Container for outputs from CmdStan generate_quantities run. Created by :meth:`CmdStanModel.generate_quantities`. """ @@ -217,16 +226,18 @@

Source code for cmdstanpy.stanfit.gq

     def __init__(
         self,
         runset: RunSet,
-        mcmc_sample: CmdStanMCMC,
+        previous_fit: Fit,
     ) -> None:
-        """Initialize object."""
+        """Initialize object."""
         if not runset.method == Method.GENERATE_QUANTITIES:
             raise ValueError(
                 'Wrong runset method, expecting generate_quantities runset, '
                 'found method {}'.format(runset.method)
             )
         self.runset = runset
-        self.mcmc_sample = mcmc_sample
+
+        self.previous_fit: Fit = previous_fit
+
         self._draws: np.ndarray = np.array(())
         config = self._validate_csv_files()
         self._metadata = InferenceMetadata(config)
@@ -245,7 +256,7 @@ 

Source code for cmdstanpy.stanfit.gq

         return repr
 
     def __getattr__(self, attr: str) -> np.ndarray:
-        """Synonymous with ``fit.stan_variable(attr)"""
+        """Synonymous with ``fit.stan_variable(attr)"""
         if attr.startswith("_"):
             raise AttributeError(f"Unknown variable name {attr}")
         try:
@@ -254,8 +265,16 @@ 

Source code for cmdstanpy.stanfit.gq

             # pylint: disable=raise-missing-from
             raise AttributeError(*e.args)
 
+    def __getstate__(self) -> dict:
+        # This function returns the mapping of objects to serialize with pickle.
+        # See https://docs.python.org/3/library/pickle.html#object.__getstate__
+        # for details. We call _assemble_generated_quantities to ensure
+        # the data are loaded prior to serialization.
+        self._assemble_generated_quantities()
+        return self.__dict__
+
     def _validate_csv_files(self) -> Dict[str, Any]:
-        """
+        """
         Checks that Stan CSV output files for all chains are consistent
         and returns dict containing config and column names.
 
@@ -299,24 +318,24 @@ 

Source code for cmdstanpy.stanfit.gq

 
     @property
     def chains(self) -> int:
-        """Number of chains."""
+        """Number of chains."""
         return self.runset.chains
 
     @property
     def chain_ids(self) -> List[int]:
-        """Chain ids."""
+        """Chain ids."""
         return self.runset.chain_ids
 
     @property
     def column_names(self) -> Tuple[str, ...]:
-        """
+        """
         Names of generated quantities of interest.
         """
         return self._metadata.cmdstan_config['column_names']  # type: ignore
 
     @property
     def metadata(self) -> InferenceMetadata:
-        """
+        """
         Returns object which contains CmdStan configuration as well as
         information about the names and structure of the inference method
         and model output variables.
@@ -330,7 +349,7 @@ 

Source code for cmdstanpy.stanfit.gq

         concat_chains: bool = False,
         inc_sample: bool = False,
     ) -> np.ndarray:
-        """
+        """
         Returns a numpy.ndarray over the generated quantities draws from
         all chains which is stored column major so that the values
         for a parameter are contiguous in memory, likewise all draws from
@@ -348,7 +367,7 @@ 

Source code for cmdstanpy.stanfit.gq

         :param concat_chains: When ``True`` return a 2D array flattening all
             all draws from all chains.  Default value is ``False``.
 
-        :param inc_sample: When ``True`` include all columns in the mcmc_sample
+        :param inc_sample: When ``True`` include all columns in the previous_fit
             draws array as well, excepting columns for variables already present
             in the generated quantities drawset. Default value is ``False``.
 
@@ -358,18 +377,32 @@ 

Source code for cmdstanpy.stanfit.gq

         CmdStanGQ.draws_xr
         CmdStanMCMC.draws
         """
-        if self._draws.shape == (0,):
-            self._assemble_generated_quantities()
-        if (
-            inc_warmup
-            and not self.mcmc_sample.metadata.cmdstan_config['save_warmup']
-        ):
-            get_logger().warning(
-                "Sample doesn't contain draws from warmup iterations,"
-                ' rerun sampler with "save_warmup=True".'
-            )
+        self._assemble_generated_quantities()
+        if inc_warmup:
+            if (
+                isinstance(self.previous_fit, CmdStanMCMC)
+                and not self.previous_fit._save_warmup
+            ):
+                get_logger().warning(
+                    "Sample doesn't contain draws from warmup iterations,"
+                    ' rerun sampler with "save_warmup=True".'
+                )
+            elif (
+                isinstance(self.previous_fit, CmdStanMLE)
+                and not self.previous_fit._save_iterations
+            ):
+                get_logger().warning(
+                    "MLE doesn't contain draws from pre-convergence iterations,"
+                    ' rerun optimization with "save_iterations=True".'
+                )
+            elif isinstance(self.previous_fit, CmdStanVB):
+                get_logger().warning(
+                    "Variational fit doesn't make sense with argument "
+                    '"inc_warmup=True"'
+                )
+
         if inc_sample:
-            cols_1 = self.mcmc_sample.column_names
+            cols_1 = self.previous_fit.column_names
             cols_2 = self.column_names
             dups = [
                 item
@@ -378,20 +411,15 @@ 

Source code for cmdstanpy.stanfit.gq

             ]
             drop_cols: List[int] = []
             for dup in dups:
-                drop_cols.extend(self.mcmc_sample.metadata.stan_vars_cols[dup])
-
-        start_idx = 0
-        if (
-            not inc_warmup
-            and self.mcmc_sample.metadata.cmdstan_config['save_warmup']
-        ):
-            start_idx = self.mcmc_sample.num_draws_warmup
+                drop_cols.extend(self.previous_fit.metadata.stan_vars_cols[dup])
 
+        start_idx, _ = self._draws_start(inc_warmup)
+        previous_draws = self._previous_draws(True)
         if concat_chains and inc_sample:
             return flatten_chains(
                 np.dstack(
                     (
-                        np.delete(self.mcmc_sample.draws(), drop_cols, axis=1),
+                        np.delete(previous_draws, drop_cols, axis=1),
                         self._draws,
                     )
                 )[start_idx:, :, :]
@@ -401,7 +429,7 @@ 

Source code for cmdstanpy.stanfit.gq

         if inc_sample:
             return np.dstack(
                 (
-                    np.delete(self.mcmc_sample.draws(), drop_cols, axis=1),
+                    np.delete(previous_draws, drop_cols, axis=1),
                     self._draws,
                 )
             )[start_idx:, :, :]
@@ -413,7 +441,7 @@ 

Source code for cmdstanpy.stanfit.gq

         inc_warmup: bool = False,
         inc_sample: bool = False,
     ) -> pd.DataFrame:
-        """
+        """
         Returns the generated quantities draws as a pandas DataFrame.
         Flattens all chains into single column.  Container variables
         (array, vector, matrix) will span multiple columns, one column
@@ -437,17 +465,33 @@ 

Source code for cmdstanpy.stanfit.gq

                 vars_list = [vars]
             else:
                 vars_list = vars
+
             vars_list = list(dict.fromkeys(vars_list))
-        if (
-            inc_warmup
-            and not self.mcmc_sample.metadata.cmdstan_config['save_warmup']
-        ):
-            get_logger().warning(
-                'Draws from warmup iterations not available,'
-                ' must run sampler with "save_warmup=True".'
-            )
-        if self._draws.shape == (0,):
-            self._assemble_generated_quantities()
+
+        if inc_warmup:
+            if (
+                isinstance(self.previous_fit, CmdStanMCMC)
+                and not self.previous_fit._save_warmup
+            ):
+                get_logger().warning(
+                    "Sample doesn't contain draws from warmup iterations,"
+                    ' rerun sampler with "save_warmup=True".'
+                )
+            elif (
+                isinstance(self.previous_fit, CmdStanMLE)
+                and not self.previous_fit._save_iterations
+            ):
+                get_logger().warning(
+                    "MLE doesn't contain draws from pre-convergence iterations,"
+                    ' rerun optimization with "save_iterations=True".'
+                )
+            elif isinstance(self.previous_fit, CmdStanVB):
+                get_logger().warning(
+                    "Variational fit doesn't make sense with argument "
+                    '"inc_warmup=True"'
+                )
+
+        self._assemble_generated_quantities()
 
         gq_cols = []
         mcmc_vars = []
@@ -458,7 +502,7 @@ 

Source code for cmdstanpy.stanfit.gq

                         gq_cols.append(self.column_names[idx])
                 elif (
                     inc_sample
-                    and var in self.mcmc_sample.metadata.stan_vars_cols
+                    and var in self.previous_fit.metadata.stan_vars_cols
                 ):
                     mcmc_vars.append(var)
                 else:
@@ -467,13 +511,13 @@ 

Source code for cmdstanpy.stanfit.gq

             gq_cols = list(self.column_names)
             vars_list = gq_cols
 
+        previous_draws_pd = self._previous_draws_pd(mcmc_vars, inc_warmup)
+
         if inc_sample and mcmc_vars:
             if gq_cols:
                 return pd.concat(
                     [
-                        self.mcmc_sample.draws_pd(
-                            vars=mcmc_vars, inc_warmup=inc_warmup
-                        ).reset_index(drop=True),
+                        previous_draws_pd,
                         pd.DataFrame(
                             data=flatten_chains(
                                 self.draws(inc_warmup=inc_warmup)
@@ -484,11 +528,9 @@ 

Source code for cmdstanpy.stanfit.gq

                     axis='columns',
                 )[vars_list]
             else:
-                return self.mcmc_sample.draws_pd(
-                    vars=mcmc_vars, inc_warmup=inc_warmup
-                )
+                return previous_draws_pd
         elif inc_sample and vars is None:
-            cols_1 = self.mcmc_sample.column_names
+            cols_1 = self.previous_fit.column_names
             cols_2 = self.column_names
             dups = [
                 item
@@ -497,16 +539,13 @@ 

Source code for cmdstanpy.stanfit.gq

             ]
             return pd.concat(
                 [
-                    self.mcmc_sample.draws_pd(inc_warmup=inc_warmup)
-                    .drop(columns=dups)
-                    .reset_index(drop=True),
+                    previous_draws_pd.drop(columns=dups).reset_index(drop=True),
                     pd.DataFrame(
                         data=flatten_chains(self.draws(inc_warmup=inc_warmup)),
                         columns=self.column_names,
                     ),
                 ],
-                axis='columns',
-                ignore_index=True,
+                axis=1,
             )
         elif gq_cols:
             return pd.DataFrame(
@@ -519,15 +558,36 @@ 

Source code for cmdstanpy.stanfit.gq

             columns=self.column_names,
         )
+ @overload + def draws_xr( + self: Union["CmdStanGQ[CmdStanMLE]", "CmdStanGQ[CmdStanVB]"], + vars: Union[str, List[str], None] = None, + inc_warmup: bool = False, + inc_sample: bool = False, + ) -> NoReturn: + ... + + @overload + def draws_xr( + self: "CmdStanGQ[CmdStanMCMC]", + vars: Union[str, List[str], None] = None, + inc_warmup: bool = False, + inc_sample: bool = False, + ) -> "xr.Dataset": + ... +
[docs] def draws_xr( self, vars: Union[str, List[str], None] = None, inc_warmup: bool = False, inc_sample: bool = False, ) -> "xr.Dataset": - """ + """ Returns the generated quantities draws as a xarray Dataset. + This method can only be called when the underlying fit was made + through sampling, it cannot be used on MLE or VB outputs. + :param vars: optional list of variable names. :param inc_warmup: When ``True`` and the warmup draws are present in @@ -544,6 +604,11 @@

Source code for cmdstanpy.stanfit.gq

             raise RuntimeError(
                 'Package "xarray" is not installed, cannot produce draws array.'
             )
+        if not isinstance(self.previous_fit, CmdStanMCMC):
+            raise RuntimeError(
+                'Method "draws_xr" is only available when '
+                'original fit is done via Sampling.'
+            )
         mcmc_vars_list = []
         dup_vars = []
         if vars is not None:
@@ -554,7 +619,7 @@ 

Source code for cmdstanpy.stanfit.gq

             for var in vars_list:
                 if var not in self.metadata.stan_vars_cols:
                     if inc_sample and (
-                        var in self.mcmc_sample.metadata.stan_vars_cols
+                        var in self.previous_fit.metadata.stan_vars_cols
                     ):
                         mcmc_vars_list.append(var)
                         dup_vars.append(var)
@@ -563,17 +628,16 @@ 

Source code for cmdstanpy.stanfit.gq

         else:
             vars_list = list(self.metadata.stan_vars_cols.keys())
             if inc_sample:
-                for var in self.mcmc_sample.metadata.stan_vars_cols.keys():
+                for var in self.previous_fit.metadata.stan_vars_cols.keys():
                     if var not in vars_list and var not in mcmc_vars_list:
                         mcmc_vars_list.append(var)
         for var in dup_vars:
             vars_list.remove(var)
 
-        if self._draws.shape == (0,):
-            self._assemble_generated_quantities()
+        self._assemble_generated_quantities()
 
-        num_draws = self.mcmc_sample.num_draws_sampling
-        sample_config = self.mcmc_sample.metadata.cmdstan_config
+        num_draws = self.previous_fit.num_draws_sampling
+        sample_config = self.previous_fit.metadata.cmdstan_config
         attrs: MutableMapping[Hashable, Any] = {
             "stan_version": f"{sample_config['stan_version_major']}."
             f"{sample_config['stan_version_minor']}."
@@ -582,8 +646,8 @@ 

Source code for cmdstanpy.stanfit.gq

             "num_draws_sampling": num_draws,
         }
         if inc_warmup and sample_config['save_warmup']:
-            num_draws += self.mcmc_sample.num_draws_warmup
-            attrs["num_draws_warmup"] = self.mcmc_sample.num_draws_warmup
+            num_draws += self.previous_fit.num_draws_warmup
+            attrs["num_draws_warmup"] = self.previous_fit.num_draws_warmup
 
         data: MutableMapping[Hashable, Any] = {}
         coordinates: MutableMapping[Hashable, Any] = {
@@ -606,11 +670,11 @@ 

Source code for cmdstanpy.stanfit.gq

                 build_xarray_data(
                     data,
                     var,
-                    self.mcmc_sample.metadata.stan_vars_dims[var],
-                    self.mcmc_sample.metadata.stan_vars_cols[var],
+                    self.previous_fit.metadata.stan_vars_dims[var],
+                    self.previous_fit.metadata.stan_vars_cols[var],
                     0,
-                    self.mcmc_sample.draws(inc_warmup=inc_warmup),
-                    self.mcmc_sample._metadata.stan_vars_types[var],
+                    self.previous_fit.draws(inc_warmup=inc_warmup),
+                    self.previous_fit._metadata.stan_vars_types[var],
                 )
 
         return xr.Dataset(data, coords=coordinates, attrs=attrs).transpose(
@@ -622,7 +686,7 @@ 

Source code for cmdstanpy.stanfit.gq

         var: str,
         inc_warmup: bool = False,
     ) -> np.ndarray:
-        """
+        """
         Return a numpy.ndarray which contains the set of draws
         for the named Stan program variable.  Flattens the chains,
         leaving the draws in chain order.  The first array dimension,
@@ -663,7 +727,7 @@ 

Source code for cmdstanpy.stanfit.gq

         CmdStanMLE.stan_variable
         CmdStanVB.stan_variable
         """
-        model_var_names = self.mcmc_sample.metadata.stan_vars_cols.keys()
+        model_var_names = self.previous_fit.metadata.stan_vars_cols.keys()
         gq_var_names = self.metadata.stan_vars_cols.keys()
         if not (var in model_var_names or var in gq_var_names):
             raise ValueError(
@@ -672,39 +736,43 @@ 

Source code for cmdstanpy.stanfit.gq

                 + ", ".join(model_var_names | gq_var_names)
             )
         if var not in gq_var_names:
-            return self.mcmc_sample.stan_variable(var, inc_warmup=inc_warmup)
-        else:  # is gq variable
-            if self._draws.shape == (0,):
-                self._assemble_generated_quantities()
-            draw1 = 0
-            if (
-                not inc_warmup
-                and self.mcmc_sample.metadata.cmdstan_config['save_warmup']
-            ):
-                draw1 = self.mcmc_sample.num_draws_warmup
-            num_draws = self.mcmc_sample.num_draws_sampling
-            if (
-                inc_warmup
-                and self.mcmc_sample.metadata.cmdstan_config['save_warmup']
-            ):
-                num_draws += self.mcmc_sample.num_draws_warmup
-            dims = [num_draws * self.chains]
-            col_idxs = self._metadata.stan_vars_cols[var]
-            if len(col_idxs) > 0:
-                dims.extend(self._metadata.stan_vars_dims[var])
+            if isinstance(self.previous_fit, CmdStanMCMC):
+                return self.previous_fit.stan_variable(
+                    var, inc_warmup=inc_warmup
+                )
+            elif isinstance(self.previous_fit, CmdStanMLE):
+                return np.atleast_1d(  # type: ignore
+                    np.asarray(
+                        self.previous_fit.stan_variable(
+                            var, inc_iterations=inc_warmup
+                        )
+                    )
+                )
+            else:
+                return np.atleast_1d(  # type: ignore
+                    np.asarray(self.previous_fit.stan_variable(var))
+                )
 
-            draws = self._draws[draw1:, :, col_idxs]
+        # is gq variable
+        self._assemble_generated_quantities()
 
-            if self._metadata.stan_vars_types[var] == BaseType.COMPLEX:
-                draws = draws[..., ::2] + 1j * draws[..., 1::2]
-                dims = dims[:-1]
+        draw1, num_draws = self._draws_start(inc_warmup)
+        dims = [num_draws * self.chains]
+        col_idxs = self._metadata.stan_vars_cols[var]
+        if len(col_idxs) > 0:
+            dims.extend(self._metadata.stan_vars_dims[var])
+        draws = self._draws[draw1:, :, col_idxs]
 
-            draws = draws.reshape(dims, order='F')
+        if self._metadata.stan_vars_types[var] == BaseType.COMPLEX:
+            draws = draws[..., ::2] + 1j * draws[..., 1::2]
+            dims = dims[:-1]
 
-            return draws
+ draws = draws.reshape(dims, order='F') + + return draws
[docs] def stan_variables(self, inc_warmup: bool = False) -> Dict[str, np.ndarray]: - """ + """ Return a dictionary mapping Stan program variables names to the corresponding numpy.ndarray containing the inferred values. @@ -720,7 +788,7 @@

Source code for cmdstanpy.stanfit.gq

         CmdStanVB.stan_variables
         """
         result = {}
-        sample_var_names = self.mcmc_sample.metadata.stan_vars_cols.keys()
+        sample_var_names = self.previous_fit.metadata.stan_vars_cols.keys()
         gq_var_names = self.metadata.stan_vars_cols.keys()
         for name in gq_var_names:
             result[name] = self.stan_variable(name, inc_warmup)
@@ -730,9 +798,11 @@ 

Source code for cmdstanpy.stanfit.gq

         return result
def _assemble_generated_quantities(self) -> None: + if self._draws.shape != (0,): + return # use numpy loadtxt - warmup = self.mcmc_sample.metadata.cmdstan_config['save_warmup'] - num_draws = self.mcmc_sample.draws(inc_warmup=warmup).shape[0] + _, num_draws = self._draws_start(inc_warmup=True) + gq_sample: np.ndarray = np.empty( (num_draws, self.chains, len(self.column_names)), dtype=float, @@ -746,8 +816,79 @@

Source code for cmdstanpy.stanfit.gq

                 )
         self._draws = gq_sample
 
+    def _draws_start(self, inc_warmup: bool) -> Tuple[int, int]:
+        draw1 = 0
+        p_fit = self.previous_fit
+        if isinstance(p_fit, CmdStanMCMC):
+            num_draws = p_fit.num_draws_sampling
+            if p_fit._save_warmup:
+                if inc_warmup:
+                    num_draws += p_fit.num_draws_warmup
+                else:
+                    draw1 = p_fit.num_draws_warmup
+
+        elif isinstance(p_fit, CmdStanMLE):
+            num_draws = 1
+            if p_fit._save_iterations:
+
+                opt_iters = len(p_fit.optimized_iterations_np)  # type: ignore
+                if inc_warmup:
+                    num_draws = opt_iters
+                else:
+                    draw1 = opt_iters - 1
+        else:  # CmdStanVB:
+            draw1 = 1  # skip mean
+            num_draws = p_fit.variational_sample.shape[0]
+            if inc_warmup:
+                num_draws += 1
+
+        return draw1, num_draws
+
+    def _previous_draws(self, inc_warmup: bool) -> np.ndarray:
+        """
+        Extract the draws from self.previous_fit.
+        Return is always 3-d
+        """
+        p_fit = self.previous_fit
+        if isinstance(p_fit, CmdStanMCMC):
+            return p_fit.draws(inc_warmup=inc_warmup)
+        elif isinstance(p_fit, CmdStanMLE):
+            if inc_warmup and p_fit._save_iterations:
+                return p_fit.optimized_iterations_np[:, None]  # type: ignore
+
+            return np.atleast_2d(p_fit.optimized_params_np,)[  # type: ignore
+                :, None
+            ]
+        else:  # CmdStanVB:
+            if inc_warmup:
+                return np.vstack(
+                    [p_fit.variational_params_np, p_fit.variational_sample]
+                )[:, None]
+            return p_fit.variational_sample[:, None]
+
+    def _previous_draws_pd(
+        self, vars: List[str], inc_warmup: bool
+    ) -> pd.DataFrame:
+        if vars:
+            sel: Union[List[str], slice] = vars
+        else:
+            sel = slice(None, None)
+
+        p_fit = self.previous_fit
+        if isinstance(p_fit, CmdStanMCMC):
+            return p_fit.draws_pd(vars or None, inc_warmup=inc_warmup)
+
+        elif isinstance(p_fit, CmdStanMLE):
+
+            if inc_warmup and p_fit._save_iterations:
+                return p_fit.optimized_iterations_pd[sel]  # type: ignore
+            else:
+                return p_fit.optimized_params_pd[sel]
+        else:  # CmdStanVB:
+            return p_fit.variational_sample_pd[sel]
+
 
[docs] def save_csvfiles(self, dir: Optional[str] = None) -> None: - """ + """ Move output CSV files to specified directory. If files were written to the temporary session directory, clean filename. E.g., save 'bernoulli-201912081451-1-5nm6as7u.csv' as @@ -760,7 +901,14 @@

Source code for cmdstanpy.stanfit.gq

         stanfit.RunSet.save_csvfiles
         cmdstanpy.from_csv
         """
-        self.runset.save_csvfiles(dir)
+ self.runset.save_csvfiles(dir)
+ + @property + def mcmc_sample(self) -> Union[CmdStanMCMC, CmdStanMLE, CmdStanVB]: + get_logger().warning( + "Property `mcmc_sample` is deprecated, use `previous_fit` instead" + ) + return self.previous_fit
diff --git a/docs/_modules/cmdstanpy/stanfit/mcmc.html b/docs/_modules/cmdstanpy/stanfit/mcmc.html index e6ce1266..7f09183e 100644 --- a/docs/_modules/cmdstanpy/stanfit/mcmc.html +++ b/docs/_modules/cmdstanpy/stanfit/mcmc.html @@ -5,7 +5,7 @@ - cmdstanpy.stanfit.mcmc — CmdStanPy 1.0.8 documentation + cmdstanpy.stanfit.mcmc — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ @@ -216,7 +216,7 @@

Source code for cmdstanpy.stanfit.mcmc

 
 
 
[docs]class CmdStanMCMC: - """ + """ Container for outputs from CmdStan sampler run. Provides methods to summarize and diagnose the model fit and accessor methods to access the entire sample or @@ -232,7 +232,7 @@

Source code for cmdstanpy.stanfit.mcmc

         self,
         runset: RunSet,
     ) -> None:
-        """Initialize object."""
+        """Initialize object."""
         if not runset.method == Method.SAMPLE:
             raise ValueError(
                 'Wrong runset method, expecting sample runset, '
@@ -255,7 +255,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

         if sampler_args.thin is not None:
             self._thin = sampler_args.thin
         self._is_fixed_param = sampler_args.fixed_param
-        self._save_warmup = sampler_args.save_warmup
+        self._save_warmup: bool = sampler_args.save_warmup
         self._sig_figs = runset._args.sig_figs
 
         # info from CSV values, instantiated lazily
@@ -289,7 +289,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

         return repr
 
     def __getattr__(self, attr: str) -> np.ndarray:
-        """Synonymous with ``fit.stan_variable(attr)"""
+        """Synonymous with ``fit.stan_variable(attr)"""
         if attr.startswith("_"):
             raise AttributeError(f"Unknown variable name {attr}")
         try:
@@ -298,24 +298,32 @@ 

Source code for cmdstanpy.stanfit.mcmc

             # pylint: disable=raise-missing-from
             raise AttributeError(*e.args)
 
+    def __getstate__(self) -> dict:
+        # This function returns the mapping of objects to serialize with pickle.
+        # See https://docs.python.org/3/library/pickle.html#object.__getstate__
+        # for details. We call _assemble_draws to ensure posterior samples have
+        # been loaded prior to serialization.
+        self._assemble_draws()
+        return self.__dict__
+
     @property
     def chains(self) -> int:
-        """Number of chains."""
+        """Number of chains."""
         return self.runset.chains
 
     @property
     def chain_ids(self) -> List[int]:
-        """Chain ids."""
+        """Chain ids."""
         return self.runset.chain_ids
 
     @property
     def num_draws_warmup(self) -> int:
-        """Number of warmup draws per chain, i.e., thinned warmup iterations."""
+        """Number of warmup draws per chain, i.e., thinned warmup iterations."""
         return int(math.ceil((self._iter_warmup) / self._thin))
 
     @property
     def num_draws_sampling(self) -> int:
-        """
+        """
         Number of sampling (post-warmup) draws per chain, i.e.,
         thinned sampling iterations.
         """
@@ -323,7 +331,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
     @property
     def metadata(self) -> InferenceMetadata:
-        """
+        """
         Returns object which contains CmdStan configuration as well as
         information about the names and structure of the inference method
         and model output variables.
@@ -332,7 +340,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
     @property
     def column_names(self) -> Tuple[str, ...]:
-        """
+        """
         Names of all outputs from the sampler, comprising sampler parameters
         and all components of all model parameters, transformed parameters,
         and quantities of interest. Corresponds to Stan CSV file header row,
@@ -342,7 +350,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
     @property
     def metric_type(self) -> Optional[str]:
-        """
+        """
         Metric type used for adaptation, either 'diag_e' or 'dense_e', according
         to CmdStan arg 'metric'.
         When sampler algorithm 'fixed_param' is specified, metric_type is None.
@@ -355,7 +363,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
     @property
     def metric(self) -> Optional[np.ndarray]:
-        """
+        """
         Metric used by sampler for each chain.
         When sampler algorithm 'fixed_param' is specified, metric is None.
         """
@@ -371,7 +379,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
     @property
     def step_size(self) -> Optional[np.ndarray]:
-        """
+        """
         Step size used by sampler for each chain.
         When sampler algorithm 'fixed_param' is specified, step size is None.
         """
@@ -380,14 +388,14 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
     @property
     def thin(self) -> int:
-        """
+        """
         Period between recorded iterations.  (Default is 1).
         """
         return self._thin
 
     @property
     def divergences(self) -> Optional[np.ndarray]:
-        """
+        """
         Per-chain total number of post-warmup divergent iterations.
         When sampler algorithm 'fixed_param' is specified, returns None.
         """
@@ -395,7 +403,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
     @property
     def max_treedepths(self) -> Optional[np.ndarray]:
-        """
+        """
         Per-chain total number of post-warmup iterations where the NUTS sampler
         reached the maximum allowed treedepth.
         When sampler algorithm 'fixed_param' is specified, returns None.
@@ -405,7 +413,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
[docs] def draws( self, *, inc_warmup: bool = False, concat_chains: bool = False ) -> np.ndarray: - """ + """ Returns a numpy.ndarray over all draws from all chains which is stored column major so that the values for a parameter are contiguous in memory, likewise all draws from a chain are contiguous. @@ -428,8 +436,7 @@

Source code for cmdstanpy.stanfit.mcmc

         CmdStanMCMC.draws_xr
         CmdStanGQ.draws
         """
-        if self._draws.shape == (0,):
-            self._assemble_draws()
+        self._assemble_draws()
 
         if inc_warmup and not self._save_warmup:
             get_logger().warning(
@@ -446,7 +453,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

         return self._draws[start_idx:, :, :]
def _validate_csv_files(self) -> Dict[str, Any]: - """ + """ Checks that Stan CSV output files for all chains are consistent and returns dict containing config and column names. @@ -509,7 +516,7 @@

Source code for cmdstanpy.stanfit.mcmc

         return dzero
 
     def _check_sampler_diagnostics(self) -> None:
-        """
+        """
         Warn if any iterations ended in divergences or hit maxtreedepth.
         """
         if np.any(self._divergences) or np.any(self._max_treedepths):
@@ -518,13 +525,13 @@ 

Source code for cmdstanpy.stanfit.mcmc

             for i in range(self.runset._chains):
                 if self._divergences[i] > 0:
                     diagnostics.append(
-                        f'Chain {i + 1} had {self._divergences[i]} '
+                        f'Chain {i + 1} had {self._divergences[i]} '
                         'divergent transitions '
                         f'({((self._divergences[i]/ct_iters)*100):.1f}%)'
                     )
                 if self._max_treedepths[i] > 0:
                     diagnostics.append(
-                        f'Chain {i + 1} had {self._max_treedepths[i]} '
+                        f'Chain {i + 1} had {self._max_treedepths[i]} '
                         'iterations at max treedepth '
                         f'({((self._max_treedepths[i]/ct_iters)*100):.1f}%)'
                     )
@@ -534,7 +541,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

             get_logger().warning('\n\t'.join(diagnostics))
 
     def _assemble_draws(self) -> None:
-        """
+        """
         Allocates and populates the step size, metric, and sample arrays
         by parsing the validated stan_csv files.
         """
@@ -615,7 +622,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

         percentiles: Sequence[int] = (5, 50, 95),
         sig_figs: int = 6,
     ) -> pd.DataFrame:
-        """
+        """
         Run cmdstan/bin/stansummary over all output CSV files, assemble
         summary into DataFrame object.  The first row contains statistics
         for the total joint log probability `lp__`, but is omitted when the
@@ -650,7 +657,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

                 )
             cur_pct = pct
         percentiles_str = (
-            f"--percentiles= {','.join(str(x) for x in percentiles)}"
+            f"--percentiles= {','.join(str(x) for x in percentiles)}"
         )
 
         if not isinstance(sig_figs, int) or sig_figs < 1 or sig_figs > 18:
@@ -705,7 +712,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

         return summary_data[mask]
[docs] def diagnose(self) -> Optional[str]: - """ + """ Run cmdstan/bin/diagnose over all output CSV files, return console output. @@ -729,7 +736,7 @@

Source code for cmdstanpy.stanfit.mcmc

         vars: Union[List[str], str, None] = None,
         inc_warmup: bool = False,
     ) -> pd.DataFrame:
-        """
+        """
         Returns the sample draws as a pandas DataFrame.
         Flattens all chains into single column.  Container variables
         (array, vector, matrix) will span multiple columns, one column
@@ -760,8 +767,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

                 ' must run sampler with "save_warmup=True".'
             )
 
-        if self._draws.shape == (0,):
-            self._assemble_draws()
+        self._assemble_draws()
         cols = []
         if vars is not None:
             for var in dict.fromkeys(vars_list):
@@ -786,7 +792,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

 
[docs] def draws_xr( self, vars: Union[str, List[str], None] = None, inc_warmup: bool = False ) -> "xr.Dataset": - """ + """ Returns the sampler draws as a xarray Dataset. :param vars: optional list of variable names. @@ -817,8 +823,7 @@

Source code for cmdstanpy.stanfit.mcmc

         else:
             vars_list = vars
 
-        if self._draws.shape == (0,):
-            self._assemble_draws()
+        self._assemble_draws()
 
         num_draws = self.num_draws_sampling
         meta = self._metadata.cmdstan_config
@@ -857,7 +862,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

         var: str,
         inc_warmup: bool = False,
     ) -> np.ndarray:
-        """
+        """
         Return a numpy.ndarray which contains the set of draws
         for the named Stan program variable.  Flattens the chains,
         leaving the draws in chain order.  The first array dimension,
@@ -904,8 +909,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

                 'Available variables are '
                 + ", ".join(self._metadata.stan_vars_dims)
             )
-        if self._draws.shape == (0,):
-            self._assemble_draws()
+        self._assemble_draws()
         draw1 = 0
         if not inc_warmup and self._save_warmup:
             draw1 = self.num_draws_warmup
@@ -927,7 +931,7 @@ 

Source code for cmdstanpy.stanfit.mcmc

         return draws
[docs] def stan_variables(self) -> Dict[str, np.ndarray]: - """ + """ Return a dictionary mapping Stan program variables names to the corresponding numpy.ndarray containing the inferred values. @@ -944,7 +948,7 @@

Source code for cmdstanpy.stanfit.mcmc

         return result
[docs] def method_variables(self) -> Dict[str, np.ndarray]: - """ + """ Returns a dictionary of all sampler variables, i.e., all output column names ending in `__`. Assumes that all variables are scalar variables where column name is variable name. @@ -952,15 +956,14 @@

Source code for cmdstanpy.stanfit.mcmc

         containing per-draw diagnostic values.
         """
         result = {}
-        if self._draws.shape == (0,):
-            self._assemble_draws()
+        self._assemble_draws()
         for idxs in self.metadata.method_vars_cols.values():
             for idx in idxs:
                 result[self.column_names[idx]] = self._draws[:, :, idx]
         return result
[docs] def save_csvfiles(self, dir: Optional[str] = None) -> None: - """ + """ Move output CSV files to specified directory. If files were written to the temporary session directory, clean filename. E.g., save 'bernoulli-201912081451-1-5nm6as7u.csv' as diff --git a/docs/_modules/cmdstanpy/stanfit/metadata.html b/docs/_modules/cmdstanpy/stanfit/metadata.html index 5302dcc5..bdfc1980 100644 --- a/docs/_modules/cmdstanpy/stanfit/metadata.html +++ b/docs/_modules/cmdstanpy/stanfit/metadata.html @@ -5,7 +5,7 @@ - cmdstanpy.stanfit.metadata — CmdStanPy 1.0.8 documentation + cmdstanpy.stanfit.metadata — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ @@ -176,14 +176,14 @@

Source code for cmdstanpy.stanfit.metadata

 
 
 
[docs]class InferenceMetadata: - """ + """ CmdStan configuration and contents of output file parsed out of the Stan CSV file header comments and column headers. Assumes valid CSV files. """ def __init__(self, config: Dict[str, Any]) -> None: - """Initialize object from CSV headers""" + """Initialize object from CSV headers""" self._cmdstan_config = config self._method_vars_cols = parse_method_vars(names=config['column_names']) stan_vars_dims, stan_vars_cols, stan_vars_types = parse_stan_vars( @@ -198,7 +198,7 @@

Source code for cmdstanpy.stanfit.metadata

 
     @property
     def cmdstan_config(self) -> Dict[str, Any]:
-        """
+        """
         Returns a dictionary containing a set of name, value pairs
         parsed out of the Stan CSV file header.  These include the
         command configuration and the CSV file header row information.
@@ -208,7 +208,7 @@ 

Source code for cmdstanpy.stanfit.metadata

 
     @property
     def method_vars_cols(self) -> Dict[str, Tuple[int, ...]]:
-        """
+        """
         Returns a map from a Stan inference method variable to
         a tuple of column indices in inference engine's output array.
         Method variable names always end in `__`, e.g. `lp__`.
@@ -218,7 +218,7 @@ 

Source code for cmdstanpy.stanfit.metadata

 
     @property
     def stan_vars_cols(self) -> Dict[str, Tuple[int, ...]]:
-        """
+        """
         Returns a map from a Stan program variable name to a
         tuple of the column indices in the vector or matrix of
         estimates produced by a CmdStan inference method.
@@ -228,7 +228,7 @@ 

Source code for cmdstanpy.stanfit.metadata

 
     @property
     def stan_vars_dims(self) -> Dict[str, Tuple[int, ...]]:
-        """
+        """
         Returns map from Stan program variable names to variable dimensions.
         Scalar types are mapped to the empty tuple, e.g.,
         program variable ``int foo`` has dimension ``()`` and
@@ -239,7 +239,7 @@ 

Source code for cmdstanpy.stanfit.metadata

 
     @property
     def stan_vars_types(self) -> Dict[str, BaseType]:
-        """
+        """
         Returns map from Stan program variable names to variable base type.
         Uses deepcopy for immutability.
         """
diff --git a/docs/_modules/cmdstanpy/stanfit/mle.html b/docs/_modules/cmdstanpy/stanfit/mle.html
index b5d9b682..84fb2e39 100644
--- a/docs/_modules/cmdstanpy/stanfit/mle.html
+++ b/docs/_modules/cmdstanpy/stanfit/mle.html
@@ -5,7 +5,7 @@
   
     
     
-    cmdstanpy.stanfit.mle — CmdStanPy 1.0.8 documentation
+    cmdstanpy.stanfit.mle — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -56,7 +56,7 @@
   
 
@@ -183,13 +183,13 @@ 

Source code for cmdstanpy.stanfit.mle

 
 
 
[docs]class CmdStanMLE: - """ + """ Container for outputs from CmdStan optimization. Created by :meth:`CmdStanModel.optimize`. """ def __init__(self, runset: RunSet) -> None: - """Initialize object.""" + """Initialize object.""" if not runset.method == Method.OPTIMIZE: raise ValueError( 'Wrong runset method, expecting optimize runset, ' @@ -202,7 +202,7 @@

Source code for cmdstanpy.stanfit.mle

         assert isinstance(
             optimize_args, OptimizeArgs
         )  # make the typechecker happy
-        self._save_iterations = optimize_args.save_iterations
+        self._save_iterations: bool = optimize_args.save_iterations
         self._set_mle_attrs(runset.csv_files[0])
 
     def __repr__(self) -> str:
@@ -220,7 +220,7 @@ 

Source code for cmdstanpy.stanfit.mle

         return repr
 
     def __getattr__(self, attr: str) -> Union[np.ndarray, float]:
-        """Synonymous with ``fit.stan_variable(attr)"""
+        """Synonymous with ``fit.stan_variable(attr)"""
         if attr.startswith("_"):
             raise AttributeError(f"Unknown variable name {attr}")
         try:
@@ -239,7 +239,7 @@ 

Source code for cmdstanpy.stanfit.mle

 
     @property
     def column_names(self) -> Tuple[str, ...]:
-        """
+        """
         Names of estimated quantities, includes joint log probability,
         and all parameters, transformed parameters, and generated quantities.
         """
@@ -247,7 +247,7 @@ 

Source code for cmdstanpy.stanfit.mle

 
     @property
     def metadata(self) -> InferenceMetadata:
-        """
+        """
         Returns object which contains CmdStan configuration as well as
         information about the names and structure of the inference method
         and model output variables.
@@ -256,7 +256,7 @@ 

Source code for cmdstanpy.stanfit.mle

 
     @property
     def optimized_params_np(self) -> np.ndarray:
-        """
+        """
         Returns all final estimates from the optimizer as a numpy.ndarray
         which contains all optimizer outputs, i.e., the value for `lp__`
         as well as all Stan program variables.
@@ -269,7 +269,7 @@ 

Source code for cmdstanpy.stanfit.mle

 
     @property
     def optimized_iterations_np(self) -> Optional[np.ndarray]:
-        """
+        """
         Returns all saved iterations from the optimizer and final estimate
         as a numpy.ndarray which contains all optimizer outputs, i.e.,
         the value for `lp__` as well as all Stan program variables.
@@ -289,7 +289,7 @@ 

Source code for cmdstanpy.stanfit.mle

 
     @property
     def optimized_params_pd(self) -> pd.DataFrame:
-        """
+        """
         Returns all final estimates from the optimizer as a pandas.DataFrame
         which contains all optimizer outputs, i.e., the value for `lp__`
         as well as all Stan program variables.
@@ -302,7 +302,7 @@ 

Source code for cmdstanpy.stanfit.mle

 
     @property
     def optimized_iterations_pd(self) -> Optional[pd.DataFrame]:
-        """
+        """
         Returns all saved iterations from the optimizer and final estimate
         as a pandas.DataFrame which contains all optimizer outputs, i.e.,
         the value for `lp__` as well as all Stan program variables.
@@ -321,8 +321,8 @@ 

Source code for cmdstanpy.stanfit.mle

         return pd.DataFrame(self._all_iters, columns=self.column_names)
 
     @property
-    def optimized_params_dict(self) -> Dict[str, float]:
-        """
+    def optimized_params_dict(self) -> Dict[str, np.float64]:
+        """
         Returns all estimates from the optimizer, including `lp__` as a
         Python Dict.  Only returns estimate from final iteration.
         """
@@ -339,7 +339,7 @@ 

Source code for cmdstanpy.stanfit.mle

         inc_iterations: bool = False,
         warn: bool = True,
     ) -> Union[np.ndarray, float]:
-        """
+        """
         Return a numpy.ndarray which contains the estimates for the
         for the named Stan program variable where the dimensions of the
         numpy.ndarray match the shape of the Stan program variable.
@@ -410,7 +410,7 @@ 

Source code for cmdstanpy.stanfit.mle

 
[docs] def stan_variables( self, inc_iterations: bool = False ) -> Dict[str, Union[np.ndarray, float]]: - """ + """ Return a dictionary mapping Stan program variables names to the corresponding numpy.ndarray containing the inferred values. @@ -439,7 +439,7 @@

Source code for cmdstanpy.stanfit.mle

         return result
[docs] def save_csvfiles(self, dir: Optional[str] = None) -> None: - """ + """ Move output CSV files to specified directory. If files were written to the temporary session directory, clean filename. E.g., save 'bernoulli-201912081451-1-5nm6as7u.csv' as diff --git a/docs/_modules/cmdstanpy/stanfit/runset.html b/docs/_modules/cmdstanpy/stanfit/runset.html index 35c9019b..d9ad3656 100644 --- a/docs/_modules/cmdstanpy/stanfit/runset.html +++ b/docs/_modules/cmdstanpy/stanfit/runset.html @@ -5,7 +5,7 @@ - cmdstanpy.stanfit.runset — CmdStanPy 1.0.8 documentation + cmdstanpy.stanfit.runset — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ @@ -186,7 +186,7 @@

Source code for cmdstanpy.stanfit.runset

 
 
 
[docs]class RunSet: - """ + """ Encapsulates the configuration and results of a call to any CmdStan inference method. Records the method return code and locations of all console, error, and output files. @@ -204,7 +204,7 @@

Source code for cmdstanpy.stanfit.runset

         time_fmt: str = "%Y%m%d%H%M%S",
         one_process_per_chain: bool = True,
     ) -> None:
-        """Initialize object (no input arg checks)."""
+        """Initialize object (no input arg checks)."""
         self._args = args
         self._chains = chains
         self._one_process_per_chain = one_process_per_chain
@@ -288,22 +288,22 @@ 

Source code for cmdstanpy.stanfit.runset

 
     @property
     def model(self) -> str:
-        """Stan model name."""
+        """Stan model name."""
         return self._args.model_name
 
     @property
     def method(self) -> Method:
-        """CmdStan method used to generate this fit."""
+        """CmdStan method used to generate this fit."""
         return self._args.method
 
     @property
     def num_procs(self) -> int:
-        """Number of processes run."""
+        """Number of processes run."""
         return self._num_procs
 
     @property
     def one_process_per_chain(self) -> bool:
-        """
+        """
         When True, for each chain, call CmdStan in its own subprocess.
         When False, use CmdStan's `num_chains` arg to run parallel chains.
         Always True if CmdStan < 2.28.
@@ -313,16 +313,16 @@ 

Source code for cmdstanpy.stanfit.runset

 
     @property
     def chains(self) -> int:
-        """Number of chains."""
+        """Number of chains."""
         return self._chains
 
     @property
     def chain_ids(self) -> List[int]:
-        """Chain ids."""
+        """Chain ids."""
         return self._chain_ids
 
 
[docs] def cmd(self, idx: int) -> List[str]: - """ + """ Assemble CmdStan invocation. When running parallel chains from single process (2.28 and up), specify CmdStan arg `num_chains` and leave chain idx off CSV files. @@ -353,19 +353,19 @@

Source code for cmdstanpy.stanfit.runset

 
     @property
     def csv_files(self) -> List[str]:
-        """List of paths to CmdStan output files."""
+        """List of paths to CmdStan output files."""
         return self._csv_files
 
     @property
     def stdout_files(self) -> List[str]:
-        """
+        """
         List of paths to transcript of CmdStan messages sent to the console.
         Transcripts include config information, progress, and error messages.
         """
         return self._stdout_files
 
     def _check_retcodes(self) -> bool:
-        """Returns ``True`` when all chains have retcode 0."""
+        """Returns ``True`` when all chains have retcode 0."""
         for code in self._retcodes:
             if code != 0:
                 return False
@@ -373,12 +373,12 @@ 

Source code for cmdstanpy.stanfit.runset

 
     @property
     def diagnostic_files(self) -> List[str]:
-        """List of paths to CmdStan hamiltonian diagnostic files."""
+        """List of paths to CmdStan hamiltonian diagnostic files."""
         return self._diagnostic_files
 
     @property
     def profile_files(self) -> List[str]:
-        """List of paths to CmdStan profiler files."""
+        """List of paths to CmdStan profiler files."""
         return self._profile_files
 
     # pylint: disable=invalid-name
@@ -393,19 +393,19 @@ 

Source code for cmdstanpy.stanfit.runset

         return file
 
     def _retcode(self, idx: int) -> int:
-        """Get retcode for process[idx]."""
+        """Get retcode for process[idx]."""
         return self._retcodes[idx]
 
     def _set_retcode(self, idx: int, val: int) -> None:
-        """Set retcode at process[idx] to val."""
+        """Set retcode at process[idx] to val."""
         self._retcodes[idx] = val
 
     def _set_timeout_flag(self, idx: int, val: bool) -> None:
-        """Set timeout_flag at process[idx] to val."""
+        """Set timeout_flag at process[idx] to val."""
         self._timeout_flags[idx] = val
 
 
[docs] def get_err_msgs(self) -> str: - """Checks console messages for each CmdStan run.""" + """Checks console messages for each CmdStan run.""" msgs = [] for i in range(self._num_procs): if ( @@ -427,7 +427,7 @@

Source code for cmdstanpy.stanfit.runset

         return '\n'.join(msgs)
[docs] def save_csvfiles(self, dir: Optional[str] = None) -> None: - """ + """ Moves CSV files to specified directory. :param dir: directory path diff --git a/docs/_modules/cmdstanpy/stanfit/vb.html b/docs/_modules/cmdstanpy/stanfit/vb.html index 0f354697..292c0c86 100644 --- a/docs/_modules/cmdstanpy/stanfit/vb.html +++ b/docs/_modules/cmdstanpy/stanfit/vb.html @@ -5,7 +5,7 @@ - cmdstanpy.stanfit.vb — CmdStanPy 1.0.8 documentation + cmdstanpy.stanfit.vb — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ @@ -183,13 +183,13 @@

Source code for cmdstanpy.stanfit.vb

 
 
 
[docs]class CmdStanVB: - """ + """ Container for outputs from CmdStan variational run. Created by :meth:`CmdStanModel.variational`. """ def __init__(self, runset: RunSet) -> None: - """Initialize object.""" + """Initialize object.""" if not runset.method == Method.VARIATIONAL: raise ValueError( 'Wrong runset method, expecting variational inference, ' @@ -211,7 +211,7 @@

Source code for cmdstanpy.stanfit.vb

         return repr
 
     def __getattr__(self, attr: str) -> Union[np.ndarray, float]:
-        """Synonymous with ``fit.stan_variable(attr)"""
+        """Synonymous with ``fit.stan_variable(attr)"""
         if attr.startswith("_"):
             raise AttributeError(f"Unknown variable name {attr}")
         try:
@@ -231,7 +231,7 @@ 

Source code for cmdstanpy.stanfit.vb

 
     @property
     def columns(self) -> int:
-        """
+        """
         Total number of information items returned by sampler.
         Includes approximation information and names of model parameters
         and computed quantities.
@@ -240,7 +240,7 @@ 

Source code for cmdstanpy.stanfit.vb

 
     @property
     def column_names(self) -> Tuple[str, ...]:
-        """
+        """
         Names of information items returned by sampler for each draw.
         Includes approximation information and names of model parameters
         and computed quantities.
@@ -249,33 +249,33 @@ 

Source code for cmdstanpy.stanfit.vb

 
     @property
     def eta(self) -> float:
-        """
+        """
         Step size scaling parameter 'eta'
         """
         return self._eta
 
     @property
     def variational_params_np(self) -> np.ndarray:
-        """
+        """
         Returns inferred parameter means as numpy array.
         """
         return self._variational_mean
 
     @property
     def variational_params_pd(self) -> pd.DataFrame:
-        """
+        """
         Returns inferred parameter means as pandas DataFrame.
         """
         return pd.DataFrame([self._variational_mean], columns=self.column_names)
 
     @property
     def variational_params_dict(self) -> Dict[str, np.ndarray]:
-        """Returns inferred parameter means as Dict."""
+        """Returns inferred parameter means as Dict."""
         return OrderedDict(zip(self.column_names, self._variational_mean))
 
     @property
     def metadata(self) -> InferenceMetadata:
-        """
+        """
         Returns object which contains CmdStan configuration as well as
         information about the names and structure of the inference method
         and model output variables.
@@ -283,7 +283,7 @@ 

Source code for cmdstanpy.stanfit.vb

         return self._metadata
 
 
[docs] def stan_variable(self, var: str) -> Union[np.ndarray, float]: - """ + """ Return a numpy.ndarray which contains the estimates for the for the named Stan program variable where the dimensions of the numpy.ndarray match the shape of the Stan program variable. @@ -324,7 +324,7 @@

Source code for cmdstanpy.stanfit.vb

             return float(self._variational_mean[col_idxs[0]])
[docs] def stan_variables(self) -> Dict[str, Union[np.ndarray, float]]: - """ + """ Return a dictionary mapping Stan program variables names to the corresponding numpy.ndarray containing the inferred values. @@ -342,11 +342,19 @@

Source code for cmdstanpy.stanfit.vb

 
     @property
     def variational_sample(self) -> np.ndarray:
-        """Returns the set of approximate posterior output draws."""
+        """Returns the set of approximate posterior output draws."""
         return self._variational_sample
 
+    @property
+    def variational_sample_pd(self) -> pd.DataFrame:
+        """
+        Returns the set of approximate posterior output draws as
+        a pandas DataFrame.
+        """
+        return pd.DataFrame(self._variational_sample, columns=self.column_names)
+
 
[docs] def save_csvfiles(self, dir: Optional[str] = None) -> None: - """ + """ Move output CSV files to specified directory. If files were written to the temporary session directory, clean filename. E.g., save 'bernoulli-201912081451-1-5nm6as7u.csv' as diff --git a/docs/_modules/cmdstanpy/utils.html b/docs/_modules/cmdstanpy/utils.html index 4a2b9550..12d51485 100644 --- a/docs/_modules/cmdstanpy/utils.html +++ b/docs/_modules/cmdstanpy/utils.html @@ -5,7 +5,7 @@ - cmdstanpy.utils — CmdStanPy 1.0.8 documentation + cmdstanpy.utils — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ @@ -220,7 +220,7 @@

Source code for cmdstanpy.utils

 
 
 
[docs]def show_versions(output: bool = True) -> str: - """Prints out system and dependency information for debugging""" + """Prints out system and dependency information for debugging""" import importlib import locale @@ -238,8 +238,8 @@

Source code for cmdstanpy.utils

                 ("machine", f"{machine}"),
                 ("processor", f"{processor}"),
                 ("byteorder", f"{sys.byteorder}"),
-                ("LC_ALL", f'{os.environ.get("LC_ALL", "None")}'),
-                ("LANG", f'{os.environ.get("LANG", "None")}'),
+                ("LC_ALL", f'{os.environ.get("LC_ALL", "None")}'),
+                ("LANG", f'{os.environ.get("LANG", "None")}'),
                 ("LOCALE", f"{locale.getlocale()}"),
             ]
         )
diff --git a/docs/_modules/cmdstanpy/utils/cmdstan.html b/docs/_modules/cmdstanpy/utils/cmdstan.html
index 5ee80990..428698ff 100644
--- a/docs/_modules/cmdstanpy/utils/cmdstan.html
+++ b/docs/_modules/cmdstanpy/utils/cmdstan.html
@@ -5,7 +5,7 @@
   
     
     
-    cmdstanpy.utils.cmdstan — CmdStanPy 1.0.8 documentation
+    cmdstanpy.utils.cmdstan — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -56,7 +56,7 @@
   
 
@@ -228,7 +228,7 @@ 

Source code for cmdstanpy.utils.cmdstan

 
 
 def validate_dir(install_dir: str) -> None:
-    """Check that specified install directory exists, can write."""
+    """Check that specified install directory exists, can write."""
     if not os.path.exists(install_dir):
         try:
             os.makedirs(install_dir)
@@ -252,7 +252,7 @@ 

Source code for cmdstanpy.utils.cmdstan

 
 
 def get_latest_cmdstan(cmdstan_dir: str) -> Optional[str]:
-    """
+    """
     Given a valid directory path, find all installed CmdStan versions
     and return highest (i.e., latest) version number.
 
@@ -294,7 +294,7 @@ 

Source code for cmdstanpy.utils.cmdstan

 
 
 def validate_cmdstan_path(path: str) -> None:
-    """
+    """
     Validate that CmdStan directory exists and binaries have been built.
     Throws exception if specified path is invalid.
     """
@@ -310,7 +310,7 @@ 

Source code for cmdstanpy.utils.cmdstan

 
 
 
[docs]def set_cmdstan_path(path: str) -> None: - """ + """ Validate, then set CmdStan directory path. """ validate_cmdstan_path(path) @@ -318,14 +318,14 @@

Source code for cmdstanpy.utils.cmdstan

 
 
 
[docs]def set_make_env(make: str) -> None: - """ + """ set MAKE environmental variable. """ os.environ['MAKE'] = make
[docs]def cmdstan_path() -> str: - """ + """ Validate, then return CmdStan directory path. """ cmdstan = '' @@ -351,7 +351,7 @@

Source code for cmdstanpy.utils.cmdstan

 
 
 
[docs]def cmdstan_version() -> Optional[Tuple[int, ...]]: - """ + """ Parses version string out of CmdStan makefile variable CMDSTAN_VERSION, returns Tuple(Major, minor). @@ -403,7 +403,7 @@

Source code for cmdstanpy.utils.cmdstan

 def cmdstan_version_before(
     major: int, minor: int, info: Optional[Dict[str, str]] = None
 ) -> bool:
-    """
+    """
     Check that CmdStan version is less than Major.minor version.
 
     :param major: Major version number
@@ -434,7 +434,7 @@ 

Source code for cmdstanpy.utils.cmdstan

 def cxx_toolchain_path(
     version: Optional[str] = None, install_dir: Optional[str] = None
 ) -> Tuple[str, ...]:
-    """
+    """
     Validate, then activate C++ toolchain directory path.
     """
     if platform.system() != 'Windows':
@@ -603,7 +603,7 @@ 

Source code for cmdstanpy.utils.cmdstan

     *,
     interactive: bool = False,
 ) -> bool:
-    """
+    """
     Download and install a CmdStan release from GitHub. Downloads the release
     tar.gz file to temporary storage.  Retries GitHub requests in order
     to allow for transient network outages. Builds CmdStan executables
@@ -692,7 +692,7 @@ 

Source code for cmdstanpy.utils.cmdstan

 
 @progbar.wrap_callback
 def wrap_url_progress_hook() -> Optional[Callable[[int, int, int], None]]:
-    """Sets up tqdm callback for url downloads."""
+    """Sets up tqdm callback for url downloads."""
     pbar: tqdm = tqdm(
         unit='B',
         unit_scale=True,
diff --git a/docs/_modules/cmdstanpy/utils/json.html b/docs/_modules/cmdstanpy/utils/json.html
index 08f128c3..6d1a9dd7 100644
--- a/docs/_modules/cmdstanpy/utils/json.html
+++ b/docs/_modules/cmdstanpy/utils/json.html
@@ -5,7 +5,7 @@
   
     
     
-    cmdstanpy.utils.json — CmdStanPy 1.0.8 documentation
+    cmdstanpy.utils.json — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -56,7 +56,7 @@
   
 
@@ -185,7 +185,7 @@ 

Source code for cmdstanpy.utils.json

 
 
 
[docs]def write_stan_json(path: str, data: Mapping[str, Any]) -> None: - """ + """ Dump a mapping of strings to data to a JSON file. Values can be any numeric type, a boolean (converted to int), diff --git a/docs/_modules/index.html b/docs/_modules/index.html index 60d7cc28..72278d65 100644 --- a/docs/_modules/index.html +++ b/docs/_modules/index.html @@ -5,7 +5,7 @@ - Overview: module code — CmdStanPy 1.0.8 documentation + Overview: module code — CmdStanPy 1.1.0rc1 documentation @@ -56,7 +56,7 @@ diff --git a/docs/_sources/changes.rst.txt b/docs/_sources/changes.rst.txt index 3b1df4b8..ca118109 100644 --- a/docs/_sources/changes.rst.txt +++ b/docs/_sources/changes.rst.txt @@ -7,6 +7,24 @@ What's New For full changes, see the `Releases page `__ on GitHub. + +CmdStanPy 1.1.0 +--------------- +- **New functionality** + + - :meth:`CmdStanModel.generate_quantities` can now accept samples from optimization and variational inference. + The argument ``mcmc_sample`` has been renamed ``previous_fit`` to reflect this; the former name is still accepted + but deprecated. + - :meth:`CmdStanModel.log_prob` is able to return the log probability and its gradient with respect to a set of parameters. + **Note** that this is *not* an efficient way of calculating this in general and should be reserved for debugging + and model development. +- **Other changes** + + - Improved some of the type hints in the package. + - Ensure draws are serialized if a fit object is pickled. + - :meth:`~CmdStanModel.src_info` now raises an error if the command fails, rather than returning ``{}``. + - CmdStanPy has transitioned all unit tests from the ``unittest`` library to use ``pytest``. + CmdStanPy 1.0.8 --------------- diff --git a/docs/_sources/community.rst.txt b/docs/_sources/community.rst.txt index 8a04d95f..ee31d594 100644 --- a/docs/_sources/community.rst.txt +++ b/docs/_sources/community.rst.txt @@ -30,3 +30,7 @@ Software Bayesian models. Includes functions for posterior analysis, data storage, model checking, comparison and diagnostics. +- `BridgeStan `_ A project which provides efficient + in-memory access through Python, Julia, and R to the methods of a Stan model, including + log densities, gradients, Hessians, and constraining and unconstraining transforms. + diff --git a/docs/_sources/installation.rst.txt b/docs/_sources/installation.rst.txt index 54e5c566..c7f26358 100644 --- a/docs/_sources/installation.rst.txt +++ b/docs/_sources/installation.rst.txt @@ -107,7 +107,7 @@ To install the current develop branch from GitHub: .. code-block:: bash - pip install -e git+https://github.com/stan-dev/cmdstanpy@/develop#egg=cmdstanpy + pip install -e git+https://github.com/stan-dev/cmdstanpy@develop#egg=cmdstanpy .. note:: diff --git a/docs/_sources/users-guide/examples/Run Generated Quantities.ipynb.txt b/docs/_sources/users-guide/examples/Run Generated Quantities.ipynb.txt index 403befa2..28ac770d 100644 --- a/docs/_sources/users-guide/examples/Run Generated Quantities.ipynb.txt +++ b/docs/_sources/users-guide/examples/Run Generated Quantities.ipynb.txt @@ -129,6 +129,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -136,7 +137,7 @@ "\n", "The arguments to the `generate_quantities` method are:\n", " + `data` - the data used to fit the model\n", - " + `mcmc_sample` - either a `CmdStanMCMC` object or a list of stan-csv files\n" + " + `previous_fit` - either a `CmdStanMCMC`, `CmdStanVB`, or `CmdStanMLE` object or a list of stan-csv files\n" ] }, { @@ -145,7 +146,7 @@ "metadata": {}, "outputs": [], "source": [ - "new_quantities = model_ppc.generate_quantities(data=data_file, mcmc_sample=fit)" + "new_quantities = model_ppc.generate_quantities(data=data_file, previous_fit=fit)" ] }, { diff --git a/docs/_sources/users-guide/workflow.rst.txt b/docs/_sources/users-guide/workflow.rst.txt index 7b857e4e..dc74f5a9 100644 --- a/docs/_sources/users-guide/workflow.rst.txt +++ b/docs/_sources/users-guide/workflow.rst.txt @@ -149,8 +149,8 @@ An example of each is provided in the `next section `__ * The :meth:`~CmdStanModel.generate_quantities` method runs Stan's `generate_quantities method `_ - which generates additional quantities of interest from a mode. Its take an existing sample as input and - uses the parameter estimates in the sample to run the Stan program's `generated quantities block `__. + which generates additional quantities of interest from a mode. Its take an existing fit as input and + uses the parameter estimates in the fit to run the Stan program's `generated quantities block `__. It returns a :class:`CmdStanGQ` object. diff --git a/docs/_static/copybutton.css b/docs/_static/copybutton.css index 40eafe5f..f1916ec7 100644 --- a/docs/_static/copybutton.css +++ b/docs/_static/copybutton.css @@ -35,7 +35,8 @@ div.highlight { position: relative; } -.highlight:hover button.copybtn { +/* Show the copybutton */ +.highlight:hover button.copybtn, button.copybtn.success { opacity: 1; } diff --git a/docs/_static/copybutton.js b/docs/_static/copybutton.js index d86e0633..3fc520a8 100644 --- a/docs/_static/copybutton.js +++ b/docs/_static/copybutton.js @@ -102,18 +102,25 @@ const clearSelection = () => { } } -// Changes tooltip text for two seconds, then changes it back +// Changes tooltip text for a moment, then changes it back +// We want the timeout of our `success` class to be a bit shorter than the +// tooltip and icon change, so that we can hide the icon before changing back. +var timeoutIcon = 2000; +var timeoutSuccessClass = 1500; + const temporarilyChangeTooltip = (el, oldText, newText) => { el.setAttribute('data-tooltip', newText) el.classList.add('success') - setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000) - setTimeout(() => el.classList.remove('success'), 2000) + // Remove success a little bit sooner than we change the tooltip + // So that we can use CSS to hide the copybutton first + setTimeout(() => el.classList.remove('success'), timeoutSuccessClass) + setTimeout(() => el.setAttribute('data-tooltip', oldText), timeoutIcon) } // Changes the copy button icon for two seconds, then changes it back const temporarilyChangeIcon = (el) => { el.innerHTML = iconCheck; - setTimeout(() => {el.innerHTML = iconCopy}, 2000) + setTimeout(() => {el.innerHTML = iconCopy}, timeoutIcon) } const addCopyButtonToCodeCells = () => { @@ -125,7 +132,8 @@ const addCopyButtonToCodeCells = () => { } // Add copybuttons to all of our code cells - const codeCells = document.querySelectorAll('div.highlight pre') + const COPYBUTTON_SELECTOR = 'div.highlight pre'; + const codeCells = document.querySelectorAll(COPYBUTTON_SELECTOR) codeCells.forEach((codeCell, index) => { const id = codeCellId(index) codeCell.setAttribute('id', id) @@ -141,10 +149,25 @@ function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } +/** + * Removes excluded text from a Node. + * + * @param {Node} target Node to filter. + * @param {string} exclude CSS selector of nodes to exclude. + * @returns {DOMString} Text from `target` with text removed. + */ +function filterText(target, exclude) { + const clone = target.cloneNode(true); // clone as to not modify the live DOM + if (exclude) { + // remove excluded nodes + clone.querySelectorAll(exclude).forEach(node => node.remove()); + } + return clone.innerText; +} + // Callback when a copy button is clicked. Will be passed the node that was clicked // should then grab the text and replace pieces of text that shouldn't be used in output function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") { - var regexp; var match; @@ -199,7 +222,12 @@ function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onl var copyTargetText = (trigger) => { var target = document.querySelector(trigger.attributes['data-clipboard-target'].value); - return formatCopyText(target.innerText, '>>> |\\.\\.\\. |\\$ |In \\[\\d*\\]: | {2,5}\\.\\.\\.: | {5,8}: ', true, true, true, true, '', '') + + // get filtered text + let exclude = '.linenos, .gp'; + + let text = filterText(target, exclude); + return formatCopyText(text, '>>> |\\.\\.\\. |\\$ |In \\[\\d*\\]: | {2,5}\\.\\.\\.: | {5,8}: ', true, true, true, true, '', '') } // Initialize with a callback so we can modify the text before copy diff --git a/docs/_static/copybutton_funcs.js b/docs/_static/copybutton_funcs.js index b9168c55..dbe1aaad 100644 --- a/docs/_static/copybutton_funcs.js +++ b/docs/_static/copybutton_funcs.js @@ -2,10 +2,25 @@ function escapeRegExp(string) { return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string } +/** + * Removes excluded text from a Node. + * + * @param {Node} target Node to filter. + * @param {string} exclude CSS selector of nodes to exclude. + * @returns {DOMString} Text from `target` with text removed. + */ +export function filterText(target, exclude) { + const clone = target.cloneNode(true); // clone as to not modify the live DOM + if (exclude) { + // remove excluded nodes + clone.querySelectorAll(exclude).forEach(node => node.remove()); + } + return clone.innerText; +} + // Callback when a copy button is clicked. Will be passed the node that was clicked // should then grab the text and replace pieces of text that shouldn't be used in output export function formatCopyText(textContent, copybuttonPromptText, isRegexp = false, onlyCopyPromptLines = true, removePrompts = true, copyEmptyLines = true, lineContinuationChar = "", hereDocDelim = "") { - var regexp; var match; diff --git a/docs/_static/documentation_options.js b/docs/_static/documentation_options.js index 0d1bbd87..4d8441a2 100644 --- a/docs/_static/documentation_options.js +++ b/docs/_static/documentation_options.js @@ -1,6 +1,6 @@ var DOCUMENTATION_OPTIONS = { URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'), - VERSION: '1.0.8', + VERSION: '1.1.0rc1', LANGUAGE: 'None', COLLAPSE_INDEX: false, BUILDER: 'html', diff --git a/docs/api.html b/docs/api.html index 22bc1344..e27cf55a 100644 --- a/docs/api.html +++ b/docs/api.html @@ -6,7 +6,7 @@ - API Reference — CmdStanPy 1.0.8 documentation + API Reference — CmdStanPy 1.1.0rc1 documentation @@ -59,7 +59,7 @@ @@ -314,23 +314,23 @@

CmdStanModel
Parameters
    -
  • model_name (Optional[str]) – Model name, used for output file names. +

  • model_name (Optional[str]) – Model name, used for output file names. Optional, default is the base filename of the Stan program file.

  • -
  • stan_file (Optional[Union[str, os.PathLike]]) – Path to Stan program file.

  • -
  • exe_file (Optional[Union[str, os.PathLike]]) – Path to compiled executable file. Optional, unless +

  • stan_file (Optional[Union[str, os.PathLike]]) – Path to Stan program file.

  • +
  • exe_file (Optional[Union[str, os.PathLike]]) – Path to compiled executable file. Optional, unless no Stan program file is specified. If both the program file and the compiled executable file are specified, the base filenames must match, (but different directory locations are allowed).

  • -
  • compile (Union[bool, str]) – Whether or not to compile the model. Default is True. +

  • compile (Union[bool, str]) – Whether or not to compile the model. Default is True. If set to the string "force", it will always compile even if an existing executable is found.

  • -
  • stanc_options (Optional[Dict[str, Any]]) – Options for stanc compiler, specified as a Python +

  • stanc_options (Optional[Dict[str, Any]]) – Options for stanc compiler, specified as a Python dictionary containing Stanc3 compiler option name, value pairs. Optional.

  • -
  • cpp_options (Optional[Dict[str, Any]]) – Options for C++ compiler, specified as a Python +

  • cpp_options (Optional[Dict[str, Any]]) – Options for C++ compiler, specified as a Python dictionary containing C++ compiler option name, value pairs. Optional.

  • -
  • user_header (Optional[Union[str, os.PathLike]]) – A path to a header file to include during C++ +

  • user_header (Optional[Union[str, os.PathLike]]) – A path to a header file to include during C++ compilation. Optional.

@@ -345,7 +345,7 @@

CmdStanModel
Return type
-

Optional[str]

+

Optional[str]

@@ -362,15 +362,15 @@

CmdStanModel
Parameters
    -
  • force (bool) – When True, always compile, even if the executable file +

  • force (bool) – When True, always compile, even if the executable file is newer than the source file. Used for Stan models which have #include directives in order to force recompilation when changes are made to the included files.

  • -
  • stanc_options (Optional[Dict[str, Any]]) – Options for stanc compiler.

  • -
  • cpp_options (Optional[Dict[str, Any]]) – Options for C++ compiler.

  • -
  • user_header (Optional[Union[str, os.PathLike]]) – A path to a header file to include during C++ +

  • stanc_options (Optional[Dict[str, Any]]) – Options for stanc compiler.

  • +
  • cpp_options (Optional[Dict[str, Any]]) – Options for C++ compiler.

  • +
  • user_header (Optional[Union[str, os.PathLike]]) – A path to a header file to include during C++ compilation.

  • -
  • override_options (bool) – When True, override existing option. +

  • override_options (bool) – When True, override existing option. When False, add/replace existing options. Default is False.

@@ -389,7 +389,7 @@

CmdStanModel
Return type
-

Dict[str, str]

+

Dict[str, str]

@@ -402,15 +402,15 @@

CmdStanModel
Parameters
    -
  • overwrite_file (bool) – If True, save the updated code to disk, rather +

  • overwrite_file (bool) – If True, save the updated code to disk, rather than printing it. By default False

  • -
  • canonicalize (Union[bool, str, Iterable[str]]) – Whether or not the compiler should ‘canonicalize’ +

  • canonicalize (Union[bool, str, Iterable[str]]) – Whether or not the compiler should ‘canonicalize’ the Stan model, removing things like deprecated syntax. Default is False. If True, all canonicalizations are run. If it is a list of strings, those options are passed to stanc (new in Stan 2.29)

  • -
  • max_line_length (int) – Set the wrapping point for the formatter. The +

  • max_line_length (int) – Set the wrapping point for the formatter. The default value is 78, which wraps most lines by the 80th character.

  • -
  • backup (bool) – If True, create a stanfile.bak backup before +

  • backup (bool) – If True, create a stanfile.bak backup before writing to the file. Only disable this if you’re sure you have other copies of the file or are using a version control system like Git.

@@ -423,12 +423,14 @@

CmdStanModel
-generate_quantities(data=None, mcmc_sample=None, seed=None, gq_output_dir=None, sig_figs=None, show_console=False, refresh=None, time_fmt='%Y%m%d%H%M%S', timeout=None)[source]#
+generate_quantities(data=None, previous_fit=None, seed=None, gq_output_dir=None, sig_figs=None, show_console=False, refresh=None, time_fmt='%Y%m%d%H%M%S', timeout=None, *, mcmc_sample=None)[source]#

Run CmdStan’s generate_quantities method which runs the generated quantities block of a model given an existing sample.

-

This function takes a CmdStanMCMC object and the dataset used -to generate that sample and calls to the CmdStan generate_quantities -method to generate additional quantities of interest.

+

This function takes one of the Stan fit objects +CmdStanMCMC, CmdStanMLE, or CmdStanVB +and the data required for the model and calls to the CmdStan +generate_quantities method to generate additional quantities of +interest.

The CmdStanGQ object records the command, the return code, and the paths to the generate method output CSV and console files. The output files are written either to a specified output directory @@ -443,42 +445,80 @@

CmdStanModel
Parameters
    -
  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified +

  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified either as a dictionary with entries matching the data variables, or as the path of a data file in JSON or Rdump format.

  • -
  • mcmc_sample (Optional[Union[cmdstanpy.stanfit.mcmc.CmdStanMCMC, List[str]]]) – Can be either a CmdStanMCMC object returned -by the sample() method or a list of stan-csv files generated -by fitting the model to the data using any Stan interface.

  • -
  • seed (Optional[int]) – The seed for random number generator. Must be an integer +

  • previous_fit (Optional[Union[cmdstanpy.model.Fit, List[str]]]) – Can be either a CmdStanMCMC, +CmdStanMLE, or CmdStanVB or a list of +stan-csv files generated by fitting the model to the data +using any Stan interface.

  • +
  • seed (Optional[int]) – The seed for random number generator. Must be an integer between 0 and 2^32 - 1. If unspecified, -numpy.random.RandomState +numpy.random.RandomState is used to generate a seed which will be used for all chains. NOTE: Specifying the seed will guarantee the same result for multiple invocations of this method with the same inputs. However this will not reproduce results from the sample method given the same inputs because the RNG will be in a different state.

  • -
  • gq_output_dir (Optional[Union[str, os.PathLike]]) – Name of the directory in which the CmdStan output +

  • gq_output_dir (Optional[Union[str, os.PathLike]]) – Name of the directory in which the CmdStan output files are saved. If unspecified, files will be written to a temporary directory which is deleted upon session exit.

  • -
  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. +

  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. Must be an integer between 1 and 18. If unspecified, the default precision for the system file I/O is used; the usual value is 6. Introduced in CmdStan-2.25.

  • -
  • show_console (bool) – If True, stream CmdStan messages sent to +

  • show_console (bool) – If True, stream CmdStan messages sent to stdout and stderr to the console. Default is False.

  • -
  • refresh (Optional[int]) – Specify the number of iterations CmdStan will take +

  • refresh (Optional[int]) – Specify the number of iterations CmdStan will take between progress messages. Default value is 100.

  • -
  • time_fmt (str) – A format string passed to -strftime() to decide the file names for +

  • time_fmt (str) – A format string passed to +strftime() to decide the file names for output CSVs. Defaults to “%Y%m%d%H%M%S”

  • -
  • timeout (Optional[float]) – Duration at which generation times out in seconds.

  • +
  • timeout (Optional[float]) – Duration at which generation times out in seconds.

  • +
  • mcmc_sample (Optional[Union[cmdstanpy.stanfit.mcmc.CmdStanMCMC, List[str]]]) –

Returns

CmdStanGQ object

Return type
-

cmdstanpy.stanfit.gq.CmdStanGQ

+

cmdstanpy.stanfit.gq.CmdStanGQ[cmdstanpy.model.Fit]

+
+ +

+ +
+
+log_prob(params, data=None)[source]#
+

Calculate the log probability and gradient at the given parameter +values.

+
+

Note

+

This function is NOT an efficient way to evaluate the log +density of the model. It should be used for diagnostics ONLY. +Please, do not use this for other purposes such as testing new +sampling algorithms!

+
+
+
Parameters
+
    +
  • params (Union[Dict[str, Any], str, os.PathLike]) –

    Values for all parameters in the model, specified +either as a dictionary with entries matching the parameter +variables, or as the path of a data file in JSON or Rdump format.

    +

    These should be given on the constrained (natural) scale.

    +

  • +
  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified +either as a dictionary with entries matching the data variables, +or as the path of a data file in JSON or Rdump format.

  • +
+
+
Returns
+

A pandas.DataFrame containing columns “lp_” and additional +columns for the gradient values. These gradients will be for the +unconstrained parameters of the model.

+
+
Return type
+

pandas.core.frame.DataFrame

@@ -507,13 +547,13 @@

CmdStanModel
Parameters
    -
  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified +

  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified either as a dictionary with entries matching the data variables, or as the path of a data file in JSON or Rdump format.

  • -
  • seed (Optional[int]) – The seed for random number generator. Must be an integer +

  • seed (Optional[int]) – The seed for random number generator. Must be an integer between 0 and 2^32 - 1. If unspecified, -numpy.random.RandomState is used to generate a seed.

  • -
  • inits (Optional[Union[Dict[str, float], float, str, os.PathLike]]) –

    Specifies how the sampler initializes parameter values. +numpy.random.RandomState is used to generate a seed.

  • +
  • inits (Optional[Union[Dict[str, float], float, str, os.PathLike]]) –

    Specifies how the sampler initializes parameter values. Initialization is either uniform random on a range centered on 0, exactly 0, or a dictionary or file of initial values for some or all parameters in the model. The default initialization behavior @@ -528,43 +568,43 @@

    CmdStanModelOptional[Union[str, os.PathLike]]) – Name of the directory to which CmdStan output +
  • output_dir (Optional[Union[str, os.PathLike]]) – Name of the directory to which CmdStan output files are written. If unspecified, output files will be written to a temporary directory which is deleted upon session exit.

  • -
  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. +

  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. Must be an integer between 1 and 18. If unspecified, the default precision for the system file I/O is used; the usual value is 6. Introduced in CmdStan-2.25.

  • -
  • save_profile (bool) – Whether or not to profile auto-diff operations in +

  • save_profile (bool) – Whether or not to profile auto-diff operations in labelled blocks of code. If True, CSV outputs are written to file ‘<model_name>-<YYYYMMDDHHMM>-profile-<chain_id>’. Introduced in CmdStan-2.26.

  • -
  • algorithm (Optional[str]) – Algorithm to use. One of: ‘BFGS’, ‘LBFGS’, ‘Newton’

  • -
  • init_alpha (Optional[float]) – Line search step size for first iteration

  • -
  • tol_obj (Optional[float]) – Convergence tolerance on changes in objective +

  • algorithm (Optional[str]) – Algorithm to use. One of: ‘BFGS’, ‘LBFGS’, ‘Newton’

  • +
  • init_alpha (Optional[float]) – Line search step size for first iteration

  • +
  • tol_obj (Optional[float]) – Convergence tolerance on changes in objective function value

  • -
  • tol_rel_obj (Optional[float]) – Convergence tolerance on relative changes +

  • tol_rel_obj (Optional[float]) – Convergence tolerance on relative changes in objective function value

  • -
  • tol_grad (Optional[float]) – Convergence tolerance on the norm of the gradient

  • -
  • tol_rel_grad (Optional[float]) – Convergence tolerance on the relative +

  • tol_grad (Optional[float]) – Convergence tolerance on the norm of the gradient

  • +
  • tol_rel_grad (Optional[float]) – Convergence tolerance on the relative norm of the gradient

  • -
  • tol_param (Optional[float]) – Convergence tolerance on changes in parameter value

  • -
  • history_size (Optional[int]) – Size of the history for LBFGS Hessian +

  • tol_param (Optional[float]) – Convergence tolerance on changes in parameter value

  • +
  • history_size (Optional[int]) – Size of the history for LBFGS Hessian approximation. The value should be less than the dimensionality of the parameter space. 5-10 usually sufficient

  • -
  • iter (Optional[int]) – Total number of iterations

  • -
  • save_iterations (bool) – When True, save intermediate approximations +

  • iter (Optional[int]) – Total number of iterations

  • +
  • save_iterations (bool) – When True, save intermediate approximations to the output CSV file. Default is False.

  • -
  • require_converged (bool) – Whether or not to raise an error if Stan +

  • require_converged (bool) – Whether or not to raise an error if Stan reports that “The algorithm may not have converged”.

  • -
  • show_console (bool) – If True, stream CmdStan messages sent to +

  • show_console (bool) – If True, stream CmdStan messages sent to stdout and stderr to the console. Default is False.

  • -
  • refresh (Optional[int]) – Specify the number of iterations cmdstan will take +

  • refresh (Optional[int]) – Specify the number of iterations cmdstan will take between progress messages. Default value is 100.

  • -
  • time_fmt (str) – A format string passed to -strftime() to decide the file names for +

  • time_fmt (str) – A format string passed to +strftime() to decide the file names for output CSVs. Defaults to “%Y%m%d%H%M%S”

  • -
  • timeout (Optional[float]) – Duration at which optimization times out in seconds.

  • +
  • timeout (Optional[float]) – Duration at which optimization times out in seconds.

Returns
@@ -601,17 +641,17 @@

CmdStanModel
Parameters
    -
  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified +

  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified either as a dictionary with entries matching the data variables, or as the path of a data file in JSON or Rdump format.

  • -
  • chains (Optional[int]) – Number of sampler chains, must be a positive integer.

  • -
  • parallel_chains (Optional[int]) – Number of processes to run in parallel. Must be -a positive integer. Defaults to multiprocessing.cpu_count(), +

  • chains (Optional[int]) – Number of sampler chains, must be a positive integer.

  • +
  • parallel_chains (Optional[int]) – Number of processes to run in parallel. Must be +a positive integer. Defaults to multiprocessing.cpu_count(), i.e., it will only run as many chains in parallel as there are cores on the machine. Note that CmdStan 2.28 and higher can run all chains in parallel providing that the model was compiled with threading support.

  • -
  • threads_per_chain (Optional[int]) – The number of threads to use in parallelized +

  • threads_per_chain (Optional[int]) – The number of threads to use in parallelized sections within an MCMC chain (e.g., when using the Stan functions reduce_sum() or map_rect()). This will only have an effect if the model was compiled with threading support. For such models, @@ -619,16 +659,16 @@

    CmdStanModelparallel_chains * threads_per_chain, where the default value for parallel_chains is the number of cpus, not chains.

  • -
  • seed (Optional[Union[int, List[int]]]) – The seed for random number generator. Must be an integer +

  • seed (Optional[Union[int, List[int]]]) – The seed for random number generator. Must be an integer between 0 and 2^32 - 1. If unspecified, -numpy.random.RandomState +numpy.random.RandomState is used to generate a seed which will be used for all chains. When the same seed is used across all chains, the chain-id is used to advance the RNG to avoid dependent samples.

  • -
  • chain_ids (Optional[Union[int, List[int]]]) – The offset for the random number generator, either +

  • chain_ids (Optional[Union[int, List[int]]]) – The offset for the random number generator, either an integer or a list of unique per-chain offsets. If unspecified, chain ids are numbered sequentially starting from 1.

  • -
  • inits (Optional[Union[Dict[str, float], float, str, List[str]]]) –

    Specifies how the sampler initializes parameter values. +

  • inits (Optional[Union[Dict[str, float], float, str, List[str]]]) –

    Specifies how the sampler initializes parameter values. Initialization is either uniform random on a range centered on 0, exactly 0, or a dictionary or file of initial values for some or all parameters in the model. The default initialization behavior will @@ -644,16 +684,16 @@

    CmdStanModelOptional[int]) – Number of warmup iterations for each chain.

  • -
  • iter_sampling (Optional[int]) – Number of draws from the posterior for each +

  • iter_warmup (Optional[int]) – Number of warmup iterations for each chain.

  • +
  • iter_sampling (Optional[int]) – Number of draws from the posterior for each chain.

  • -
  • save_warmup (bool) – When True, sampler saves warmup draws as part of +

  • save_warmup (bool) – When True, sampler saves warmup draws as part of the Stan CSV output file.

  • -
  • thin (Optional[int]) – Period between recorded iterations. Default is 1, i.e., +

  • thin (Optional[int]) – Period between recorded iterations. Default is 1, i.e., all iterations are recorded.

  • -
  • max_treedepth (Optional[int]) – Maximum depth of trees evaluated by NUTS sampler +

  • max_treedepth (Optional[int]) – Maximum depth of trees evaluated by NUTS sampler per iteration.

  • -
  • metric (Optional[Union[str, Dict[str, Any], List[str], List[Dict[str, Any]]]]) –

    Specification of the mass matrix, either as a +

  • metric (Optional[Union[str, Dict[str, Any], List[str], List[Dict[str, Any]]]]) –

    Specification of the mass matrix, either as a vector consisting of the diagonal elements of the covariance matrix (‘diag’ or ‘diag_e’) or the full covariance matrix (‘dense’ or ‘dense_e’).

    @@ -673,28 +713,28 @@

    CmdStanModelOptional[Union[float, List[float]]]) – Initial step size for HMC sampler. The value is +
  • step_size (Optional[Union[float, List[float]]]) – Initial step size for HMC sampler. The value is either a single number or a list of numbers which will be used as the global or per-chain initial step size, respectively. The length of the list of step sizes must match the number of chains.

  • -
  • adapt_engaged (bool) – When True, adapt step size and metric.

  • -
  • adapt_delta (Optional[float]) – Adaptation target Metropolis acceptance rate. +

  • adapt_engaged (bool) – When True, adapt step size and metric.

  • +
  • adapt_delta (Optional[float]) – Adaptation target Metropolis acceptance rate. The default value is 0.8. Increasing this value, which must be strictly less than 1, causes adaptation to use smaller step sizes which improves the effective sample size, but may increase the time per iteration.

  • -
  • adapt_init_phase (Optional[int]) – Iterations for initial phase of adaptation +

  • adapt_init_phase (Optional[int]) – Iterations for initial phase of adaptation during which step size is adjusted so that the chain converges towards the typical set.

  • -
  • adapt_metric_window (Optional[int]) – The second phase of adaptation tunes +

  • adapt_metric_window (Optional[int]) – The second phase of adaptation tunes the metric and step size in a series of intervals. This parameter specifies the number of iterations used for the first tuning interval; window size increases for each subsequent interval.

  • -
  • adapt_step_size (Optional[int]) – Number of iterations given over to adjusting +

  • adapt_step_size (Optional[int]) – Number of iterations given over to adjusting the step size given the tuned metric during the final phase of adaptation.

  • -
  • fixed_param (bool) – When True, call CmdStan with argument +

  • fixed_param (bool) – When True, call CmdStan with argument algorithm=fixed_param which runs the sampler without updating the Markov Chain, thus the values of all parameters and transformed parameters are constant across all draws and @@ -703,37 +743,37 @@

    CmdStanModelFalse.

  • -
  • output_dir (Optional[Union[str, os.PathLike]]) – Name of the directory to which CmdStan output +

  • output_dir (Optional[Union[str, os.PathLike]]) – Name of the directory to which CmdStan output files are written. If unspecified, output files will be written to a temporary directory which is deleted upon session exit.

  • -
  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. +

  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. Must be an integer between 1 and 18. If unspecified, the default precision for the system file I/O is used; the usual value is 6. Introduced in CmdStan-2.25.

  • -
  • save_latent_dynamics (bool) – Whether or not to output the position and +

  • save_latent_dynamics (bool) – Whether or not to output the position and momentum information for the model parameters (unconstrained). If True, CSV outputs are written to an output file ‘<model_name>-<YYYYMMDDHHMM>-diagnostic-<chain_id>’, e.g. ‘bernoulli-201912081451-diagnostic-1.csv’, see https://mc-stan.org/docs/cmdstan-guide/stan-csv.html, section “Diagnostic CSV output file” for details.

  • -
  • save_profile (bool) – Whether or not to profile auto-diff operations in +

  • save_profile (bool) – Whether or not to profile auto-diff operations in labelled blocks of code. If True, CSV outputs are written to file ‘<model_name>-<YYYYMMDDHHMM>-profile-<chain_id>’. Introduced in CmdStan-2.26, see https://mc-stan.org/docs/cmdstan-guide/stan-csv.html, section “Profiling CSV output file” for details.

  • -
  • show_progress (bool) – If True, display progress bar to track +

  • show_progress (bool) – If True, display progress bar to track progress for warmup and sampling iterations. Default is True, unless package tqdm progress bar encounter errors.

  • -
  • show_console (bool) – If True, stream CmdStan messages sent to stdout +

  • show_console (bool) – If True, stream CmdStan messages sent to stdout and stderr to the console. Default is False.

  • -
  • refresh (Optional[int]) – Specify the number of iterations CmdStan will take +

  • refresh (Optional[int]) – Specify the number of iterations CmdStan will take between progress messages. Default value is 100.

  • -
  • time_fmt (str) – A format string passed to -strftime() to decide the file names for +

  • time_fmt (str) – A format string passed to +strftime() to decide the file names for output CSVs. Defaults to “%Y%m%d%H%M%S”

  • -
  • force_one_process_per_chain (Optional[bool]) –

    If True, run multiple chains in +

  • force_one_process_per_chain (Optional[bool]) –

    If True, run multiple chains in distinct processes regardless of model ability to run parallel chains (CmdStan 2.28+ feature). If False, always run multiple chains in one process (does not check that this is valid).

    @@ -741,7 +781,7 @@

    CmdStanModelOptional[float]) – Duration at which sampling times out in seconds.

  • +
  • timeout (Optional[float]) – Duration at which sampling times out in seconds.

Returns
@@ -761,7 +801,7 @@

CmdStanModel
Return type
-

Dict[str, Any]

+

Dict[str, Any]

@@ -790,54 +830,54 @@

CmdStanModel
Parameters
    -
  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified +

  • data (Optional[Union[Mapping[str, Any], str, os.PathLike]]) – Values for all data variables in the model, specified either as a dictionary with entries matching the data variables, or as the path of a data file in JSON or Rdump format.

  • -
  • seed (Optional[int]) – The seed for random number generator. Must be an integer +

  • seed (Optional[int]) – The seed for random number generator. Must be an integer between 0 and 2^32 - 1. If unspecified, -numpy.random.RandomState +numpy.random.RandomState is used to generate a seed which will be used for all chains.

  • -
  • inits (Optional[float]) – Specifies how the sampler initializes parameter values. +

  • inits (Optional[float]) – Specifies how the sampler initializes parameter values. Initialization is uniform random on a range centered on 0 with default range of 2. Specifying a single number n > 0 changes the initialization range to [-n, n].

  • -
  • output_dir (Optional[Union[str, os.PathLike]]) – Name of the directory to which CmdStan output +

  • output_dir (Optional[Union[str, os.PathLike]]) – Name of the directory to which CmdStan output files are written. If unspecified, output files will be written to a temporary directory which is deleted upon session exit.

  • -
  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. +

  • sig_figs (Optional[int]) – Numerical precision used for output CSV and text files. Must be an integer between 1 and 18. If unspecified, the default precision for the system file I/O is used; the usual value is 6. Introduced in CmdStan-2.25.

  • -
  • save_latent_dynamics (bool) – Whether or not to save diagnostics. +

  • save_latent_dynamics (bool) – Whether or not to save diagnostics. If True, CSV outputs are written to output file ‘<model_name>-<YYYYMMDDHHMM>-diagnostic-<chain_id>’, e.g. ‘bernoulli-201912081451-diagnostic-1.csv’.

  • -
  • save_profile (bool) – Whether or not to profile auto-diff operations in +

  • save_profile (bool) – Whether or not to profile auto-diff operations in labelled blocks of code. If True, CSV outputs are written to file ‘<model_name>-<YYYYMMDDHHMM>-profile-<chain_id>’. Introduced in CmdStan-2.26.

  • -
  • algorithm (Optional[str]) – Algorithm to use. One of: ‘meanfield’, ‘fullrank’.

  • -
  • iter (Optional[int]) – Maximum number of ADVI iterations.

  • -
  • grad_samples (Optional[int]) – Number of MC draws for computing the gradient. +

  • algorithm (Optional[str]) – Algorithm to use. One of: ‘meanfield’, ‘fullrank’.

  • +
  • iter (Optional[int]) – Maximum number of ADVI iterations.

  • +
  • grad_samples (Optional[int]) – Number of MC draws for computing the gradient. Default is 10. If problems arise, try doubling current value.

  • -
  • elbo_samples (Optional[int]) – Number of MC draws for estimate of ELBO.

  • -
  • eta (Optional[float]) – Step size scaling parameter.

  • -
  • adapt_engaged (bool) – Whether eta adaptation is engaged.

  • -
  • adapt_iter (Optional[int]) – Number of iterations for eta adaptation.

  • -
  • tol_rel_obj (Optional[float]) – Relative tolerance parameter for convergence.

  • -
  • eval_elbo (Optional[int]) – Number of iterations between ELBO evaluations.

  • -
  • output_samples (Optional[int]) – Number of approximate posterior output draws +

  • elbo_samples (Optional[int]) – Number of MC draws for estimate of ELBO.

  • +
  • eta (Optional[float]) – Step size scaling parameter.

  • +
  • adapt_engaged (bool) – Whether eta adaptation is engaged.

  • +
  • adapt_iter (Optional[int]) – Number of iterations for eta adaptation.

  • +
  • tol_rel_obj (Optional[float]) – Relative tolerance parameter for convergence.

  • +
  • eval_elbo (Optional[int]) – Number of iterations between ELBO evaluations.

  • +
  • output_samples (Optional[int]) – Number of approximate posterior output draws to save.

  • -
  • require_converged (bool) – Whether or not to raise an error if Stan +

  • require_converged (bool) – Whether or not to raise an error if Stan reports that “The algorithm may not have converged”.

  • -
  • show_console (bool) – If True, stream CmdStan messages sent to +

  • show_console (bool) – If True, stream CmdStan messages sent to stdout and stderr to the console. Default is False.

  • -
  • refresh (Optional[int]) – Specify the number of iterations CmdStan will take +

  • refresh (Optional[int]) – Specify the number of iterations CmdStan will take between progress messages. Default value is 100.

  • -
  • time_fmt (str) – A format string passed to -strftime() to decide the file names for +

  • time_fmt (str) – A format string passed to +strftime() to decide the file names for output CSVs. Defaults to “%Y%m%d%H%M%S”

  • -
  • timeout (Optional[float]) – Duration at which variational Bayesian inference times +

  • timeout (Optional[float]) – Duration at which variational Bayesian inference times out in seconds.

@@ -852,19 +892,19 @@

CmdStanModel
-property cpp_options: Dict[str, Union[bool, int]]#
+property cpp_options: Dict[str, Union[bool, int]]#

Options to C++ compilers.

-property exe_file: Optional[Union[str, os.PathLike]]#
+property exe_file: Optional[Union[str, os.PathLike]]#

Full path to Stan exe file.

-property name: str#
+property name: str#

Model name used in output filename templates. Default is basename of Stan program or exe file, unless specified in call to constructor via argument model_name.

@@ -872,19 +912,19 @@

CmdStanModel
-property stan_file: Optional[Union[str, os.PathLike]]#
+property stan_file: Optional[Union[str, os.PathLike]]#

Full path to Stan program file.

-property stanc_options: Dict[str, Union[bool, int, str]]#
+property stanc_options: Dict[str, Union[bool, int, str]]#

Options to stanc compilers.

-property user_header: str#
+property user_header: str#

The user header file if it exists, otherwise empty

@@ -927,7 +967,7 @@

CmdStanMCMC
Return type
-

Optional[str]

+

Optional[str]

@@ -946,15 +986,15 @@

CmdStanMCMC
Parameters
    -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • inc_warmup (bool) – When True and the warmup draws are present in the output, i.e., the sampler was run with save_warmup=True, then the warmup draws are included. Default value is False.

  • -
  • concat_chains (bool) – When True return a 2D array flattening all +

  • concat_chains (bool) – When True return a 2D array flattening all all draws from all chains. Default value is False.

Return type
-

numpy.ndarray

+

numpy.ndarray

@@ -974,14 +1014,14 @@

CmdStanMCMC
Parameters
    -
  • vars (Optional[Union[List[str], str]]) – optional list of variable names.

  • -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • vars (Optional[Union[List[str], str]]) – optional list of variable names.

  • +
  • inc_warmup (bool) – When True and the warmup draws are present in the output, i.e., the sampler was run with save_warmup=True, then the warmup draws are included. Default value is False.

Return type
-

pandas.core.frame.DataFrame

+

pandas.core.frame.DataFrame

@@ -997,14 +1037,14 @@

CmdStanMCMC
Parameters
    -
  • vars (Optional[Union[List[str], str]]) – optional list of variable names.

  • -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • vars (Optional[Union[List[str], str]]) – optional list of variable names.

  • +
  • inc_warmup (bool) – When True and the warmup draws are present in the output, i.e., the sampler was run with save_warmup=True, then the warmup draws are included. Default value is False.

Return type
-

xarray.core.dataset.Dataset

+

xarray.core.dataset.Dataset

@@ -1023,7 +1063,7 @@

CmdStanMCMC
Return type
-

Dict[str, numpy.ndarray]

+

Dict[str, numpy.ndarray]

@@ -1037,7 +1077,7 @@

CmdStanMCMC
Parameters
-

dir (Optional[str]) – directory path

+

dir (Optional[str]) – directory path

Return type

None

@@ -1079,14 +1119,14 @@

CmdStanMCMC
Parameters
    -
  • var (str) – variable name

  • -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • var (str) – variable name

  • +
  • inc_warmup (bool) – When True and the warmup draws are present in the output, i.e., the sampler was run with save_warmup=True, then the warmup draws are included. Default value is False.

Return type
-

numpy.ndarray

+

numpy.ndarray

@@ -1106,7 +1146,7 @@

CmdStanMCMC
Return type
-

Dict[str, numpy.ndarray]

+

Dict[str, numpy.ndarray]

@@ -1123,10 +1163,10 @@

CmdStanMCMC
Parameters
    -
  • percentiles (Sequence[int]) – Ordered non-empty sequence of percentiles to report. +

  • percentiles (Sequence[int]) – Ordered non-empty sequence of percentiles to report. Must be integers from (1, 99), inclusive. Defaults to (5, 50, 95)

  • -
  • sig_figs (int) – Number of significant figures to report. +

  • sig_figs (int) – Number of significant figures to report. Must be an integer between 1 and 18. If unspecified, the default precision for the system file I/O is used; the usual value is 6. If precision above 6 is requested, sample must have been produced @@ -1138,26 +1178,26 @@

    CmdStanMCMC

    pandas.DataFrame

Return type
-

pandas.core.frame.DataFrame

+

pandas.core.frame.DataFrame

-property chain_ids: List[int]#
+property chain_ids: List[int]#

Chain ids.

-property chains: int#
+property chains: int#

Number of chains.

-property column_names: Tuple[str, ...]#
+property column_names: Tuple[str, ...]#

Names of all outputs from the sampler, comprising sampler parameters and all components of all model parameters, transformed parameters, and quantities of interest. Corresponds to Stan CSV file header row, @@ -1166,14 +1206,14 @@

CmdStanMCMC
-property divergences: Optional[numpy.ndarray]#
+property divergences: Optional[numpy.ndarray]#

Per-chain total number of post-warmup divergent iterations. When sampler algorithm ‘fixed_param’ is specified, returns None.

-property max_treedepths: Optional[numpy.ndarray]#
+property max_treedepths: Optional[numpy.ndarray]#

Per-chain total number of post-warmup iterations where the NUTS sampler reached the maximum allowed treedepth. When sampler algorithm ‘fixed_param’ is specified, returns None.

@@ -1189,14 +1229,14 @@

CmdStanMCMC
-property metric: Optional[numpy.ndarray]#
+property metric: Optional[numpy.ndarray]#

Metric used by sampler for each chain. When sampler algorithm ‘fixed_param’ is specified, metric is None.

-property metric_type: Optional[str]#
+property metric_type: Optional[str]#

Metric type used for adaptation, either ‘diag_e’ or ‘dense_e’, according to CmdStan arg ‘metric’. When sampler algorithm ‘fixed_param’ is specified, metric_type is None.

@@ -1204,27 +1244,27 @@

CmdStanMCMC
-property num_draws_sampling: int#
+property num_draws_sampling: int#

Number of sampling (post-warmup) draws per chain, i.e., thinned sampling iterations.

-property num_draws_warmup: int#
+property num_draws_warmup: int#

Number of warmup draws per chain, i.e., thinned warmup iterations.

-property step_size: Optional[numpy.ndarray]#
+property step_size: Optional[numpy.ndarray]#

Step size used by sampler for each chain. When sampler algorithm ‘fixed_param’ is specified, step size is None.

-property thin: int#
+property thin: int#

Period between recorded iterations. (Default is 1).

@@ -1255,7 +1295,7 @@

CmdStanMLE
Parameters
-

dir (Optional[str]) – directory path

+

dir (Optional[str]) – directory path

Return type

None

@@ -1278,16 +1318,16 @@

CmdStanMLE
Parameters
    -
  • var (str) – variable name

  • -
  • inc_iterations (bool) – When True and the intermediate estimates +

  • var (str) – variable name

  • +
  • inc_iterations (bool) – When True and the intermediate estimates are included in the output, i.e., the optimizer was run with save_iterations=True, then intermediate estimates are included. Default value is False.

  • -
  • warn (bool) –

  • +
  • warn (bool) –

Return type
-

Union[numpy.ndarray, float]

+

Union[numpy.ndarray, float]

@@ -1303,13 +1343,13 @@

CmdStanMLE
Parameters
-

inc_iterations (bool) – When True and the intermediate estimates +

inc_iterations (bool) – When True and the intermediate estimates are included in the output, i.e., the optimizer was run with save_iterations=True, then intermediate estimates are included. Default value is False.

Return type
-

Dict[str, Union[numpy.ndarray, float]]

+

Dict[str, Union[numpy.ndarray, float]]

@@ -1320,7 +1360,7 @@

CmdStanMLE
-property column_names: Tuple[str, ...]#
+property column_names: Tuple[str, ...]#

Names of estimated quantities, includes joint log probability, and all parameters, transformed parameters, and generated quantities.

@@ -1335,7 +1375,7 @@

CmdStanMLE
-property optimized_iterations_np: Optional[numpy.ndarray]#
+property optimized_iterations_np: Optional[numpy.ndarray]#

Returns all saved iterations from the optimizer and final estimate as a numpy.ndarray which contains all optimizer outputs, i.e., the value for lp__ as well as all Stan program variables.

@@ -1343,7 +1383,7 @@

CmdStanMLE
-property optimized_iterations_pd: Optional[pandas.core.frame.DataFrame]#
+property optimized_iterations_pd: Optional[pandas.core.frame.DataFrame]#

Returns all saved iterations from the optimizer and final estimate as a pandas.DataFrame which contains all optimizer outputs, i.e., the value for lp__ as well as all Stan program variables.

@@ -1351,14 +1391,14 @@

CmdStanMLE
-property optimized_params_dict: Dict[str, float]#
+property optimized_params_dict: Dict[str, numpy.float64]#

Returns all estimates from the optimizer, including lp__ as a Python Dict. Only returns estimate from final iteration.

-property optimized_params_np: numpy.ndarray#
+property optimized_params_np: numpy.ndarray#

Returns all final estimates from the optimizer as a numpy.ndarray which contains all optimizer outputs, i.e., the value for lp__ as well as all Stan program variables.

@@ -1366,7 +1406,7 @@

CmdStanMLE
-property optimized_params_pd: pandas.core.frame.DataFrame#
+property optimized_params_pd: pandas.core.frame.DataFrame#

Returns all final estimates from the optimizer as a pandas.DataFrame which contains all optimizer outputs, i.e., the value for lp__ as well as all Stan program variables.

@@ -1379,14 +1419,14 @@

CmdStanMLE#

-class cmdstanpy.CmdStanGQ(runset, mcmc_sample)[source]#
+class cmdstanpy.CmdStanGQ(runset, previous_fit)[source]#

Container for outputs from CmdStan generate_quantities run. Created by CmdStanModel.generate_quantities().

Parameters
Return type
@@ -1408,18 +1448,18 @@

CmdStanGQ
Parameters
    -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • inc_warmup (bool) – When True and the warmup draws are present in the output, i.e., the sampler was run with save_warmup=True, then the warmup draws are included. Default value is False.

  • -
  • concat_chains (bool) – When True return a 2D array flattening all +

  • concat_chains (bool) – When True return a 2D array flattening all all draws from all chains. Default value is False.

  • -
  • inc_sample (bool) – When True include all columns in the mcmc_sample +

  • inc_sample (bool) – When True include all columns in the previous_fit draws array as well, excepting columns for variables already present in the generated quantities drawset. Default value is False.

Return type
-

numpy.ndarray

+

numpy.ndarray

@@ -1439,15 +1479,15 @@

CmdStanGQ
Parameters
    -
  • vars (Optional[Union[List[str], str]]) – optional list of variable names.

  • -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • vars (Optional[Union[List[str], str]]) – optional list of variable names.

  • +
  • inc_warmup (bool) – When True and the warmup draws are present in the output, i.e., the sampler was run with save_warmup=True, then the warmup draws are included. Default value is False.

  • -
  • inc_sample (bool) –

  • +
  • inc_sample (bool) –

Return type
-

pandas.core.frame.DataFrame

+

pandas.core.frame.DataFrame

@@ -1458,21 +1498,21 @@

CmdStanGQ
-draws_xr(vars=None, inc_warmup=False, inc_sample=False)[source]#
+draws_xr(vars: Optional[Union[str, List[str]]] = None, inc_warmup: bool = False, inc_sample: bool = False) NoReturn[source]# +
+draws_xr(vars: Optional[Union[str, List[str]]] = None, inc_warmup: bool = False, inc_sample: bool = False) xarray.core.dataset.Dataset

Returns the generated quantities draws as a xarray Dataset.

+

This method can only be called when the underlying fit was made +through sampling, it cannot be used on MLE or VB outputs.

Parameters
    -
  • vars (Optional[Union[List[str], str]]) – optional list of variable names.

  • -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • vars – optional list of variable names.

  • +
  • inc_warmup – When True and the warmup draws are present in the MCMC sample, then the warmup draws are included. Default value is False.

  • -
  • inc_sample (bool) –

-
Return type
-

xarray.core.dataset.Dataset

-

See also

@@ -1489,7 +1529,7 @@

CmdStanGQ
Parameters
-

dir (Optional[str]) – directory path

+

dir (Optional[str]) – directory path

Return type

None

@@ -1531,14 +1571,14 @@

CmdStanGQ
Parameters
    -
  • var (str) – variable name

  • -
  • inc_warmup (bool) – When True and the warmup draws are present in +

  • var (str) – variable name

  • +
  • inc_warmup (bool) – When True and the warmup draws are present in the MCMC sample, then the warmup draws are included. Default value is False.

Return type
-

numpy.ndarray

+

numpy.ndarray

@@ -1554,12 +1594,12 @@

CmdStanGQ
Parameters
-

inc_warmup (bool) – When True and the warmup draws are present in +

inc_warmup (bool) – When True and the warmup draws are present in the MCMC sample, then the warmup draws are included. Default value is False

Return type
-

Dict[str, numpy.ndarray]

+

Dict[str, numpy.ndarray]

@@ -1570,19 +1610,19 @@

CmdStanGQ
-property chain_ids: List[int]#
+property chain_ids: List[int]#

Chain ids.

-property chains: int#
+property chains: int#

Number of chains.

-property column_names: Tuple[str, ...]#
+property column_names: Tuple[str, ...]#

Names of generated quantities of interest.

@@ -1621,7 +1661,7 @@

CmdStanVB
Parameters
-

dir (Optional[str]) – directory path

+

dir (Optional[str]) – directory path

Return type

None

@@ -1643,10 +1683,10 @@

CmdStanVBfit.a is a synonym for fit.stan_variable("a")

Parameters
-

var (str) – variable name

+

var (str) – variable name

Return type
-

Union[numpy.ndarray, float]

+

Union[numpy.ndarray, float]

@@ -1666,14 +1706,14 @@

CmdStanVB
Return type
-

Dict[str, Union[numpy.ndarray, float]]

+

Dict[str, Union[numpy.ndarray, float]]

-property column_names: Tuple[str, ...]#
+property column_names: Tuple[str, ...]#

Names of information items returned by sampler for each draw. Includes approximation information and names of model parameters and computed quantities.

@@ -1681,7 +1721,7 @@

CmdStanVB
-property columns: int#
+property columns: int#

Total number of information items returned by sampler. Includes approximation information and names of model parameters and computed quantities.

@@ -1689,7 +1729,7 @@

CmdStanVB
-property eta: float#
+property eta: float#

Step size scaling parameter ‘eta’

@@ -1703,28 +1743,35 @@

CmdStanVB
-property variational_params_dict: Dict[str, numpy.ndarray]#
+property variational_params_dict: Dict[str, numpy.ndarray]#

Returns inferred parameter means as Dict.

-property variational_params_np: numpy.ndarray#
+property variational_params_np: numpy.ndarray#

Returns inferred parameter means as numpy array.

-property variational_params_pd: pandas.core.frame.DataFrame#
+property variational_params_pd: pandas.core.frame.DataFrame#

Returns inferred parameter means as pandas DataFrame.

-property variational_sample: numpy.ndarray#
+property variational_sample: numpy.ndarray#

Returns the set of approximate posterior output draws.

+
+
+property variational_sample_pd: pandas.core.frame.DataFrame#
+

Returns the set of approximate posterior output draws as +a pandas DataFrame.

+
+

@@ -1739,10 +1786,10 @@

show_versions
Parameters
-

output (bool) –

+

output (bool) –

Return type
-

str

+

str

@@ -1756,7 +1803,7 @@

cmdstan_path
Return type
-

str

+

str

@@ -1774,25 +1821,25 @@

install_cmdstan
Parameters
    -
  • version (Optional[str]) – CmdStan version string, e.g. “2.29.2”. +

  • version (Optional[str]) – CmdStan version string, e.g. “2.29.2”. Defaults to latest CmdStan release.

  • -
  • dir (Optional[str]) – Path to install directory. Defaults to hidden directory +

  • dir (Optional[str]) – Path to install directory. Defaults to hidden directory $HOME/.cmdstan. If no directory is specified and the above directory does not exist, directory $HOME/.cmdstan will be created and populated.

  • -
  • overwrite (bool) – Boolean value; when True, will overwrite and +

  • overwrite (bool) – Boolean value; when True, will overwrite and rebuild an existing CmdStan installation. Default is False.

  • -
  • compiler (bool) – Boolean value; when True on WINDOWS ONLY, use the +

  • compiler (bool) – Boolean value; when True on WINDOWS ONLY, use the C++ compiler from the install_cxx_toolchain command or install one if none is found.

  • -
  • progress (bool) – Boolean value; when True, show a progress bar for +

  • progress (bool) – Boolean value; when True, show a progress bar for downloading and unpacking CmdStan. Default is False.

  • -
  • verbose (bool) – Boolean value; when True, show console output from all +

  • verbose (bool) – Boolean value; when True, show console output from all intallation steps, i.e., download, build, and test CmdStan release. Default is False.

  • -
  • cores (int) – Integer, number of cores to use in the make command. +

  • cores (int) – Integer, number of cores to use in the make command. Default is 1 core.

  • -
  • interactive (bool) –

    Boolean value; if true, ignore all other arguments +

  • interactive (bool) –

    Boolean value; if true, ignore all other arguments to this function and run in an interactive mode, prompting the user to provide the other information manually through the standard input.

    This flag should only be used in interactive environments, @@ -1804,7 +1851,7 @@

    install_cmdstan

    Boolean value; True for success.

Return type
-

bool

+

bool

@@ -1818,7 +1865,7 @@

set_cmdstan_path
Parameters
-

path (str) –

+

path (str) –

Return type

None

@@ -1840,7 +1887,7 @@

cmdstan_versionhttps://github.com/stan-dev/cmdstanpy/pull/321#issuecomment-733817554

Return type
-

Optional[Tuple[int, …]]

+

Optional[Tuple[int, …]]

@@ -1854,7 +1901,7 @@

set_make_env
Parameters
-

make (str) –

+

make (str) –

Return type

None

@@ -1879,15 +1926,15 @@

from_csv
Parameters
Returns

either a CmdStanMCMC, CmdStanMLE, or CmdStanVB object

Return type
-

Optional[Union[cmdstanpy.stanfit.mcmc.CmdStanMCMC, cmdstanpy.stanfit.mle.CmdStanMLE, cmdstanpy.stanfit.vb.CmdStanVB]]

+

Optional[Union[cmdstanpy.stanfit.mcmc.CmdStanMCMC, cmdstanpy.stanfit.mle.CmdStanMLE, cmdstanpy.stanfit.vb.CmdStanVB]]

@@ -1900,17 +1947,17 @@

write_stan_jsoncmdstanpy.write_stan_json(path, data)[source]#

Dump a mapping of strings to data to a JSON file.

Values can be any numeric type, a boolean (converted to int), -or any collection compatible with numpy.asarray(), e.g a -pandas.Series.

+or any collection compatible with numpy.asarray(), e.g a +pandas.Series.

Produces a file compatible with the Json Format for Cmdstan

Parameters
    -
  • path (str) – File path for the created json. Will be overwritten if +

  • path (str) – File path for the created json. Will be overwritten if already in existence.

  • -
  • data (Mapping[str, Any]) – A mapping from strings to values. This can be a dictionary -or something more exotic like an xarray.Dataset. This will be +

  • data (Mapping[str, Any]) – A mapping from strings to values. This can be a dictionary +or something more exotic like an xarray.Dataset. This will be copied before type conversion, not modified

diff --git a/docs/changes.html b/docs/changes.html index da9dcfbe..f6d7da98 100644 --- a/docs/changes.html +++ b/docs/changes.html @@ -6,7 +6,7 @@ - What’s New — CmdStanPy 1.0.8 documentation + What’s New — CmdStanPy 1.1.0rc1 documentation @@ -59,7 +59,7 @@ @@ -167,6 +167,11 @@

@@ -625,7 +626,7 @@

Example: add posterior predictive checks to
-13:59:43 - cmdstanpy - INFO - CmdStan start processing
+14:17:36 - cmdstanpy - INFO - CmdStan start processing
 chain 1 |          | 00:00 Status
 chain 2 |          | 00:00 Status
 
@@ -652,7 +653,7 @@ 

Example: add posterior predictive checks to
 
-13:59:43 - cmdstanpy - INFO - CmdStan done processing.
+14:17:36 - cmdstanpy - INFO - CmdStan done processing.
 

@@ -709,27 +710,27 @@

Example: add posterior predictive checks to
-13:59:44 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc
-13:59:55 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc
+14:17:37 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc
+14:17:44 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc
 

@@ -781,12 +782,12 @@

Example: add posterior predictive checks to generate_quantities method on bernoulli_ppc using existing sample fit as input. The generate_quantities method takes the values of theta in the fit sample as the set of draws from the posterior used to generate the corresponsing y_rep quantities of interest.

-

The arguments to the generate_quantities method are: + data - the data used to fit the model + mcmc_sample - either a CmdStanMCMC object or a list of stan-csv files

+

The arguments to the generate_quantities method are: + data - the data used to fit the model + previous_fit - either a CmdStanMCMC, CmdStanVB, or CmdStanMLE object or a list of stan-csv files

[6]:
 
-
new_quantities = model_ppc.generate_quantities(data=data_file, mcmc_sample=fit)
+
new_quantities = model_ppc.generate_quantities(data=data_file, previous_fit=fit)
 
@@ -795,14 +796,14 @@

Example: add posterior predictive checks to
-13:59:55 - cmdstanpy - INFO - Chain [1] start processing
-13:59:55 - cmdstanpy - INFO - Chain [1] done processing
-13:59:55 - cmdstanpy - INFO - Chain [2] start processing
-13:59:55 - cmdstanpy - INFO - Chain [2] done processing
-13:59:55 - cmdstanpy - INFO - Chain [3] start processing
-13:59:55 - cmdstanpy - INFO - Chain [3] done processing
-13:59:55 - cmdstanpy - INFO - Chain [4] start processing
-13:59:55 - cmdstanpy - INFO - Chain [4] done processing
+14:17:44 - cmdstanpy - INFO - Chain [1] start processing
+14:17:44 - cmdstanpy - INFO - Chain [1] done processing
+14:17:44 - cmdstanpy - INFO - Chain [2] start processing
+14:17:44 - cmdstanpy - INFO - Chain [2] done processing
+14:17:44 - cmdstanpy - INFO - Chain [3] start processing
+14:17:44 - cmdstanpy - INFO - Chain [3] done processing
+14:17:44 - cmdstanpy - INFO - Chain [4] start processing
+14:17:44 - cmdstanpy - INFO - Chain [4] done processing
 

The generate_quantities method returns a CmdStanGQ object which contains the values for all variables in the generated quantitites block of the program bernoulli_ppc.stan. Unlike the output from the sample method, it doesn’t contain any information on the joint log probability density, sampler state, or parameters or transformed parameter values.

@@ -817,24 +818,35 @@

Example: add posterior predictive checks to +
+
+
+
+14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with "save_warmup=True".
+14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with "save_warmup=True".
+14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with "save_warmup=True".
+14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with "save_warmup=True".
+
+

 (1000, 4, 10) ('y_rep[1]', 'y_rep[2]', 'y_rep[3]', 'y_rep[4]', 'y_rep[5]', 'y_rep[6]', 'y_rep[7]', 'y_rep[8]', 'y_rep[9]', 'y_rep[10]')
-[[0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]
- [0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]
- [0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]
- [0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]]
-[[0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]
- [0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]
- [0. 1. 0. 0. 1. 1. 0. 1. 0. 0.]
- [0. 1. 0. 1. 1. 1. 0. 1. 0. 0.]]
-[[1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]
- [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
- [1. 0. 0. 0. 0. 1. 0. 0. 0. 1.]
- [1. 0. 0. 0. 0. 1. 0. 0. 0. 1.]]
+[[0. 0. 0. 0. 1. 0. 0. 1. 0. 0.]
+ [0. 0. 0. 0. 1. 0. 0. 1. 1. 0.]
+ [0. 1. 0. 0. 1. 1. 0. 1. 1. 0.]
+ [0. 1. 0. 0. 1. 1. 0. 1. 1. 0.]]
+[[0. 1. 1. 0. 1. 1. 1. 1. 0. 0.]
+ [0. 1. 1. 1. 1. 1. 1. 1. 1. 0.]
+ [0. 1. 0. 0. 0. 0. 1. 0. 0. 0.]
+ [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]
+[[0. 1. 1. 0. 0. 0. 1. 0. 0. 0.]
+ [0. 1. 0. 0. 0. 0. 1. 0. 0. 0.]
+ [0. 1. 0. 0. 0. 0. 1. 0. 0. 0.]
+ [0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]]
 

We can also use draws_pd(inc_sample=True) to get a pandas DataFrame which combines the input drawset with the generated quantities.

@@ -852,6 +864,14 @@

Example: add posterior predictive checks to
+
+
+14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with "save_warmup=True".
+
+

+
+
+
 <class 'pandas.core.frame.DataFrame'> (4000, 18)
@@ -880,89 +900,89 @@ 

Example: add posterior predictive checks to - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - 15 - 16 - 17 + lp__ + accept_stat__ + stepsize__ + treedepth__ + n_leapfrog__ + divergent__ + energy__ + theta + y_rep[1] + y_rep[2] + y_rep[3] + y_rep[4] + y_rep[5] + y_rep[6] + y_rep[7] + y_rep[8] + y_rep[9] + y_rep[10] 0 - -6.78689 - 0.983668 - 1.02377 + -7.17160 + 0.862288 + 1.12917 2.0 3.0 0.0 - 7.21986 - 0.216274 + 7.76061 + 0.148160 0.0 0.0 - 1.0 - 1.0 0.0 - 1.0 0.0 + 1.0 0.0 0.0 1.0 + 0.0 + 0.0 1 - -8.02517 - 0.765605 - 1.02377 - 1.0 + -6.77512 + 0.977473 + 1.12917 + 2.0 3.0 0.0 - 8.22072 - 0.092059 + 7.33108 + 0.221682 0.0 1.0 + 1.0 0.0 - 0.0 - 0.0 - 0.0 - 0.0 - 0.0 + 1.0 + 1.0 + 1.0 + 1.0 0.0 0.0 2 - -7.26300 - 1.000000 - 1.02377 - 1.0 - 1.0 - 0.0 - 7.89245 - 0.139341 - 1.0 + -6.85645 + 0.868190 + 1.12917 + 2.0 + 3.0 0.0 + 7.42914 + 0.310981 0.0 + 1.0 + 1.0 0.0 0.0 0.0 + 1.0 0.0 0.0 0.0 - 1.0 diff --git a/docs/users-guide/examples/Run Generated Quantities.ipynb b/docs/users-guide/examples/Run Generated Quantities.ipynb index 19a78fe4..1b63dd47 100644 --- a/docs/users-guide/examples/Run Generated Quantities.ipynb +++ b/docs/users-guide/examples/Run Generated Quantities.ipynb @@ -42,10 +42,10 @@ "execution_count": 1, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:43.160254Z", - "iopub.status.busy": "2022-10-25T13:59:43.159905Z", - "iopub.status.idle": "2022-10-25T13:59:43.720042Z", - "shell.execute_reply": "2022-10-25T13:59:43.718950Z" + "iopub.execute_input": "2023-01-18T14:17:36.214280Z", + "iopub.status.busy": "2023-01-18T14:17:36.214058Z", + "iopub.status.idle": "2023-01-18T14:17:36.633258Z", + "shell.execute_reply": "2023-01-18T14:17:36.632445Z" } }, "outputs": [ @@ -53,7 +53,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, @@ -102,10 +102,10 @@ "execution_count": 2, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:43.724935Z", - "iopub.status.busy": "2022-10-25T13:59:43.724236Z", - "iopub.status.idle": "2022-10-25T13:59:43.801360Z", - "shell.execute_reply": "2022-10-25T13:59:43.800377Z" + "iopub.execute_input": "2023-01-18T14:17:36.637452Z", + "iopub.status.busy": "2023-01-18T14:17:36.636820Z", + "iopub.status.idle": "2023-01-18T14:17:36.808399Z", + "shell.execute_reply": "2023-01-18T14:17:36.807730Z" } }, "outputs": [ @@ -140,10 +140,10 @@ "execution_count": 3, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:43.805733Z", - "iopub.status.busy": "2022-10-25T13:59:43.805427Z", - "iopub.status.idle": "2022-10-25T13:59:44.000166Z", - "shell.execute_reply": "2022-10-25T13:59:43.997498Z" + "iopub.execute_input": "2023-01-18T14:17:36.811378Z", + "iopub.status.busy": "2023-01-18T14:17:36.811158Z", + "iopub.status.idle": "2023-01-18T14:17:36.945944Z", + "shell.execute_reply": "2023-01-18T14:17:36.945248Z" } }, "outputs": [ @@ -151,7 +151,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "13:59:43 - cmdstanpy - INFO - CmdStan start processing\n" + "14:17:36 - cmdstanpy - INFO - CmdStan start processing\n" ] }, { @@ -299,7 +299,7 @@ "output_type": "stream", "text": [ "\n", - "13:59:43 - cmdstanpy - INFO - CmdStan done processing.\n" + "14:17:36 - cmdstanpy - INFO - CmdStan done processing.\n" ] }, { @@ -327,10 +327,10 @@ "execution_count": 4, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:44.004728Z", - "iopub.status.busy": "2022-10-25T13:59:44.004422Z", - "iopub.status.idle": "2022-10-25T13:59:44.091778Z", - "shell.execute_reply": "2022-10-25T13:59:44.090770Z" + "iopub.execute_input": "2023-01-18T14:17:36.949290Z", + "iopub.status.busy": "2023-01-18T14:17:36.948691Z", + "iopub.status.idle": "2023-01-18T14:17:37.014821Z", + "shell.execute_reply": "2023-01-18T14:17:37.014101Z" } }, "outputs": [ @@ -369,40 +369,40 @@ " \n", " \n", " lp__\n", - " -7.261840\n", - " 0.019730\n", - " 0.759061\n", - " -8.799640\n", - " -6.966800\n", - " -6.750220\n", - " 1480.07\n", - " 25518.4\n", - " 1.00197\n", + " -7.304290\n", + " 0.019035\n", + " 0.769326\n", + " -8.88120\n", + " -7.010090\n", + " -6.749920\n", + " 1633.52\n", + " 38893.4\n", + " 0.999465\n", " \n", " \n", " theta\n", - " 0.246352\n", - " 0.002884\n", - " 0.116454\n", - " 0.077285\n", - " 0.233223\n", - " 0.459592\n", - " 1630.56\n", - " 28113.2\n", - " 1.00198\n", + " 0.255031\n", + " 0.003321\n", + " 0.124443\n", + " 0.07711\n", + " 0.237863\n", + " 0.482914\n", + " 1404.12\n", + " 33431.4\n", + " 1.000390\n", " \n", " \n", "\n", "

" ], "text/plain": [ - " Mean MCSE StdDev 5% 50% 95% N_Eff \\\n", - "lp__ -7.261840 0.019730 0.759061 -8.799640 -6.966800 -6.750220 1480.07 \n", - "theta 0.246352 0.002884 0.116454 0.077285 0.233223 0.459592 1630.56 \n", + " Mean MCSE StdDev 5% 50% 95% N_Eff \\\n", + "lp__ -7.304290 0.019035 0.769326 -8.88120 -7.010090 -6.749920 1633.52 \n", + "theta 0.255031 0.003321 0.124443 0.07711 0.237863 0.482914 1404.12 \n", "\n", - " N_Eff/s R_hat \n", - "lp__ 25518.4 1.00197 \n", - "theta 28113.2 1.00198 " + " N_Eff/s R_hat \n", + "lp__ 38893.4 0.999465 \n", + "theta 33431.4 1.000390 " ] }, "execution_count": 4, @@ -426,10 +426,10 @@ "execution_count": 5, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:44.096799Z", - "iopub.status.busy": "2022-10-25T13:59:44.096293Z", - "iopub.status.idle": "2022-10-25T13:59:55.593277Z", - "shell.execute_reply": "2022-10-25T13:59:55.592237Z" + "iopub.execute_input": "2023-01-18T14:17:37.018003Z", + "iopub.status.busy": "2023-01-18T14:17:37.017552Z", + "iopub.status.idle": "2023-01-18T14:17:44.260265Z", + "shell.execute_reply": "2023-01-18T14:17:44.259455Z" } }, "outputs": [ @@ -437,14 +437,14 @@ "name": "stderr", "output_type": "stream", "text": [ - "13:59:44 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc\n" + "14:17:37 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc\n" + "14:17:44 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli_ppc\n" ] }, { @@ -479,6 +479,7 @@ ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ @@ -486,7 +487,7 @@ "\n", "The arguments to the `generate_quantities` method are:\n", " + `data` - the data used to fit the model\n", - " + `mcmc_sample` - either a `CmdStanMCMC` object or a list of stan-csv files\n" + " + `previous_fit` - either a `CmdStanMCMC`, `CmdStanVB`, or `CmdStanMLE` object or a list of stan-csv files\n" ] }, { @@ -494,10 +495,10 @@ "execution_count": 6, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:55.598269Z", - "iopub.status.busy": "2022-10-25T13:59:55.597938Z", - "iopub.status.idle": "2022-10-25T13:59:55.749138Z", - "shell.execute_reply": "2022-10-25T13:59:55.743423Z" + "iopub.execute_input": "2023-01-18T14:17:44.263834Z", + "iopub.status.busy": "2023-01-18T14:17:44.263337Z", + "iopub.status.idle": "2023-01-18T14:17:44.363090Z", + "shell.execute_reply": "2023-01-18T14:17:44.362372Z" } }, "outputs": [ @@ -505,61 +506,61 @@ "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [1] start processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [1] start processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [1] done processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [1] done processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [2] start processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [2] start processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [2] done processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [2] done processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [3] start processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [3] start processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [3] done processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [3] done processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [4] start processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [4] start processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "13:59:55 - cmdstanpy - INFO - Chain [4] done processing\n" + "14:17:44 - cmdstanpy - INFO - Chain [4] done processing\n" ] } ], "source": [ - "new_quantities = model_ppc.generate_quantities(data=data_file, mcmc_sample=fit)" + "new_quantities = model_ppc.generate_quantities(data=data_file, previous_fit=fit)" ] }, { @@ -576,30 +577,58 @@ "execution_count": 7, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:55.758291Z", - "iopub.status.busy": "2022-10-25T13:59:55.757900Z", - "iopub.status.idle": "2022-10-25T13:59:55.819842Z", - "shell.execute_reply": "2022-10-25T13:59:55.818315Z" + "iopub.execute_input": "2023-01-18T14:17:44.366744Z", + "iopub.status.busy": "2023-01-18T14:17:44.366318Z", + "iopub.status.idle": "2023-01-18T14:17:44.394954Z", + "shell.execute_reply": "2023-01-18T14:17:44.394281Z" } }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with \"save_warmup=True\".\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with \"save_warmup=True\".\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with \"save_warmup=True\".\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with \"save_warmup=True\".\n" + ] + }, { "name": "stdout", "output_type": "stream", "text": [ "(1000, 4, 10) ('y_rep[1]', 'y_rep[2]', 'y_rep[3]', 'y_rep[4]', 'y_rep[5]', 'y_rep[6]', 'y_rep[7]', 'y_rep[8]', 'y_rep[9]', 'y_rep[10]')\n", - "[[0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]\n", - " [0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]\n", - " [0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]\n", - " [0. 0. 1. 1. 0. 1. 0. 0. 0. 1.]]\n", - "[[0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]\n", - " [0. 1. 0. 0. 0. 0. 0. 0. 0. 0.]\n", - " [0. 1. 0. 0. 1. 1. 0. 1. 0. 0.]\n", - " [0. 1. 0. 1. 1. 1. 0. 1. 0. 0.]]\n", - "[[1. 0. 0. 0. 0. 0. 0. 0. 0. 1.]\n", - " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]\n", - " [1. 0. 0. 0. 0. 1. 0. 0. 0. 1.]\n", - " [1. 0. 0. 0. 0. 1. 0. 0. 0. 1.]]\n" + "[[0. 0. 0. 0. 1. 0. 0. 1. 0. 0.]\n", + " [0. 0. 0. 0. 1. 0. 0. 1. 1. 0.]\n", + " [0. 1. 0. 0. 1. 1. 0. 1. 1. 0.]\n", + " [0. 1. 0. 0. 1. 1. 0. 1. 1. 0.]]\n", + "[[0. 1. 1. 0. 1. 1. 1. 1. 0. 0.]\n", + " [0. 1. 1. 1. 1. 1. 1. 1. 1. 0.]\n", + " [0. 1. 0. 0. 0. 0. 1. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]]\n", + "[[0. 1. 1. 0. 0. 0. 1. 0. 0. 0.]\n", + " [0. 1. 0. 0. 0. 0. 1. 0. 0. 0.]\n", + " [0. 1. 0. 0. 0. 0. 1. 0. 0. 0.]\n", + " [0. 0. 0. 0. 0. 0. 1. 0. 0. 0.]]\n" ] } ], @@ -621,13 +650,20 @@ "execution_count": 8, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T13:59:55.824323Z", - "iopub.status.busy": "2022-10-25T13:59:55.823713Z", - "iopub.status.idle": "2022-10-25T13:59:55.869196Z", - "shell.execute_reply": "2022-10-25T13:59:55.868189Z" + "iopub.execute_input": "2023-01-18T14:17:44.398918Z", + "iopub.status.busy": "2023-01-18T14:17:44.398330Z", + "iopub.status.idle": "2023-01-18T14:17:44.420972Z", + "shell.execute_reply": "2023-01-18T14:17:44.420326Z" } }, "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "14:17:44 - cmdstanpy - WARNING - Sample doesn't contain draws from warmup iterations, rerun sampler with \"save_warmup=True\".\n" + ] + }, { "name": "stdout", "output_type": "stream", @@ -656,104 +692,109 @@ " \n", " \n", " \n", - " 0\n", - " 1\n", - " 2\n", - " 3\n", - " 4\n", - " 5\n", - " 6\n", - " 7\n", - " 8\n", - " 9\n", - " 10\n", - " 11\n", - " 12\n", - " 13\n", - " 14\n", - " 15\n", - " 16\n", - " 17\n", + " lp__\n", + " accept_stat__\n", + " stepsize__\n", + " treedepth__\n", + " n_leapfrog__\n", + " divergent__\n", + " energy__\n", + " theta\n", + " y_rep[1]\n", + " y_rep[2]\n", + " y_rep[3]\n", + " y_rep[4]\n", + " y_rep[5]\n", + " y_rep[6]\n", + " y_rep[7]\n", + " y_rep[8]\n", + " y_rep[9]\n", + " y_rep[10]\n", " \n", " \n", " \n", " \n", " 0\n", - " -6.78689\n", - " 0.983668\n", - " 1.02377\n", + " -7.17160\n", + " 0.862288\n", + " 1.12917\n", " 2.0\n", " 3.0\n", " 0.0\n", - " 7.21986\n", - " 0.216274\n", + " 7.76061\n", + " 0.148160\n", " 0.0\n", " 0.0\n", - " 1.0\n", - " 1.0\n", " 0.0\n", - " 1.0\n", " 0.0\n", + " 1.0\n", " 0.0\n", " 0.0\n", " 1.0\n", + " 0.0\n", + " 0.0\n", " \n", " \n", " 1\n", - " -8.02517\n", - " 0.765605\n", - " 1.02377\n", - " 1.0\n", + " -6.77512\n", + " 0.977473\n", + " 1.12917\n", + " 2.0\n", " 3.0\n", " 0.0\n", - " 8.22072\n", - " 0.092059\n", + " 7.33108\n", + " 0.221682\n", " 0.0\n", " 1.0\n", + " 1.0\n", " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", - " 0.0\n", + " 1.0\n", + " 1.0\n", + " 1.0\n", + " 1.0\n", " 0.0\n", " 0.0\n", " \n", " \n", " 2\n", - " -7.26300\n", - " 1.000000\n", - " 1.02377\n", - " 1.0\n", - " 1.0\n", - " 0.0\n", - " 7.89245\n", - " 0.139341\n", - " 1.0\n", + " -6.85645\n", + " 0.868190\n", + " 1.12917\n", + " 2.0\n", + " 3.0\n", " 0.0\n", + " 7.42914\n", + " 0.310981\n", " 0.0\n", + " 1.0\n", + " 1.0\n", " 0.0\n", " 0.0\n", " 0.0\n", + " 1.0\n", " 0.0\n", " 0.0\n", " 0.0\n", - " 1.0\n", " \n", " \n", "\n", "
" ], "text/plain": [ - " 0 1 2 3 4 5 6 7 8 9 \\\n", - "0 -6.78689 0.983668 1.02377 2.0 3.0 0.0 7.21986 0.216274 0.0 0.0 \n", - "1 -8.02517 0.765605 1.02377 1.0 3.0 0.0 8.22072 0.092059 0.0 1.0 \n", - "2 -7.26300 1.000000 1.02377 1.0 1.0 0.0 7.89245 0.139341 1.0 0.0 \n", + " lp__ accept_stat__ stepsize__ treedepth__ n_leapfrog__ divergent__ \\\n", + "0 -7.17160 0.862288 1.12917 2.0 3.0 0.0 \n", + "1 -6.77512 0.977473 1.12917 2.0 3.0 0.0 \n", + "2 -6.85645 0.868190 1.12917 2.0 3.0 0.0 \n", + "\n", + " energy__ theta y_rep[1] y_rep[2] y_rep[3] y_rep[4] y_rep[5] \\\n", + "0 7.76061 0.148160 0.0 0.0 0.0 0.0 1.0 \n", + "1 7.33108 0.221682 0.0 1.0 1.0 0.0 1.0 \n", + "2 7.42914 0.310981 0.0 1.0 1.0 0.0 0.0 \n", "\n", - " 10 11 12 13 14 15 16 17 \n", - "0 1.0 1.0 0.0 1.0 0.0 0.0 0.0 1.0 \n", - "1 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 \n", - "2 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 " + " y_rep[6] y_rep[7] y_rep[8] y_rep[9] y_rep[10] \n", + "0 0.0 0.0 1.0 0.0 0.0 \n", + "1 1.0 1.0 1.0 0.0 0.0 \n", + "2 0.0 1.0 0.0 0.0 0.0 " ] }, "execution_count": 8, @@ -792,7 +833,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.15" + "version": "3.9.16" }, "vscode": { "interpreter": { diff --git a/docs/users-guide/examples/Using External C++.html b/docs/users-guide/examples/Using External C++.html index 1db59dd7..5859de7e 100644 --- a/docs/users-guide/examples/Using External C++.html +++ b/docs/users-guide/examples/Using External C++.html @@ -6,7 +6,7 @@ - Advanced Topic: Using External C++ Functions — CmdStanPy 1.0.8 documentation + Advanced Topic: Using External C++ Functions — CmdStanPy 1.1.0rc1 documentation @@ -59,7 +59,7 @@ @@ -364,10 +364,11 @@ } } -/* disable scrollbars on prompts */ +/* disable scrollbars and line breaks on prompts */ div.nbinput.container div.prompt pre, div.nboutput.container div.prompt pre { overflow: hidden; + white-space: pre; } /* input/output area */ @@ -699,16 +700,16 @@

Advanced Topic: Using External C++ Functions
#include <boost/math/tools/promotion.hpp>
-#include <ostream>
-
-namespace bernoulli_model_namespace {
-    template <typename T0__>  inline  typename
-          boost::math::tools::promote_args<T0__>::type
-          make_odds(const T0__& theta, std::ostream* pstream__) {
-            return theta / (1 - theta);
-       }
-}
+
#include <boost/math/tools/promotion.hpp>
+#include <ostream>
+
+namespace bernoulli_model_namespace {
+    template <typename T0__>  inline  typename
+          boost::math::tools::promote_args<T0__>::type
+          make_odds(const T0__& theta, std::ostream* pstream__) {
+            return theta / (1 - theta);
+       }
+}
 
diff --git a/docs/users-guide/examples/VI as Sampler Inits.html b/docs/users-guide/examples/VI as Sampler Inits.html index c161ace7..9654903b 100644 --- a/docs/users-guide/examples/VI as Sampler Inits.html +++ b/docs/users-guide/examples/VI as Sampler Inits.html @@ -6,7 +6,7 @@ - Using Variational Estimates to Initialize the NUTS-HMC Sampler — CmdStanPy 1.0.8 documentation + Using Variational Estimates to Initialize the NUTS-HMC Sampler — CmdStanPy 1.1.0rc1 documentation @@ -59,7 +59,7 @@
@@ -379,10 +379,11 @@ } } -/* disable scrollbars on prompts */ +/* disable scrollbars and line breaks on prompts */ div.nbinput.container div.prompt pre, div.nboutput.container div.prompt pre { overflow: hidden; + white-space: pre; } /* input/output area */ @@ -554,10 +555,10 @@

Model and data
-/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
+/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
   from .autonotebook import tqdm as notebook_tqdm
-13:59:59 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr
-14:00:14 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr
+14:17:47 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr
+14:17:57 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr
 

@@ -647,22 +648,22 @@

Run Stan’s variational inference algorithm, obtain fitted estimates
-14:00:14 - cmdstanpy - INFO - CmdStan start processing
+14:17:57 - cmdstanpy - INFO - CmdStan start processing
 chain 1 |          | 00:00 Status
 chain 2 |          | 00:00 Status
 
 chain 3 |          | 00:00 Status
 
 
-chain 1 |██████▋   | 00:00 Iteration:  575 / 1075 [ 53%]  (Sampling)
-chain 2 |██████▋   | 00:00 Iteration:  575 / 1075 [ 53%]  (Sampling)
+chain 1 |████████▎ | 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)
+chain 2 |████████▎ | 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)
 
 chain 3 || 00:00 Status
 
 
 chain 4 || 00:00 Status
 
-chain 3 |███████▌  | 00:00 Iteration:  675 / 1075 [ 62%]  (Sampling)
+chain 3 |████████▎ | 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)
 
 
 chain 1 |██████████| 00:00 Sampling completed
@@ -685,8 +686,8 @@ 

Run Stan’s variational inference algorithm, obtain fitted estimates
 
-14:00:14 - cmdstanpy - INFO - CmdStan done processing.
-14:00:14 - cmdstanpy - WARNING - Non-fatal error during sampling:
+14:17:57 - cmdstanpy - INFO - CmdStan done processing.
+14:17:57 - cmdstanpy - WARNING - Non-fatal error during sampling:
 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan', line 16, column 2 to column 45)
 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan', line 16, column 2 to column 45)
 Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan', line 16, column 2 to column 45)
@@ -754,7 +755,7 @@ 

Run Stan’s variational inference algorithm, obtain fitted estimates-156.532000 -154.64600 938.42000 - 1672.760000 + 1983.980000 1.001480 @@ -766,7 +767,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates0.999461 1.00107 4863.49000 - 8669.320000 + 10282.200000 1.000320 @@ -778,7 +779,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.000210 1.00210 4344.92000 - 7744.960000 + 9185.880000 0.999725 @@ -790,7 +791,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.000430 1.00200 4385.54000 - 7817.360000 + 9271.760000 0.999669 @@ -802,7 +803,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.001150 1.00292 4664.71000 - 8315.000000 + 9861.970000 0.999536 @@ -814,7 +815,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.001540 1.00321 4786.98000 - 8532.940000 + 10120.500000 0.999197 @@ -826,7 +827,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates0.961783 1.09259 256.47117 - 457.167861 + 542.222346 1.011019 @@ -847,7 +848,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates
-Processing csv files: /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_1.csv, /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_2.csv, /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_3.csv, /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_4.csv
+Processing csv files: /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_1.csv, /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_2.csv, /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_3.csv, /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_4.csv
 
 Checking sampler transitions treedepth.
 Treedepth satisfactory for all transitions.
@@ -880,7 +881,7 @@ 

Run Stan’s variational inference algorithm, obtain fitted estimates
-14:00:14 - cmdstanpy - INFO - CmdStan start processing
+14:17:57 - cmdstanpy - INFO - CmdStan start processing
 chain 1 |          | 00:00 Status
 chain 2 |          | 00:00 Status
 
@@ -888,7 +889,7 @@ 

Run Stan’s variational inference algorithm, obtain fitted estimates | 00:00 Status -chain 2 |█████▊ | 00:00 Iteration: 475 / 1075 [ 44%] (Sampling) +chain 2 |████████▎ | 00:00 Iteration: 775 / 1075 [ 72%] (Sampling) chain 1 |██████████| 00:00 Sampling completed @@ -913,8 +914,8 @@

Run Stan’s variational inference algorithm, obtain fitted estimates
 
-14:00:15 - cmdstanpy - INFO - CmdStan done processing.
-14:00:15 - cmdstanpy - WARNING - Some chains may have failed to converge.
+14:17:57 - cmdstanpy - INFO - CmdStan done processing.
+14:17:57 - cmdstanpy - WARNING - Some chains may have failed to converge.
         Chain 1 had 161 divergent transitions (16.1%)
         Chain 3 had 147 divergent transitions (14.7%)
         Chain 4 had 244 divergent transitions (24.4%)
@@ -981,7 +982,7 @@ 

Run Stan’s variational inference algorithm, obtain fitted estimates-165.541000 -154.33900 2.03097 - 9.53509 + 12.16150 11.37150 @@ -993,7 +994,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates0.999494 1.00252 232.18100 - 1090.05000 + 1390.31000 1.01286 @@ -1005,7 +1006,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.000410 1.00459 110.88200 - 520.57400 + 663.96600 1.04571 @@ -1017,7 +1018,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.000480 1.00442 62.47110 - 293.29200 + 374.07900 1.04607 @@ -1029,7 +1030,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.001690 1.00512 103.34500 - 485.18600 + 618.83000 1.09049 @@ -1041,7 +1042,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates1.001290 1.00443 180.70500 - 848.38100 + 1082.07000 1.03165 @@ -1053,7 +1054,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates2.708830 3.17346 2.03514 - 9.55465 + 12.18647 10.50420 @@ -1073,7 +1074,7 @@

Run Stan’s variational inference algorithm, obtain fitted estimates
-Processing csv files: /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_1.csv, /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_2.csv, /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_3.csv, /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_4.csv
+Processing csv files: /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_1.csv, /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_2.csv, /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_3.csv, /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_4.csv
 
 Checking sampler transitions treedepth.
 Treedepth satisfactory for all transitions.
diff --git a/docs/users-guide/examples/VI as Sampler Inits.ipynb b/docs/users-guide/examples/VI as Sampler Inits.ipynb
index de91cb0d..c96352cf 100644
--- a/docs/users-guide/examples/VI as Sampler Inits.ipynb	
+++ b/docs/users-guide/examples/VI as Sampler Inits.ipynb	
@@ -26,10 +26,10 @@
    "execution_count": 1,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T13:59:58.899187Z",
-     "iopub.status.busy": "2022-10-25T13:59:58.898601Z",
-     "iopub.status.idle": "2022-10-25T14:00:14.019616Z",
-     "shell.execute_reply": "2022-10-25T14:00:14.018504Z"
+     "iopub.execute_input": "2023-01-18T14:17:47.308664Z",
+     "iopub.status.busy": "2023-01-18T14:17:47.308255Z",
+     "iopub.status.idle": "2023-01-18T14:17:57.186819Z",
+     "shell.execute_reply": "2023-01-18T14:17:57.186041Z"
     }
    },
    "outputs": [
@@ -37,7 +37,7 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
+      "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
       "  from .autonotebook import tqdm as notebook_tqdm\n"
      ]
     },
@@ -45,14 +45,14 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "13:59:59 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr\n"
+      "14:17:47 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr\n"
      ]
     },
     {
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:14 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr\n"
+      "14:17:57 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr\n"
      ]
     },
     {
@@ -108,10 +108,10 @@
    "execution_count": 2,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:14.024801Z",
-     "iopub.status.busy": "2022-10-25T14:00:14.024476Z",
-     "iopub.status.idle": "2022-10-25T14:00:14.160076Z",
-     "shell.execute_reply": "2022-10-25T14:00:14.158979Z"
+     "iopub.execute_input": "2023-01-18T14:17:57.190270Z",
+     "iopub.status.busy": "2023-01-18T14:17:57.189796Z",
+     "iopub.status.idle": "2023-01-18T14:17:57.291590Z",
+     "shell.execute_reply": "2023-01-18T14:17:57.290920Z"
     }
    },
    "outputs": [
@@ -119,21 +119,21 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:14 - cmdstanpy - INFO - Chain [1] start processing\n"
+      "14:17:57 - cmdstanpy - INFO - Chain [1] start processing\n"
      ]
     },
     {
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:14 - cmdstanpy - INFO - Chain [1] done processing\n"
+      "14:17:57 - cmdstanpy - INFO - Chain [1] done processing\n"
      ]
     },
     {
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:14 - cmdstanpy - WARNING - The algorithm may not have converged.\n",
+      "14:17:57 - cmdstanpy - WARNING - The algorithm may not have converged.\n",
       "Proceeding because require_converged is set to False\n"
      ]
     }
@@ -157,10 +157,10 @@
    "execution_count": 3,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:14.164922Z",
-     "iopub.status.busy": "2022-10-25T14:00:14.164397Z",
-     "iopub.status.idle": "2022-10-25T14:00:14.170419Z",
-     "shell.execute_reply": "2022-10-25T14:00:14.169454Z"
+     "iopub.execute_input": "2023-01-18T14:17:57.294978Z",
+     "iopub.status.busy": "2023-01-18T14:17:57.294356Z",
+     "iopub.status.idle": "2023-01-18T14:17:57.299906Z",
+     "shell.execute_reply": "2023-01-18T14:17:57.299295Z"
     }
    },
    "outputs": [
@@ -192,10 +192,10 @@
    "execution_count": 4,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:14.176101Z",
-     "iopub.status.busy": "2022-10-25T14:00:14.175802Z",
-     "iopub.status.idle": "2022-10-25T14:00:14.596086Z",
-     "shell.execute_reply": "2022-10-25T14:00:14.594971Z"
+     "iopub.execute_input": "2023-01-18T14:17:57.303018Z",
+     "iopub.status.busy": "2023-01-18T14:17:57.302696Z",
+     "iopub.status.idle": "2023-01-18T14:17:57.641619Z",
+     "shell.execute_reply": "2023-01-18T14:17:57.640875Z"
     }
    },
    "outputs": [
@@ -203,7 +203,7 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:14 - cmdstanpy - INFO - CmdStan start processing\n"
+      "14:17:57 - cmdstanpy - INFO - CmdStan start processing\n"
      ]
     },
     {
@@ -288,7 +288,7 @@
      "output_type": "stream",
      "text": [
       "\r",
-      "chain 1 |\u001b[34m██████▋   \u001b[0m| 00:00 Iteration:  575 / 1075 [ 53%]  (Sampling)"
+      "chain 1 |\u001b[34m████████▎ \u001b[0m| 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)"
      ]
     },
     {
@@ -303,7 +303,7 @@
      "output_type": "stream",
      "text": [
       "\r",
-      "chain 2 |\u001b[34m██████▋   \u001b[0m| 00:00 Iteration:  575 / 1075 [ 53%]  (Sampling)"
+      "chain 2 |\u001b[34m████████▎ \u001b[0m| 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)"
      ]
     },
     {
@@ -373,7 +373,7 @@
      "output_type": "stream",
      "text": [
       "\r",
-      "chain 3 |\u001b[34m███████▌  \u001b[0m| 00:00 Iteration:  675 / 1075 [ 62%]  (Sampling)"
+      "chain 3 |\u001b[34m████████▎ \u001b[0m| 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)"
      ]
     },
     {
@@ -397,7 +397,7 @@
      "output_type": "stream",
      "text": [
       "\r",
-      "chain 4 |\u001b[34m███████▌  \u001b[0m| 00:00 Iteration:  675 / 1075 [ 62%]  (Sampling)"
+      "chain 4 |\u001b[34m████████▎ \u001b[0m| 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)"
      ]
     },
     {
@@ -475,14 +475,14 @@
      "output_type": "stream",
      "text": [
       "\n",
-      "14:00:14 - cmdstanpy - INFO - CmdStan done processing.\n"
+      "14:17:57 - cmdstanpy - INFO - CmdStan done processing.\n"
      ]
     },
     {
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:14 - cmdstanpy - WARNING - Non-fatal error during sampling:\n",
+      "14:17:57 - cmdstanpy - WARNING - Non-fatal error during sampling:\n",
       "Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan', line 16, column 2 to column 45)\n",
       "Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan', line 16, column 2 to column 45)\n",
       "Exception: normal_lpdf: Scale parameter is 0, but must be positive! (in '/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/blr.stan', line 16, column 2 to column 45)\n",
@@ -510,10 +510,10 @@
    "execution_count": 5,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:14.600214Z",
-     "iopub.status.busy": "2022-10-25T14:00:14.599895Z",
-     "iopub.status.idle": "2022-10-25T14:00:14.721935Z",
-     "shell.execute_reply": "2022-10-25T14:00:14.720920Z"
+     "iopub.execute_input": "2023-01-18T14:17:57.645170Z",
+     "iopub.status.busy": "2023-01-18T14:17:57.644584Z",
+     "iopub.status.idle": "2023-01-18T14:17:57.736958Z",
+     "shell.execute_reply": "2023-01-18T14:17:57.736237Z"
     }
    },
    "outputs": [
@@ -559,7 +559,7 @@
        "      -156.532000\n",
        "      -154.64600\n",
        "      938.42000\n",
-       "      1672.760000\n",
+       "      1983.980000\n",
        "      1.001480\n",
        "    \n",
        "    \n",
@@ -571,7 +571,7 @@
        "      0.999461\n",
        "      1.00107\n",
        "      4863.49000\n",
-       "      8669.320000\n",
+       "      10282.200000\n",
        "      1.000320\n",
        "    \n",
        "    \n",
@@ -583,7 +583,7 @@
        "      1.000210\n",
        "      1.00210\n",
        "      4344.92000\n",
-       "      7744.960000\n",
+       "      9185.880000\n",
        "      0.999725\n",
        "    \n",
        "    \n",
@@ -595,7 +595,7 @@
        "      1.000430\n",
        "      1.00200\n",
        "      4385.54000\n",
-       "      7817.360000\n",
+       "      9271.760000\n",
        "      0.999669\n",
        "    \n",
        "    \n",
@@ -607,7 +607,7 @@
        "      1.001150\n",
        "      1.00292\n",
        "      4664.71000\n",
-       "      8315.000000\n",
+       "      9861.970000\n",
        "      0.999536\n",
        "    \n",
        "    \n",
@@ -619,7 +619,7 @@
        "      1.001540\n",
        "      1.00321\n",
        "      4786.98000\n",
-       "      8532.940000\n",
+       "      10120.500000\n",
        "      0.999197\n",
        "    \n",
        "    \n",
@@ -631,7 +631,7 @@
        "      0.961783\n",
        "      1.09259\n",
        "      256.47117\n",
-       "      457.167861\n",
+       "      542.222346\n",
        "      1.011019\n",
        "    \n",
        "  \n",
@@ -648,14 +648,14 @@
        "beta[5]    1.001540  0.000015  0.001033    0.999865    1.001540    1.00321   \n",
        "sigma      0.963840  0.004465  0.071505    0.849600    0.961783    1.09259   \n",
        "\n",
-       "              N_Eff      N_Eff/s     R_hat  \n",
-       "lp__      938.42000  1672.760000  1.001480  \n",
-       "beta[1]  4863.49000  8669.320000  1.000320  \n",
-       "beta[2]  4344.92000  7744.960000  0.999725  \n",
-       "beta[3]  4385.54000  7817.360000  0.999669  \n",
-       "beta[4]  4664.71000  8315.000000  0.999536  \n",
-       "beta[5]  4786.98000  8532.940000  0.999197  \n",
-       "sigma     256.47117   457.167861  1.011019  "
+       "              N_Eff       N_Eff/s     R_hat  \n",
+       "lp__      938.42000   1983.980000  1.001480  \n",
+       "beta[1]  4863.49000  10282.200000  1.000320  \n",
+       "beta[2]  4344.92000   9185.880000  0.999725  \n",
+       "beta[3]  4385.54000   9271.760000  0.999669  \n",
+       "beta[4]  4664.71000   9861.970000  0.999536  \n",
+       "beta[5]  4786.98000  10120.500000  0.999197  \n",
+       "sigma     256.47117    542.222346  1.011019  "
       ]
      },
      "execution_count": 5,
@@ -679,10 +679,10 @@
    "execution_count": 6,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:14.726911Z",
-     "iopub.status.busy": "2022-10-25T14:00:14.726419Z",
-     "iopub.status.idle": "2022-10-25T14:00:14.804384Z",
-     "shell.execute_reply": "2022-10-25T14:00:14.803269Z"
+     "iopub.execute_input": "2023-01-18T14:17:57.740736Z",
+     "iopub.status.busy": "2023-01-18T14:17:57.740173Z",
+     "iopub.status.idle": "2023-01-18T14:17:57.797890Z",
+     "shell.execute_reply": "2023-01-18T14:17:57.797054Z"
     }
    },
    "outputs": [
@@ -690,7 +690,7 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Processing csv files: /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_1.csv, /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_2.csv, /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_3.csv, /tmp/tmp0t3q4rnl/blrvg9rfjou/blr-20221025140014_4.csv\n",
+      "Processing csv files: /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_1.csv, /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_2.csv, /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_3.csv, /tmp/tmp_lmrk0hc/blrmyh0ja4b/blr-20230118141757_4.csv\n",
       "\n",
       "Checking sampler transitions treedepth.\n",
       "Treedepth satisfactory for all transitions.\n",
@@ -726,10 +726,10 @@
    "execution_count": 7,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:14.809039Z",
-     "iopub.status.busy": "2022-10-25T14:00:14.808604Z",
-     "iopub.status.idle": "2022-10-25T14:00:15.055994Z",
-     "shell.execute_reply": "2022-10-25T14:00:15.055049Z"
+     "iopub.execute_input": "2023-01-18T14:17:57.801289Z",
+     "iopub.status.busy": "2023-01-18T14:17:57.800809Z",
+     "iopub.status.idle": "2023-01-18T14:17:57.989401Z",
+     "shell.execute_reply": "2023-01-18T14:17:57.988559Z"
     }
    },
    "outputs": [
@@ -737,7 +737,7 @@
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:14 - cmdstanpy - INFO - CmdStan start processing\n"
+      "14:17:57 - cmdstanpy - INFO - CmdStan start processing\n"
      ]
     },
     {
@@ -829,7 +829,7 @@
      "output_type": "stream",
      "text": [
       "\r",
-      "chain 2 |\u001b[34m█████▊    \u001b[0m| 00:00 Iteration:  475 / 1075 [ 44%]  (Sampling)"
+      "chain 2 |\u001b[34m████████▎ \u001b[0m| 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)"
      ]
     },
     {
@@ -853,7 +853,7 @@
      "output_type": "stream",
      "text": [
       "\r",
-      "chain 4 |\u001b[34m█▋        \u001b[0m| 00:00 Iteration:    1 / 1075 [  0%]  (Warmup)"
+      "chain 4 |\u001b[34m████████▎ \u001b[0m| 00:00 Iteration:  775 / 1075 [ 72%]  (Sampling)"
      ]
     },
     {
@@ -926,7 +926,7 @@
      "text": [
       "\n",
       "\r",
-      "chain 4 |\u001b[34m██████████\u001b[0m| 00:00 Sampling completed                     "
+      "chain 4 |\u001b[34m██████████\u001b[0m| 00:00 Sampling completed                       "
      ]
     },
     {
@@ -962,14 +962,14 @@
      "output_type": "stream",
      "text": [
       "\n",
-      "14:00:15 - cmdstanpy - INFO - CmdStan done processing.\n"
+      "14:17:57 - cmdstanpy - INFO - CmdStan done processing.\n"
      ]
     },
     {
      "name": "stderr",
      "output_type": "stream",
      "text": [
-      "14:00:15 - cmdstanpy - WARNING - Some chains may have failed to converge.\n",
+      "14:17:57 - cmdstanpy - WARNING - Some chains may have failed to converge.\n",
       "\tChain 1 had 161 divergent transitions (16.1%)\n",
       "\tChain 3 had 147 divergent transitions (14.7%)\n",
       "\tChain 4 had 244 divergent transitions (24.4%)\n",
@@ -993,10 +993,10 @@
    "execution_count": 8,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:15.060517Z",
-     "iopub.status.busy": "2022-10-25T14:00:15.060151Z",
-     "iopub.status.idle": "2022-10-25T14:00:15.167408Z",
-     "shell.execute_reply": "2022-10-25T14:00:15.166338Z"
+     "iopub.execute_input": "2023-01-18T14:17:57.992781Z",
+     "iopub.status.busy": "2023-01-18T14:17:57.992321Z",
+     "iopub.status.idle": "2023-01-18T14:17:58.081476Z",
+     "shell.execute_reply": "2023-01-18T14:17:58.080585Z"
     }
    },
    "outputs": [
@@ -1042,7 +1042,7 @@
        "      -165.541000\n",
        "      -154.33900\n",
        "      2.03097\n",
-       "      9.53509\n",
+       "      12.16150\n",
        "      11.37150\n",
        "    \n",
        "    \n",
@@ -1054,7 +1054,7 @@
        "      0.999494\n",
        "      1.00252\n",
        "      232.18100\n",
-       "      1090.05000\n",
+       "      1390.31000\n",
        "      1.01286\n",
        "    \n",
        "    \n",
@@ -1066,7 +1066,7 @@
        "      1.000410\n",
        "      1.00459\n",
        "      110.88200\n",
-       "      520.57400\n",
+       "      663.96600\n",
        "      1.04571\n",
        "    \n",
        "    \n",
@@ -1078,7 +1078,7 @@
        "      1.000480\n",
        "      1.00442\n",
        "      62.47110\n",
-       "      293.29200\n",
+       "      374.07900\n",
        "      1.04607\n",
        "    \n",
        "    \n",
@@ -1090,7 +1090,7 @@
        "      1.001690\n",
        "      1.00512\n",
        "      103.34500\n",
-       "      485.18600\n",
+       "      618.83000\n",
        "      1.09049\n",
        "    \n",
        "    \n",
@@ -1102,7 +1102,7 @@
        "      1.001290\n",
        "      1.00443\n",
        "      180.70500\n",
-       "      848.38100\n",
+       "      1082.07000\n",
        "      1.03165\n",
        "    \n",
        "    \n",
@@ -1114,7 +1114,7 @@
        "      2.708830\n",
        "      3.17346\n",
        "      2.03514\n",
-       "      9.55465\n",
+       "      12.18647\n",
        "      10.50420\n",
        "    \n",
        "  \n",
@@ -1132,13 +1132,13 @@
        "sigma      1.962000   0.725020   1.034300    0.907470    2.708830    3.17346   \n",
        "\n",
        "             N_Eff     N_Eff/s     R_hat  \n",
-       "lp__       2.03097     9.53509  11.37150  \n",
-       "beta[1]  232.18100  1090.05000   1.01286  \n",
-       "beta[2]  110.88200   520.57400   1.04571  \n",
-       "beta[3]   62.47110   293.29200   1.04607  \n",
-       "beta[4]  103.34500   485.18600   1.09049  \n",
-       "beta[5]  180.70500   848.38100   1.03165  \n",
-       "sigma      2.03514     9.55465  10.50420  "
+       "lp__       2.03097    12.16150  11.37150  \n",
+       "beta[1]  232.18100  1390.31000   1.01286  \n",
+       "beta[2]  110.88200   663.96600   1.04571  \n",
+       "beta[3]   62.47110   374.07900   1.04607  \n",
+       "beta[4]  103.34500   618.83000   1.09049  \n",
+       "beta[5]  180.70500  1082.07000   1.03165  \n",
+       "sigma      2.03514    12.18647  10.50420  "
       ]
      },
      "execution_count": 8,
@@ -1155,10 +1155,10 @@
    "execution_count": 9,
    "metadata": {
     "execution": {
-     "iopub.execute_input": "2022-10-25T14:00:15.172604Z",
-     "iopub.status.busy": "2022-10-25T14:00:15.172102Z",
-     "iopub.status.idle": "2022-10-25T14:00:15.247524Z",
-     "shell.execute_reply": "2022-10-25T14:00:15.246430Z"
+     "iopub.execute_input": "2023-01-18T14:17:58.084945Z",
+     "iopub.status.busy": "2023-01-18T14:17:58.084575Z",
+     "iopub.status.idle": "2023-01-18T14:17:58.145220Z",
+     "shell.execute_reply": "2023-01-18T14:17:58.144374Z"
     }
    },
    "outputs": [
@@ -1166,7 +1166,7 @@
      "name": "stdout",
      "output_type": "stream",
      "text": [
-      "Processing csv files: /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_1.csv, /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_2.csv, /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_3.csv, /tmp/tmp0t3q4rnl/blr549cam7k/blr-20221025140014_4.csv\n",
+      "Processing csv files: /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_1.csv, /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_2.csv, /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_3.csv, /tmp/tmp_lmrk0hc/blrt2k5apiw/blr-20230118141757_4.csv\n",
       "\n",
       "Checking sampler transitions treedepth.\n",
       "Treedepth satisfactory for all transitions.\n",
@@ -1216,7 +1216,7 @@
    "name": "python",
    "nbconvert_exporter": "python",
    "pygments_lexer": "ipython3",
-   "version": "3.9.15"
+   "version": "3.9.16"
   }
  },
  "nbformat": 4,
diff --git a/docs/users-guide/examples/Variational Inference.html b/docs/users-guide/examples/Variational Inference.html
index 816fcc35..85fd1e26 100644
--- a/docs/users-guide/examples/Variational Inference.html	
+++ b/docs/users-guide/examples/Variational Inference.html	
@@ -6,7 +6,7 @@
     
     
 
-    Variational Inference in Stan — CmdStanPy 1.0.8 documentation
+    Variational Inference in Stan — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -59,7 +59,7 @@
   
 
@@ -379,10 +379,11 @@
     }
 }
 
-/* disable scrollbars on prompts */
+/* disable scrollbars and line breaks on prompts */
 div.nbinput.container div.prompt pre,
 div.nboutput.container div.prompt pre {
     overflow: hidden;
+    white-space: pre;
 }
 
 /* input/output area */
@@ -556,10 +557,10 @@ 

Example: variational inference for model
-/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
+/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
   from .autonotebook import tqdm as notebook_tqdm
-14:00:17 - cmdstanpy - INFO - Chain [1] start processing
-14:00:17 - cmdstanpy - INFO - Chain [1] done processing
+14:18:00 - cmdstanpy - INFO - Chain [1] start processing
+14:18:00 - cmdstanpy - INFO - Chain [1] done processing
 

The class `CmdStanVB <https://cmdstanpy.readthedocs.io/en/latest/api.html#stanvariational>`__ provides the following properties to access information about the parameter names, estimated means, and the sample: + column_names + variational_params_dict + variational_params_np + variational_params_pd + variational_sample

@@ -592,7 +593,7 @@

Example: variational inference for model
-0.227477
+0.230085
 

@@ -626,10 +627,10 @@

Example: variational inference for model
-14:00:17 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail
-14:00:33 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail
-14:00:33 - cmdstanpy - INFO - Chain [1] start processing
-14:00:33 - cmdstanpy - INFO - Chain [1] done processing
+14:18:00 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail
+14:18:10 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail
+14:18:10 - cmdstanpy - INFO - Chain [1] start processing
+14:18:10 - cmdstanpy - INFO - Chain [1] done processing
 

@@ -639,24 +640,24 @@

Example: variational inference for model
 ---------------------------------------------------------------------------
 RuntimeError                              Traceback (most recent call last)
-Cell In [5], line 2
+Cell In[5], line 2
       1 model_fail = CmdStanModel(stan_file='eta_should_fail.stan')
 ----> 2 vi_fail = model_fail.variational()
 
-File ~/work/cmdstanpy/cmdstanpy/cmdstanpy/model.py:1516, in CmdStanModel.variational(self, data, seed, inits, output_dir, sig_figs, save_latent_dynamics, save_profile, algorithm, iter, grad_samples, elbo_samples, eta, adapt_engaged, adapt_iter, tol_rel_obj, eval_elbo, output_samples, require_converged, show_console, refresh, time_fmt, timeout)
-   1514 if len(re.findall(pat, contents)) > 0:
-   1515     if require_converged:
--> 1516         raise RuntimeError(
-   1517             'The algorithm may not have converged.\n'
-   1518             'If you would like to inspect the output, '
-   1519             're-call with require_converged=False'
-   1520         )
-   1521     # else:
-   1522     get_logger().warning(
-   1523         '%s\n%s',
-   1524         'The algorithm may not have converged.',
-   1525         'Proceeding because require_converged is set to False',
-   1526     )
+File ~/work/cmdstanpy/cmdstanpy/cmdstanpy/model.py:1559, in CmdStanModel.variational(self, data, seed, inits, output_dir, sig_figs, save_latent_dynamics, save_profile, algorithm, iter, grad_samples, elbo_samples, eta, adapt_engaged, adapt_iter, tol_rel_obj, eval_elbo, output_samples, require_converged, show_console, refresh, time_fmt, timeout)
+   1557 if len(re.findall(pat, contents)) > 0:
+   1558     if require_converged:
+-> 1559         raise RuntimeError(
+   1560             'The algorithm may not have converged.\n'
+   1561             'If you would like to inspect the output, '
+   1562             're-call with require_converged=False'
+   1563         )
+   1564     # else:
+   1565     get_logger().warning(
+   1566         '%s\n%s',
+   1567         'The algorithm may not have converged.',
+   1568         'Proceeding because require_converged is set to False',
+   1569     )
 
 RuntimeError: The algorithm may not have converged.
 If you would like to inspect the output, re-call with require_converged=False
@@ -676,9 +677,9 @@ 

Example: variational inference for model
-14:00:34 - cmdstanpy - INFO - Chain [1] start processing
-14:00:34 - cmdstanpy - INFO - Chain [1] done processing
-14:00:34 - cmdstanpy - WARNING - The algorithm may not have converged.
+14:18:10 - cmdstanpy - INFO - Chain [1] start processing
+14:18:10 - cmdstanpy - INFO - Chain [1] done processing
+14:18:10 - cmdstanpy - WARNING - The algorithm may not have converged.
 Proceeding because require_converged is set to False
 

@@ -700,8 +701,8 @@

Example: variational inference for model api docs, section `CmdStanModel.variational <https://cmdstanpy.readthedocs.io/en/latest/api.html#cmdstanpy.CmdStanModel.variational>`__ for a full description of all arguments.

diff --git a/docs/users-guide/examples/Variational Inference.ipynb b/docs/users-guide/examples/Variational Inference.ipynb index 8c75525a..c9c57f1f 100644 --- a/docs/users-guide/examples/Variational Inference.ipynb +++ b/docs/users-guide/examples/Variational Inference.ipynb @@ -42,10 +42,10 @@ "execution_count": 1, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T14:00:17.148135Z", - "iopub.status.busy": "2022-10-25T14:00:17.147378Z", - "iopub.status.idle": "2022-10-25T14:00:17.718528Z", - "shell.execute_reply": "2022-10-25T14:00:17.717455Z" + "iopub.execute_input": "2023-01-18T14:17:59.919454Z", + "iopub.status.busy": "2023-01-18T14:17:59.919122Z", + "iopub.status.idle": "2023-01-18T14:18:00.365048Z", + "shell.execute_reply": "2023-01-18T14:18:00.364311Z" } }, "outputs": [ @@ -53,7 +53,7 @@ "name": "stderr", "output_type": "stream", "text": [ - "/opt/hostedtoolcache/Python/3.9.15/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + "/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] }, @@ -61,14 +61,14 @@ "name": "stderr", "output_type": "stream", "text": [ - "14:00:17 - cmdstanpy - INFO - Chain [1] start processing\n" + "14:18:00 - cmdstanpy - INFO - Chain [1] start processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "14:00:17 - cmdstanpy - INFO - Chain [1] done processing\n" + "14:18:00 - cmdstanpy - INFO - Chain [1] done processing\n" ] } ], @@ -103,10 +103,10 @@ "execution_count": 2, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T14:00:17.723482Z", - "iopub.status.busy": "2022-10-25T14:00:17.723159Z", - "iopub.status.idle": "2022-10-25T14:00:17.731121Z", - "shell.execute_reply": "2022-10-25T14:00:17.727527Z" + "iopub.execute_input": "2023-01-18T14:18:00.368404Z", + "iopub.status.busy": "2023-01-18T14:18:00.368171Z", + "iopub.status.idle": "2023-01-18T14:18:00.373399Z", + "shell.execute_reply": "2023-01-18T14:18:00.372738Z" }, "scrolled": true }, @@ -128,10 +128,10 @@ "execution_count": 3, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T14:00:17.734873Z", - "iopub.status.busy": "2022-10-25T14:00:17.734577Z", - "iopub.status.idle": "2022-10-25T14:00:17.739824Z", - "shell.execute_reply": "2022-10-25T14:00:17.738894Z" + "iopub.execute_input": "2023-01-18T14:18:00.376117Z", + "iopub.status.busy": "2023-01-18T14:18:00.375902Z", + "iopub.status.idle": "2023-01-18T14:18:00.380451Z", + "shell.execute_reply": "2023-01-18T14:18:00.379832Z" } }, "outputs": [ @@ -139,7 +139,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "0.227477\n" + "0.230085\n" ] } ], @@ -152,10 +152,10 @@ "execution_count": 4, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T14:00:17.744945Z", - "iopub.status.busy": "2022-10-25T14:00:17.744652Z", - "iopub.status.idle": "2022-10-25T14:00:17.749266Z", - "shell.execute_reply": "2022-10-25T14:00:17.748343Z" + "iopub.execute_input": "2023-01-18T14:18:00.383196Z", + "iopub.status.busy": "2023-01-18T14:18:00.382997Z", + "iopub.status.idle": "2023-01-18T14:18:00.386204Z", + "shell.execute_reply": "2023-01-18T14:18:00.385600Z" } }, "outputs": [ @@ -185,10 +185,10 @@ "execution_count": 5, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T14:00:17.754120Z", - "iopub.status.busy": "2022-10-25T14:00:17.753831Z", - "iopub.status.idle": "2022-10-25T14:00:34.056074Z", - "shell.execute_reply": "2022-10-25T14:00:34.055086Z" + "iopub.execute_input": "2023-01-18T14:18:00.389802Z", + "iopub.status.busy": "2023-01-18T14:18:00.389602Z", + "iopub.status.idle": "2023-01-18T14:18:10.598259Z", + "shell.execute_reply": "2023-01-18T14:18:10.597559Z" }, "tags": [ "raises-exception" @@ -199,28 +199,28 @@ "name": "stderr", "output_type": "stream", "text": [ - "14:00:17 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail\n" + "14:18:00 - cmdstanpy - INFO - compiling stan file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail.stan to exe file /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "14:00:33 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail\n" + "14:18:10 - cmdstanpy - INFO - compiled model executable: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/eta_should_fail\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "14:00:33 - cmdstanpy - INFO - Chain [1] start processing\n" + "14:18:10 - cmdstanpy - INFO - Chain [1] start processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "14:00:33 - cmdstanpy - INFO - Chain [1] done processing\n" + "14:18:10 - cmdstanpy - INFO - Chain [1] done processing\n" ] }, { @@ -230,8 +230,8 @@ "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn [5], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m model_fail \u001b[38;5;241m=\u001b[39m CmdStanModel(stan_file\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124meta_should_fail.stan\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m vi_fail \u001b[38;5;241m=\u001b[39m \u001b[43mmodel_fail\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvariational\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", - "File \u001b[0;32m~/work/cmdstanpy/cmdstanpy/cmdstanpy/model.py:1516\u001b[0m, in \u001b[0;36mCmdStanModel.variational\u001b[0;34m(self, data, seed, inits, output_dir, sig_figs, save_latent_dynamics, save_profile, algorithm, iter, grad_samples, elbo_samples, eta, adapt_engaged, adapt_iter, tol_rel_obj, eval_elbo, output_samples, require_converged, show_console, refresh, time_fmt, timeout)\u001b[0m\n\u001b[1;32m 1514\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(re\u001b[38;5;241m.\u001b[39mfindall(pat, contents)) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 1515\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m require_converged:\n\u001b[0;32m-> 1516\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\n\u001b[1;32m 1517\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe algorithm may not have converged.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1518\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mIf you would like to inspect the output, \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1519\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mre-call with require_converged=False\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1520\u001b[0m )\n\u001b[1;32m 1521\u001b[0m \u001b[38;5;66;03m# else:\u001b[39;00m\n\u001b[1;32m 1522\u001b[0m get_logger()\u001b[38;5;241m.\u001b[39mwarning(\n\u001b[1;32m 1523\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 1524\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe algorithm may not have converged.\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 1525\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mProceeding because require_converged is set to False\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 1526\u001b[0m )\n", + "Cell \u001b[0;32mIn[5], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m model_fail \u001b[38;5;241m=\u001b[39m CmdStanModel(stan_file\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124meta_should_fail.stan\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m----> 2\u001b[0m vi_fail \u001b[38;5;241m=\u001b[39m \u001b[43mmodel_fail\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mvariational\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/work/cmdstanpy/cmdstanpy/cmdstanpy/model.py:1559\u001b[0m, in \u001b[0;36mCmdStanModel.variational\u001b[0;34m(self, data, seed, inits, output_dir, sig_figs, save_latent_dynamics, save_profile, algorithm, iter, grad_samples, elbo_samples, eta, adapt_engaged, adapt_iter, tol_rel_obj, eval_elbo, output_samples, require_converged, show_console, refresh, time_fmt, timeout)\u001b[0m\n\u001b[1;32m 1557\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(re\u001b[38;5;241m.\u001b[39mfindall(pat, contents)) \u001b[38;5;241m>\u001b[39m \u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 1558\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m require_converged:\n\u001b[0;32m-> 1559\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\n\u001b[1;32m 1560\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe algorithm may not have converged.\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1561\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mIf you would like to inspect the output, \u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1562\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mre-call with require_converged=False\u001b[39m\u001b[38;5;124m'\u001b[39m\n\u001b[1;32m 1563\u001b[0m )\n\u001b[1;32m 1564\u001b[0m \u001b[38;5;66;03m# else:\u001b[39;00m\n\u001b[1;32m 1565\u001b[0m get_logger()\u001b[38;5;241m.\u001b[39mwarning(\n\u001b[1;32m 1566\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 1567\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mThe algorithm may not have converged.\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 1568\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mProceeding because require_converged is set to False\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[1;32m 1569\u001b[0m )\n", "\u001b[0;31mRuntimeError\u001b[0m: The algorithm may not have converged.\nIf you would like to inspect the output, re-call with require_converged=False" ] } @@ -253,10 +253,10 @@ "execution_count": 6, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T14:00:34.062165Z", - "iopub.status.busy": "2022-10-25T14:00:34.061829Z", - "iopub.status.idle": "2022-10-25T14:00:34.133854Z", - "shell.execute_reply": "2022-10-25T14:00:34.132866Z" + "iopub.execute_input": "2023-01-18T14:18:10.601230Z", + "iopub.status.busy": "2023-01-18T14:18:10.601009Z", + "iopub.status.idle": "2023-01-18T14:18:10.661449Z", + "shell.execute_reply": "2023-01-18T14:18:10.660778Z" } }, "outputs": [ @@ -264,21 +264,21 @@ "name": "stderr", "output_type": "stream", "text": [ - "14:00:34 - cmdstanpy - INFO - Chain [1] start processing\n" + "14:18:10 - cmdstanpy - INFO - Chain [1] start processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "14:00:34 - cmdstanpy - INFO - Chain [1] done processing\n" + "14:18:10 - cmdstanpy - INFO - Chain [1] done processing\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "14:00:34 - cmdstanpy - WARNING - The algorithm may not have converged.\n", + "14:18:10 - cmdstanpy - WARNING - The algorithm may not have converged.\n", "Proceeding because require_converged is set to False\n" ] } @@ -299,10 +299,10 @@ "execution_count": 7, "metadata": { "execution": { - "iopub.execute_input": "2022-10-25T14:00:34.139604Z", - "iopub.status.busy": "2022-10-25T14:00:34.138498Z", - "iopub.status.idle": "2022-10-25T14:00:34.153514Z", - "shell.execute_reply": "2022-10-25T14:00:34.152559Z" + "iopub.execute_input": "2023-01-18T14:18:10.664443Z", + "iopub.status.busy": "2023-01-18T14:18:10.664217Z", + "iopub.status.idle": "2023-01-18T14:18:10.673795Z", + "shell.execute_reply": "2023-01-18T14:18:10.673229Z" } }, "outputs": [ @@ -312,8 +312,8 @@ "OrderedDict([('lp__', 0.0),\n", " ('log_p__', 0.0),\n", " ('log_g__', 0.0),\n", - " ('mu[1]', 0.0154586),\n", - " ('mu[2]', -0.0039066)])" + " ('mu[1]', -0.0286462),\n", + " ('mu[2]', -0.0433573)])" ] }, "execution_count": 7, @@ -349,7 +349,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.15" + "version": "3.9.16" } }, "nbformat": 4, diff --git a/docs/users-guide/hello_world.html b/docs/users-guide/hello_world.html index 805a7e14..358bbfc5 100644 --- a/docs/users-guide/hello_world.html +++ b/docs/users-guide/hello_world.html @@ -6,7 +6,7 @@ - “Hello, World!” — CmdStanPy 1.0.8 documentation + “Hello, World!” — CmdStanPy 1.1.0rc1 documentation @@ -59,7 +59,7 @@ @@ -360,7 +360,7 @@

The Stan model# inspect compiled model In [6]: print(model.exe_info()) -{'stan_version_major': '2', 'stan_version_minor': '30', 'stan_version_patch': '0', 'STAN_THREADS': 'false', 'STAN_MPI': 'false', 'STAN_OPENCL': 'false', 'STAN_NO_RANGE_CHECKS': 'false', 'STAN_CPP_OPTIMS': 'false'} +{'stan_version_major': '2', 'stan_version_minor': '31', 'stan_version_patch': '0', 'STAN_THREADS': 'false', 'STAN_MPI': 'false', 'STAN_OPENCL': 'false', 'STAN_NO_RANGE_CHECKS': 'false', 'STAN_CPP_OPTIMS': 'false'}

@@ -433,13 +433,13 @@

Accessing the results
# access model variable by name
 In [9]: print(fit.stan_variable('theta'))
-[0.358901 0.335727 0.359319 ... 0.106376 0.342337 0.323726]
+[0.185217 0.18556  0.271468 ... 0.437813 0.307052 0.307052]
 
 In [10]: print(fit.draws_pd('theta')[:3])
       theta
-0  0.358901
-1  0.335727
-2  0.359319
+0  0.185217
+1  0.185560
+2  0.271468
 
 In [11]: print(fit.draws_xr('theta'))
 <xarray.Dataset>
@@ -448,9 +448,9 @@ 

Accessing the results * chain (chain) int64 1 2 3 4 * draw (draw) int64 0 1 2 3 4 5 6 7 8 ... 992 993 994 995 996 997 998 999 Data variables: - theta (chain, draw) float64 0.3589 0.3357 0.3593 ... 0.1064 0.3423 0.3237 + theta (chain, draw) float64 0.1852 0.1856 0.2715 ... 0.4378 0.3071 0.3071 Attributes: - stan_version: 2.30.0 + stan_version: 2.31.0 model: bernoulli_model num_draws_sampling: 1000 @@ -477,19 +477,19 @@

Accessing the resultsnumpy.ndarray of draws: (1000, 4, 8) In [15]: fit.draws_pd() -Out[15]: +Out[15]: lp__ accept_stat__ stepsize__ ... divergent__ energy__ theta -0 -7.07527 0.953914 0.903413 ... 0.0 7.07652 0.358901 -1 -6.95593 1.000000 0.903413 ... 0.0 7.06948 0.335727 -2 -7.07765 0.990586 0.903413 ... 0.0 7.09961 0.359319 -3 -7.07635 0.926813 0.903413 ... 0.0 7.75164 0.359091 -4 -7.59296 0.880607 0.903413 ... 0.0 7.60144 0.430225 +0 -6.90218 0.941218 0.786759 ... 0.0 7.21770 0.185217 +1 -6.90042 1.000000 0.786759 ... 0.0 6.90230 0.185560 +2 -6.76225 0.985432 0.786759 ... 0.0 7.05216 0.271468 +3 -6.76225 0.893758 0.786759 ... 0.0 7.46688 0.271468 +4 -6.82910 0.972041 0.786759 ... 0.0 6.96485 0.202052 ... ... ... ... ... ... ... ... -3995 -6.99833 0.912517 0.858657 ... 0.0 7.36603 0.169198 -3996 -6.90213 0.953438 0.858657 ... 0.0 7.47845 0.323266 -3997 -7.73457 0.670993 0.858657 ... 0.0 9.10937 0.106376 -3998 -6.98744 0.882321 0.858657 ... 0.0 8.96453 0.342337 -3999 -6.90398 1.000000 0.858657 ... 0.0 6.98883 0.323726 +3995 -6.94318 0.971930 1.037460 ... 0.0 8.36266 0.332923 +3996 -7.72362 0.780736 1.037460 ... 0.0 7.72730 0.444524 +3997 -7.66118 1.000000 1.037460 ... 0.0 7.98100 0.437813 +3998 -6.84342 0.736103 1.037460 ... 0.0 9.06725 0.307052 +3999 -6.84342 0.593001 1.037460 ... 0.0 8.76548 0.307052 [4000 rows x 8 columns]

@@ -501,13 +501,13 @@

Accessing the resultsdiag_e In [17]: print(fit.metric) -[[0.42496 ] - [0.467264] - [0.506406] - [0.540077]] +[[0.515918] + [0.404077] + [0.500632] + [0.421908]] In [18]: print(fit.step_size) -[0.903413 0.902643 0.929784 0.858657] +[0.786759 1.15306 0.973618 1.03746 ]

The CmdStanMCMC object also provides access to metadata about the model and the sampler run.

@@ -515,7 +515,7 @@

Accessing the resultsbernoulli_model In [20]: print(fit.metadata.cmdstan_config['seed']) -77387 +61137 In [21]: print(fit.metadata.stan_vars_cols.keys()) dict_keys(['theta']) @@ -535,10 +535,10 @@

CmdStan utilities:
In [23]: fit.summary()
-Out[23]: 
+Out[23]: 
            Mean      MCSE    StdDev  ...    N_Eff  N_Eff/s    R_hat
-lp__  -7.294880  0.023511  0.806983  ...  1178.10  22228.3  1.00351
-theta  0.252124  0.003057  0.120963  ...  1565.43  29536.4  1.00286
+lp__  -7.247540  0.016973  0.695820  ...  1680.72  40993.3  1.00044
+theta  0.252689  0.003007  0.118066  ...  1541.34  37593.7  1.00061
 
 [2 rows x 9 columns]
 
@@ -550,7 +550,7 @@

CmdStan utilities: diagnose() method runs this utility and prints the output to the console.

In [24]: print(fit.diagnose())
-Processing csv files: /tmp/tmp4eva36zg/bernoullityrry5tn/bernoulli-20221025140048_1.csv, /tmp/tmp4eva36zg/bernoullityrry5tn/bernoulli-20221025140048_2.csv, /tmp/tmp4eva36zg/bernoullityrry5tn/bernoulli-20221025140048_3.csv, /tmp/tmp4eva36zg/bernoullityrry5tn/bernoulli-20221025140048_4.csv
+Processing csv files: /tmp/tmpdff017o2/bernoullixnx88lrf/bernoulli-20230118141820_1.csv, /tmp/tmpdff017o2/bernoullixnx88lrf/bernoulli-20230118141820_2.csv, /tmp/tmpdff017o2/bernoullixnx88lrf/bernoulli-20230118141820_3.csv, /tmp/tmpdff017o2/bernoullixnx88lrf/bernoulli-20230118141820_4.csv
 
 Checking sampler transitions treedepth.
 Treedepth satisfactory for all transitions.
diff --git a/docs/users-guide/outputs.html b/docs/users-guide/outputs.html
index 413c988b..8049e972 100644
--- a/docs/users-guide/outputs.html
+++ b/docs/users-guide/outputs.html
@@ -6,7 +6,7 @@
     
     
 
-    Controlling Outputs — CmdStanPy 1.0.8 documentation
+    Controlling Outputs — CmdStanPy 1.1.0rc1 documentation
     
   
   
@@ -59,7 +59,7 @@
   
 
@@ -297,15 +297,15 @@ 

CSV File OutputsIn [7]: print(fit) CmdStanMCMC: model=bernoulli chains=4['method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] csv_files: - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_1.csv - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_2.csv - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_3.csv - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_4.csv + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_1.csv + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_2.csv + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_3.csv + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_4.csv output_files: - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_0-stdout.txt - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_1-stdout.txt - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_2-stdout.txt - /tmp/tmp4eva36zg/bernoulliyzzmuedi/bernoulli-20221025140048_3-stdout.txt + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_0-stdout.txt + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_1-stdout.txt + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_2-stdout.txt + /tmp/tmpdff017o2/bernoulliahbr6v_m/bernoulli-20230118141821_3-stdout.txt

The output_dir argument is an optional argument which specifies @@ -318,11 +318,11 @@

CSV File Outputs INFO:cmdstanpy:CmdStan done processing. -In [9]: !ls outputs/ -bernoulli-20221025140048_0-stdout.txt bernoulli-20221025140048_2.csv -bernoulli-20221025140048_1-stdout.txt bernoulli-20221025140048_3-stdout.txt -bernoulli-20221025140048_1.csv bernoulli-20221025140048_3.csv -bernoulli-20221025140048_2-stdout.txt bernoulli-20221025140048_4.csv +In [9]: !ls outputs/ +bernoulli-20230118141821_0-stdout.txt bernoulli-20230118141821_2.csv +bernoulli-20230118141821_1-stdout.txt bernoulli-20230118141821_3-stdout.txt +bernoulli-20230118141821_1.csv bernoulli-20230118141821_3.csv +bernoulli-20230118141821_2-stdout.txt bernoulli-20230118141821_4.csv

Alternatively, the save_csvfiles() function moves the CSV files @@ -334,9 +334,9 @@

CSV File OutputsIn [11]: fit.save_csvfiles(dir='some/path') -In [12]: !ls some/path -bernoulli-20221025140049_1.csv bernoulli-20221025140049_3.csv -bernoulli-20221025140049_2.csv bernoulli-20221025140049_4.csv +In [12]: !ls some/path +bernoulli-20230118141821_1.csv bernoulli-20230118141821_3.csv +bernoulli-20230118141821_2.csv bernoulli-20230118141821_4.csv

@@ -355,7 +355,7 @@

LoggingINFO:cmdstanpy:Chain [4] done processing

-

This output is managed through the built-in logging module. For example, it can be disabled entirely:

+

This output is managed through the built-in logging module. For example, it can be disabled entirely:

In [14]: import logging
 
 In [15]: cmdstanpy_logger = logging.getLogger("cmdstanpy")
@@ -399,40 +399,40 @@ 

Logging ....: for line in logs.readlines(): ....: print(line.strip()) ....: -14:00:49 - cmdstanpy - DEBUG - cmd: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli info +14:18:22 - cmdstanpy - DEBUG - cmd: /home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli info cwd: None -14:00:49 - cmdstanpy - INFO - CmdStan start processing -14:00:49 - cmdstanpy - DEBUG - idx 0 -14:00:49 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 -14:00:49 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=1', 'random', 'seed=20102', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_1.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] -14:00:49 - cmdstanpy - INFO - Chain [1] start processing -14:00:49 - cmdstanpy - DEBUG - idx 1 -14:00:49 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 -14:00:49 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=2', 'random', 'seed=20102', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_2.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] -14:00:49 - cmdstanpy - INFO - Chain [2] start processing -14:00:49 - cmdstanpy - INFO - Chain [2] done processing -14:00:49 - cmdstanpy - DEBUG - idx 2 -14:00:49 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 -14:00:49 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=3', 'random', 'seed=20102', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_3.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] -14:00:49 - cmdstanpy - INFO - Chain [3] start processing -14:00:49 - cmdstanpy - INFO - Chain [1] done processing -14:00:49 - cmdstanpy - DEBUG - idx 3 -14:00:49 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 -14:00:49 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=4', 'random', 'seed=20102', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_4.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] -14:00:49 - cmdstanpy - INFO - Chain [4] start processing -14:00:49 - cmdstanpy - INFO - Chain [3] done processing -14:00:49 - cmdstanpy - INFO - Chain [4] done processing -14:00:49 - cmdstanpy - DEBUG - runset +14:18:22 - cmdstanpy - INFO - CmdStan start processing +14:18:22 - cmdstanpy - DEBUG - idx 0 +14:18:22 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 +14:18:22 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=1', 'random', 'seed=36778', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_1.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] +14:18:22 - cmdstanpy - INFO - Chain [1] start processing +14:18:22 - cmdstanpy - DEBUG - idx 1 +14:18:22 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 +14:18:22 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=2', 'random', 'seed=36778', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_2.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] +14:18:22 - cmdstanpy - INFO - Chain [2] start processing +14:18:22 - cmdstanpy - INFO - Chain [1] done processing +14:18:22 - cmdstanpy - DEBUG - idx 2 +14:18:22 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 +14:18:22 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=3', 'random', 'seed=36778', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_3.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] +14:18:22 - cmdstanpy - INFO - Chain [3] start processing +14:18:22 - cmdstanpy - INFO - Chain [2] done processing +14:18:22 - cmdstanpy - DEBUG - idx 3 +14:18:22 - cmdstanpy - DEBUG - running CmdStan, num_threads: 1 +14:18:22 - cmdstanpy - DEBUG - CmdStan args: ['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=4', 'random', 'seed=36778', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_4.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] +14:18:22 - cmdstanpy - INFO - Chain [4] start processing +14:18:22 - cmdstanpy - INFO - Chain [3] done processing +14:18:22 - cmdstanpy - INFO - Chain [4] done processing +14:18:22 - cmdstanpy - DEBUG - runset RunSet: chains=4, chain_ids=[1, 2, 3, 4], num_processes=4 cmd (chain 1): -['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=1', 'random', 'seed=20102', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_1.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] +['/home/runner/work/cmdstanpy/cmdstanpy/docsrc/users-guide/examples/bernoulli', 'id=1', 'random', 'seed=36778', 'data', 'file=users-guide/examples/bernoulli.data.json', 'output', 'file=/tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_1.csv', 'method=sample', 'algorithm=hmc', 'adapt', 'engaged=1'] retcodes=[0, 0, 0, 0] per-chain output files (showing chain 1 only): csv_file: -/tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_1.csv +/tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_1.csv console_msgs (if any): -/tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_0-stdout.txt -14:00:49 - cmdstanpy - DEBUG - Chain 1 console: +/tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_0-stdout.txt +14:18:22 - cmdstanpy - DEBUG - Chain 1 console: method = sample (Default) sample num_samples = 1000 (Default) @@ -463,9 +463,9 @@

Loggingfile = users-guide/examples/bernoulli.data.json init = 2 (Default) random -seed = 20102 +seed = 36778 output -file = /tmp/tmp4eva36zg/bernoulli8epzm16g/bernoulli-20221025140049_1.csv +file = /tmp/tmpdff017o2/bernoullivqe_nxh9/bernoulli-20230118141822_1.csv diagnostic_file = (Default) refresh = 100 (Default) sig_figs = -1 (Default) @@ -501,9 +501,9 @@

LoggingIteration: 1900 / 2000 [ 95%] (Sampling) Iteration: 2000 / 2000 [100%] (Sampling) -Elapsed Time: 0.007 seconds (Warm-up) -0.019 seconds (Sampling) -0.026 seconds (Total) +Elapsed Time: 0.004 seconds (Warm-up) +0.011 seconds (Sampling) +0.015 seconds (Total)

diff --git a/docs/users-guide/overview.html b/docs/users-guide/overview.html index 4894fcfb..cc7ad6e0 100644 --- a/docs/users-guide/overview.html +++ b/docs/users-guide/overview.html @@ -6,7 +6,7 @@ - Overview — CmdStanPy 1.0.8 documentation + Overview — CmdStanPy 1.1.0rc1 documentation @@ -59,7 +59,7 @@ diff --git a/docs/users-guide/workflow.html b/docs/users-guide/workflow.html index e409de4f..1bea33cf 100644 --- a/docs/users-guide/workflow.html +++ b/docs/users-guide/workflow.html @@ -6,7 +6,7 @@ - CmdStanPy Workflow — CmdStanPy 1.0.8 documentation + CmdStanPy Workflow — CmdStanPy 1.1.0rc1 documentation @@ -59,7 +59,7 @@ @@ -417,8 +417,8 @@

Run the CmdStan inference enginegenerate_quantities() method runs Stan’s generate_quantities method -which generates additional quantities of interest from a mode. Its take an existing sample as input and -uses the parameter estimates in the sample to run the Stan program’s generated quantities block.

+which generates additional quantities of interest from a mode. Its take an existing fit as input and +uses the parameter estimates in the fit to run the Stan program’s generated quantities block.

It returns a CmdStanGQ object.

@@ -476,7 +476,7 @@

Output dataCmdStanMCMC and CmdStanGQ return the sample contents in tabular form, see draws() and draws_pd(). Similarly, the draws_xr() method returns the sample -contents as an xarray.Dataset which is a mapping from variable names to their respective values.

+contents as an xarray.Dataset which is a mapping from variable names to their respective values.