
    ]h                      p    S r SSKJrJrJrJrJr  SSK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)
z1
Container for the result of running Pathfinder.
    )DictListOptionalTupleUnionN)Method)InferenceMetadata)RunSet)scan_generic_csvc                      \ rS rSrSrS\4S jr SS\\   S\S\	\
\\\R                  4      \\\R                  4   4   4S	 jjr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\R                  4S jrS\4S jr\S\4S j5       r\S\\S4   4S j5       r\S\4S j5       rSS\\   SS4S jjr Sr!g)CmdStanPathfinder   zd
Container for outputs from the Pathfinder algorithm.
Created by :meth:`CmdStanModel.pathfinder()`.
runsetc                    UR                   [        R                  :X  d$  [        SR	                  UR                   5      5      eXl        [        R                  " S5      U l        [        UR                  S   5      n[        U5      U l        g)zInitialize object.zAWrong runset method, expecting Pathfinder runset, found method {} r   N)methodr   
PATHFINDER
ValueErrorformat_runsetnparray_drawsr   	csv_filesr	   	_metadata)selfr   configs      oC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\cmdstanpy/stanfit/pathfinder.py__init__CmdStanPathfinder.__init__   sk    }} 1 11""(&"7  "$((2,!&"2"21"56*62    Nseedchainsreturnc                 j   U R                  5         [        R                  R                  U5      nUR	                  U R
                  R                  S   USS9nUS:X  aZ  U R
                  US      nU R                  R                  R                  5        VVs0 s H  u  pgXgR                  U5      _M     snn$ U VVVs/ s HX  nU R                  R                  R                  5        VVs0 s H#  u  pgXgR                  U R
                  U   5      _M%     snnPMZ     snnn$ s  snnf s  snnf s  snnnf )a  
Create initial values for the parameters of the model
by randomly selecting draws from the Pathfinder approximation.

:param seed: Used for random selection, defaults to None
:param chains: Number of initial values to return, defaults to 4
:return: The initial values for the parameters of the model.

If ``chains`` is 1, a dictionary is returned, otherwise a list
of dictionaries is returned, in the format expected for the
``inits`` argument. of :meth:`CmdStanModel.sample`.
r   F)sizereplace   )_assemble_drawsr   randomdefault_rngchoicer   shaper   	stan_varsitemsextract_reshape)	r   r"   r#   rngidxsdrawnamevaridxs	            r   create_initsCmdStanPathfinder.create_inits#   s    	ii##D)zz$++++A.VUzKQ;;;tAw'D "&!9!9!?!?!A!AID ))$//!A   
  C &*^^%=%=%C%C%E%E	 --dkk#.>??%E   s   D">-D.+*D(D.(D.c                 \   SR                  U R                  R                  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$ )NzCmdStanPathfinder: model={}{}r   )cmdz%{}
 csv_files:
	{}
 output_files:
	{}z
	)	r   r   model_argsmethod_argscomposejoinr   stdout_files)r   reps     r   __repr__CmdStanPathfinder.__repr__D   s    -44LLLL**221"2=
 <BBKK../KK112

 
r!   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   r-   openr   r   readline
startswithr   loadtxtfloat)r   fds     r   r)   !CmdStanPathfinder._assemble_drawsQ   s    ;;$$,,((+S1R;;=,,S11 ;;=,,S11**DK 211s   A
B5!B55
Cr5   c                 .   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
--------
CmdStanPathfinder.stan_variables
CmdStanMLE.stan_variable
CmdStanMCMC.stan_variable
CmdStanVB.stan_variable
CmdStanGQ.stan_variable
CmdStanLaplace.stan_variable
zUnknown variable name: z
Available variables are z, )	r)   r   r.   r0   r   KeyErrorr   r?   keys)r   r5   outs      r   stan_variableCmdStanPathfinder.stan_variable`   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$ )a5  
Return a dictionary mapping Stan program variables names
to the corresponding numpy.ndarray containing the inferred values.

See Also
--------
CmdStanPathfinder.stan_variable
CmdStanMCMC.stan_variables
CmdStanMLE.stan_variables
CmdStanVB.stan_variables
CmdStanGQ.stan_variables
CmdStanLaplace.stan_variables
)r   r.   rX   )r   resultr4   s      r   stan_variables CmdStanPathfinder.stan_variables   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_varsr/   r0   r   )r   r4   r5   s      r   method_variables"CmdStanPathfinder.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CmdStanPathfinder.draws   s     	{{r!   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)rO   AttributeErrorrX   r   args)r   rf   es      r   __getattr__CmdStanPathfinder.__getattr__   sY    ??3 #9$!@AA	*%%d++ 	* !&&))	*s   7 
AAAc                 :    U R                  5         U R                  $ N)r)   __dict__rc   s    r   __getstate__CmdStanPathfinder.__getstate__   s    
 	}}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   rc   s    r   metadataCmdStanPathfinder.metadata   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`.
column_names)r   cmdstan_configrc   s    r   rw   CmdStanPathfinder.column_names   s     ~~,,^<<r!   c                    U R                   R                  R                  SS5      S:  =(       aY    U R                   R                  R                  SS5      S;   =(       a)    U R                   R                  R                  SS5      S;   $ )zc
Returns True if the draws were resampled from several Pathfinder
approximations, False otherwise.
	num_paths   r(   psis_resample)r(   truecalculate_lp)r   rx   getrc   s    r   is_resampledCmdStanPathfinder.is_resampled   sx     NN))--k1=A --11/1E --11.!D		
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   CmdStanPathfinder.save_csvfiles   s     	""3'r!   )r   r   r   )Nr|   )r$   Nro   )"__name__
__module____qualname____firstlineno____doc__r
   r   r   intr   r   r   strr   ndarrayr7   rB   r)   rX   r\   r`   rd   rl   dictrq   propertyr	   rt   r   rw   boolr   r   __static_attributes__r   r!   r   r   r      sg   
3v 3 9:SM25	tDbjj)*Dbjj,AA	BB
# 
     DS"**_ 5 &
$sBJJ"7 
rzz * *

 *d  +   =eCHo = = 
d 
 
(# ($ ( (r!   r   )r   typingr   r   r   r   r   numpyr   cmdstanpy.cmdstan_argsr   cmdstanpy.stanfit.metadatar	   cmdstanpy.stanfit.runsetr
   cmdstanpy.utils.stancsvr   r   r   r!   r   <module>r      s-    6 5  ) 8 + 4^( ^(r!   