Contrast optimized stimulus generator (COSgen) is a highly parameterized genetic algorithm implementation to produce optimized stimulus sequences for clinical and preclinical fMRI. Our package is fully compatible with a pure Micro/Python stimulus delivery solution (COSplay), and provides a convenient and well documented API. Because of its modular structure, the implementation is highly adaptable for specific use cases.


  • High adaptability for specific use cases
  • Full compatability with COSgen
  • Custom model specification (design matrix construction, covariance matrix computation)
  • Custom fitness measure specification



The module can be installed using setuptools. Run python install inside the COSgen folder you downloaded. After installation you can use COSgen, make_test_data and estimate_autocorr directly as commands.