Skip to content

FORM should note lack of copula in human-readable error #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
zdelrosario opened this issue Apr 22, 2021 · 0 comments
Open

FORM should note lack of copula in human-readable error #107

zdelrosario opened this issue Apr 22, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@zdelrosario
Copy link
Owner

FORM routines should provide a human-readable error when a model without copula is provided.

Reprex follows:

import grama as gr

md = (
    gr.Model()
    >> gr.cp_vec_function(
        fun=lambda df: gr.df_make(g=df.x - 1),
        var=["x"],
        out=["g"],
    )
    >> gr.cp_marginals(x=dict(dist="norm", loc=0, scale=1))
)

(
    md
    >> gr.ev_form_pma(df_det="nom", betas=dict(g=3))
)
#> Traceback (most recent call last):
#> <ipython-input-5-ada1eb74ad57> in <module>
#>       1 (
#> ----> 2     md
#>       3     >> gr.ev_form_pma(df_det="nom", betas=dict(g=3))
#>       4 )
#> ~/Git/py_grama/grama/tools.py in __rrshift__(self, other)
#>     286                 other_copy = copy_meta(other, other_copy)
#>     287 
#> --> 288         result = self.function(other_copy)
#>     289 
#>     290         for p in self.chained_pipes:
#> ~/Git/py_grama/grama/tools.py in <lambda>(x)
#>     301 
#>     302     def __call__(self, *args, **kwargs):
#> --> 303         return pipe(lambda x: self.function(x, *args, **kwargs))
#>     304 
#>     305 
#> ~/Bin/anaconda3/lib/python3.8/site-packages/toolz/functoolz.py in __call__(self, *args, **kwargs)
#>     301     def __call__(self, *args, **kwargs):
#>     302         try:
#> --> 303             return self._partial(*args, **kwargs)
#>     304         except TypeError as exc:
#>     305             if self._should_curry(args, kwargs, exc):
#> ~/Git/py_grama/grama/eval_tail.py in eval_form_pma(model, betas, cons, df_corr, df_det, append, tol, n_maxiter, n_restart, verbose)
#>     134             res_all = []
#>     135             for jnd in range(n_restart):
#> --> 136                 res = minimize(
#>     137                     objective,
#>     138                     z0,
#> ~/.local/lib/python3.8/site-packages/scipy/optimize/_minimize.py in minimize(fun, x0, args, method, jac, hess, hessp, bounds, constraints, tol, callback, options)
#>     625         return _minimize_cobyla(fun, x0, args, constraints, **options)
#>     626     elif meth == 'slsqp':
#> --> 627         return _minimize_slsqp(fun, x0, args, jac, bounds,
#>     628                                constraints, callback=callback, **options)
#>     629     elif meth == 'trust-constr':
#> ~/.local/lib/python3.8/site-packages/scipy/optimize/slsqp.py in _minimize_slsqp(func, x0, args, jac, bounds, constraints, maxiter, ftol, iprint, disp, eps, callback, finite_diff_rel_step, **unknown_options)
#>     373 
#>     374     # ScalarFunction provides function and gradient evaluation
#> --> 375     sf = _prepare_scalar_function(func, x, jac=jac, args=args, epsilon=eps,
#>     376                                   finite_diff_rel_step=finite_diff_rel_step,
#>     377                                   bounds=new_bounds)
#> ~/.local/lib/python3.8/site-packages/scipy/optimize/optimize.py in _prepare_scalar_function(fun, x0, jac, args, bounds, epsilon, finite_diff_rel_step, hess)
#>     259     # ScalarFunction caches. Reuse of fun(x) during grad
#>     260     # calculation reduces overall function evaluations.
#> --> 261     sf = ScalarFunction(fun, x0, args, grad, hess,
#>     262                         finite_diff_rel_step, bounds, epsilon=epsilon)
#>     263 
#> ~/.local/lib/python3.8/site-packages/scipy/optimize/_differentiable_functions.py in __init__(self, fun, x0, args, grad, hess, finite_diff_rel_step, finite_diff_bounds, epsilon)
#>     134 
#>     135         self._update_fun_impl = update_fun
#> --> 136         self._update_fun()
#>     137 
#>     138         # Gradient evaluation
#> ~/.local/lib/python3.8/site-packages/scipy/optimize/_differentiable_functions.py in _update_fun(self)
#>     224     def _update_fun(self):
#>     225         if not self.f_updated:
#> --> 226             self._update_fun_impl()
#>     227             self.f_updated = True
#>     228 
#> ~/.local/lib/python3.8/site-packages/scipy/optimize/_differentiable_functions.py in update_fun()
#>     131 
#>     132         def update_fun():
#> --> 133             self.f = fun_wrapped(self.x)
#>     134 
#>     135         self._update_fun_impl = update_fun
#> ~/.local/lib/python3.8/site-packages/scipy/optimize/_differentiable_functions.py in fun_wrapped(x)
#>     128         def fun_wrapped(x):
#>     129             self.nfev += 1
#> --> 130             return fun(x, *args)
#>     131 
#>     132         def update_fun():
#> ~/Git/py_grama/grama/eval_tail.py in objective(z)
#>     112                 ## Transform: standard normal-to-random variable
#>     113                 df_norm = DataFrame(data=[z], columns=model.var_rand)
#> --> 114                 df_rand = model.norm2rand(df_norm)
#>     115                 df = model.var_outer(df_rand, df_det=df_inner)
#>     116 
#> ~/Git/py_grama/grama/core.py in norm2rand(self, df)
#>    1246         data = zeros((df.shape[0], self.n_var_rand))
#>    1247         for i in range(df.shape[0]):
#> -> 1248             data[i] = self.z2x(df[self.var_rand].iloc[i].values)
#>    1249 
#>    1250         return DataFrame(data=data, columns=self.var_rand)
#> ~/Git/py_grama/grama/core.py in z2x(self, z)
#>    1171         """
#>    1172         ## Correlate and map to uniform
#> -> 1173         u = self.density.copula.z2u(z)
#>    1174         ## Transform per marginal
#>    1175         x = zeros(self.n_var_rand)
#> AttributeError: 'NoneType' object has no attribute 'z2u'

Created on 2021-04-22 by the reprexpy package

@zdelrosario zdelrosario added the enhancement New feature or request label Apr 22, 2021
@zdelrosario zdelrosario self-assigned this Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant