{'fraction_non_alphanumeric': 0.04417462726542273, 'fraction_numerical': 0.017837693063119366, 'mean_word_length': 4.5287265547877595, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Spectral density-based and measure-preserving ABC for partially observed diffusion processes. An illustration on Hamiltonian SDEs

Approximate Bayesian computation (ABC) has become one of the major tools of likelihood-free statistical inference in complex mathematical models. Simultaneously, stochastic differential equations (SDEs) have developed to an established tool for modelling time-dependent, real-world phenomena with underlying random effects. When applying ABC to stochastic models, two major difficulties arise: First, the derivation of effective summary statistics and proper distances is particularly challenging, since simulations from the stochastic process under the same parameter configuration result in different trajectories. Second, exact simulation schemes to generate trajectories from the stochastic model are rarely available, requiring the derivation of suitable numerical methods for the synthetic data generation. To obtain summaries that are less sensitive to the intrinsic stochasticity of the model, we propose to build up the statistical method (e.g. the choice of the summary statistics) on the underlying structural properties of the model. Here, we focus on the existence of an invariant measure and we map the data to their estimated invariant density and invariant spectral density. Then, to ensure that these model properties are kept in the synthetic data generation, we adopt measure-preserving numerical splitting schemes. The derived property-based and measure-preserving ABC method is illustrated on the broad class of partially observed Hamiltonian type SDEs, both with simulated data and with real electroencephalography data. The derived summaries are particularly robust to the model simulation, and this fact, combined with the proposed reliable numerical scheme, yields accurate ABC inference. In contrast, the inference returned using standard numerical methods (Euler–Maruyama discretisation) fails. The proposed ingredients can be incorporated into any type of ABC algorithm and directly applied to all SDEs that are characterised by an invariant distribution and for which a measure-preserving numerical method can be derived.


Introduction
Over the last decades, stochastic differential equations (SDEs) have become an established and powerful tool for modelling time-dependent, real-world phenomena with underlying random effects. They have been successfully applied to a variety of scientific fields, ranging from biology over finance to physics, chemistry, neuroscience and others. Diffusion processes obtained as solutions of SDEs are typically characterised by some underlying structural properties whose investigation and preservation are crucial. Examples are boundary properties, symmetries or the preservation of invariants or qualitative behaviour such as the ergodicity or the conservation of energy. Here, we focus on a specific structural property, namely the existence of a unique invariant measure. Besides the modelling, it is of primary interest to estimate the underlying model parameters. This is particularly difficult when the multivariate stochastic process is only partially observed through a 1-dimensional function of its coordinates (the output process), a scenario that we tackle here. Moreover, due to the complexity of SDEs, needed to understand and reproduce the real data, the underlying likelihood is often unknown or intractable. Among several likelihood-free inference approaches, we focus on the simulation-based approximate Bayesian computation (ABC) method. We refer to Marin et al. (2012) and to the recently published book "Handbook of approximate Bayesian computation" for an exhaustive discussion .
ABC has become one of the major tools for parameter inference in complex mathematical models in the last decade. The method is based on the idea of deriving an approximate posterior density targeting the true (unavailable) posterior by running massive simulations from the model to replace the intractable likelihood. It was first introduced in the context of population genetics; see, e.g. Beaumont et al. (2002). Since then, it has been successfully applied in a wide range of fields; see, e.g. Barnes et al. (2012), Blum (2010a), Boys et al. (2008), McKinley et al. (2017), Moores et al. (2015) and Toni et al. (2009). Moreover, ABC has also been proposed to infer parameters from time series models (see, e.g. Drovandi et al. 2016;Jasra 2015), state space models (see, e.g. Martin et al. 2019;Tancredi 2019) and SDE models (see, e.g. Kypraios et al. 2017;Maybank et al. 2017;Picchini 2014;Picchini and Forman 2016;Picchini and Samson 2018;Sun et al. 2015;Zhu et al. 2016). Several advanced ABC algorithms have been proposed in the literature, such as sequential Monte Carlo (SMC) ABC, Markov Chain Monte Carlo (MCMC) ABC, sequential annealing ABC, noisy ABC; see, e.g. Fan and Sisson (2018) and the references therein for a recent review. The idea of the basic acceptance-rejection ABC algorithm is to keep a sampled parameter value from the prior as a realisation from the approximate posterior, if the distance between the summary statistics of the synthetic dataset, which is generated conditioned on this parameter value, and the summaries of the original reference data is smaller than some tolerance level. The goal of this paper is to illustrate how building up the ABC method on the structural properties of the underlying SDE, and using a numerical method capable of preserving them in the generation of the data from the model, leads to a successful inference even when applying ABC in this basic acceptance-rejection form.
The performance of any ABC method depends heavily on the choice of "informative enough" summary statistics, a suitable distance measure and a tolerance level . The quality of the approximation improves as decreases, and it has been shown that, under some conditions, the approximated ABC posterior converges to the true one when → 0 (Jasra 2015). At the same time though, the computational cost increases when decreases. A possibility is to use ad hoc threshold selection procedures; see, e.g. Barber et al. (2015), Blum (2010b), Lintusaari et al. (2017), Prangle et al. (2014) and Robert (2016). Here, we fix the tolerance level as a percentile of the calculated distances. This is another common practice known as "reference table acceptancerejection ABC" (Cornuet et al. 2008) and used, for example, in Beaumont et al. (2002), Biau et al. (2015), Sun et al. (2015) and Vo et al. (2015). Instructions for constructing effective summaries and distances are rare, and they depend on the problem under consideration; see, e.g. Fearnhead and Prangle (2012) for a semiautomatic linear regression approach, Jiang et al. (2017) for an automatic construction approach based on training deep neural networks and Blum (2010b) and Prangle (2018) for two recent reviews. To avoid the information loss caused by using non-sufficient summary statistics, another common procedure is to work with the entire dataset; see, e.g. Jasra (2015) and Sun et al. (2015). This requires the application of more sophisticated distances d such as the Wasserstein metric (Bernton et al. 2019;Muskulus and Verduyn-Lunel 2011) or other distances designed for time series; for an overview see, e.g. Mori et al. (2016) and the references therein.
When working with stochastic models, simulations from the stochastic simulator, conditionally to the same parameter configuration, yield different trajectories. To consider summary statistics that are less sensitive to the intrinsic stochasticity of the model (Wood 2010), we choose them based on the structural property of an underlying invariant measure. The idea is to map the data, i.e. the realisations of the output process, to an object that is invariant for repeated simulations under the same parameter setting and is instead sensitive to small changes in the parameters. In particular, we map the data to their estimated invariant density and invariant spectral density, taking thus the dependence structure of the dynamical model into account. The distance measure can then be chosen according to the mapped data.
As other simulation-based statistical methods, e.g. MCMC, SMC or machine learning algorithms, ABC relies on the ability of simulating data from the model. However, the exact simulation from complex stochastic models is rarely possible, and thus, numerical methods need to be applied. This introduces a new level of approximation into the ABC framework. When the statistical method is build upon the structural properties of the underlying model, the successful inference can only be guaranteed when these properties are preserved in the synthetic data generated from the model. However, the issue of deriving a property-preserving numerical method when applying ABC to SDEs is usually seen as not so relevant, and it is usually recommended to use the Euler-Maruyama scheme or one of the higher-order approximation methods described in Kloeden and Platen (1992); see, e.g. Picchini (2014), Picchini and Forman (2016), Picchini and Samson (2018) and Sun et al. (2015). In general, these standard methods do not preserve the underlying structural local and global properties of the model; see, e.g. Ableidinger et al. (2017), Malham and Wiese (2013), Moro and Schurz (2007) and Strømmen Melbø and Higham (2004).
Here, we propose to apply structure-preserving numerical splitting schemes within the ABC algorithm. The idea of these methods is to split the SDE into explicitly solvable subequations and to apply a proper composition of the resulting exact solutions. Standard procedures are, for example, the Lie-Trotter method and the usually more accurate Strang approach; see, e.g. Leimkuhler et al. (2016). Since the only approximation enters through the composition of the derived explicit solutions, numerical splitting schemes usually preserve the structural properties of the underlying SDE and accurately reproduce its qualitative behaviour. Moreover, they usually have the same order of convergence as the frequently applied Euler-Maruyama method and are likewise efficient. We refer to Blanes et al. (2009) and Mclachlan and Quispel (2002) for an exhaustive discussion of splitting methods for broad classes of ordinary differential equations (ODEs), which partially have already been carried over to SDEs; see, e.g. Misawa (2001) for a general class of SDEs, Ableidinger and Buckwar (2016) for the stochastic Landau-Lifshitz equations, Bréhier and Goudenège (2019) for the Allen-Cahn equation and Ableidinger et al. (2017) for Hamiltonian type SDEs.
The main contribution of this work lies in the combination of the proposed invariant measure-based summary statistics and the measure-preserving numerical splitting schemes within the ABC framework. We demonstrate that a simulation-based inference method, here ABC, can only perform well if the underlying simulation method preserves the structural properties of the SDE. While the use of preserving splitting schemes within the ABC method yields successful results, applying a general purpose numerical method, such as the Euler-Maruyama discretisation, may result in seriously wrong inferences. We illustrate the proposed spectral density-based and measure-preserving ABC method on the class of stochastic Hamiltonian type equations for which the existence of an underlying unique invariant distribution and measure-preserving numerical splitting schemes have been already intensively studied in the literature; see, e.g. Ableidinger et al. (2017), Mattingly et al. (2002), Leimkuhler and Matthews (2015) and Milstein and Tretyakov (2004). Hamiltonian type SDEs have been investigated in molecular dynamics, where they are typically referred to as Langevin equations; see, e.g. Leimkuhler and Matthews (2015). Recently, they have also received considerable attention in the field of neuroscience as the so-called neural mass models (Ableidinger et al. 2017).
The paper is organised as follows: In Sect. 2, we recall the acceptance-rejection ABC setting. We introduce the invariant measure-based summary statistics and propose a proper distance. We then discuss the importance of considering measure-preserving numerical schemes for the synthetic data generation when exact simulation methods are not applicable and provide a short introduction to numerical splitting meth-ods. In Sect. 3, we introduce Hamiltonian type SDEs and recall two splitting integrators preserving the invariant measure of the model. In Sect. 4, we validate the proposed method by investigating the stochastic harmonic oscillator, for which exact simulation is possible. In Sect. 5, we apply the proposed ABC method to the stochastic Jansen and Rit neural mass model (JR-NMM). We refer to Jansen and Rit (1995) for the original version, an ODE with a stochastic input function, and to Ableidinger et al. (2017) for its reformulation as a Hamiltonian type SDE. This model has been reported to successfully reproduce electroencephalography (EEG) data. We illustrate the performance of the proposed ABC method with both simulated and real data. Final remarks, possible extensions and conclusions are reported in Sect. 6. A supplementary material (Online Resource 1) with further illustrations of the proposed method is available online, and a sample code used to generate the main results is available on github at https://github. com/massimilianotamborrino/sdbmpABC.

Spectral density-based and measure-preserving ABC for partially observed SDEs with an invariant distribution
Let (Ω, F, P) be a complete probability space with right continuous and complete filtration F = {F} t∈ [0,T ] . Let θ = (θ 1 , . . . , θ k ), k ∈ N, be a vector of relevant model parameters. We consider the following n-dimensional, n ∈ N, non-autonomous SDE of Itô-type describing the time evolution of a system of interest The initial value X 0 is either deterministic or a R n -valued random variable, measurable with respect to F. Here, W = (W (t)) t∈[0,T ] is a r -dimensional, r ∈ N, Wiener process with independent and F-adapted components. We further assume that the drift component f : [0, T ] × R n → R n and the diffusion component G : [0, T ] × R n → R n×r fulfil the necessary global Lipschitz and linear growth conditions, such that the existence and the pathwise uniqueness of an F-adapted strong solution process X = (X (t)) t∈[0,T ] ∈ R n of (1) are guaranteed; see, e.g. Arnold (1974). We aim to infer the parameter vector θ inherent in the SDE (1), when the n-dimensional solution process X is only partially observed through the 1-dimensional and parameterdependent output process where g : R n → R is a real-valued continuous function of the components of X. Here, we assume that the process Y θ is observed without measurement error, referring to, e.g. Picchini (2014) and Picchini and Forman (2016), where the measurement error is taken into account. Further, we assume a specific underlying structural model property, namely the existence of a unique invariant measure η Y θ on (R, B(R)) of the output process Y θ , where B denotes the Borel Sigma-algebra. The process has invariant density f Y θ and mean, autocovariance and variance given by If the solution process X of SDE (1) admits an invariant distribution η X on (R n , B(R n )), then the output process Y θ inherits this structural property by means of the marginal invariant distributions of η X . Furthermore, if X (0) ∼ η X , then the process Y θ = (Y θ (t)) t∈[0,∞) evolves according to the distribution η Y θ for all t ≥ 0. Our goal is to perform statistical inference for the parameter vector θ of the SDE (1), when the solution process X is partially observed through discrete time measurements of the output process Y θ given in (2), by benefiting from the (in general unknown) invariant distribution η Y θ satisfying (3).

The ABC method
Let y = (y(t i )) l i=1 , l ∈ N, be the reference data, corresponding to discrete time observations of the output process Y θ . Let us denote by π(θ) and π(θ|y) the prior and the posterior density, respectively. For multivariate complex SDEs, the underlying likelihood is often unknown or intractable. The idea of the ABC method is to derive an approximate posterior density for θ by replacing the unknown likelihood by many simulations of synthetic datasets from the underlying model (1) that are mapped to Y θ through (2). The basic acceptancerejection ABC algorithm consists of the following three steps: i. Sample a value θ from the prior π(θ); ii. Conditionally on θ , simulate a new artificial dataset from the model (1) and derive the synthetic data y θ = (y θ (t i )) m i=0 , t 0 = 0, t m = T , m ∈ N, from the process Y θ given by (2); iii. Keep the sampled parameter value θ as a realisation from an ABC posterior if the distance d(·) between a vector of summary statistics s = (s 1 , . . . , s h ), h ∈ N, of the original and the synthetic data is smaller than some threshold level ≥ 0, i.e. d(s(y), s(y θ )) < . When = 0 and s is a vector of sufficient statistics for θ , the acceptance-rejection ABC produces samples from the true posterior π(θ|y). Due to the complexity of the underlying SDE (1), we cannot derive non-trivial sufficient statistics s for θ . Moreover, due to the underly-ing stochasticity of the model, P(d(s(y), s(y θ )) = 0) = 0. Thus, is required to be strictly positive.
Algorithm 1 Reference table acceptance-rejection ABC Input: Observed data y Output: Samples from the posterior π ABC (θ |y) 1: Precompute a vector of summary statistics s(y) 2: Choose a prior distribution π(θ) and a percentile p 3: for i = 1 : N do 4: Draw θ i = (θ i 1 , ..., θ i k ) from the prior π(θ) 5: Conditionally on θ i , simulate a new realisation y θ i from the output process Y θ 6: Compute the summaries s(y θ i ) 7: Calculate the distance D i = d(s(y), s(y θ i )) 8: end for 9: Compute as the percentile p of the calculated distances 10: If D i < , keep θ i as a sample from the posterior, for i = 1, . . . , N Throughout, we set a posteriori, in the spirit of the reference table acceptance-rejection ABC (Cornuet et al. 2008), summarised in Algorithm 1, that is, we first produce the reference table (θ i , D i ), i = 1, . . . , N , and then obtain as a percentile p of the calculated distances D i . Algorithm 1 yields samples from an approximated posterior π ABC (θ |y) according to π(θ|y) ≈ π ABC (θ |y) = π {θ |d(s(y), s(y θ )) < }.
Besides the tolerance level , the quality of the ABC method depends strongly on the choice of suitable summary statistics combined with a proper distance measure and on the numerical method used to generate the synthetic data from the model. In the following, we introduce summaries that are very effective for the class of models having an underlying invariant distribution, we suggest a proper distance based on them, and we propose the use of measure-preserving numerical splitting schemes.

An effective choice of summaries and distances: spectral density-based ABC
When applying ABC to stochastic models, an important statistical challenge arises. Due to the intrinsic randomness, repeated simulations of the process Y θ under the same parameter vector θ may yield very different trajectories. An illustration is given in Fig. 1 (top and middle panels), where we report two trajectories of the output process of the stochastic JR-NMM (25) generated with an identical parameter configuration. This model is a specific SDE of type (1), observed through Y θ as in (2)  Proposal 1 To use the property of an invariant measure η Y θ and to map the data y θ to their estimated invariant densitŷ f y θ and invariant spectral densityŜ y θ .
Instead of working with the output process Y θ , we take advantage of the structural model property η Y θ and focus on its invariant density f Y θ and its invariant spectral density S Y θ . Both are deterministic functions characterised by the underlying parameters θ and thus invariant for repeated simulations under the same parameter configuration. The invariant spectral density is obtained from the Fourier transformation of the autocovariance function r θ , and it is given by for ω ∈ [−π, π]. The angular frequency ω relates to the ordinary frequency ν via ω = 2πν. Since both f Y θ and S Y θ are typically unknown, we estimate them from a dataset y θ . First, we estimate the invariant density f Y θ with a kernel density estimator, denoted byf y θ ; see, e.g. Pons (2011). Second, we estimate the invariant spectral density S Y θ (4) with a smoothed periodogram estimator (Cadonna et al. 2017;Quinn et al. 2014), denoted byŜ y θ , which is typically evaluated at Fourier frequencies. Differently from the invariant density, the invariant spectral density does not account for the mean E[Y θ ] but captures the dependence structure of the data coming from the model. We define the invariant measure-based summary statistics s of a dataset y θ as Figure 1 shows the two estimated invariant densities (left lower panel) and invariant spectral densities (right lower panel), all derived from the full paths of the output process Y θ (top panel). After performing the data mapping (5), which significantly reduces the randomness in the output of the stochastic simulator, the distance d(·) can be chosen among the distance measures between two R-valued functions. Here, we consider the integrated absolute error (IAE) defined by Another natural possibility could be a distance chosen among the so-called f -divergences (see, e.g. Sason and Verdú 2016), or the Wasserstein distance, recently proposed for ABC (Bernton et al. 2019). Within the ABC framework (see Step 7 in Algorithm 1), we suggest to use the following distance returning a weighted sum of the areas between the densities estimated from the original and the synthetic datasets. Here, w ≥ 0 is a weight that we assign to the part related to the IAE of the invariant densities such that the two errors are of the same "order of magnitude". This is particularly needed because, differently from the invariant density, the invariant spectral density does not integrate to 1. We obtain a value for the weight by performing an ABC pilot simulation. It consists in reiterating the following steps L times: 1: Draw θ from the prior π(θ) 2: Conditionally on θ , simulate two artificial datasets y 1 θ and y 2 θ from the output process Y θ 3: Compute the corresponding summaries as in (5) : Determine a value for the weight using (7), i.e., Then, we take the median of the resulting L values w . See, e.g. Prangle (2017) for alternative approaches for the derivation of weights among summary statistics. Since the densitieŝ f y θ andŜ y θ are estimated at discrete points, the IAE (6) is approximated applying trapezoidal integration. In our applications we consider M ∈ N realisations of the output process Y θ sampled at l ∈ N discrete points in time, resulting in observed data arranged as a matrix y ∈ R M×l . Under this experimental scenario, the median of the distances (7) computed for each of the M datasets is then returned as a global distance in Step 7 of Algorithm 1. Other strategies can be adopted. For example, considering the mean instead yields similar results in all our experiments. One can interpret y as a long-time trajectory (when using simulated observed reference data) or as a long-time recording of the modelled phenomenon (when using real observed reference data) that is cut into M pieces. Alternatively, y would consist of M independent repeated experiments or simulations, when dealing with real or simulated data, respectively. As expected, having M > 1 datasets improves the quality of the estimation due to the increased number of observations.

A new proposal of synthetic data generation: measure-preserving ABC
A crucial aspect of ABC and of all other simulation-based methods is the ability of simulating from the model (Step 5 of Algorithm 1). Consider a discretised time grid with the equidistant time step , introduces a new level of approximation in the statistical inference. In particular, Algorithm 1 samples from an approximated posterior density of the form As a consequence, y θ in Step 5 of Algorithm 1 is replaced by its numerical approximationỹ θ . The commonly used Euler-Maruyama scheme yields discretised trajectories of the solution process X of the SDE (1) through (Kloeden and Platen 1992) where ξ i are Gaussian vectors with null mean and variance ΔI n , where I n denotes the n ×n-dimensional identity matrix. As previously discussed, in general, the Euler-Maruyama method does not preserve the underlying invariant distribution η Y θ .
Proposal 2 To adopt a numerical method for the synthetic data generation that preserves the underlying invariant measure of the model.
We apply numerical splitting schemes within the ABC framework and provide a brief account of their theory. Let us assume that the drift f and the diffusion G of SDE (1) can be written as The goal is to decompose f and G in a way such that the resulting d subequations for j ∈ {1, . . . , d}, can be solved exactly. Note that, the terms G [ j] can be null, resulting in deterministic equations Δ=4.5*10 −3 Fig. 2 Comparison of the true invariant density of the weakly damped stochastic harmonic oscillator (23) (blue solid lines) with the densities estimated using a kernel density estimator applied on data y θ generated by the measure-preserving splitting scheme (22) t (X 0 ) denote the exact solutions (flows) of the above subequations at time t and starting from X 0 . Once these explicit solutions are derived, a proper composition needs to be applied. Here we use the Strang approach (Mclachlan and Quispel 2002;Strang 1968) x ∈ R n , that provides a numerical solution for the original SDE (1). In Fig. 2, we illustrate how the numerical splitting method preserves the underlying invariant measure of the weakly damped stochastic harmonic oscillator (23), independently from the choice of the time step Δ. This is a specific SDE of type (1), observed through Y θ as in (2) and with a known invariant distribution η Y θ . See Sect. 3 for the detailed numerical splitting scheme and Sect. 4 for a description of the model. In contrast, the Euler-Maruyama scheme performs worse as Δ increases. Each subplot shows a comparison of the true invariant density (blue solid lines) and the corresponding kernel estimatef y θ based on a path y θ from the model, generated from the measure-preserving numerical splitting scheme (22) (orange dashed lines) or the Euler-Maruyama approach (green dotted lines). The data are generated under T = 10 3 and different values for the time step, namely Δ = 10 −3 , 3 · 10 −3 , 4.5 · 10 −3 .

Notation
We apply the summary statistics (5) and the distance (8) in Algorithm 1. We use the notation Algorithm 1 (i) [spectral density-based ABC method] when the synthetic data are simulated exactly, Algorithm 1 (ii) [spectral density-based and measure-preserving ABC method] when a measure-preserving numerical splitting scheme is applied and Algorithm 1 (iii) when we generate the data with the non-preserving Euler-Maruyama scheme.

An illustration on Hamiltonian type SDEs
We illustrate the proposed ABC approach on Hamiltonian type SDEs and define the n-dimensional (n = 2d, d ∈ N) stochastic process consisting of the two d-dimensional components Q = (X 1 , . . . , X d ) and P = (X d+1 , . . . , X 2d ) , where denotes the transpose. The n-dimensional SDE of Hamiltonian type with initial value X 0 = (Q 0 , P 0 ) and ddimensional (r = d) Wiener process W describes the time evolution of X by d Q(t) P(t) We denote with O d the d × d-dimensional zero matrix and with ∇ Q and ∇ P the gradient with respect to Q and P, respectively. The SDE (10) consists of 4 parts, each representing a specific type of behaviour. In this configuration, the first is the Hamiltonian part involving H : The second is the linear damping part, described by the diag-

Structural model property
Under the requirement of non-degenerate matrices Λ θ , Γ θ and Σ θ , i.e. strictly positive diagonal entries, Hamiltonian type SDEs as in (10) are often ergodic. As a consequence, the distribution of the solution process X (and thus of the output process Y θ ) converges exponentially fast towards a unique invariant measure η X on (R n , B(R n )) (and thus η Y θ on (R, B(R)); see, e.g. Ableidinger et al. (2017) and the references therein.

Measure-preserving numerical splitting schemes
Two splitting approaches for SDE (10) are provided, see Ableidinger et al. (2017). Due to the nonlinear term G, the SDE (10) cannot be solved explicitly. With the purpose of excluding G, the Hamiltonian type SDE (10) is split into the two subsystems where 0 d denotes the d-dimensional zero vector. This results in a linear SDE with additive noise (11) and a nonlinear ODE (12) that can be both explicitly solved. Indeed, since ∇ P H (Q(t), P(t)) = P(t) and ∇ Q H (Q(t), (11) can be rewritten as (13) is obtained through (Arnold 1974) where ξ i are n-dimensional Gaussian vectors with null mean and variance C(Δ), where the matrix C(t) follows the dynamics of the matrix-valued ODĖ Moreover, since the nonlinear term G depends only on the component Q, the exact path of Subsystem (12) is obtained through We apply the Strang approach given by where ϕ a t and ϕ b t denote the exact solutions (14) and (16) of (11) and (12), respectively. Hence, given X (t i ), we obtain the next value X (t i+1 ) by applying the following three steps: θ) The derivation of the subsystems is not unique. For example, another possibility is to combine the stochastic term with the nonlinear part, yielding the subsystems The exact path of (18) is given by while the exact path of (19) is obtained through where ξ i are d-dimensional Gaussian vectors with null mean and variance ΔI d . The Strang approach is now given by where ϕ c t and ϕ d t denote the exact solutions (20) and (21) of (18) and (19), respectively. Thus, given X (t i ), the next value X (t i+1 ) is obtained via:

Implementation details
The ABC procedure is coded in the computing environment R (R Development Core Team 2011), using the package Rcpp (Eddelbuettel and François 2011), which offers a seamless integration of R and C++, drastically reducing the computational time of the algorithms. The code is then parallelised using the R-packages foreach and doParallel, taking advantage of the for loop in the algorithm. All simulations are run on the HPC cluster RADON1, a high-performing multiple core cluster located at the Johannes Kepler University Linz. To obtain smoothed periodogram estimates, we apply the R-function spectrum. It requires the specification of a smoothing parameter span. In all our experiments, we use span = 5T . In addition, we avoid using a logarithmic scale by setting the log parameter to "no". To obtain kernel estimates of the invariant density, we apply the R-function density. Here, we use the default value for the smoothing bandwidth bw and set the number of points at which the invariant density has to be estimated to n= 10 3 . The invariant spectral density is estimated at the default values of the spectrum function. A sample code is publicly available on github at https://github.com/ massimilianotamborrino/sdbmpABC.

Validation of the proposed ABC method when exact simulation is possible
In this section, we illustrate the performance of the proposed ABC approach on a model problem (weakly damped stochastic harmonic oscillator) of Hamiltonian type (10) with vanishing nonlinear displacement term G ≡ 0. Linear SDEs of this type reduce to (13) and allow for an exact simulation of sample paths through (14). Therefore, we can apply the spectral density-based ABC Algorithm 1 (i) under the optimal condition of exact and thus η Y θ -preserving data generation. Its performance is illustrated in Sect. 4.2. To investigate how the numerical error in the synthetic data generation impinges on the ABC performance, in Sect. 4.3 we compare π ABC (θ |y) with the posterior densities π num ABC (θ |y) and π e ABC (θ |y) obtained from Algorithm 1 (ii) and (iii) using the measure-preserving numerical splitting scheme (22) and the non-preserving Euler-Maruyama method (9), respectively.

Weakly damped stochastic harmonic oscillator: the model and its properties
We investigate the 2-dimensional Hamiltonian type SDE with strictly positive parameters γ , λ and σ . Depending on the choice of γ and λ, (23) models different types of harmonic oscillators, which are common in nature and of great interest in classical mechanics. Here, we focus on the weakly damped harmonic oscillator, satisfying the condition λ 2 − γ 2 > 0. Our goal is to estimate θ = (λ, γ, σ ) assuming that the solution process X = (Q, P) is partially observed through the first coordinate, i.e. Y θ = Q. An illustration of the performance of Algorithm 1 (i) for the critically damped case satisfying λ 2 − γ 2 = 0, when only the second coordinate is observed, is reported in the supplementary material. The solution process X of SDE (23) is normally distributed according to with A and C introduced in (13) and (15), respectively. The invariant distribution η X of the solution process X is given by Consequently, the structural property η Y θ of the output process Y θ becomes and the stationary dependency is captured by the autocovariance function

Validation of the spectral density-based ABC Algorithm 1 (i)
To compare the performances of Algorithms 1 (i)-(iii) on the same data, we consider the same M = 10 observed paths simulated with the exact scheme (14), using a time step Δ = 10 −2 over a time interval of length T = 10 3 . As true parameters for the simulation of the reference data, we choose θ t = (λ t , γ t , σ t ) = (20, 1, 2).
We use the exact simulation scheme (14) to generate N = 2 · 10 6 synthetic datasets in [0, T ] and with the same time step as the observed data. We choose independent uniform priors, in particular, The tolerance level is chosen as the 0.05th percentile of the calculated distances. Hence, we keep 10 3 of all the sampled values for θ . In all the considered examples (see also the supplementary material), the performance of the ABC algorithms for the estimation of the parameters of SDE (23) does not improve when incorporating the information of the invariant densities into the distance (7). This is because the mean of the invariant distribution (24) is zero. Hence, to reduce the computational cost, we set w = 0 and base our distance only on the invariant spectral density, estimated by the periodogram. Figure 3 (top panels) shows the marginal ABC posterior densities π ABC (θ j |y) (blue lines) and their flat uniform priors π(θ j ) (red lines). The proposed ABC Algorithm 1 (i) provides marginal posterior densities centred around the true values θ t , represented by the black vertical lines. The posterior means are given by (λ ABC ,γ ABC ,σ ABC ) = (20.015, 1.022, 2.011).
In the lower panels of Fig. 3, we report the pairwise scatterplots of the kept ABC posterior samples. Note that, since the kept values of λ are uncorrelated with those of the other parameters, the support of the obtained marginal posterior density is approximately the same as when estimating only θ = λ or θ = (λ, γ ) (cf. supplementary material). Vice versa, since the kept ABC posterior samples of the parameters γ and σ are correlated, the support of π ABC (γ |y) is larger than that obtained when estimating θ = (λ, γ ). Despite this correlation, Algorithm 1 (i) allows for a successful inference of all the three parameters.

Validation of the spectral density-based and measure-preserving ABC Algorithm 1 (ii)
In Fig. 4, we report the approximated marginal posteriors π ABC (θ j |y) (blue solid lines) and π num ABC (θ j |y) (orange dashed lines) obtained with the same priors, , T , w, M and N as before, for different values of the time step Δ. In particular, we choose Δ = 5 · 10 −3 (top panels), Δ = 7.5 · 10 −3 (middle panels) and Δ = 10 −2 (lower panels). The posteriors obtained from Algorithm 1 (ii) successfully targets π ABC (θ |y), even for a time step as large as Δ = 10 −2 . On the contrary, Algorithm 1 (iii) is not even applicable. Indeed, the numerical scheme computationally pushes the amplitude of the oscillator towards infinity, resulting in a computer overflow, i.e. Y θ (t i ) ≈ ∞. Thus, neitherfỹ θ norŜỹ θ can be computed and the density π e ABC (θ |y) cannot be derived. As a further illustration of the poor performance of the Euler-Maruyama scheme, even for smaller choices of Δ, we now consider the simplest possible scenario where we only estimate one parameter, namely θ = λ. We set N = 10 5 , M = 10, = 1st percentile and we choose a uniform prior λ ∼ U (10, 30). To be able to derive π e ABC (λ|y), we simulate the synthetic data using the Euler-Maruyama method with the time steps Δ = 10 −3 , 2.5 · 10 −3 and 3.5 · 10 −3 . Figure 5 shows the three ABC posterior densities π ABC (θ |y) (blue solid lines), π num ABC (θ |y) (orange dashed lines) and π e ABC (θ |y) (green dotted lines) for the different choices of Δ. The horizontal red lines and the black vertical lines denote the uniform prior and the true parameter value, respectively. In all cases, Algorithm 1 (iii) does not lead to a successful inference. In addition, these results are not stable for the different choices of Δ, and the derived ABC posterior density may not even cover the true parameter value.

Validation of the spectral density-based and measure-preserving ABC Algorithm 1 (ii) on simulated and real data
We now illustrate the performance of Algorithm 1 (ii) by applying it to the stochastic JR-NMM. We rely on the efficient numerical splitting scheme (17) to guarantee measure-preserving synthetic data generation within the ABC framework. After estimating the parameters from simulated data, we infer them from real EEG data. In the available supplementary material, we illustrate the performance of Algorithm 1 (ii) also on the nonlinear damped stochastic oscillator, an extended version of the weakly damped harmonic oscillator discussed in Sect. 4.

The stochastic Jansen and Rit neural mass model
The stochastic JR-NMM describes the electrical activity of an entire population of neurons through their average properties by modelling the interaction of the main pyramidal cells with the surrounding excitatory and inhibitory interneurons. The model has been reported to successfully reproduce EEG data and is applied in the research of neurological disorders such as epilepsy or schizophrenia (Wendling et al. 2000(Wendling et al. , 2002. The model is a 6-dimensional SDE of the form where the 6-dimensional solution process is given by X = (Q, P) with components Q = (X 1 , X 2 , X 3 ) and P = (X 4 , X 5 , X 6 ) . None of the coordinates of X is directly observed. Only the difference between the second and third coordinates can be measured with EEG recording techniques, yielding the output process In (25), the diagonal diffusion matrix is given by Σ θ = diag[σ 4 , σ 5 , σ 6 ] ∈ R 3×3 with σ i > 0, i = 4, 5, 6. The matrix Γ = diag[a, a, b] ∈ R 3×3 is also diagonal with coefficients a, b > 0, representing the time constants of the excitatory and inhibitory postsynaptic potentials, respectively. The nonlinear displacement term is given by where the sigmoid function Sigm: R → [0, v max ] is defined as with v max > 0 referring to the maximum firing rate of the neural populations, v 0 ∈ R describing the value for which 50 % of the maximum firing rate is attained and r > 0 denoting the slope of the sigmoid function at v 0 . The parameters entering in G are μ, A, B and C i , i = 1, 2, 3, 4 ∈ R + . The coefficients A and B describe the average excitatory and inhibitory synaptic gain, respectively. The parameters C i are internal connectivity constants, which reduce to only one parameter C, by using the relations C 1 = C, C 2 = 0.8C, C 3 = 0.25C and C 4 = 0.25C; see Jansen and Rit (1995).

Parameter inference from simulated data
Not all model parameters of the JR-NMM are of biological interest or can be simultaneously identified. For example, the noise coefficients σ 4 and σ 6 were introduced mainly for mathematical convenience in Ableidinger et al. (2017). To guarantee the existence of a unique invariant measure η X on (R 6 , B(R 6 )), they are required to be strictly positive. However, from a modelling point of view, only the parameter σ := σ 5 plays a role. Hence, we fix σ 4 = 0.01 and σ 6 = 1. The coefficients A, B, a, b, v 0 , v max and r have been experimentally recorded; see, e.g. Jansen et al. (1993), Jansen and Rit (1995) and van Rotterdam et al. (1982). Thus, we fix them according to these values reported, for example, in Table 1 of Ableidinger et al. (2017). In contrast, the connectivity parameter C, which represents the average number of synapses between the neural subpopulations and controls to what extent the main population interacts with the interneurons, varies under different physiological constraints. Changing C allows, for example, a transition from α-rhythmic activity to epileptic spiking behaviour; see, e.g. Ableidinger et al. (2017). Here, we focus on the α-rhythmic activity, which has a frequency of around 10 Hz. Since the parameters σ and μ are new in the SDE version (25), they have not yet been estimated. They can be interpreted as stochastic and deterministic external inputs coming from neighbouring or more distant cortical columns, respectively. Thus, together with the internal connectivity parameter C, they are of specific interest. Before inferring θ = (σ, μ, C), we take into account the coefficients A and B to discuss a model-specific issue of identifiability.

Identifiability issues: the detection of an invariant manifold, i.e. a set of parameters yielding the same type of data
For the original JR-NMM, it has been shown that different combinations of the parameters A, B and C yield the same type of output, namely α-rhythmic brain activity. Applying the proposed spectral density-based and measure-preserving ABC Algorithm 1 (ii) for the inference of θ = (A, B, C), with given μ = 220 and σ = 2000, we confirm that the same nonidentifiability arises for the SDE version (25). We choose M = 30 observed paths generated assuming 3.25, 22, 135), as suggested in the literature (Jansen and Rit 1995). The reference data and the synthetic data are generated over a time interval of length T = 200 and using a time step Δ = 2·10 −3 . Within the algorithm, we generate N = 2.5 · 10 6 synthetic datasets. We choose the weight w in (7) according to the procedure introduced in Sect. 2.2 (based on L = 10 5 iterations) and fix the tolerance level = 0.04th percentile to keep 10 3 of all the sampled values for θ , as in the previous examples. Further, we choose independent uniform prior distributions, namely (1, 10), B ∼ U(10, 100), C ∼ U(10, 600).
Figure 6 (top panels) shows the marginal ABC posterior densities π num ABC (θ j |y) and the uniform prior densities π(θ j ). Clearly, the parameters cannot be inferred simultaneously. The kept ABC posterior values of the parameters A, B and C are strongly correlated, as observed in the pairwise scatterplots (middle panels) and in the 3-dimensional scatterplot (two different views, lower panels). The cuboid covers all possible values for θ drawn from the prior. After running the ABC algorithm, the kept values of θ from the ABC posterior form an invariant manifold, in the sense that all the parameter values θ lying on this manifold yield similar pathsỹ θ of the output process. This is shown in Fig. 7, where we report four trajectories that have been simulated with the same pseudorandom numbers but using the parameters θ t (green dot in Fig. 6) and three of the kept ABC posterior samples lying on the invariant manifold (red, orange and grey dots in Fig. 6). A segment of T = 10 is split in the top and middle panels. In addition, we visualise the corresponding estimated invariant densities (bottom left) and invariant spectral densities (bottom right). This explains why the parameters A, B and C are not simultaneously identifiable from the observed data. Similar results are obtained when choosing smaller values of . Interestingly, when increasing , a second invariant manifold arises. Values for θ lying on this manifold yield similar estimated densities and spectral densities that slightly deviate from those derived under the observed data (cf. Section 3 of the supplementary material).
Since the internal connectivity parameter C has an important neuronal meaning, in the following we assume A and B to be known and infer θ = (σ, μ, C). The estimation of θ = (σ, μ) when C is known is reported in the supplementary material.
The reference data are simulated under 2000,220,135).
In Fig. 8, we report the marginal ABC posterior densities π num ABC (θ j |y) (blue lines), the uniform prior densities π(θ j ) (red lines) and the true parameter values θ t (black vertical lines). We obtain unimodal posterior densities, centred around the true parameter values. The posterior density of σ is slightly broader compared to that obtained when C is known (cf. Figure 21 of the supplementary material). This results from a weak correlation that we detect among the kept ABC posterior samples of the parameters σ and C (figures not reported). The posterior means are equal to 1992.253, 219.744, 134.899) and are thus close to θ t . These results suggest an excellent performance of the proposed spectral density-based and measure-preserving ABC Algorithm 1 (ii). Similar satisfactory results are obtained even when adding a fourth parameter, for example, when inferring θ = (σ, μ, C, b) (cf. Figure 22 of the supplementary material). When applying Algorithm 1 (ii) to real EEG data (cf. Figure 23 of the supplementary material), the marginal posterior for b is centred around the value b = 50, which is that reported in the literature. Due to the existence of underlying invariant manifolds, identifiability issues, similar to those reported in Fig. 6, arise when adding further or other coefficients, revealing model-specific issues for the stochastic JR-NMM.
To illustrate again the importance of the structure preservation within the ABC method, we now apply Algorithm 1 (iii). We use the same conditions as before, except for a smaller time step Δ = 10 −4 used for the generation of the observed reference data with the Euler-Maruyama method aiming for a realistic data structure. In Fig.9, we report the marginal ABC posterior densities π e ABC (θ j |y) (top panels) and the uniform prior densities. In the 3-dimensional scatterplot of Fig. 9 (lower panel), the green dots in the middle of the cuboid represent the kept ABC posterior samples when applying Algorithm 1 (ii) (see the previous results reported in Fig. 8), which are nicely spread out around the true parameter vector θ t (black dot). The red dots correspond to the kept ABC posterior samples from π e ABC (θ |y). Hence, Algorithm 1 (iii) based on the Euler-Maruyama scheme provides a posterior that is far off from the true parameter vector.

Parameter inference from real EEG data
Finally, we use the spectral density-based and measurepreserving ABC Algorithm 1 (ii) to estimate the parameter vector θ = (σ, μ, C) of the stochastic JR-NMM from real EEG recordings. We use M = 3 α-rhythmic recordings, rescaled to a realistic range. The EEG data were sampled according to a sampling rate of 173.61 Hz, i.e. a time step Δ of approximately 5.76 ms over a time interval of length T = 23.6 s. All measurements were carried out with a standardised electrode placement scheme; see Andrzejak et al. (2001) for further information on the data. 1 Figure 10 shows the first 20 seconds of one of the observed EEG datasets. Here, we simulate N = 5 · 10 6 synthetic paths from the output process of the stochastic JR-NMM (25) over the same time interval T as the real data, with a time step Δ = 2 · 10 −3 and = 0.02nd percentile. We choose independent uniform priors π(θ j ) according to σ ∼ U(500, 3500), μ ∼ U(70, 370), C ∼ U(120, 150). Figure 11 shows the resulting marginal ABC posterior densities π num ABC (θ j |y) and the uniform prior densities π(θ j ).
Since μ and σ have not been estimated before, we cannot compare the obtained results with those available in the literature. The ABC posterior density for C is centred around π(C) π ABC EM (C|y) Fig. 9 Top panels: Marginal ABC posterior densities π e ABC (θ j |y) (blue lines) of θ = (σ, μ, C) of the stochastic JR-NMM (25) obtained from Algorithm 1 (iii) using the non-preservative Euler-Maruyama scheme (9). The horizontal red lines and the vertical black lines represent the uniform priors and the true parameter values, respectively. Lower panel: 3-dimensional scatterplot of the kept ABC posterior samples using Algorithm 1 (ii) (green dots; see the previous results reported in Fig. 8) and Algorithm 1 (iii) (red dots). The cuboid is formed by the prior. The black dot corresponds to θ t . (Color figure online) C = 135 that is the reference literature value for α-rhythmic EEG data.
In Fig. 12 (top two panels), we report the median (blue solid line) and the shaded 95% credible bands (obtained from the central posterior intervals) of the first 10 seconds of trajectories simulated from the fitted stochastic JR-NMM (25). The paths are generated with the numerical splitting scheme (17) for Δ = 2 · 10 −3 and T = 23.6, using the 10 3 kept ABC posterior samples derived from Algorithm 1 (ii) under the same seed for pseudo-random numbers. The narrow 95% confidence bands suggest how the kept ABC posterior samples yield similar paths. When using different pseudorandom numbers, both the median and the 95% credible bands of the generated trajectories look constant in time, as expected due to the underlying invariant distribution of the model (figures not shown). The bands show a similar oscillatory behaviour as shown in Fig. 10, with an approximate frequency of 10 Hz, successfully reproducing the underlying α-rhythmic behaviour. This can be clearly distinguished in the middle lower panel, where we report a zoom of 1 second. The successful ABC inference is also confirmed by noting the matches between the invariant densities (bottom left) and the invariant spectral densities (bottom right) estimated from the EEG recording shown in Fig. 10 (red dashed lines) and from the fitted model when considering the median (blue solid lines) and the 95% credible bands (grey shaded areas). The match is poor only for low frequencies of the invariant spectral density, even when choosing broader priors. This may result from a lack of fit of the JR-NMM or of stationarity in the considered EEG data. A deeper investigation of the model (including adapted versions, see, e.g. Wendling et al. 2002) and of its ability in reproducing real EEG data is currently under investigation, but it is out of the scope of this work.

Conclusion
When performing parameter inference through ABC, crucial and non-trivial tasks are to propose suitable summary statistics and distances to compare the observed and the synthetic datasets. When the underlying models are stochastic, repeated simulations from the same parameter setting yield different outputs, making the comparison between the observed and the synthetic data more difficult. To derive summary statistics that are less sensitive to the intrinsic randomness of the stochastic model, we propose to map the data to their invariant density and invariant spectral density, estimated by a kernel density estimator and a smoothed periodogram, respectively. By doing this, different trajectories of the output process are mapped to the same objects only when they are generated from the same underlying parameters, provided that all parameters are simultaneously identifiable. These transformations are based on the existence of an underlying invariant measure for the model, fully characterised by the parameters. A necessary condition of ABC, and of all other simulation-based methods, is the ability to generate data from the model. This is often taken for granted but, in general, it is not the case. Indeed, exact simulation is rarely possible and property-preserving numerical methods have to be derived.
The combination of the measure-preserving numerical splitting schemes and the use of the spectral density-based distances in the ABC algorithm lead to a successful inference of the parameters, as illustrated on stochastic Hamiltonian type equations when the process Y θ is observed without measurement error. We validated the proposed ABC approach on both linear model problems, allowing for an exact simulation of the synthetic data, and nonlinear problems, including an application to real EEG data. Our choice of the crucial ingredients (summary statistics and distances based on the underlying invariant distribution and a measure-preserving numerical method) yields excellent results even when applied to ABC in its basic acceptance-rejection form. However, they can be directly applied to more advanced ABC algorithms. In contrast, the ABC method based on the Euler-Maruyama scheme drastically fails. Its performance may improve for "small enough" time steps. However, there is a trade-off between the runtime and the acceptance performance of Algorithm 1 (iii). Indeed, the simulation of one trajectory with a time step 10 −4 requires approximately hundred times more than the generation of one trajectory using a time step 10 −2 . Hence, a runtime of a few hours would turn to months. In addition, even for "arbitrary small" time steps, one cannot guarantee that the Euler-Maruyama scheme preserves the underlying invariant measure. For these reasons, it is crucial to base our ABC method on the reliable measurepreserving numerical splitting scheme combined with the invariant measure-based distances. Our results were discussed in the case of an observable 1-dimensional output process. However, the approach can be directly applied to d-dimensional output processes, d > 1, as long as the underlying SDEs are characterised by an invariant distribution and a measure-preserving numerical method can be derived. In particular, one can compute the distances in (8) for each of the d components and derive a global distance by combining them, e.g. via their sum. Moreover, to account for possible dependences between the observed components, one can incorporate the cross-spectral densities which are expected to provide further information resulting in an improvement in the performance of the method. An investigation in this direction is currently undergoing. Finally, our proposed ABC method may be also used to investigate invariant manifolds characterised by sets of parameters yielding the same type of data, as illustrated on the stochastic JR-NMM. This may result in a better understanding of the qualitative behaviour of the underlying model and its ability of reproducing the true features of the modelled phenomenon.

Supplementary material
Further illustrations of the proposed ABC method are available in the provided supplementary material. In particular, we illustrate the performance of: (a) Algorithm 1 (i) for the estimation of the parameters of the critically damped stochastic oscillator, for which the exact simulation is possible; Algorithm 1 (i) applied to the critically and weakly damped stochastic harmonic oscillators (see Sect. 4) when estimating a smaller number of parameters; (b) Algorithm 1 (ii) for the estimation of the parameters of a nonlinear damped stochastic oscillator; (c) Algorithm 1 (ii) for the estimation of the two parameters θ = (σ, μ) of the stochastic JR-NMM, which are of specific interest; (d) Algorithm 1 (ii) for the estimation of θ = (σ, μ, C, b) of the stochastic JR-NMM, based on simulated and real EEG data. Moreover, we provide an investigation of the influence of on the identifiability issues discussed in Sect. 5.2.1.