[2]:
rm *.dill *.dill.hdf5 *.svg
rm: cannot remove '*.dill.hdf5': No such file or directory
rm: cannot remove '*.svg': No such file or directory

High-level Command Line Interface (CLI)

We provide here a short tutorial of some useful command line scripts (bash/sh terminal) that allow an user-friendly access to the potential of the TransportMap module.

One needs first to store a Distribution object. Then, the following scripts can be applied to it:

We will use the Stochastic Volatility model (\(d=6\)) as an example and store the distribution \(\nu_\pi\) in the file Distribution.pkl.

[2]:
import TransportMaps.Distributions.Examples.StochasticVolatility as SV
yt,zt = SV.generate_data(4, -.5, .25, .95)
yt[2] = None   # Missing data
d = SV.StocVolHyperDistribution(True, False, True, sigma=.25)
for n in range(4):
    d.assimilate(y=yt[n], Xt=zt[n])
d.store('Distribution.pkl', force=True)

Note: In the following we will use the esclamation point ! to indicate the execution of command line scripts

[ ]:
ls

tmap-laplace

This scripts builds a Laplace approximation and the corresponding linear map, and stores it on an output file. Let’s check its syntax…

[5]:
! tmap-laplace --help
Usage: tmap-laplace [OPTIONS]

  Given a file (--input) storing the target distribution, generate the linear
  map corresponding to the Laplace approximation of it. All files involved are
  stored and loaded using the python package pickle.

