You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# weights can also be an array, giving different mixing weights# for each observation (first dimension must be number of components)
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# While this code works for univariate normal, I failed to do so for two multivariate normal mixture. Here is a toy codeweights<- uniform(0,1,dim= c(2,10))
bb<- mixture(multivariate_normal(t(c(3,-3)), diag(1,2),n_realisations=10),
multivariate_normal(t(c(-3,3)), diag(1,2),n_realisations=10),
weights=weights)
#> Error in `initialize()`:#> ! The dimension of weights must be either "2x1" or "2x"#> but was ""
This error message didn't work and didn't tell the user what to do - I've now handled the way that we do the printing of the dimensions - effectively this allows us to pass it a dimension, or just a vector of numbers.
Print method is now:
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,#> tapplyweights<- uniform(0,1,dim= c(2,10))
bb<- mixture(multivariate_normal(t(c(3,-3)), diag(1,2),n_realisations=10),
multivariate_normal(t(c(-3,3)), diag(1,2),n_realisations=10),
weights=weights)
#> Error in `initialize()`:#> ! The dimension of weights must be either "2x1" or "2x10x2"#> but was "2x10"
Which tells us that we need dimension 2x10x2, which when we do that, we get the correct result:
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,#> tapplyweights<- uniform(0,1,dim= c(2,10, 2))
#> ℹ Initialising python and checking dependencies, this may take a moment.#> ✔ Initialising python and checking dependencies ... done!#> bb<- mixture(multivariate_normal(t(c(3,-3)), diag(1,2),n_realisations=10),
multivariate_normal(t(c(-3,3)), diag(1,2),n_realisations=10),
weights=weights)
From https://forum.greta-stats.org/t/issues-with-mixtures-of-multivariate-normal/368
Created on 2025-01-10 with reprex v2.1.1
Session info
This error message didn't work and didn't tell the user what to do - I've now handled the way that we do the printing of the dimensions - effectively this allows us to pass it a dimension, or just a vector of numbers.
Print method is now:
Created on 2025-01-10 with reprex v2.1.1
Session info
Which tells us that we need dimension 2x10x2, which when we do that, we get the correct result:
Created on 2025-01-10 with reprex v2.1.1
Session info
The text was updated successfully, but these errors were encountered: