greta-dev / greta

simple and scalable statistical modelling in R
https://greta-stats.org
Other
541 stars 63 forks source link

multivariate_normal problem #251

Closed howardnewyork closed 2 years ago

howardnewyork commented 6 years ago

I am getting an error when I run models that previously worked when I use multivariate_normal.

I have tensorflow 1.12 installed (but not sure how to downgrade)

The error is:

Error: greta hit a tensorflow error:

Error in py_call_impl(callable, dots$args, dots$keywords): InvalidArgumentError: Offset dimension 0 in gather op is out of bounds; got 3, but should have been in [0,3).
     [[node MultivariateNormalTriL/log_prob/affine_linear_operator/inverse/LinearOperatorLowerTriangular/solve/LinearOperatorLowerTriangular/solve/MatrixTriangularSolve/MatrixTriangularSolve (defined at /home/howard/.virtualenvs/r-tensorflow/lib/python2.7/site-packages/tensorflow_probability/python/bijectors/affine_linear_operator.py:180)  = MatrixTriangularSolve[T=DT_DOUBLE, adjoint=false, lower=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](MultivariateNormalTriL/log_prob/affine_linear_operator/inverse/LinearOperatorLowerTriangular/solve/LinearOperatorLowerTriangular/solve/MatrixTriangularSolve/broadcast_matrix_batch_dims/add, MultivariateNormalTriL/log_prob/affine_linear_operator/inverse/LinearOperatorLowerTriangular/solve/LinearOperatorLowerTriangular/solve/MatrixTr

Here is an example that causes the problem. The example is taken straight from the greta website with the last two lines added

library(greta)

int  <- variable()
coef <- normal(0, 5)
sd   <- cauchy(0, 3, truncation = c(0, Inf))

n_species  <- length(unique(iris$Species))
species_id <- as.numeric(iris$Species)

Z <- model.matrix(~ Species + Sepal.Length * Species - 1, data = iris)
G  <- zeros(n_species * 2, n_species * 2)

for (s in unique(species_id)) {
  G[c(s, s + n_species), c(s, s + n_species)] <- diag(2)
}

mu <- int + coef * iris$Sepal.Width
V <- zeros(nrow(iris), nrow(iris))
diag(V) <- sd

Z <- as_data(Z)
V <- V + Z %*% G %*% t(Z)

sep <- t(iris$Sepal.Width)
distribution(sep) <- multivariate_normal(t(mu), V)

m= model(int, coef, sd)
draws=greta::mcmc(m, n_samples = 10, warmup=5)
howardnewyork commented 6 years ago

... also I am using the development version of Greta. If I use the CRAN version I get another error (which from prior posts appear to be a tensorflow 1.12 issue), namely:

 Error in py_call_impl(callable, dots$args, dots$keywords) : 
  ValueError: Tensor conversion requested dtype int64 for Tensor with dtype int32: 'Tensor("Placeholder_16:0", dtype=int32)' 
goldingn commented 6 years ago

Thanks!

Seems like another breaking change in TF/TFP. I'll take a look.

howardnewyork commented 6 years ago

Note: In my initial error, python 2.7 was referenced. I uninstalled and reinstalled everything to correctly point to python 3.6, but still get pretty much the same error (using development version of Greta):

Error: greta hit a tensorflow error:

Error in py_call_impl(callable, dots$args, dots$keywords): InvalidArgumentError: Offset dimension 0 in gather op is out of bounds; got 3, but should have been in [0,3).
     [[node MultivariateNormalTriL/log_prob/affine_linear_operator/inverse/LinearOperatorLowerTriangular/solve/LinearOperatorLowerTriangular/solve/MatrixTriangularSolve/MatrixTriangularSolve (defined at /home/howard/anaconda3/envs/r-tensorflow/lib/python3.6/site-packages/tensorflow_probability/python/bijectors/affine_linear_operator.py:180)  = MatrixTriangularSolve[T=DT_DOUBLE, adjoint=false, lower=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](MultivariateNormalTriL/log_prob/affine_linear_operator/inverse/LinearOperatorLowerTriangular/solve/LinearOperatorLowerTriangular/solve/MatrixTriangularSolve/broadcast_matrix_batch_dims/add, MultivariateNormalTriL/log_prob/affine_linear_operator/inverse/LinearOperatorLowerTriangular/solve/LinearOperatorLowerTriangular/solve/Matrix
goldingn commented 6 years ago

Yeah, that's gotta be a change to TFP then.

jeffreypullin commented 6 years ago

I cannot reproduce this error with Tensorflow 1.12 and Python 3.6.

Instead the model hits a matrix is not invertible error:

Error in py_call_impl(callable, dots$args, dots$keywords): InvalidArgumentError: Input matrix is not invertible.

When I run with one_by_one = TRUE the sampler runs, albeit it does not seem to explore the sample space well - all parameters stay on the initial values

howardnewyork commented 6 years ago

I basically cannot get any model with multivariate_normal to work. I am also using tensorflow-probability 0.5. Here are more details of my setup:

> tensorflow::tf_version()
[1] ‘1.12’
> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.5 LTS

Matrix products: default
BLAS: /usr/lib/libblas/libblas.so.3.6.0
LAPACK: /usr/lib/lapack/liblapack.so.3.6.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] bayesplot_1.6.0  coda_0.19-2      bindrcpp_0.2.2   greta_0.3.0.9001

loaded via a namespace (and not attached):
 [1] reticulate_1.10.0.9003 progress_1.2.0         tidyselect_0.2.5       Rook_1.1-1             purrr_0.2.5           
 [6] listenv_0.7.0          lattice_0.20-38        colorspace_1.3-2       viridisLite_0.3.0      htmltools_0.3.6       
[11] yaml_2.2.0             base64enc_0.1-3        XML_3.98-1.16          rlang_0.3.0.1          pillar_1.3.0          
[16] glue_1.3.0             RColorBrewer_1.1-2     bindr_0.1.1            plyr_1.8.4             stringr_1.3.1         
[21] tensorflow_1.9         munsell_0.5.0          gtable_0.2.0           visNetwork_2.0.4       future_1.10.0         
[26] htmlwidgets_1.3        codetools_0.2-15       tfruns_1.4             DiagrammeR_1.0.0       parallel_3.5.1        
[31] Rcpp_1.0.0             readr_1.1.1            scales_1.0.0           jsonlite_1.5           rgexf_0.15.3          
[36] gridExtra_2.3          brew_1.0-6             ggplot2_3.1.0          hms_0.4.2              digest_0.6.18         
[41] stringi_1.2.4          dplyr_0.7.8            grid_3.5.1             influenceR_0.1.0       tools_3.5.1           
[46] magrittr_1.5           lazyeval_0.2.1         tibble_1.4.2           tidyr_0.8.2            crayon_1.3.4          
[51] whisker_0.3-2          pkgconfig_2.0.2        Matrix_1.2-15          downloader_0.4         prettyunits_1.0.2     
[56] ggridges_0.5.1         viridis_0.5.1          assertthat_0.2.0       rstudioapi_0.8         R6_2.3.0              
[61] globals_0.12.4         igraph_1.2.2           compiler_3.5.1       
reticulate::py_config()
python:         /home/howard/anaconda3/envs/r-tensorflow/bin/python
libpython:      /home/howard/anaconda3/envs/r-tensorflow/lib/libpython3.6m.so
pythonhome:     /home/howard/anaconda3/envs/r-tensorflow:/home/howard/anaconda3/envs/r-tensorflow
version:        3.6.6 | packaged by conda-forge | (default, Oct 12 2018, 14:08:43)  [GCC 4.8.2 20140120 (Red Hat 4.8.2-15)]
numpy:          /home/howard/anaconda3/envs/r-tensorflow/lib/python3.6/site-packages/numpy
numpy_version:  1.15.4
tensorflow:     /home/howard/anaconda3/envs/r-tensorflow/lib/python3.6/site-packages/tensorflow
goldingn commented 6 years ago

Likewise, I can't replicate the error on OSX with TF 0.12.0 and TFP 0.5.0. Strange!

@howardnewyork could you please let me know the result of these commands (to get TF and TFP versions):

library(tensorflow)
pkg <- reticulate::import("pkg_resources")
tfp_version <- pkg$get_distribution("tensorflow_probability")$version
tf_version <- tf$`__version__`
tf_version
tfp_version

Just to make sure it's the TF and TFP versions you are expecting!

P.S. @Voltemand were your convergence issues on the example above, with warmup = 5 and n_samples = 10? If so, I would expect that, since the sampler needs some time to tune parameters.

jeffreypullin commented 6 years ago

@goldingn Good point! They were - I hadn't considered that.

howardnewyork commented 6 years ago
> tf_version
[1] "1.12.0"
> tfp_version
[1] "0.5.0"
howardnewyork commented 6 years ago

sorry - did not mean to close the issue. It is still a problem.

jeffreypullin commented 6 years ago

@howardnewyork Are you running this on a GPU or CPU?

howardnewyork commented 6 years ago

Gpu

On Wed, Nov 14, 2018 at 6:02 PM Voltemand notifications@github.com wrote:

@howardnewyork https://github.com/howardnewyork Are you running this on a GPU or CPU?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/greta-dev/greta/issues/251#issuecomment-438851752, or mute the thread https://github.com/notifications/unsubscribe-auth/ABunF5ZdJyGsS8-ta6PzMcQZv55W3cWpks5uvKDngaJpZM4YcWaa .

jeffreypullin commented 6 years ago

That probably explains why I at least can't reproduce it as I'm using a CPU.

howardnewyork commented 6 years ago

I can confirm that on the CPU version, the error does not occur, but the GPU version it does.

For the CPU version, you have to use the one_by_one = TRUE setting to avoid a matrix inversion problem. This setting makes no difference on the GPU version.

So the GPU version looks broken. I am not sure where to go from here.

goldingn commented 6 years ago

Thanks for checking that!

It's curious, since neither greta nor TFP (which appears to be throwing the error message) have any GPU-specific code, and similar code has run fine for me on a GPU previously.

I won't be able to debug this on a GPU-enabled machine this week, but will feed back as soon as I can.

goldingn commented 6 years ago

Here's a stopgap solution that may work (and will probably work better anyway), it's generally sensible to use a whitening transformation when doing MCMC on an unobserved multivariate normal. That looks something like this:

library(greta)
m <- 3
n <- 5
mu <- normal(0, 3, dim = c(n, m))
Sigma <- lkj_correlation(5, m)

# # usual multivariate normal
# x <- multivariate_normal(mu, Sigma, n_realisations = n)

# whitened version of multivariate normal, x is the same as above
U <- chol(Sigma)
z <- normal(0, 1, dim = c(n, m))
x <- mu + z %*% U
goldingn commented 6 years ago

At some point, I'd like to make this happen automatically, along with other tricks #47

howardnewyork commented 6 years ago

Thanks Nick... Some comments:

1: The problem does not go away. It looks like the issue occurs with the cholesky decomposition on the GPU. I think now this could be the same issue as #246. 2: The error shown (on my own problem using the whitening approach) is:

Error: greta hit a tensorflow error:

Error in py_call_impl(callable, dots$args, dots$keywords): InvalidArgumentError: Offset dimension 1 in gather op is out of bounds; got 3, but should have been in [0,3).
     [[node mcmc_sample_chain/mh_bootstrap_results/hmc_kernel_bootstrap_results/maybe_call_fn_and_grads/value_and_gradients/gradients/mcmc_sample_chain/mh_bootstrap_results/hmc_kernel_bootstrap_results/maybe_call_fn_and_grads/value_and_gradients/Cholesky_grad/MatrixTriangularSolve (defined at /home/howard/anaconda3/envs/r-tensorflow/lib/python3.6/site-packages/tensorflow_probability/python/mcmc/util.py:220)  = MatrixTriangularSolve[T=DT_DOUBLE, adjoint=false, lower=true, _device="/job:localhost/replica:0/task:0/device:GPU:0"](mcmc_sample_chain/mh_bootstrap_results/hmc_kernel_bootstrap_results/maybe_call_fn_and_grads/value_and_gradients/Cholesky, mcmc_sample_chain/mh_bootstrap_results/hmc_kernel_bootstrap_results/maybe_call_fn_and_grads/value_and_gradients/gradients/mcmc_sample_chain/m
  1. With regard to making the whitening approach the default method for multi-variate normal, I have found in models I built in Stan that the benefit of whitening can be quite problem specific. In some small data problems, whitening has had a significant deleterious effect. There is a discussion somewhere on the Stan forum (which I cannot find now) which deals with this in more depth. On other problems, whitening can make a huge positive difference. As such, if you are going to change the multivariate_normal function I would recommend including a parameter to allow the user to choose a whitening vs. non-whitening algorithm.

  2. Also, if x is the training data, and Sigma can be decomposed into Sigma = K + s*I, where I is an identity matrix, (as is usually the case with Gaussian Process models), then I can see the whitening method be programmed as:

U <- chol(K)
z <- normal(0, 1, dim = c(n, m))
f <- mu + z %*% U
distribution(x)  = normal(f, s)

But if Sigma cannot be decomposed in such a way, it is not clear to me how the method can be generalized for all multivariate normal distributions.

Thanks again for all your help on this!!!

goldingn commented 5 years ago

Hmmmm, that is strange and frustrating. I'll leave this open until I have a chance to debug this and #246 on a GPU

  1. That's interesting, I've not yet run into a case where it doesn't work better. But I'm usually working on Gaussian processes, and I can see that if the posterior correlations in the random variables are very different from those defined in the covariance matrix, then whitening would make things worse. Definitely important to have that switch!

  2. In the case you describe, the multivariate normal variable is observed (it's data, not a parameter), so there's nothing to be gained from whitening in that case anyway. That's the tricky bit of the automatic whitening idea, being able to undo the whitening once the distribution is moved from a variable onto data (the bit I just mentioned in #47, @Voltemand ).

drewancameron commented 5 years ago

Did y'all ever fix this? I'm having the same error whenever trying to sample a model with the mcmc() command. opt() works fine though.

goldingn commented 5 years ago

I wasn't able to replicate the error. Though I haven't had much of a chance to try either.

If you were able to replicate your error in a minimal reproducible example, that would really help.

drewancameron commented 5 years ago

The most minimal example returns the error for me:

library(greta)

int <- normal(0, 10) coef <- normal(0, 10) sd <- cauchy(0, 3, truncation = c(0, Inf))

n_species <- length(unique(iris$Species)) species_id <- as.numeric(iris$Species)

Z <- model.matrix(~ Species + Sepal.Length * Species - 1, data = iris)

gamma_matrix <- multivariate_normal(matrix(0, 1, 2), diag(2), n_realisations = 3) gamma <- c(gamma_matrix)

wi <- as_data(iris$Sepal.Width) Z <- as_data(Z) mu <- int + coef wi + Z %% gamma

distribution(iris$Sepal.Length) <- normal(mu, sd)

m <- model(int,coef,sd) draws <- mcmc(m)

Error in py_call_impl(callable, dots$args, dots$keywords) : ValueError: Tensor conversion requested dtype int64 for Tensor with dtype int32: 'Tensor("Placeholder_16:0", dtype=int32)'

My tensorflow version is 1.13 and I'm running on a dell laptop with Nvidia gpu

On Fri, 21 Jun 2019 at 10:28, Nick Golding notifications@github.com wrote:

I wasn't able to replicate the error. Though I haven't had much of a chance to try either.

If you were able to replicate your error in a minimal reproducible example, that would really help.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/greta-dev/greta/issues/251?email_source=notifications&email_token=ACVNJQQNVFLAWMXSMGT2YB3P3SNKBA5CNFSM4GDRM2NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYH6TII#issuecomment-504359329, or mute the thread https://github.com/notifications/unsubscribe-auth/ACVNJQQPZPZVVUNGJZJEGRDP3SNKBANCNFSM4GDRM2NA .

goldingn commented 5 years ago

Can you (re-)install the version of greta from GitHub and run it again? I think that error is an issue with TF probability we managed to work around in the most recent version

drewancameron commented 5 years ago

I just did but i still get the error. There were some warnings on the installation that might be relevant:

devtools::install_github("greta-dev/greta") Downloading GitHub repo greta-dev/greta@master from URL https://api.github.com/repos/greta-dev/greta/zipball/master Installing greta Installing 1 package: coda Installing package into ‘C:/Users/zool1232/Documents/R/win-library/3.4’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/coda_0.19-2.zip ' Content type 'application/zip' length 201882 bytes (197 KB) downloaded 197 KB

package ‘coda’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in C:\Users\zool1232\AppData\Local\Temp\Rtmp6r5xGq\downloaded_packages Installing 1 package: R6 Installing package into ‘C:/Users/zool1232/Documents/R/win-library/3.4’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/R6_2.4.0.zip' Content type 'application/zip' length 36837 bytes (35 KB) downloaded 35 KB

package ‘R6’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in C:\Users\zool1232\AppData\Local\Temp\Rtmp6r5xGq\downloaded_packages "C:/PROGRA~1/R/R-34~1.3/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL \

"C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0" \ --library="C:/Users/zool1232/Documents/R/win-library/3.4" --install-tests

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

On Fri, 21 Jun 2019 at 11:44, Nick Golding notifications@github.com wrote:

Can you (re-)install the version of greta from GitHub and run it again? I think that error is an issue with TF probability we managed to work around in the most recent version

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/greta-dev/greta/issues/251?email_source=notifications&email_token=ACVNJQQEUEMGCS3Y7A5VU4LP3SWIRA5CNFSM4GDRM2NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYIEBNY#issuecomment-504381623, or mute the thread https://github.com/notifications/unsubscribe-auth/ACVNJQX3B2FO5KURMV7SCD3P3SWIRANCNFSM4GDRM2NA .

drewancameron commented 5 years ago

and it runs fine if I do Sys.setenv("CUDA_VISIBLE_DEVICES" = -1)

On Fri, 21 Jun 2019 at 11:46, Ewan Cameron dr.ewan.cameron@gmail.com wrote:

I just did but i still get the error. There were some warnings on the installation that might be relevant:

devtools::install_github("greta-dev/greta") Downloading GitHub repo greta-dev/greta@master from URL https://api.github.com/repos/greta-dev/greta/zipball/master Installing greta Installing 1 package: coda Installing package into ‘C:/Users/zool1232/Documents/R/win-library/3.4’ (as ‘lib’ is unspecified) trying URL ' https://cran.rstudio.com/bin/windows/contrib/3.4/coda_0.19-2.zip' Content type 'application/zip' length 201882 bytes (197 KB) downloaded 197 KB

package ‘coda’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in C:\Users\zool1232\AppData\Local\Temp\Rtmp6r5xGq\downloaded_packages Installing 1 package: R6 Installing package into ‘C:/Users/zool1232/Documents/R/win-library/3.4’ (as ‘lib’ is unspecified) trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.4/R6_2.4.0.zip' Content type 'application/zip' length 36837 bytes (35 KB) downloaded 35 KB

package ‘R6’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in C:\Users\zool1232\AppData\Local\Temp\Rtmp6r5xGq\downloaded_packages "C:/PROGRA~1/R/R-34~1.3/bin/x64/R" --no-site-file --no-environ --no-save --no-restore --quiet CMD INSTALL \

"C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0" \ --library="C:/Users/zool1232/Documents/R/win-library/3.4" --install-tests

  • installing source package 'greta' ... R inst tests preparing package for lazy loading help ** installing help indices converting help for package 'greta' finding HTML links ... done as_data html calculate html distribution html distributions html Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:175: missing file link 'dunif' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:176: missing file link 'dnorm' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:177: missing file link 'dlnorm' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:179: missing file link 'dbinom' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:181: missing file link 'dnbinom' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:182: missing file link 'dhyper' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:183: missing file link 'dpois' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:184: missing file link 'dgamma' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:186: missing file link 'dweibull' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:187: missing file link 'dexp' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:191: missing file link 'dbeta' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:192: missing file link 'dcauchy' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:193: missing file link 'dchisq' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:194: missing file link 'dlogis' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:195: missing file link 'df' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:196: missing file link 'dmvnorm' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:197: missing file link 'dmultinom' Rd warning: C:/Users/zool1232/AppData/Local/Temp/Rtmp6r5xGq/devtools19842b28e98/greta-dev-greta-cde31d0/man/distributions.Rd:198: missing file link 'dmultinom' extract-replace-combine html functions html greta html inference html internals html joint html mixture html model html operators html optimisers html overloaded html reexports html samplers html structures html transforms html variable html copying figures building package indices installing vignettes testing if installed package can be loaded ** arch - i386 arch - x64
  • DONE (greta) In R CMD INSTALL Reloading installed 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

On Fri, 21 Jun 2019 at 11:44, Nick Golding notifications@github.com wrote:

Can you (re-)install the version of greta from GitHub and run it again? I think that error is an issue with TF probability we managed to work around in the most recent version

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/greta-dev/greta/issues/251?email_source=notifications&email_token=ACVNJQQEUEMGCS3Y7A5VU4LP3SWIRA5CNFSM4GDRM2NKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYIEBNY#issuecomment-504381623, or mute the thread https://github.com/notifications/unsubscribe-auth/ACVNJQX3B2FO5KURMV7SCD3P3SWIRANCNFSM4GDRM2NA .

goldingn commented 5 years ago

Hmmm, strange. Thanks for running that. I suspect this may be a TF probability x GPU interaction, given it optimises fine. I've not had problems like this with GPUs on Google Cloud Compute, so may even be device specific

It's a wild guess, but you could try doing precision = 'single' in the call to model()?

njtierney commented 3 years ago

Hi there! :wave:

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?

Install current master branch of greta

# install.packages("remotes")
remotes::install_github("greta-dev/greta")

Restart R

Load greta with library(greta)

library(greta)

image

Create a greta model

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))

image

Then this:

image

Follow these instructions:

Install greta dependencies

install_greta_deps()

image

image

image

Restart R + run library(greta)

library(greta)

Create a greta model

model(normal(0,1))

image

image

Let us know if this works! 😄

njtierney commented 2 years ago

I could not replicate the errors given above in the latest version of greta (0.4.1)

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

int  <- normal(0, 10)
#> ℹ Initialising python and checking dependencies, this may take a moment.
#> ✓ Initialising python and checking dependencies ... done!
#> 
coef <- normal(0, 10)
sd   <- cauchy(0, 3, truncation = c(0, Inf))

n_species  <- length(unique(iris$Species))
species_id <- as.numeric(iris$Species)

Z <- model.matrix(~ Species + Sepal.Length * Species - 1, data = iris)

gamma_matrix <- multivariate_normal(matrix(0, 1, 2),
                                    diag(2),
                                    n_realisations = 3)
gamma <- c(gamma_matrix)

wi <- as_data(iris$Sepal.Width)
Z  <- as_data(Z)
mu <- int + coef * wi + Z %*% gamma

distribution(iris$Sepal.Length) <- normal(mu, sd)

m <- model(int,coef,sd)
draws <- mcmc(m)
#> running 4 chains simultaneously on up to 8 cores

\#\> warmup 0/1000 \| eta: ?s warmup == 50/1000 \| eta: 48s \| 4% bad warmup ==== 100/1000 \| eta: 31s \| 2% bad warmup ====== 150/1000 \| eta: 24s \| 1% bad warmup ======== 200/1000 \| eta: 20s \| \<1% bad warmup ========== 250/1000 \| eta: 18s \| \<1% bad warmup =========== 300/1000 \| eta: 16s \| \<1% bad warmup ============= 350/1000 \| eta: 14s \| \<1% bad warmup =============== 400/1000 \| eta: 13s \| \<1% bad warmup ================= 450/1000 \| eta: 11s \| \<1% bad warmup =================== 500/1000 \| eta: 10s \| \<1% bad warmup ===================== 550/1000 \| eta: 9s \| \<1% bad warmup ======================= 600/1000 \| eta: 8s \| \<1% bad warmup ========================= 650/1000 \| eta: 7s \| \<1% bad warmup =========================== 700/1000 \| eta: 6s \| \<1% bad warmup ============================ 750/1000 \| eta: 5s \| \<1% bad warmup ============================== 800/1000 \| eta: 4s \| \<1% bad warmup ================================ 850/1000 \| eta: 3s \| \<1% bad warmup ================================== 900/1000 \| eta: 2s \| \<1% bad warmup ==================================== 950/1000 \| eta: 1s \| \<1% bad warmup ====================================== 1000/1000 \| eta: 0s \| \<1% bad
\#\> sampling 0/1000 \| eta: ?s sampling == 50/1000 \| eta: 11s sampling ==== 100/1000 \| eta: 12s sampling ====== 150/1000 \| eta: 11s sampling ======== 200/1000 \| eta: 11s sampling ========== 250/1000 \| eta: 10s sampling =========== 300/1000 \| eta: 9s sampling ============= 350/1000 \| eta: 8s sampling =============== 400/1000 \| eta: 8s sampling ================= 450/1000 \| eta: 7s sampling =================== 500/1000 \| eta: 6s sampling ===================== 550/1000 \| eta: 6s sampling ======================= 600/1000 \| eta: 5s sampling ========================= 650/1000 \| eta: 5s sampling =========================== 700/1000 \| eta: 4s sampling ============================ 750/1000 \| eta: 4s sampling ============================== 800/1000 \| eta: 3s sampling ================================ 850/1000 \| eta: 2s sampling ================================== 900/1000 \| eta: 1s sampling ==================================== 950/1000 \| eta: 1s sampling ====================================== 1000/1000 \| eta: 0s

Created on 2022-03-18 by the reprex package (v2.0.1)

Session info ```r sessioninfo::session_info() #> ─ Session info ─────────────────────────────────────────────────────────────── #> setting value #> version R version 4.1.3 (2022-03-10) #> os macOS Big Sur/Monterey 10.16 #> system x86_64, darwin17.0 #> ui X11 #> language (EN) #> collate en_AU.UTF-8 #> ctype en_AU.UTF-8 #> tz Australia/Perth #> date 2022-03-18 #> pandoc 2.17.1.1 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/ (via rmarkdown) #> #> ─ Packages ─────────────────────────────────────────────────────────────────── #> package * version date (UTC) lib source #> abind 1.4-5 2016-07-21 [1] CRAN (R 4.1.0) #> backports 1.4.1 2021-12-13 [1] CRAN (R 4.1.0) #> base64enc 0.1-3 2015-07-28 [1] CRAN (R 4.1.0) #> callr 3.7.0 2021-04-20 [1] CRAN (R 4.1.0) #> cli 3.2.0 2022-02-14 [1] CRAN (R 4.1.2) #> coda 0.19-4 2020-09-30 [1] CRAN (R 4.1.0) #> codetools 0.2-18 2020-11-04 [1] CRAN (R 4.1.3) #> crayon 1.5.0 2022-02-14 [1] CRAN (R 4.1.2) #> digest 0.6.29 2021-12-01 [1] CRAN (R 4.1.0) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.1.0) #> evaluate 0.15 2022-02-18 [1] CRAN (R 4.1.2) #> fansi 1.0.2 2022-01-14 [1] CRAN (R 4.1.2) #> fastmap 1.1.0 2021-01-25 [1] CRAN (R 4.1.0) #> fs 1.5.2 2021-12-08 [1] CRAN (R 4.1.0) #> future 1.24.0 2022-02-19 [1] CRAN (R 4.1.2) #> globals 0.14.0 2020-11-22 [1] CRAN (R 4.1.0) #> glue 1.6.2 2022-02-24 [1] CRAN (R 4.1.2) #> greta * 0.4.1 2022-03-15 [1] CRAN (R 4.1.2) #> here 1.0.1 2020-12-13 [1] CRAN (R 4.1.0) #> highr 0.9 2021-04-16 [1] CRAN (R 4.1.0) #> hms 1.1.1 2021-09-26 [1] CRAN (R 4.1.0) #> htmltools 0.5.2 2021-08-25 [1] CRAN (R 4.1.0) #> jsonlite 1.8.0 2022-02-22 [1] CRAN (R 4.1.2) #> knitr 1.37 2021-12-16 [1] CRAN (R 4.1.0) #> lattice 0.20-45 2021-09-22 [1] CRAN (R 4.1.3) #> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.0) #> listenv 0.8.0 2019-12-05 [1] CRAN (R 4.1.0) #> magrittr 2.0.2 2022-01-26 [1] CRAN (R 4.1.2) #> Matrix 1.4-0 2021-12-08 [1] CRAN (R 4.1.3) #> parallelly 1.30.0 2021-12-17 [1] CRAN (R 4.1.0) #> pillar 1.7.0 2022-02-01 [1] CRAN (R 4.1.2) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.1.0) #> png 0.1-7 2013-12-03 [1] CRAN (R 4.1.0) #> prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.1.0) #> processx 3.5.2 2021-04-30 [1] CRAN (R 4.1.0) #> progress 1.2.2 2019-05-16 [1] CRAN (R 4.1.0) #> ps 1.6.0 2021-02-28 [1] CRAN (R 4.1.0) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.0) #> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.1.0) #> R.methodsS3 1.8.1 2020-08-26 [1] CRAN (R 4.1.0) #> R.oo 1.24.0 2020-08-26 [1] CRAN (R 4.1.0) #> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.1.0) #> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.0) #> Rcpp 1.0.8.2 2022-03-11 [1] CRAN (R 4.1.2) #> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.0) #> reticulate 1.24 2022-01-26 [1] CRAN (R 4.1.2) #> rlang 1.0.2 2022-03-04 [1] CRAN (R 4.1.2) #> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.0) #> rprojroot 2.0.2 2020-11-15 [1] CRAN (R 4.1.0) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 4.1.0) #> sessioninfo 1.2.2.9000 2022-03-01 [1] Github (r-lib/sessioninfo@d70760d) #> stringi 1.7.6 2021-11-29 [1] CRAN (R 4.1.0) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.0) #> styler 1.6.2 2021-09-23 [1] CRAN (R 4.1.0) #> tensorflow 2.8.0 2022-02-09 [1] CRAN (R 4.1.2) #> tfruns 1.5.0 2021-02-26 [1] CRAN (R 4.1.0) #> tibble 3.1.6 2021-11-07 [1] CRAN (R 4.1.0) #> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.0) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 4.1.0) #> whisker 0.4 2019-08-28 [1] CRAN (R 4.1.0) #> withr 2.5.0 2022-03-03 [1] CRAN (R 4.1.2) #> xfun 0.30 2022-03-02 [1] CRAN (R 4.1.2) #> yaml 2.3.5 2022-02-21 [1] CRAN (R 4.1.2) #> #> [1] /Library/Frameworks/R.framework/Versions/4.1/Resources/library #> #> ─ Python configuration ─────────────────────────────────────────────────────── #> python: /Users/njtierney/Library/r-miniconda/envs/greta-env/bin/python #> libpython: /Users/njtierney/Library/r-miniconda/envs/greta-env/lib/libpython3.7m.dylib #> pythonhome: /Users/njtierney/Library/r-miniconda/envs/greta-env:/Users/njtierney/Library/r-miniconda/envs/greta-env #> version: 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 05:59:23) [Clang 11.1.0 ] #> numpy: /Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/numpy #> numpy_version: 1.16.4 #> tensorflow: /Users/njtierney/Library/r-miniconda/envs/greta-env/lib/python3.7/site-packages/tensorflow #> #> NOTE: Python version was forced by use_python function #> #> ──────────────────────────────────────────────────────────────────────────────

Closing this issue as it seems to be related to installation issues, which are hopefully solved in the latest release of greta. Happy to reopen this to explore further!