No BSD License  

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Sampling from multivariate correlated binary and poisson random variables

4.0 | 2 ratings Rate this file 13 Downloads (last 30 days) File Size: 71.7 KB File ID: #20591 Version: 1.0

Sampling from multivariate correlated binary and poisson random variables


Philipp Berens (view profile)


07 Jul 2008 (Updated )

These Matlab functions can be used to generate multivariate correlated binary variables, and correl

| Watch this File

File Information

You can use the software in this package to efficiently sample from
(1) correlated multivariate binary random variables (multivariate Bernoulli)
(2) correlated multivariate Poisson random variables
(3) correlated random variables with arbitrary marginal statistics.
Applications include modeling and generating of artificial neural data.

The implementation includes sampling and parameter fitting for the Dichotomized Gaussian distribution. For some parameters this provides and efficient alternative to the maximum-entropy distribution, the Ising model.

Detailed information about the contents are contained in the readme-file at For an instruction on how to use the code, run the demo.m script.

The methods implemented here are described in two publications:

J. H. Macke, P. Berens, et al., Generating spike-trains with specified correlation-coefficients, Neural Computation, 2008 (accepted) (

Matthias Bethge and Philipp Berens, Near-Maximum Entropy Models for Binary Neural Representations of Natural Images, Advances in Neural Information Processing 2008 (

Required Products Optimization Toolbox
Statistics and Machine Learning Toolbox
MATLAB release MATLAB 7.5 (R2007b)
Tags for This File   Please login to tag files.

No tags are associated with this file.

Please login to add a comment or rating.
Comments and Ratings (5)
21 Jul 2012 Kozlov Sacha

OK, I see, it's a problem of Win64 MatLab: C compiler is not included, so you have to download it first (see "mex -setup") and then compile your bivnor.c for this plateform ("mex bivnor.c").

Comment only
07 Apr 2010 Andrea Carbone

I really appreciate your work on spike train modeling. I am using the DG model to reproduce the statistics of a population of responses from a set ICA-like estimated receptive fields to visual stimuli from natural image statistics. the DG-generated population reproduce nicely the correlation patterns of the original dataset (in a very clever way, I'd say).

However, I found that the DG Covariance matrix generated by findLatentGaussian is often not definite positive or non-invertible (null determinant).

Is this an expected outcome of the algorithm implemented in findLatentGaussian?

Comment only
07 Apr 2010 Andrea Carbone  
08 Feb 2010 Philipp Berens

Philipp Berens (view profile)

Thank you for your inquiry. We decided not to switch this feature on in the default version (although the readme said so). In the version uploaded today, you just need to change line 33 to line 34 in sampleDichGauss01.m to use this feature.

Generally, higham.m may be used to obtain the closest correlation matrix to a predescribed matrix which is not a valid correlation matrix. In the case of sampling from binary variables, you can use this function to obtain a valid latent correlation matrix in case the usual transformation does not result in one.

Comment only
21 Dec 2009 Paolo Bocchini

The code is exactly what I am looking for.
Unfortunately, I almost always get the error
"A joint Bernulli distribution with the given covariance matrix does not exist!"
Isn't the code supposed to find an approximate latent Gaussian in this case?
Thank you,
Paolo Bocchini

Contact us