Open lionel68 opened 4 years ago
Using your code, I was not able to reproduce the error.
R v3.6.1 Greta v0.3.1 Python v3.6 TF v1.14 TF-Probability v0.7
Hi there, are you able to confirm if this error is still happening with the new version of greta?
There is a new approach in {greta} to installation, it involves some interactive prompts that arise when you install greta, which help setup a python environment with a specific version of python and other python packages. It should help make everything more reproducible and easier to implement. Are you able to give this a try? Let us know if you run into any issues and we will try and resolve as soon as possible.
# install.packages("remotes")
remotes::install_github("greta-dev/greta")
library(greta)
library(greta)
This will initialise python and trigger internal checks that make sure packages are installed. Something like this code is short and sweet and should trigger this.
model(normal(0,1))
Then this:
Follow these instructions:
install_greta_deps()
library(greta)
library(greta)
model(normal(0,1))
Let us know if this works! 😄
Just wanted to write that I get the same error on the latest version of greta:
library(greta)
#>
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#>
#> binomial, cov2cor, poisson
#> The following objects are masked from 'package:base':
#>
#> %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#> eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#> tapply
modmat <- model.matrix(~ Sepal.Width, iris)
# index of species
jj <- as.numeric(iris$Species)
M <- ncol(modmat) # number of varying coefficients
N <- max(jj) # number of species
# prior on the standard deviation of the varying coefficient
tau <- exponential(0.5, dim = M)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✓ Initialising python and checking dependencies ... done!
#>
# prior on the correlation between the varying coefficient
Omega <- lkj_correlation(3, M)
# optimization of the varying coefficient sampling through
# cholesky factorization and whitening
Omega_U <- chol(Omega)
Sigma_U <- sweep(Omega_U, 2, tau, "*")
z <- normal(0, 1, dim = c(N, M))
ab <- z %*% Sigma_U # equivalent to: ab ~ multi_normal(0, Sigma_U)
# the linear predictor
mu <- rowSums(ab[jj,] * modmat)
# the residual variance
sigma_e <- cauchy(0, 3, truncation = c(0, Inf))
#model
y <- as_data(iris$Sepal.Length)
distribution(y) <- normal(mu, sigma_e)
# get priors
calculate(y)
#> Error in py_call_impl(callable, dots$args, dots$keywords): InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_3' with dtype double and shape [1,2,2]
#> [[node Placeholder_3 (defined at /ops/array_ops.py:2143) ]]
#>
#> Original stack trace for 'Placeholder_3':
#> File "/ops/array_ops.py", line 2143, in placeholder
#> return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
#> File "/ops/gen_array_ops.py", line 6262, in placeholder
#> "Placeholder", dtype=dtype, shape=shape, name=name)
#> File "/framework/op_def_library.py", line 788, in _apply_op_helper
#> op_def=op_def)
#> File "/util/deprecation.py", line 507, in new_func
#> return func(*args, **kwargs)
#> File "/framework/ops.py", line 3616, in create_op
#> op_def=op_def)
#> File "/framework/ops.py", line 2005, in __init__
#> self._traceback = tf_stack.extract_stack()
#>
#>
#> Detailed traceback:
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 950, in run
#> run_metadata_ptr)
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1173, in _run
#> feed_dict_tensor, options, run_metadata)
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1350, in _do_run
#> run_metadata)
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1370, in _do_call
#> raise type(e)(node_def, op, message)
Created on 2022-03-18 by the reprex package (v2.0.1)
Working through this, here is a more minimal reproducible example - something is going wrong with how it is accessing/calculating chol
:
library(greta)
#>
#> Attaching package: 'greta'
#> The following objects are masked from 'package:stats':
#>
#> binomial, cov2cor, poisson, sd
#> The following objects are masked from 'package:base':
#>
#> %*%, apply, backsolve, beta, chol2inv, colMeans, colSums, diag,
#> eigen, forwardsolve, gamma, identity, rowMeans, rowSums, sweep,
#> tapply
Omega <- lkj_correlation(3, 2)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✓ Initialising python and checking dependencies ... done!
#>
# optimization of the varying coefficient sampling through
# cholesky factorization and whitening
Omega_U <- chol(Omega)
calculate(Omega, nsim = 3)
#> $Omega
#> , , 1
#>
#> [,1] [,2]
#> [1,] 1 0.2870519
#> [2,] 1 0.5621991
#> [3,] 1 0.3855464
#>
#> , , 2
#>
#> [,1] [,2]
#> [1,] 0.2870519 1
#> [2,] 0.5621991 1
#> [3,] 0.3855464 1
calculate(Omega_U, nsim = 3)
#> Error in py_call_impl(callable, dots$args, dots$keywords): InvalidArgumentError: You must feed a value for placeholder tensor 'Placeholder_1' with dtype double and shape [1,2,2]
#> [[node Placeholder_1 (defined at /ops/array_ops.py:2143) ]]
#>
#> Original stack trace for 'Placeholder_1':
#> File "/ops/array_ops.py", line 2143, in placeholder
#> return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
#> File "/ops/gen_array_ops.py", line 6262, in placeholder
#> "Placeholder", dtype=dtype, shape=shape, name=name)
#> File "/framework/op_def_library.py", line 788, in _apply_op_helper
#> op_def=op_def)
#> File "/util/deprecation.py", line 507, in new_func
#> return func(*args, **kwargs)
#> File "/framework/ops.py", line 3616, in create_op
#> op_def=op_def)
#> File "/framework/ops.py", line 2005, in __init__
#> self._traceback = tf_stack.extract_stack()
#>
#>
#> Detailed traceback:
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 950, in run
#> run_metadata_ptr)
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1173, in _run
#> feed_dict_tensor, options, run_metadata)
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1350, in _do_run
#> run_metadata)
#> File "/Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow/python/client/session.py", line 1370, in _do_call
#> raise type(e)(node_def, op, message)
Created on 2022-03-31 by the reprex package (v2.0.1)
While trying to use
calculate
to get prior distribution of an hierarchical model with correlated varying effect I get an error:Returns an error:
This was done with the following package versions:
R version 3.6.2 greta_0.3.1.9011