
    ]h%                         S r SSKJrJrJrJrJrJrJrJ	r	  SSK
rSSKr SSKrSrSSKJr  SSKJr  SSKJr  S	S
KJr  S	SKJr  S	SKJr   " S S5      rg! \ a    Sr N9f = f)z>
Container for the result of running a laplace approximation.
    )AnyDictHashableListMutableMappingOptionalTupleUnionNTF)Method)build_xarray_data)scan_generic_csv   )InferenceMetadata)
CmdStanMLE)RunSetc                      \ rS rSrS\S\SS4S jrSS jrS\S\	R                  4S	 jrS\\\	R                  4   4S
 jrS\\\	R                  4   4S jrS\	R                  4S jr SS\\\   \S4   S\R&                  4S jjr SS\\\\   S4   SS4S jjr\S\4S j5       r\S\4S j5       rS\4S jrS\S\	R                  4S jrS\4S jr\S\\S4   4S j5       rSS\ \   SS4S jjr!Sr"g)CmdStanLaplace'   runsetmodereturnNc                 &   UR                   [        R                  :X  d$  [        SR	                  UR                   5      5      eXl        X l        [        R                  " S5      U l	        [        UR                  S   5      n[        U5      U l        g)zInitialize object.z>Wrong runset method, expecting laplace runset, found method {} r   N)methodr   LAPLACE
ValueErrorformat_runset_modenparray_drawsr   	csv_filesr   	_metadata)selfr   r   configs       lC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\cmdstanpy/stanfit/laplace.py__init__CmdStanLaplace.__init__(   sn    }}.""(&"7  
"$((2,!&"2"21"56*62    c           	         U R                   R                  S:w  a  g [        U R                  R                  S   S5       nUR                  5       R                  S5      (       a'   UR                  5       R                  S5      (       a  M'  [        R                  " U[        SSSS9U l         S S S 5        g ! , (       d  f       g = f)N)r   r   r#   ,)dtypendmin	delimitercomments)
r"   shapeopenr   r#   readline
startswithr    loadtxtfloat)r%   fds     r'   _assemble_drawsCmdStanLaplace._assemble_draws7   s    ;;$$,,((+S1R;;=,,S11 ;;=,,S11**DK 211s   A
B5!B55
Cvarc                 .   U R                  5          U R                  R                  U   R                  U R                  5      nU$ ! [
         aD    [        SU S3SR                  U R                  R                  R                  5       5      -   5      ef = f)a  
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.

This functionaltiy is also available via a shortcut using ``.`` -
writing ``fit.a`` is a synonym for ``fit.stan_variable("a")``

:param var: variable name

See Also
--------
CmdStanMLE.stan_variables
CmdStanMCMC.stan_variable
CmdStanPathfinder.stan_variable
CmdStanVB.stan_variable
CmdStanGQ.stan_variable
zUnknown variable name: z
Available variables are z, )	r;   r$   	stan_varsextract_reshaper"   KeyErrorr   joinkeys)r%   r=   outs      r'   stan_variableCmdStanLaplace.stan_variableF   s    & 		"nn66s;KKC J 	)# /+ +))DNN4499;<= 	s   3A ABc                 j    0 nU R                   R                   H  nU R                  U5      X'   M     U$ )a  
Return a dictionary mapping Stan program variables names
to the corresponding numpy.ndarray containing the inferred values.

:param inc_warmup: When ``True`` and the warmup draws are present in
    the MCMC sample, then the warmup draws are included.
    Default value is ``False``

See Also
--------
CmdStanGQ.stan_variable
CmdStanMCMC.stan_variables
CmdStanMLE.stan_variables
CmdStanPathfinder.stan_variables
CmdStanVB.stan_variables
)r$   r?   rE   )r%   resultnames      r'   stan_variablesCmdStanLaplace.stan_variablesg   s4    " NN,,D--d3FL -r*   c                     U R                  5         U R                  R                  R                  5        VVs0 s H   u  pXR	                  U R
                  5      _M"     snn$ s  snnf )a  
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.
Maps each column name to a numpy.ndarray (draws x chains x 1)
containing per-draw diagnostic values.
)r;   r$   method_varsitemsr@   r"   )r%   rI   r=   s      r'   method_variablesCmdStanLaplace.method_variables}   s^     	 "^^77==?
?	 %%dkk22?
 	
 
s   'A#c                 :    U R                  5         U R                  $ )z
Return a numpy.ndarray containing the draws from the
approximate posterior distribution. This is a 2-D array
of shape (draws, parameters).
)r;   r"   r%   s    r'   drawsCmdStanLaplace.draws   s     	{{r*   varsc                 `   Ub  [        U[        5      (       a  U/nOUnU R                  5         / nUb  [        R	                  W5       H  nX@R
                  R                  ;   a  UR                  U5        M/  X@R
                  R                  ;   aM  U R
                  R                  U   nUR                  U R                  UR                  UR                   5        M  [        SU 35      e   O[        U R                  5      n[        R                   " U R"                  U R                  S9U   $ )NzUnknown variable: )columns)
isinstancestrr;   dictfromkeysr$   rM   appendr?   extendcolumn_names	start_idxend_idxr   listpd	DataFramer"   )r%   rU   	vars_listcolsr=   infos         r'   draws_pdCmdStanLaplace.draws_pd   s     $$$!F	 	}}Y/..444KK$NN444>>33C8DKK))$..4<<H %'9#%?@@ 0 ))*D||DKK1B1BCDIIr*   z
xr.Datasetc           
         [         (       d  [        S5      eUc.  [        U R                  R                  R                  5       5      nO[        U[        5      (       a  U/nOUnU R                  5         U R                  R                  nUS    SUS    SUS    3US   S.n0 nS	[        R                  " U R                  R                  S
   5      0nU HI  n[        UU R                  R                  U   U R                  SS2[        R                  SS24   5        MK     [         R"                  " XVUS9R%                  S	S5      R'                  5       $ )z
Returns the sampler draws as a xarray Dataset.

:param vars: optional list of variable names.

See Also
--------
CmdStanMCMC.draws_xr
CmdStanGQ.draws_xr
z>Package "xarray" is not installed, cannot produce draws array.Nstan_version_major.stan_version_minorstan_version_patchmodel)stan_versionrn   drawr   )coordsattrs.)XARRAY_INSTALLEDRuntimeErrorra   r$   r?   rC   rX   rY   r;   cmdstan_configr    aranger"   r4   r   newaxisxrDataset	transposesqueeze)r%   rU   rd   metarr   datacoordinatesr=   s           r'   draws_xrCmdStanLaplace.draws_xr   s@     P  <T^^55::<=Ic""II~~,,#$89:!()*!D1E,F+GI']0
 /1BIIdkk//236
 C((-Arzz1,-  JJtu=Yvs#WY	
r*   c                     U R                   $ )zR
Return the maximum a posteriori estimate (mode)
as a :class:`CmdStanMLE` object.
)r   rR   s    r'   r   CmdStanLaplace.mode   s     zzr*   c                     U R                   $ )z
Returns object which contains CmdStan configuration as well as
information about the names and structure of the inference method
and model output variables.
)r$   rR   s    r'   metadataCmdStanLaplace.metadata   s     ~~r*   c           	         SR                  [        U R                  5      R                  5        Vs/ s H  nSU-   PM
     sn5      SS  nSR	                  U R
                  R                  UU R
                  R                  R                  R                  S/ S95      nSR	                  USR                  U R
                  R                  5      SR                  U R
                  R                  5      5      nU$ s  snf )	N
	r   z&CmdStanLaplace: model={} 
mode=({})
{}r   )cmdz%{}
 csv_files:
	{}
 output_files:
	{}z
	)rB   reprr   
splitlinesr   r   rn   _argsmethod_argscomposer#   stdout_files)r%   liner   reps       r'   __repr__CmdStanLaplace.__repr__   s    yy%)$))_%?%?%AB%ATTD[%AB

" 9??LLLL**221"2=

 <BBKK../KK112

 
 Cs   C8attrc                     UR                  S5      (       a  [        SU 35      e U R                  U5      $ ! [         a  n[        UR                  6 eSnAff = f)z)Synonymous with ``fit.stan_variable(attr)_zUnknown variable name N)r7   AttributeErrorrE   r   args)r%   r   es      r'   __getattr__CmdStanLaplace.__getattr__  sY    ??3 #9$!@AA	*%%d++ 	* !&&))	*s   7 
AAAc                 :    U R                  5         U R                  $ N)r;   __dict__rR   s    r'   __getstate__CmdStanLaplace.__getstate__  s    
 	}}r*   .c                 4    U R                   R                  S   $ )a  
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,
with names munged to array notation, e.g. `beta[1]` not `beta.1`.
r^   )r$   ru   rR   s    r'   r^   CmdStanLaplace.column_names  s     ~~,,^<<r*   dirc                 :    U R                   R                  U5        g)a/  
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
'bernoulli-201912081451-1.csv'.

:param dir: directory path

See Also
--------
stanfit.RunSet.save_csvfiles
cmdstanpy.from_csv
N)r   save_csvfiles)r%   r   s     r'   r   CmdStanLaplace.save_csvfiles"  s     	""3'r*   )r"   r$   r   r   )r   Nr   )#__name__
__module____qualname____firstlineno__r   r   r(   r;   rY   r    ndarrayrE   r   rJ   rO   rS   r
   r   rb   rc   rg   r   propertyr   r   r   r   r   rZ   r   r	   r^   r   r   __static_attributes__r   r*   r'   r   r   '   s   3v 3Z 3D 3  BS"**_ 5 ,
$sBJJ"7 
rzz  -1JDIsD()J 
J> -12
CcD()2
 
2
h j   +  #  * *

 *d  =eCHo = =(# ($ ( (r*   r   )__doc__typingr   r   r   r   r   r   r	   r
   numpyr    pandasrb   xarrayrx   rs   ImportErrorcmdstanpy.cmdstan_argsr   cmdstanpy.utils.data_mungingr   cmdstanpy.utils.stancsvr   r   r   mler   r   r   r   r   r*   r'   <module>r      sf   	 	 	   * : 4 '  I( I(!  s   A A A 