#'SMOPposteriorBeta
#' 
#'@author Paola Marson, \email{paola.marson@meteo.fr}
#'
#'@description #takes as input the previous value of tau (typically from its posteriors) and the gaussian field x generated from the Gibbs sampling. It generates the current values of parameters beta. 
#'
#'@param tau   numeric previous value of tau; 
#'       x     array numeric of lenght mesh size containing the values of the latent gaussian field generated by the Gibbs Sampling;
#'       W     squared matrix of expected dimension side*side, where side is the number of spatial points in the side of the mesh, containing the spatial neighbours wights
#'       TT    elements managed inside the wrap function - more accurate desc will follow
#'       tX    elements managed inside the wrap function - more accurate desc will follow
#'       sigmasq numeric value of the variance 
#' 
#'@import Matrix
#'
#'@return array numeric of length 2 containing the generated values of beta (beta_1, beta_2)
#'
#'@example

SMOPposteriorBeta<-function(tau, W, TT, sigmasq){  
  require(mvrnorm)
  require(Matrix)        
  beta<-array(dim=2)
  object<-Matrix(In - tau*(W), doDiag=TRUE,sparse=TRUE)
  c<-(TT%*%(tX%*%as.matrix(object)%*%x)) +matrix(c(1/10000000000,0,0,1/10000000000),2)%*%c(1,1))   
beta<-mvrnorm(n = 1, mu=c, Sigma=sigmasq*TT, tol = 1e-6, empirical = FALSE, EISPACK = FALSE)

return(beta)
}