  Modelling a complex system is almost invariably a challenging task. The
incorporation of experimental observations can be used to improve the quality
of a model, and thus to obtain better predictions about the behavior of the
corresponding system. This approach, however, is affected by a variety of
different errors, especially when a system populates simultaneously an ensemble
of different states and experimental data are measured as averages over such
states. To address this problem we present a Bayesian inference method, called
metainference, that is able to deal with errors in experimental measurements as
well as with experimental measurements averaged over multiple states. To
achieve this goal, metainference models a finite sample of the distribution of
models using a replica approach, in the spirit of the replica-averaging
modelling based on the maximum entropy principle. To illustrate the method we
present its application to a heterogeneous model system and to the
determination of an ensemble of structures corresponding to the thermal
fluctuations of a protein molecule. Metainference thus provides an approach to
model complex systems with heterogeneous components and interconverting between
different states by taking into account all possible sources of errors.