Options:
  --input PATH                   path to the file containing the target
                                 distribution  [required]
  --output PATH                  path to the output file containing the
                                 transport map, the base distribution, the
                                 target distribution and all the additional
                                 parameters used for the construction
                                 [required]
  --tol FLOAT                    optimization tolerance
  --ders INTEGER                 order of derivatives to be used in the
                                 optimization {0: 'BFGS (gradient free)', 1:
                                 'BFGS (gradient needed)', 2: 'Newton-CG
                                 (Hessian needed)'}
  --fungrad                      whether the distributions provide a method to
                                 compute the log pdf and its gradient at the
                                 same time
  --hessact                      whether to use the action of the Hessian
  --x0 [rnd|zero]                Initial value to be used for the search of
                                 the MAP point. Options are {'rnd': 'will
                                 sample randomly from the prior (if
                                 available)', 'zero': 'will start with a zero
                                 initial guess'}
  --sqrt [sym|tri|kl|lis]        Type of factorization to build the linear
                                 term of the Laplace map from the Laplace
                                 distribution
  --hess-approx [low-rank|fd]    how to approximate the Hessian
  --low-rank-rnd-eps FLOAT       tolerance to be used in the pursue of a
                                 randomized low-rank approximation of the
                                 prior preconditioned Hessian of the log-
                                 likelihood
  --low-rank-rnd-pow-n INTEGER   number of power iterations to be used in the
                                 pursue of a randomized low-rank approximation
                                 of the prior preconditioned Hessian of the
                                 log-likelihood
  --low-rank-rnd-ovsamp INTEGER  oversampling to be used in the pursue of a
                                 randomized low-rank approximation of the
                                 prior preconditioned Hessian of the log-
                                 likelihood
  --fd-eps FLOAT                 Tolerance to be used for the finite
                                 difference approximation of the Hessian
  --overwrite                    overwrite file if it exists
  --log INTEGER                  logging level (see logging)
  --help                         Show this message and exit.

We can check its extended documentation using the flag -h

Let us run tmap-laplace on the stored density…

[6]:
! tmap-laplace --input=Distribution.pkl --output=Laplace.pkl --log=30
INFO:root:Compute Laplace approximation
2023-03-26 01:30:59 WARNING: TransportMaps: laplace_approximation(): Sampling from the prior is not implemented. Initial conditions set to zero.
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 1 - f val. = -1.7082003851e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 1 - ||grad f|| = 8.4716836717e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 2 - f val. = 4.8776911761e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 2 - ||grad f|| = 2.0879642592e+01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 3 - f val. = -1.7252598723e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 3 - ||grad f|| = 6.4207907313e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 4 - f val. = -1.7481942943e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 4 - ||grad f|| = 8.0022174958e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 5 - f val. = -1.7843407302e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 5 - ||grad f|| = 4.5952070200e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 6 - f val. = -1.8248113721e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 6 - ||grad f|| = 4.4234601089e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 7 - f val. = -1.8236398504e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 7 - ||grad f|| = 5.9370017641e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 8 - f val. = -1.8369497496e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 8 - ||grad f|| = 3.0121445803e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 9 - f val. = -1.8459687471e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 9 - ||grad f|| = 1.4687326123e-01
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 10 - f val. = -1.8483180862e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 10 - ||grad f|| = 3.3410440895e-02
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 11 - f val. = -1.8486660626e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 11 - ||grad f|| = 7.8616405401e-03
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 12 - f val. = -1.8486791596e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 12 - ||grad f|| = 1.2671275411e-03
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Obj. Eval. 13 - f val. = -1.8486792802e+00
2023-03-26 01:30:59 INFO: TransportMaps: Lap. Grad. Obj. Eval. 13 - ||grad f|| = 7.8786259601e-05
2023-03-26 01:30:59 INFO: TransportMaps: Optimization terminated successfully
2023-03-26 01:30:59 INFO: TransportMaps:   Function value:          -1.848679
2023-03-26 01:30:59 INFO: TransportMaps:   Jacobian: 2-norm: 7.878626e-05 inf-norm: 6.021736e-05
2023-03-26 01:30:59 INFO: TransportMaps:   Number of iterations:        10
2023-03-26 01:30:59 INFO: TransportMaps:   N. function evaluations:     13
2023-03-26 01:30:59 INFO: TransportMaps:   N. Jacobian evaluations:     13
2023-03-26 01:30:59 INFO: TransportMaps: Building finite difference approximation of the Hessian
INFO:root:Build Laplace map
2023-03-26 01:30:59 WARNING: TransportMaps: sigma DEPRECATED since v3.0. Use property covariance instead.
2023-03-26 01:30:59 WARNING: TransportMaps: LinearTransportMap DEPRECATED since v3.0. Use Maps.AffineTransportMap instead
INFO:root:Build Identity Laplace
INFO:root:Store tmap-laplace data
[7]:
ls
cli.ipynb  Distribution.dill  Laplace.dill  xml/

tmap-tm

This script builds the map \(T\) such that \(T_\sharp \nu_\rho \approx \nu_\pi\), where \(\nu_\rho\) and \(\nu_\pi\) are two Distributions which provide the implementation of the necessary methods (densities and their derivatives) for solving

\[T^\star = \arg\min_{T \in \mathcal{T}} \mathcal{D}_{\rm KL}\left( T_\sharp \nu_\rho \middle\vert \nu_\pi \right)\]

Let’s check its syntax…

[9]:
! tmap-tm --help
Usage: tmap-tm [OPTIONS]

  Given a file (--input) storing the target distribution, produce the
  transport map that pushes forward the base distribution (default: standard
  normal) to the target distribution. All files involved are stored and loaded
  using the python package pickle.

Options:
  --input PATH                    path to the file containing the target
                                  distribution  [required]
  --output PATH                   path to the output file containing the
                                  transport map, the base distribution, the
                                  target distribution and all the additional
                                  parameters used for the construction
                                  [required]
  --base-dist PATH                path to the file containing the base
                                  distribution (default: a standard normal of
                                  suitable dimension)
  --mtype [linspan|intexp|intsq]  monotone format for the transport
                                  {'linspan': 'monotone linear span',
                                  'intexp': 'integrated exponential', 'intsq':
                                  'integrated square'}
  --span [full|total]             span type for all the components of the map
                                  {'full': 'full span', 'total': 'total order
                                  span'}
  --btype [poly|rbf]              basis types for all the components of the
                                  map {'poly': 'polynomial basis', 'rbf':
                                  'radial basis functions (requires
                                  SPAN=full)'}
  --order INTEGER                 order of the transport map
  --sparsity [tri|diag]           sparsity pattern {'tri': 'lower triangular
                                  map', 'diag': 'diagonal map'}
  --map-descr PATH                XML file containing the skeleton of the
                                  transport map
  --map-pkl PATH                  unpickable (pickle) file containing the map
                                  to be used.It may be a comma separated list
                                  of files, containing the maps to be used for
                                  sequential adaptation schemes. In the latter
                                  case the maps must be nested (i.e. the next
                                  map must be an enrichment of the previous
                                  map). The map must be of the correct
                                  dimension
  --map-factory-pkl PATH          unpickable (pickle) file containing a map
                                  factory (instance of MapFactory or
                                  MapListFactory) used to generate maps (or
                                  list of maps). This is used for only
                                  algorithms based on tmap-tm, not by tmap-tm
                                  itself. Therefore this option is not
                                  sufficient/necessary to run tmap-tm itself.
  --qtype INTEGER RANGE           quadrature type for the discretization of
                                  the KL-divergence {0: 'Monte Carlo', 3:
                                  'Gauss quadrature'}  [0<=x<=3; required]
  --qnum <LAMBDA>                 quadrature level (must be a comma separated
                                  list if qtype requires it)  [required]
  --tol FLOAT                     kl minimization tolerance
  --maxit INTEGER                 maximum number of iterations for kl
                                  minimization
  --reg FLOAT                     a float L2 regularization parameter
  --ders INTEGER                  order of derivatives to be used in the
                                  optimization {0: 'BFGS (gradient free)', 1:
                                  'BFGS (gradient needed)', 2: 'Newton-CG
                                  (Hessian needed)'}
  --fungrad                       whether the distributions provide a method
                                  to compute the log pdf and its gradient at
                                  the same time
  --hessact                       whether to use the action of the Hessian
  --validator [none|saa|gradboot]
                                  valiator to be used {'none': 'no validator
                                  used', 'saa': 'Sample Average
                                  Approximation', 'gradboot': 'Gradient
                                  bootstrap'}
  --val-eps FLOAT                 target tolerance for solution of the
                                  stochastic program
  --val-cost-fun [tot-time]       validator cost function {'tot-time': 'total
                                  elapsed time'}
  --val-max-cost FLOAT            validator total cost limit
  --val-max-nsamps FLOAT          maximum number of samples to use in the
                                  approximation of the expecations
  --val-stop-on-fcast             whether to stop on a forecast to exceed the
                                  cost limit (by default it stops only after
                                  exceeding the cost limit)
  --val-saa-eps-abs FLOAT         [SAA] absolute error to be used (--val-eps
                                  is relative)
  --val-saa-upper-mult FLOAT      [SAA] upper multiplier
  --val-saa-lower-n INTEGER       [SAA] number of samples for lower bound
  --val-saa-alpha FLOAT           [SAA] quantile
  --val-saa-lmb-def INTEGER       [SAA] default refinement multiplier
  --val-saa-lmb-max INTEGER       [SAA] maximum refinement multiplier
  --val-gradboot-delta FLOAT      [GRADBOOT] multiplicative factor of the
                                  gradient obtained
  --val-gradboot-n-grad INTEGER   [GRADBOOT] multiplicative factor for the
                                  bootstrap sample size
  --val-gradboot-n-boot INTEGER   [GRADBOOT] number of bootstrap repicas
  --val-gradboot-alpha FLOAT      [GRADBOOT] tolerance interval quantile
  --val-gradboot-lmb-min INTEGER  [GRADBOOT] minimum refinement multiplier
  --val-gradboot-lmb-max INTEGER  [GRADBOOT] maximum refinement multiplier
  --adapt [none|sequential|tol-sequential|fv]
                                  adaptivity algorithm for map construction
                                  {'none': 'no adaptivity', 'sequential': 'a
                                  prefix sequence of maps is used', 'tol-
                                  sequential': 'a sequence of maps is used
                                  until tolerance is met', 'fv': 'first
                                  variation [FV] adaptivity'}
  --adapt-tol FLOAT               target variance diagnostic tolerance
  --adapt-verbosity INTEGER       This regulates the amount of information
                                  printed by the logger. Values are >0 with
                                  higher values corresponding to higher
                                  verbosity.
  --adapt-regr [none|tol-sequential]
                                  regression algorithm to be used within
                                  adaptivity {'none': 'no adaptivity', 'tol-
                                  sequential': 'meet a tolerance using a
                                  prefix sequence of maps'}
  --adapt-regr-reg TEXT           regularization to be used in regression
  --adapt-regr-tol FLOAT          regression tolerance
  --adapt-regr-maxit INTEGER      maximum number of iteration in regression
  --adapt-fv-maxit INTEGER        [FV] maximum number of iterations
  --adapt-fv-prune-trunc-type [manual|percentage|constant]
                                  [FV] type of pruning truncation {'manual':
                                  'the user is queried for every truncation
                                  (matplotlib required)', 'percentage': 'the
                                  number of basis is increase/decreased by a
                                  percentage value', 'constant': 'the number
                                  of basis is increase/decreased by a constant
                                  value'}
  --adapt-fv-prune-trunc-val FLOAT
                                  [FV] prune truncation parameter
  --adapt-fv-avar-trunc-type [manual|percentage|constant]
                                  [FV] type of active variable truncation
                                  {'manual': 'the user is queried for every
                                  truncation (matplotlib required)',
                                  'percentage': 'the number of basis is
                                  increase/decreased by a percentage value',
                                  'constant': 'the number of basis is
                                  increase/decreased by a constant value'}
  --adapt-fv-avar-trunc-val FLOAT
                                  [FV] active variables trunc parameter
  --adapt-fv-coeff-trunc-type [manual|percentage|constant]
                                  [FV] type of enrichment truncation
                                  {'manual': 'the user is queried for every
                                  truncation (matplotlib required)',
                                  'percentage': 'the number of basis is
                                  increase/decreased by a percentage value',
                                  'constant': 'the number of basis is
                                  increase/decreased by a constant value'}
  --adapt-fv-coeff-trunc-val INTEGER
                                  [FV] coefficient truncation parameter
  --adapt-fv-ls-maxit INTEGER     [FV] maximum number of line search
                                  iterations
  --adapt-fv-ls-delta FLOAT       [FV] initial step size for line search
  --adapt-fv-interactive          [FV] whether to query the user for approval
                                  to continue
  --laplace-pull                  whether to precondition pulling back the
                                  target through its Laplace approximation
  --map-pull PATH                 path to file containing a map through which
                                  to pullback the target (this is done before
                                  pulling back thorugh the Laplace, if
                                  --laplace-pull is provided). The file may
                                  cointain just the map or may be the output
                                  of any other map construction scripts (tmap-
                                  tm, ...)
  --overwrite                     overwrite file if it exists
  --reload                        reload file if it exists
  --seed INTEGER                  random seed to be used
  --log INTEGER                   log level
  --nprocs INTEGER                number of processors to be used (MPI support
                                  needed)
  --batch <LAMBDA>                batch size for evaluation of function,
                                  gradient and Hessian
  --interactive                   enter interactive mode after finishing
  --verbose                       whether to run in verbose mode
  --help                          Show this message and exit.

We can check its extended documentation using the -h flag …

Let us build an IsotropicIntegratedSquaredTriangularTransportMap of total order 2 such that \(T_\sharp \nu_\rho \approx \nu_\pi\), where \(\nu_\rho = \mathcal{N}(0,{\bf I})\).

[10]:
! tmap-tm --input=Distribution.pkl --output=Direct-IntSq.pkl \
    --mtype=intsq --span=total --btype=poly --order=2 \
    --qtype=3 --qnum=3,3,3,3,3,3 --log=30
INFO:root:Number coefficients: 83
2023-03-26 01:32:03 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Gradient norm tolerance set to 0.0001
2023-03-26 01:32:03 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Starting BFGS with user provided Jacobian
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 1 - obj = 1.44181e+01 - jac 2-norm = 8.13e+00 - jac inf-norm = 6.15e+00
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 2 - obj = 1.37922e+01 - jac 2-norm = 7.90e+00 - jac inf-norm = 6.15e+00
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 3 - obj = 1.26872e+01 - jac 2-norm = 6.76e+00 - jac inf-norm = 5.19e+00
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 4 - obj = 1.08707e+01 - jac 2-norm = 4.31e+00 - jac inf-norm = 3.19e+00
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 5 - obj = 8.77868e+00 - jac 2-norm = 1.59e+00 - jac inf-norm = 8.73e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 6 - obj = 8.06008e+00 - jac 2-norm = 1.53e+00 - jac inf-norm = 1.03e+00
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 7 - obj = 7.82642e+00 - jac 2-norm = 1.15e+00 - jac inf-norm = 7.72e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 8 - obj = 7.52823e+00 - jac 2-norm = 6.37e-01 - jac inf-norm = 3.87e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 9 - obj = 7.47300e+00 - jac 2-norm = 4.82e-01 - jac inf-norm = 2.73e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 10 - obj = 7.41844e+00 - jac 2-norm = 3.85e-01 - jac inf-norm = 2.42e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 11 - obj = 7.34497e+00 - jac 2-norm = 4.40e-01 - jac inf-norm = 1.96e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 12 - obj = 7.25918e+00 - jac 2-norm = 7.04e-01 - jac inf-norm = 3.59e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 13 - obj = 7.11770e+00 - jac 2-norm = 5.57e-01 - jac inf-norm = 3.08e-01
2023-03-26 01:32:04 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 14 - obj = 6.94961e+00 - jac 2-norm = 6.02e-01 - jac inf-norm = 4.19e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 15 - obj = 6.89654e+00 - jac 2-norm = 3.64e-01 - jac inf-norm = 2.03e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 16 - obj = 6.84712e+00 - jac 2-norm = 2.00e-01 - jac inf-norm = 8.70e-02
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 17 - obj = 6.80806e+00 - jac 2-norm = 3.19e-01 - jac inf-norm = 1.27e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 18 - obj = 6.78046e+00 - jac 2-norm = 2.96e-01 - jac inf-norm = 1.18e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 19 - obj = 6.75214e+00 - jac 2-norm = 2.27e-01 - jac inf-norm = 1.07e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 20 - obj = 6.71010e+00 - jac 2-norm = 1.98e-01 - jac inf-norm = 1.14e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 21 - obj = 6.67578e+00 - jac 2-norm = 3.26e-01 - jac inf-norm = 1.87e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 22 - obj = 6.65293e+00 - jac 2-norm = 1.94e-01 - jac inf-norm = 1.23e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 23 - obj = 6.62799e+00 - jac 2-norm = 1.56e-01 - jac inf-norm = 8.91e-02
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 24 - obj = 6.61474e+00 - jac 2-norm = 2.67e-01 - jac inf-norm = 1.72e-01
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 25 - obj = 6.59938e+00 - jac 2-norm = 1.67e-01 - jac inf-norm = 8.35e-02
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 26 - obj = 6.58676e+00 - jac 2-norm = 1.63e-01 - jac inf-norm = 9.27e-02
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 27 - obj = 6.56884e+00 - jac 2-norm = 1.44e-01 - jac inf-norm = 8.36e-02
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 28 - obj = 6.55859e+00 - jac 2-norm = 1.32e-01 - jac inf-norm = 8.33e-02
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 29 - obj = 6.55322e+00 - jac 2-norm = 6.63e-02 - jac inf-norm = 3.22e-02
2023-03-26 01:32:05 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 30 - obj = 6.54947e+00 - jac 2-norm = 5.40e-02 - jac inf-norm = 2.54e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 31 - obj = 6.54654e+00 - jac 2-norm = 6.49e-02 - jac inf-norm = 3.08e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 32 - obj = 6.54256e+00 - jac 2-norm = 8.42e-02 - jac inf-norm = 4.63e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 33 - obj = 6.53779e+00 - jac 2-norm = 1.19e-01 - jac inf-norm = 8.80e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 34 - obj = 6.53305e+00 - jac 2-norm = 1.11e-01 - jac inf-norm = 8.27e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 35 - obj = 6.52898e+00 - jac 2-norm = 9.70e-02 - jac inf-norm = 6.94e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 36 - obj = 6.52500e+00 - jac 2-norm = 6.71e-02 - jac inf-norm = 3.23e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 37 - obj = 6.52116e+00 - jac 2-norm = 4.90e-02 - jac inf-norm = 2.21e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 38 - obj = 6.51852e+00 - jac 2-norm = 4.15e-02 - jac inf-norm = 2.19e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 39 - obj = 6.51727e+00 - jac 2-norm = 3.42e-02 - jac inf-norm = 2.21e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 40 - obj = 6.51651e+00 - jac 2-norm = 2.62e-02 - jac inf-norm = 9.84e-03
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 41 - obj = 6.51547e+00 - jac 2-norm = 2.94e-02 - jac inf-norm = 1.30e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 42 - obj = 6.51390e+00 - jac 2-norm = 3.93e-02 - jac inf-norm = 1.78e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 43 - obj = 6.51211e+00 - jac 2-norm = 3.87e-02 - jac inf-norm = 1.87e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 44 - obj = 6.51064e+00 - jac 2-norm = 3.28e-02 - jac inf-norm = 1.85e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 45 - obj = 6.50954e+00 - jac 2-norm = 2.39e-02 - jac inf-norm = 9.43e-03
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 46 - obj = 6.50862e+00 - jac 2-norm = 2.39e-02 - jac inf-norm = 1.05e-02
2023-03-26 01:32:06 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 47 - obj = 6.50788e+00 - jac 2-norm = 2.26e-02 - jac inf-norm = 1.10e-02
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 48 - obj = 6.50744e+00 - jac 2-norm = 1.38e-02 - jac inf-norm = 6.42e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 49 - obj = 6.50717e+00 - jac 2-norm = 1.22e-02 - jac inf-norm = 5.87e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 50 - obj = 6.50690e+00 - jac 2-norm = 1.71e-02 - jac inf-norm = 8.48e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 51 - obj = 6.50655e+00 - jac 2-norm = 1.89e-02 - jac inf-norm = 9.16e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 52 - obj = 6.50619e+00 - jac 2-norm = 1.94e-02 - jac inf-norm = 1.20e-02
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 53 - obj = 6.50590e+00 - jac 2-norm = 1.23e-02 - jac inf-norm = 6.09e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 54 - obj = 6.50571e+00 - jac 2-norm = 9.40e-03 - jac inf-norm = 4.19e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 55 - obj = 6.50560e+00 - jac 2-norm = 8.14e-03 - jac inf-norm = 2.78e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 56 - obj = 6.50553e+00 - jac 2-norm = 5.87e-03 - jac inf-norm = 2.41e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 57 - obj = 6.50548e+00 - jac 2-norm = 5.19e-03 - jac inf-norm = 2.27e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 58 - obj = 6.50543e+00 - jac 2-norm = 6.60e-03 - jac inf-norm = 2.38e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 59 - obj = 6.50535e+00 - jac 2-norm = 8.86e-03 - jac inf-norm = 3.27e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 60 - obj = 6.50525e+00 - jac 2-norm = 1.01e-02 - jac inf-norm = 4.96e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 61 - obj = 6.50516e+00 - jac 2-norm = 7.24e-03 - jac inf-norm = 3.12e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 62 - obj = 6.50511e+00 - jac 2-norm = 4.36e-03 - jac inf-norm = 1.31e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 63 - obj = 6.50508e+00 - jac 2-norm = 3.67e-03 - jac inf-norm = 1.27e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 64 - obj = 6.50507e+00 - jac 2-norm = 3.68e-03 - jac inf-norm = 1.32e-03
2023-03-26 01:32:07 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 65 - obj = 6.50505e+00 - jac 2-norm = 3.38e-03 - jac inf-norm = 1.63e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 66 - obj = 6.50504e+00 - jac 2-norm = 2.75e-03 - jac inf-norm = 9.81e-04
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 67 - obj = 6.50502e+00 - jac 2-norm = 2.88e-03 - jac inf-norm = 1.20e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 68 - obj = 6.50501e+00 - jac 2-norm = 3.59e-03 - jac inf-norm = 1.82e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 69 - obj = 6.50498e+00 - jac 2-norm = 4.44e-03 - jac inf-norm = 2.18e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 70 - obj = 6.50494e+00 - jac 2-norm = 4.76e-03 - jac inf-norm = 1.99e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 71 - obj = 6.50491e+00 - jac 2-norm = 3.91e-03 - jac inf-norm = 1.31e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 72 - obj = 6.50489e+00 - jac 2-norm = 2.75e-03 - jac inf-norm = 1.41e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 73 - obj = 6.50488e+00 - jac 2-norm = 2.28e-03 - jac inf-norm = 1.27e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 74 - obj = 6.50487e+00 - jac 2-norm = 2.16e-03 - jac inf-norm = 1.05e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 75 - obj = 6.50486e+00 - jac 2-norm = 2.33e-03 - jac inf-norm = 8.04e-04
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 76 - obj = 6.50485e+00 - jac 2-norm = 2.63e-03 - jac inf-norm = 1.08e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 77 - obj = 6.50484e+00 - jac 2-norm = 2.78e-03 - jac inf-norm = 1.14e-03
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 78 - obj = 6.50483e+00 - jac 2-norm = 2.63e-03 - jac inf-norm = 9.58e-04
2023-03-26 01:32:08 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 79 - obj = 6.50482e+00 - jac 2-norm = 2.13e-03 - jac inf-norm = 7.23e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 80 - obj = 6.50481e+00 - jac 2-norm = 1.45e-03 - jac inf-norm = 5.24e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 81 - obj = 6.50481e+00 - jac 2-norm = 8.70e-04 - jac inf-norm = 2.44e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 82 - obj = 6.50481e+00 - jac 2-norm = 6.62e-04 - jac inf-norm = 2.23e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 83 - obj = 6.50481e+00 - jac 2-norm = 6.81e-04 - jac inf-norm = 2.69e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 84 - obj = 6.50481e+00 - jac 2-norm = 8.07e-04 - jac inf-norm = 2.52e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 85 - obj = 6.50480e+00 - jac 2-norm = 8.98e-04 - jac inf-norm = 2.70e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 86 - obj = 6.50480e+00 - jac 2-norm = 9.50e-04 - jac inf-norm = 3.17e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 87 - obj = 6.50480e+00 - jac 2-norm = 1.09e-03 - jac inf-norm = 6.84e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 88 - obj = 6.50480e+00 - jac 2-norm = 1.22e-03 - jac inf-norm = 8.61e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 89 - obj = 6.50480e+00 - jac 2-norm = 1.15e-03 - jac inf-norm = 7.76e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 90 - obj = 6.50480e+00 - jac 2-norm = 7.83e-04 - jac inf-norm = 4.06e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 91 - obj = 6.50480e+00 - jac 2-norm = 4.54e-04 - jac inf-norm = 1.60e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 92 - obj = 6.50480e+00 - jac 2-norm = 4.99e-04 - jac inf-norm = 2.54e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 93 - obj = 6.50480e+00 - jac 2-norm = 7.00e-04 - jac inf-norm = 4.33e-04
2023-03-26 01:32:09 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 94 - obj = 6.50480e+00 - jac 2-norm = 9.02e-04 - jac inf-norm = 5.55e-04
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 95 - obj = 6.50480e+00 - jac 2-norm = 9.52e-04 - jac inf-norm = 5.50e-04
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 96 - obj = 6.50480e+00 - jac 2-norm = 6.99e-04 - jac inf-norm = 3.57e-04
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 97 - obj = 6.50480e+00 - jac 2-norm = 3.95e-04 - jac inf-norm = 2.16e-04
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 98 - obj = 6.50480e+00 - jac 2-norm = 3.36e-04 - jac inf-norm = 2.08e-04
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 99 - obj = 6.50480e+00 - jac 2-norm = 3.89e-04 - jac inf-norm = 1.79e-04
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: Iteration 100 - obj = 6.50479e+00 - jac 2-norm = 4.13e-04 - jac inf-norm = 1.92e-04
2023-03-26 01:32:10 WARNING: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: minimize_kl_divergence: Minimization of KL-divergence failed.
2023-03-26 01:32:10 WARNING: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: minimize_kl_divergence: Message: Maximum number of iterations has been exceeded.
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: minimize_kl_divergence:   Function value: 6.504795e+00
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: minimize_kl_divergence:   Jacobian 2-norm: 4.129150e-04 inf-norm: 1.921409e-04
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: minimize_kl_divergence:   Number of iterations:       100
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: minimize_kl_divergence:   N. function evaluations:    106
2023-03-26 01:32:10 INFO: TM.IntegratedSquaredParametricTriangularComponentwiseTransportMap: minimize_kl_divergence:   N. Jacobian evaluations:    106
[11]:
ls
cli.ipynb  Direct-IntSq.dill  Distribution.dill  Laplace.dill  xml/

The same map \(T\) (and more complex ones) can be defined using XML descriptors

tmap-sequential-tm

This script builds a transport map pushing forward \(\mathcal{N}(0,{\bf I})\) to the sequential Hidden Markov Chain distribution \(\pi\) using the algorithm for decomposable transports.

Let us check its syntax …

[15]:
! tmap-sequential-tm
/bin/bash: line 1: tmap-sequential-tm: command not found
[15]:
! tmap-sequential-tm --dist=Distribution.dill --output=Sequential-IntSq.dill -v -f \
    --mtype=intsq --span=total --btype=poly --order=3 \
    --qtype=3 --qnum=4,4,4,4 \
    --hyper-mtype=intsq --hyper-span=total --hyper-btype=poly --hyper-order=4 \
    --hyper-qtype=3 --hyper-qnum=5,5
2017-06-18 16:48:43 Step     0    [DONE]
2017-06-18 16:48:44 Step     1    [DONE]
2017-06-18 16:48:48 Step     2    [DONE]
2017-06-18 16:48:58 Step     3    [DONE]
[16]:
! ls
cli.ipynb          Distribution.dill  Sequential-IntSq.dill
Direct-IntSq.dill  Laplace.dill       xml

The same maps \(R_i\) and \(\mathfrak{H}_i\) (and more complex ones) can be defined using XML descriptors

tmap-postprocess

This script provides a number of diagnostics and postprocessing routines. We test it on the output Sequential-IntSq.dill generated by tmap-sequential-tm. However this could be applied directly also to the output Laplace.dill and Direct-IntSq.dill generated by tmap-laplace and tmap-tm respectively.

Let us first check its syntax …

[16]:
! tmap-postprocess --help
Usage: tmap-postprocess [OPTIONS] COMMAND [ARGS]...

  Given a file (--input) storing the transport map pushing forward a base
  distribution to a target distribution, provides a number of diagnositic
  routines. All files involved are stored and loaded using the python package
  pickle and an extra file OUTPUT.hdf5 is created to store big datasets in the
  hdf5 format.

Options:
  --help  Show this message and exit.

Commands:
  aligned-conditionals  plot aligned slices of the selected distribution
  aligned-marginals     compute aligned marginals of the distribution --dist
  ess                   compute the effective sample size of a Markov Chain
  random-conditionals   plot random slices of the selected distribution
  variance-diagnostic   compute variance diagostic using the sampling...
[19]:
! tmap-postprocess aligned-conditionals --input=Direct-IntSq.pkl --output-pkl=Direct-IntSq-Postprocess.pkl \
    --store-fig-dir=./ --log=20 \
    --dist=approx-base
Traceback (most recent call last):
  File "/home/dabi/.virtualenvs/transportmaps-private/bin/tmap-postprocess", line 8, in <module>
    sys.exit(tmap_postprocess())
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/TransportMaps/CLI/_utils.py", line 23, in wrapper
    return f(*args, **kwargs)
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/TransportMaps/CLI/cli_tmap_postprocess.py", line 139, in aligned_conditionals
    stg = _load_input(path_input)
  File "/home/dabi/.virtualenvs/transportmaps-private/lib/python3.10/site-packages/TransportMaps/CLI/_utils.py", line 70, in _load_input
    with open(path_input, 'rb') as in_stream:
FileNotFoundError: [Errno 2] No such file or directory: 'Direct-IntSq.pkl'
[20]:
! tmap-postprocess --data=Sequential-IntSq.dill --output=Sequential-IntSq-Postprocess.dill -v \
    --store-fig-dir=./ --log=20 \
    --aligned-conditionals=approx-base \
    --random-conditionals=approx-base --rndc-n-plots-x-ax=4 \
    --var-diag=exact-base --var-diag-qtype=0 --var-diag-qnum=10000 \
    --aligned-marginals=approx-target --alm-n-points=10000 \
    --quadrature=approx-target --quadrature-qtype=0 --quadrature-qnum=10000 \
    --importance-samples=10000 \
    --metropolis-samples=10000 --metropolis-burnin=5000 --metropolis-ess-plot-lag=50
2017-06-18 16:49:47 [Start] Aligned conditionals approx-base
2017-06-18 16:49:59 [Stop]  Aligned conditionals approx-base
2017-06-18 16:49:59 [Start] Random conditionals approx-base
2017-06-18 16:50:12 [Stop]  Random conditionals approx-base
2017-06-18 16:50:12 [Start] Variance diagnostic exact-base
2017-06-18 16:50:15 [Stop]  Variance Diagnostic exact-base: 3.153136e-02
2017-06-18 16:50:15 [Start] Aligned marginals approx-target - Sample generation
2017-06-18 16:50:16         Aligned marginals approx-target - Plotting
2017-06-18 16:51:45 [Stop]  Aligned marginals approx-target
2017-06-18 16:51:45 [Start] Quadrature 0
2017-06-18 16:51:45 [Stop]  Quadrature
2017-06-18 16:51:45 [Start] Importance sampling
2017-06-18 16:51:49 [Stop]  Importance sampling
2017-06-18 16:51:49 [Start] Metropolis-Hastings with Independent Proposals
2017-06-18 16:52:14         Metropolis-Hastings with Independent Proposals - Estimating ESS
2017-06-18 16:52:15 [Stop]  Metropolis-Hastings with Independent Proposals - ESS: 2230
[21]:
! ls
cli.ipynb
Direct-IntSq.dill
Distribution.dill
Laplace.dill
Sequential-IntSq-aligned-conditionals-approx-base.svg
Sequential-IntSq-aligned-marginals-approx-target.svg
Sequential-IntSq.dill
Sequential-IntSq-metropolis-ess.svg
Sequential-IntSq-Postprocess.dill
Sequential-IntSq-Postprocess.dill.hdf5
Sequential-IntSq-random-conditionals-approx-base.svg
xml

The command above produced a number of outputs. Let us show the figures generated

In the following we show how to access all these outputs.

Aligned conditionals

These are contained in the figures *-aligned-conditionals-approx-base.*.

image0

Random conditionals

These are contained in the figures *-random-conditionals-approx-base.*.

image1

Variance diagnostic

The values for the variance diagnostic are stored in the field vals_var_diag in the file -Postprocess.dill.hdf5 in the HDF5 format. The accuracy of the variance diagnostic can be improved by calling tmap-postprocess again with a higher number of samples/higher order quadrature.

[22]:
import h5py
f = h5py.File('Sequential-IntSq-Postprocess.dill.hdf5','r')
print( list(f.keys()) )
f.close()
['importance-samples', 'metropolis-independent-proposal-samples', 'quadrature', 'vals_var_diag']

Aligned marginals

We are contained in the figures *-aligned-marginals-approx-target.*.

image0

Monte-Carlo quadrature

A Monte-Carlo quadrature with \(10^4\) points for the density \(T_\sharp \nu_\rho\) is stored in Sequential-IntSq-Postprocess.dill.hdf5.

[23]:
import h5py
f = h5py.File('Sequential-IntSq-Postprocess.dill.hdf5','r')
x = f['quadrature']['approx-target']['0'][:,:]
f.close()

Importance samples

A set of \(10^4\) importance samples for \(\nu_\pi\) are generated using the biasing distribution \(T_\sharp \nu_\rho\).

[24]:
import h5py
f = h5py.File('Sequential-IntSq-Postprocess.dill.hdf5','r')
x = f['importance-samples']['x']
w = f['importance-samples']['w']
f.close()

Metropolis-Hastings with independent proposals

A \(10^4\) long Markov chain with invariant distribution \(\nu_\pi\) is generated using \(T_\sharp \nu_\rho\) as proposal distribution.

[25]:
import h5py
f = h5py.File('Sequential-IntSq-Postprocess.dill.hdf5','r')
mc = f['metropolis-independent-proposal-samples']['x']
f.close()

Additionally the Effective Sample Size (ESS) of the Markov chain is estimated using the \(0.99\) percentile accurate decay of the auto-correlation of its components. This analysis is shown in the figures *-metropolis-ess.* and the ESS is reported as an output of tmap-postprocess.

image0

tmap-sequential-posprocess

This script provides a number of postprocessing routines for approximations of sequential Hidden Markov Chain distributions. In particular it deals with the characterization of the filtering distributions \(\nu_\pi\left({\bf Z}_k\middle\vert {\bf y}_{0:k}\right)\).

[26]:
! tmap-sequential-postprocess

Usage: tmap-sequential-postprocess [-h -v -I]
  --data=DATA --output=OUTPUT
  [--store-fig-dir=DIR --store-fig-fmats=FMATS
   --extra-tit=TITLE --no-plotting
   --filtering-conditionals
     --filt-alc-n-points-x-ax=N --filt-alc-n-tri-plots=N
     --filt-alc-anchor=LIST --filt-alc-range=LIST
   --filtering-marginals
     --filt-alm-n-points=N --filt-alm-n-tri-plots=N
   --filtering-quadrature
     --filt-quad-qtype=QTYPE
     --filt-quad-qnum=QNUM
   --log=LOG --batch=BATCH --nprocs=NPROCS]

2017-06-18 16:52:19 ERROR: Option --data and --output must be specified
[27]:
! tmap-sequential-postprocess -h

Usage: tmap-sequential-postprocess [-h -v -I]
  --data=DATA --output=OUTPUT
  [--store-fig-dir=DIR --store-fig-fmats=FMATS
   --extra-tit=TITLE --no-plotting
   --filtering-conditionals
     --filt-alc-n-points-x-ax=N --filt-alc-n-tri-plots=N
     --filt-alc-anchor=LIST --filt-alc-range=LIST
   --filtering-marginals
     --filt-alm-n-points=N --filt-alm-n-tri-plots=N
   --filtering-quadrature
     --filt-quad-qtype=QTYPE
     --filt-quad-qnum=QNUM
   --log=LOG --batch=BATCH --nprocs=NPROCS]

DESCRIPTION
Given a file (--data) storing the transport map pushing forward a base distribution
to a sequential Hidden Markov target distribution,
provides a number of postrprocessing routines.
All files involved are stored and loaded using the python package dill and
an extra file OUTPUT.hdf5 is created to store big datasets in the hdf5 format.
In the following default values are shown in brackets.

OPTIONS - input/output:
  --data=DATA           path to the file containing the target distribution,
                          the base distribution and the transport map pushing forward
                          the base to the target.
  --output=OUTPUT       path to the file storing all postprocess data.
                          The additional file OUTPUT.hdf5 will be used to store
                          the more memory consuming data.
  --store-fig-dir=DIR   path to the directory where to store the figures.
  --store-fig-fmats=FMATS  figure formats - see matplotlib for supported formats (svg)
  --extra-tit=TITLE     additional title for the figures' file names.
  --no-plotting         do not plot figures, but only store their data.
                          (requires --output or --store-fig-dir)
OPTIONS - Diagnostics:
  --filtering-conditionals  plot aligned slices of the filtering distribution:
                        Optional arguments:
    --filt-alc-n-points-x-ax=N  number of discretization points per axis (30)
    --filt-alc-n-tri-plots=N    number of subplots (0)
    --filt-alc-anchor=LIST      list of floats "f1,f2,f3..." for the anchor point (0)
    --filt-alc-range=LIST       list of two floats "f1,f2" for the range (-5,5)
OPTIONS - Sampling:
  --filtering-marginals  plot aligned marginals of the filtering distribution:
                        Optional arguments:
    --filt-alm-n-points=N     number of samples to be used for the kernel density estimation
    --filt-alm-n-tri-plots=N  number of subplots (0)
  --filtering-quadrature  generate quadrature of the filtering distribution:
                        Optional arguments:
    --filt-quad-qtype=QTYPE  generate quadrature of type QTYPE (0)
    --filt-quad-qnum=QNUM    level of the quadrature (int or list)
OPTIONS - Computation:
  --log=LOG               log level (default=30). Uses package logging.
                          Available options:
                            10: debug
                            20: info
                            30: warning
                            40: error
                            50: critical
  --nprocs=NPROCS         number of processors to be used (default=1)
  --batch=BATCH           list of batch sizes for function evaluation, gradient
                          evaluation and Hessian evaluation
OPTIONS - other:
  -v                      verbose output (not affecting --log)
  -I                      enter interactive mode after finishing
  -h                      print this help

[28]:
! tmap-sequential-postprocess \
    --data=Sequential-IntSq.dill --output=Sequential-IntSq-Postprocess.dill -v \
    --store-fig-dir=./ --log=20 \
    --filtering-conditionals \
    --filtering-marginals --filt-alm-n-points=2000 \
    --filtering-quadrature --filt-quad-qtype=0 --filt-quad-qnum=10000
2017-06-18 16:52:25 [Start] Filtering conditionals
2017-06-18 16:52:25         Filtering conditionals - Step 0
2017-06-18 16:53:53         Filtering conditionals - Step 1
2017-06-18 16:55:24         Filtering conditionals - Step 2
2017-06-18 16:57:25         Filtering conditionals - Step 3
2017-06-18 16:59:42 [Stop]  Filtering conditionals
2017-06-18 16:59:42 [Start] Filtering marginals
2017-06-18 16:59:42         Filtering marginals - Step 0 - Sample generation
2017-06-18 16:59:42         Filtering marginals - Step 0 - Plotting
2017-06-18 16:59:46         Filtering marginals - Step 1 - Sample generation
2017-06-18 16:59:46         Filtering marginals - Step 1 - Plotting
2017-06-18 16:59:51         Filtering marginals - Step 2 - Sample generation
2017-06-18 16:59:51         Filtering marginals - Step 2 - Plotting
2017-06-18 16:59:56         Filtering marginals - Step 3 - Sample generation
2017-06-18 16:59:56         Filtering marginals - Step 3 - Plotting
2017-06-18 17:00:01 [Stop]  Filtering marginals
2017-06-18 17:00:01 [Start] Quadrature 0
2017-06-18 17:00:01         Quadrature 0- Step 0 - Sample generation
2017-06-18 17:00:01         Quadrature 0- Step 1 - Sample generation
2017-06-18 17:00:01         Quadrature 0- Step 2 - Sample generation
2017-06-18 17:00:01         Quadrature 0- Step 3 - Sample generation
2017-06-18 17:00:01 [Stop]  Quadrature
[29]:
! ls
cli.ipynb
Direct-IntSq.dill
Distribution.dill
Laplace.dill
Sequential-IntSq-aligned-conditionals-approx-base.svg
Sequential-IntSq-aligned-marginals-approx-target.svg
Sequential-IntSq.dill
Sequential-IntSq-filtering-conditionals-0.svg
Sequential-IntSq-filtering-conditionals-1.svg
Sequential-IntSq-filtering-conditionals-2.svg
Sequential-IntSq-filtering-conditionals-3.svg
Sequential-IntSq-filtering-marginals-0.svg
Sequential-IntSq-filtering-marginals-1.svg
Sequential-IntSq-filtering-marginals-2.svg
Sequential-IntSq-filtering-marginals-3.svg
Sequential-IntSq-metropolis-ess.svg
Sequential-IntSq-Postprocess.dill
Sequential-IntSq-Postprocess.dill.hdf5
Sequential-IntSq-random-conditionals-approx-base.svg
xml

The command above procuced several outputs:

Aligned conditionals of filtering distributions

Step 0

Step 1

image0

image1

Step 2

Step 3

image2

image3

Aligned marginals of filtering distributions

Step 0

Step 1

image4

image5

Step 2

Step 3

image6

image7

Monte-Carlo samples of filtering distributions

[30]:
import h5py
f = h5py.File('Sequential-IntSq-Postprocess.dill.hdf5','r')
x_list = []
for i in range(4):
    x_list.append( f['filtering']['step-%d' % i]['quadrature']['0'] )
f.close()