BACKGROUND
the gastrointestinal tract extends from the mouth to the anus.
swallowed food travels along the length of this tube at an appropriate speed to allow for the breakdown and absorption of nutrients.
the movement of content results from a complex series of muscular contractions and relaxations.
these movements of the gut wall alter the pressure profiles within the gut  <cit>  which in-turn cause the digesting contents to move in an oral or anal direction.
abnormalities in these motor patterns are associated with several prevalent and unpleasant disorders that cost health care systems billions of dollars per year  <cit> .
the ability to define the relationship that exist between wall motion, intraluminal pressure and the flow of content is a fundamental step in understanding how altered motor patterns effect the transport of luminal content.
however, accurately defining these relationships in the human gut in vivo is problematic; ethical constraints prevent detailed examination of real-time movement of the gut wall.
to overcome this problem we developed an in vitro animal preparation that allowed us to record simultaneously, both intraluminal pressure  and gut diameter  in real time, across varying length  of intestine  <cit>  .
in the next stage of this research we published a theory based paper in which we developed a strategy based on simple principle of biomechanics to deduce the mechanical state of the muscle  by calculating the relation between pressure and diameter at every point along the gut segment, and establishing where and when the muscle is actively contracting or relaxing  <cit>  .
in that paper, space prevented a detailed description of the mathematical model involved in developing this process.
in this work we address the details of the strategy that enabled us to confidently identify, for the first time, the mechanical states of the muscle during peristaltic contractions, and plot them as a functional spatiotemporal map.
a major factor in our work involved the use of hidden markov models .
the hmm have found extensive use in a variety of fields, stemming from their seminal application in speech recognition in the 1970s  <cit> .
in gastroenterology, hmms have been used to classify the location of a video capsule in the gastrointestinal tract  <cit> .
in their application to hand written recognition, hmms were utilized by observing lines and curves drawn on a 2d plane and inferring the most probable characters they represent  <cit> .
in developing our intestinal model of mechanical states, one of the major challenges we faced was how to identify the beginning and the end of the periods of the various different states of the muscle.
however, analogous to hand written recognition, our diameter-pressure plots can be observed as lines in the 2d plane.
therefore the hmm was adapted to infer the most probable muscles states at any given point in time along the length of the studies gut segment.
a description of the steps involved in this process are detailed here.
identification of muscle states
the circular muscle of the gut is arranged as continuous rings of smooth muscle forming the inner muscle layer of the tubular structure.
the circular muscle layer is thicker than the external longitudinal muscle layer and thus is mechanically more powerful.
when it contracts, propulsion of the luminal content can occur.
this prolusion is made more efficient if the adjacent regions of the gut  concurrently relax, thus effectively allowing the bolus to move into a region of lower pressure  <cit> .
these regions of contraction and relaxation can be detailed by simultaneously recording the diameter of the gut and the intraluminal pressure .
from the resultant spatiotemporal map of diameter and pressure  we can plot, at any point in time, pressure and diameter curves .
from these we can then begin to express the mechanical relation between pressure and diameter as a pressure-diameter orbit plot .
in publishing the theory behind this concept  <cit>  we also established that twelve distinct mechanical muscle states can be predicted .
the mechanical states are summarized below; occluded isometric contraction : active; occurs with an increase in pressure, with no change in diameter, when the gut is at its minimum diameter.
occluded isometric relaxation : passive; occurs with a decrease in pressure and no change in diameter, when the gut is at its minimum diameter.
distended isometric pressure increase : passive; occurs with an increase in pressure, no change in diameter, when the gut is at its maximum diameter.
distended isometric pressure decrease : passive; occurs with a decrease in pressure, no change in diameter, and a maximum diameter.
isotonic contraction : active; occurs with a decrease in diameter and no change in pressure.
isotonic relaxation : active; occurs with an increase in diameter and no change in pressure.
auxotonic contraction : active: occurs with a decrease in diameter and an increase in pressure.
auxotonic relaxation : active: occurs with an increase in diameter and a decrease in pressure.
passive shortening : passive; occurs with a decrease in diameter and pressure.
passive dilation : passive; occurs with an increase in diameter and pressure.
occluded quiescence : passive; occurs with no change in diameter nor pressure, when the gut is at its minimum diameter.
distended quiescence : passive; occurs with no change in diameter nor pressure, when the gut is at a non-minimum diameter.
having established that  <dig> mechanical states exist we then need to develop a means to determine when and where each state existed along the gut in an automated fashion.
in addition we had to detect both the changes in the mechanical states  and the permanence in that state .
methods
the intraluminal pressures were recorded by a manometry catheter with pressure sensors spaced at  <dig> mm intervals and each of these was considered independent for modelling purposes.
at each sensor location, diameter and pressure values were recorded continuously.
data acquisition
a detailed description of the techniques used to collate the data has been published elsewhere  <cit> .
here we will provide a brief overview.
rabbits were euthanized humanely by intravenous injection of pentobarbitone sodium  in accordance with approval by the animal welfare committee of flinders university.
the gut diameter and internal pressure were recorded using two different methods, at different sampling rates, spacial resolutions, and offsets in time and space.
resampling and spatiotemporal alignment was required to coincide values of pressure and diameter for use as a single observation vector for each node in the markov chain.
each spatial location was assigned its own markov chain.
a spatiotemporal map of colonic diameter was based on techniques developed in our lab  <cit> .
briefly the spatiotemporal maps were obtained by recording a top-down video of the colon suspended in a bath of krebs solution, such that the length of the colon appeared horizontally in the video, and the number of pixels that the colon spans for each vertical pixel line in each frame was counted.
using a reference ruler visible in the recorded video, the colonic diameter in millimetres was obtained.
pressures were recorded by  <dig> mm-spaced sensors at  <dig> hz with a catheter inserted into the colon.
baseline drift was removed with iterated gaussian minima smoothing  <cit> .
different spatiotemporal resolutions and offsets required resampling and alignment.
a diameter map and a pressure map were combined by creating a grid of coordinates using the coarsest resolution in time and space from either map aligned with an adjustable spatiotemporal offset, and then binning the original maps into the grid.
this resulted in a spatial and time resolution of  <dig> mm and  <dig>  s respectively.
the alignment resulted in a single set of spatiotemporal coordinates that map to coincident diameter and pressure values, allowing diameters and pressures to be quickly compared for analysis without further interpolation.
the temporal offset was determined by aligning events that were synchronously recorded by video as flashes from a light bulb  and embedded into the pressure recording as meta-data.
the spatial offset was manually obtained by observing overlapping images of the two maps, while adjusting the offset to a value best representative of correct alignment that correlates with the video.
the entire data set consisted of  <dig> rabbits recorded with approximately  <dig> sensors over periods of  <dig> to  <dig> minutes each, resulting in just over  <dig>  samples ; orbits were created for each sensor.
hidden markov model
given a sequence of observations of diameter and pressure at a single location in the colon, our objective was to infer the most-likely sequence of mechanical muscle states that could have resulted in those observations.
each mechanical muscle state was directly represented as a hidden state in the hidden markov model.
in our application, the dependence of a state on the previous state in the markov chain was required as an implicit smoothing technique.
observations
for each sensor location there are two values observed, the diameter d and pressure p, sampled at a frequency of  <dig> hz.
sample i of the diameter and pressure is given by d
i
and p
i
, where i∈{1…n}.
the time derivatives of those values are denoted with an overdot and estimated using central differences as
d˙i≈di+1−di−12Δt
d˙1≈d2−d1Δt
d˙n≈dn−dn−1Δt
where Δt= <dig> s for the  <dig> hz sampling, and p˙ defined in the same manner as d˙.
observation i is defined as the vector
oi=di,d˙i,p˙i
any general sequence  will be written as x
a:b
for the sake of brevity.
states
we segment a sensor’s recording and classify each observation into one of twelve discrete mechanical states of the set
s={oimc,oimr,dipi,dipd,itc,itr,atc,atr,ps,pd,oq,dq}
the conceptual directions and positions of subsequences of observations on a diameter-pressure plot representing examples of each of the twelves states is depicted in figure  <dig> and described in figure 1a.
the state-observation model is based on developing a quantitative model for classifying the dynamics depicted in that figure.
state-observation model
the state-observation model defines the conditional probabilities of observations and states.
the goal is to arrive at a formula describing the distribution of possible observations, under the assumption that they were produced while the muscle was in any given mechanical state.
the sample subscript i is omitted for brevity in this section, since the state-observation model is independent of the sample number.
each state in s is composed of  <dig> state components, where each component c
o
corresponds to an element o of the observation o, and non corresponding components and elements are considered independent.
the components quiet, pos, and neg correspond to the d˙ and p˙ velocity elements.
the quiet component corresponds to a value of the velocity element close to  <dig>  and pos and neg represent the positive and negative values.
the components occ, dis, and any correspond to the diameter d, where occ represents an occluded diameter, dis a distended diameter, and any if the diameter is irrelevent.
for example, the state dipd is composed of dis, quietd˙, and negp˙, where the subscripts disambiguate the corresponding velocity elements.
the states in s can be considered a vector of state components , where
cd∈{any,dis,occ}
cd˙∈{quietd˙,posd˙,negd˙}
cp˙∈{quietp˙,posp˙,negp˙}
given a velocity observation v∈{d˙,p˙}, the probability of the corresponding state component being quiet is modelled on the basis of a normal distribution located at  <dig> with width free parameters σd˙ and σp˙.
the normal distribution is the most common way to model noise and errors, justified by the central limit theorem.
since very low speeds are considered quiescent, slow tonic muscle activity will be absorbed into passive states, with only phasic contractions exposed as active states.
the probability of the state component being pos or neg is modelled on the basis of normal cumulative distribution functions with the same parameters.
probability mass functions are normalised to ensure
f+f+f= <dig>
see – for the formulae, and figure  <dig>  for a visual example.
given an observation of diameter d, the probability of the corresponding state component being occ or dis is modelled on the basis of a normal cumulative distribution function and its complement, located at μ
d
+min
d
with width σ
d
, where min
d
is the value of the minimum recorded diameter.
the value d−min
d
is referred to as “dilation”, and μ
d
represents the amount of dilation that separates occluded and distended states.
the probability of the state being any given d is a constant.
the probability mass functions are normalised to ensure
f+f+f= <dig>
see – for the formulae, and figure  <dig>  for a visual example.
the probability mass functions  f are given by
f=zvexp−v22σv <dig>
f=zvΦvσv
f=zvΦ−vσv
zv=exp−v22σv2+1−1f=zd <dig>
f=zdΦd−mind−μdσd
f=zdΦμd−d+mindσd
zd= <dig>
where Φ is the cumulative standard normal distribution function, v is an alias for either d˙ or p˙, and z
v
and z
d
are normalisation constants ensuring the probabilities sum to  <dig> for any given observation and all corresponding states.
the probability density function  of the model emitting a particular observation element o∈{d,d˙,p˙} given a corresponding state component c
o
, is known as the emission pdf, which can be obtained from bayes’ theorem
f=fff
the emission pdf is used to determine the distribution of observations that can be made assuming an underlying muscle mechanical state.
since only the relative sizes of emission pdfs are required for calculating the optimal state sequence , the observation prior density f can be removed which is independent of state and so does not change which state is most likely to have produced a given observation.
in a similar way, if we approximate the state component prior distribution f with a constant, then it can also be removed resulting in the following practical approximation
f≈f
note that under this approximation, f no longer represents a pdf, that is, ∫fdo≠ <dig>
this approximation isn’t necessary for performance, since finding the priors numerically is straight forward with gaussian kernel density estimation of f and the marginalization f=∫ffdo, which resulted in priors of f =  <dig>  ±  <dig>  for our data.
rather it is our desire to keep the emission pdfs free of any other data-based attributes besides the few parameters that were chosen by hand.
this allows for the consistent interpretation of results by having a homogeneous muscle mechanics model which is comparable among different preparations and recordings.
assuming independence of the variables d, d˙, and p˙, the joint emission pdf can be factorized into
f=f=fff
where the model of the state s=cd,cd˙,cp˙ subtends the following specific factorisation associations
oimc=oimr=dipi=dipd=itc=itr=atc=atr=ps=pd=oq=dq=
with implicit substitutions of – and – to be made in  due the approximation .
the independence assumption is a model simplification rather than an observed independence in the data, and allows for the factorization of the joint emission pdf into component emission pdfs.
making such an independence assumption, where none exists in reality, is common practice in machine learning for simplifying models and algorithms used to make inference.
in practice, inference algorithms are often robust despite such assumptions, and we observe that inferences obtained by our technique remain consistent with expected states.
optimal state sequence
given an observation sequence o1:n
, our goal is to find the optimal sequence of states s1:n
that explains the observations.
the joint pdf of the observation and state sequences is given by a hidden markov model  <cit> , which subsumes the following factorisation
f=ff∏i=2nff
to keep the number of free parameters small, we choose the state transition probabilities to be independent of state for non self-transitions, given by
f=γ,ifsi=si−11−γ|s|− <dig> otherwise
where γ ∈  is a free parameter that represents a penalty  for changing states between samples.
such a penalty allows the inferred state sequence to be desensitised to noisy observations, resulting in practical smoothing of the sequence.
it is important to include this implicit smoothing so that linear segments of orbits containing undulations are not subdivided, which may result in incorrect state inferences based on arbitrary angles of small subsegments of the undulated linear segment.
a value of γ=1|s| would result in modelling the states in adjacent samples as independent, effectively eliminating the links in the markov chain.
due to the difficulty in quantifying and translating physically realistic dynamics into transition probabilities under our model, state-dependent transition probabilities were not used.
however, by plotting all of the transition occurrences from our complete data set  we have been able to demonstrate that qualitatively unlikely transitions were either not observed or rarely observed in the inference results .
for example we did not have a single example of a mechanical state moving from occluded quiescence to a distended isometric pressure increase.
thus we are confident that state-independent transition probabilities are sufficient.
the probability of the initial state is modelled with the discrete uniform distribution
f=1|s|
the solution to the most likely sequence of states for a given sequence of observations is obtained by performing the following maximisation
argmaxs1:nf
where f is proportional over s1:n
to , and the solution can be found by applying the viterbi algorithm.
the viterbi algorithm works by calculating the most likely sequence of states based on a sequence of discrete observations.
to handle continuous observations we used the value of the emission pdf at each observation as a substitute for the probability of making that observation.
parameters
through an iterative trial-and-error approach we manually selected and tuned parameter values, checking selected areas of data where we could verify whether the inference resulted in states consistent with existing domain knowledge of the expected muscular activity.
for example, when the gut contracts and squeezes the catheter we expect the pressure to rise.
for this approach, data was drawn from a total of  <dig> rabbits, each with  <dig> to  <dig> minutes of recording.
the values for parameters are given in the middle column of table  <dig>
μ
d
σ
d
to test the classification sensitivity of different parameter values to the ones selected manually, parameters were varied one at a time through a range of values .
one reference classification, considered as ground-truth, was performed with the manually selected parameter values .
the reference classification was compared to many comparison classifications with the varied parameter values.
a ratio ε of the number of incorrect active-state classifications to the total number of states which were active in both reference and comparison classification over the entire spatiotemporal map was given by the equation
ε=1∑j,iαji∑j,iαjiŝji≠ŝji′
αji=1{ac,ar}1{ac,ar}
where the square brackets denote iverson bracketsa,  <dig> is the indicator functionb, i and j denote the sample and sensor number  respectively.
a simplified state ŝj,i∈{ac,ar,ps} is one of: active contraction ac = {oimr, itc, act}, active relaxation ar = {itr, atr}, or passive states ps = {oimr, dipi, dipd, ps, pd, oq, dq}.
a simplified state in the comparison classification is denoted with a prime ŝj,i′.
results on the error ε as parameter values vary  shows that the model is adequately robust to variations in the parameters, as the errors are qualitatively considered small.
the test was performed on a 10-minute recording with  <dig> sensors of a single isolated rabbit colon which exhibited typical activity .
RESULTS
the optimal state sequence for each of the sensor locations  was independently inferred.
when visualising, each state sequence was placed according to the location of the corresponding sensor in the colon, resulting in a 2d map where horizontal sequence strips are vertically stacked, shown in figure  <dig> –.
parameters of the hidden markov model were chosen manually, giving robust results with respect to variations in the parameters, shown in figure  <dig>  the γ parameter specifying transition probabilities should be adjusted to account for variations in time sampling frequency, which was not required here as our data consisted entirely of  <dig> hz sampling.
the states inferred by our method coincided with hypothesised states based on manual observation of orbital plots and the expected mechanical function of the colon.
this allowed qualitative analysis of colon dynamics as given in the description of figure 6–.
a more detailed description of these finding can be found in our previous paper  <cit> .
CONCLUSIONS
the use of the hidden markov model to discriminate mechanical states of the intestinal muscle in an isolated preparation of the rabbit colon has given experimental neurogastroenterologists a novel powerful tool to identify the active and passive states of the intestinal muscle.
the graphic representation of where the active contractions and relaxations occur in the intestine at any particular time  will allow for the testing of many hypotheses currently proposed but not validated on the mechanisms responsible for the appropriate mixing and propulsive movements  <cit> .
at the present the parameters described here have been shown to work with the rabbit distal colon.
whether or not the same criteria could be applied to different species with different sized diameters is still to be determined.
it is likely that the parameter will need to be adjusted for each species .
we are currently setting up studies with different animal species to test this hypothesis.
endnotes
a  =  <dig> if p is true,  <dig> if p is false.
b1
a
=  <dig> if x ∈ a, and  <dig> otherwise.
competing interests
the authors declare that they have no competing interests.
authors’ contributions
lw, mc, and pd - study concept and design, drafting of the manuscript; critical revision of the manuscript for important intellectual content.
pd - recorded the data.
lw - software development and analysis.
all authors read and approved the final manuscript.

 the gastrointestinal tract extends from the mouth to the anus. swallowed food travels along the length of this tube at an appropriate speed to allow for the breakdown and absorption of nutrients. the movement of content results from a complex series of muscular contractions and relaxations. these movements of the gut wall alter the pressure profiles within the gut which in-turn cause the digesting contents to move in an oral or anal direction. abnormalities in these motor patterns are associated with several prevalent and unpleasant disorders that cost health care systems billions of dollars per year. the ability to define the relationship that exist between wall motion, intraluminal pressure and the flow of content is a fundamental step in understanding how altered motor patterns effect the transport of luminal content. however, accurately defining these relationships in the human gut in vivo is problematic; ethical constraints prevent detailed examination of real-time movement of the gut wall. to overcome this problem we developed an in vitro animal preparation that allowed us to record simultaneously, both intraluminal pressure and gut diameter in real time, across varying length of intestine. in the next stage of this research we published a theory based paper in which we developed a strategy based on simple principle of biomechanics to deduce the mechanical state of the muscle by calculating the relation between pressure and diameter at every point along the gut segment, and establishing where and when the muscle is actively contracting or relaxing. in that paper, space prevented a detailed description of the mathematical model involved in developing this process. in this work we address the details of the strategy that enabled us to confidently identify, for the first time, the mechanical states of the muscle during peristaltic contractions, and plot them as a functional spatiotemporal map. a major factor in our work involved the use of hidden markov models. the hmm have found extensive use in a variety of fields, stemming from their seminal application in speech recognition in the 1970s. in gastroenterology, hmms have been used to classify the location of a video capsule in the gastrointestinal tract. in their application to hand written recognition, hmms were utilized by observing lines and curves drawn on a 2d plane and inferring the most probable characters they represent. in developing our intestinal model of mechanical states, one of the major challenges we faced was how to identify the beginning and the end of the periods of the various different states of the muscle. however, analogous to hand written recognition, our diameter-pressure plots can be observed as lines in the 2d plane. therefore the hmm was adapted to infer the most probable muscles states at any given point in time along the length of the studies gut segment. a description of the steps involved in this process are detailed here. identification of muscle states the circular muscle of the gut is arranged as continuous rings of smooth muscle forming the inner muscle layer of the tubular structure. the circular muscle layer is thicker than the external longitudinal muscle layer and thus is mechanically more powerful. when it contracts, propulsion of the luminal content can occur. this prolusion is made more efficient if the adjacent regions of the gut concurrently relax, thus effectively allowing the bolus to move into a region of lower pressure. these regions of contraction and relaxation can be detailed by simultaneously recording the diameter of the gut and the intraluminal pressure. from the resultant spatiotemporal map of diameter and pressure we can plot, at any point in time, pressure and diameter curves. from these we can then begin to express the mechanical relation between pressure and diameter as a pressure-diameter orbit plot. in publishing the theory behind this concept we also established that twelve distinct mechanical muscle states can be predicted. the mechanical states are summarized below; occluded isometric contraction: active; occurs with an increase in pressure, with no change in diameter, when the gut is at its minimum diameter. occluded isometric relaxation: passive; occurs with a decrease in pressure and no change in diameter, when the gut is at its minimum diameter. distended isometric pressure increase: passive; occurs with an increase in pressure, no change in diameter, when the gut is at its maximum diameter. distended isometric pressure decrease: passive; occurs with a decrease in pressure, no change in diameter, and a maximum diameter. isotonic contraction: active; occurs with a decrease in diameter and no change in pressure. isotonic relaxation: active; occurs with an increase in diameter and no change in pressure. auxotonic contraction: active: occurs with a decrease in diameter and an increase in pressure. auxotonic relaxation: active: occurs with an increase in diameter and a decrease in pressure. passive shortening: passive; occurs with a decrease in diameter and pressure. passive dilation: passive; occurs with an increase in diameter and pressure. occluded quiescence: passive; occurs with no change in diameter nor pressure, when the gut is at its minimum diameter. distended quiescence: passive; occurs with no change in diameter nor pressure, when the gut is at a non-minimum diameter. having established that mechanical states exist we then need to develop a means to determine when and where each state existed along the gut in an automated fashion. in addition we had to detect both the changes in the mechanical states and the permanence in that state. methods the intraluminal pressures were recorded by a manometry catheter with pressure sensors spaced at mm intervals and each of these was considered independent for modelling purposes. at each sensor location, diameter and pressure values were recorded continuously. data acquisition a detailed description of the techniques used to collate the data has been published elsewhere. here we will provide a brief overview. rabbits were euthanized humanely by intravenous injection of pentobarbitone sodium in accordance with approval by the animal welfare committee of flinders university. the gut diameter and internal pressure were recorded using two different methods, at different sampling rates, spacial resolutions, and offsets in time and space. resampling and spatiotemporal alignment was required to coincide values of pressure and diameter for use as a single observation vector for each node in the markov chain. each spatial location was assigned its own markov chain. a spatiotemporal map of colonic diameter was based on techniques developed in our lab. briefly the spatiotemporal maps were obtained by recording a top-down video of the colon suspended in a bath of krebs solution, such that the length of the colon appeared horizontally in the video, and the number of pixels that the colon spans for each vertical pixel line in each frame was counted. using a reference ruler visible in the recorded video, the colonic diameter in millimetres was obtained. pressures were recorded by mm-spaced sensors at hz with a catheter inserted into the colon. baseline drift was removed with iterated gaussian minima smoothing. different spatiotemporal resolutions and offsets required resampling and alignment. a diameter map and a pressure map were combined by creating a grid of coordinates using the coarsest resolution in time and space from either map aligned with an adjustable spatiotemporal offset, and then binning the original maps into the grid. this resulted in a spatial and time resolution of mm and s respectively. the alignment resulted in a single set of spatiotemporal coordinates that map to coincident diameter and pressure values, allowing diameters and pressures to be quickly compared for analysis without further interpolation. the temporal offset was determined by aligning events that were synchronously recorded by video as flashes from a light bulb and embedded into the pressure recording as meta-data. the spatial offset was manually obtained by observing overlapping images of the two maps, while adjusting the offset to a value best representative of correct alignment that correlates with the video. the entire data set consisted of rabbits recorded with approximately sensors over periods of to minutes each, resulting in just over samples; orbits were created for each sensor. hidden markov model given a sequence of observations of diameter and pressure at a single location in the colon, our objective was to infer the most-likely sequence of mechanical muscle states that could have resulted in those observations. each mechanical muscle state was directly represented as a hidden state in the hidden markov model. in our application, the dependence of a state on the previous state in the markov chain was required as an implicit smoothing technique. observations for each sensor location there are two values observed, the diameter d and pressure p, sampled at a frequency of hz. sample i of the diameter and pressure is given by d i and p i, where i∈{1…n}. the time derivatives of those values are denoted with an overdot and estimated using central differences as d˙i≈di+1−di−12Δt d˙1≈d2−d1Δt d˙n≈dn−dn−1Δt where Δt= s for the hz sampling, and p˙ defined in the same manner as d˙. observation i is defined as the vector oi=di,d˙i,p˙i any general sequence will be written as x a:b for the sake of brevity. states we segment a sensor’s recording and classify each observation into one of twelve discrete mechanical states of the set s={oimc,oimr,dipi,dipd,itc,itr,atc,atr,ps,pd,oq,dq} the conceptual directions and positions of subsequences of observations on a diameter-pressure plot representing examples of each of the twelves states is depicted in figure and described in figure 1a. the state-observation model is based on developing a quantitative model for classifying the dynamics depicted in that figure. state-observation model the state-observation model defines the conditional probabilities of observations and states. the goal is to arrive at a formula describing the distribution of possible observations, under the assumption that they were produced while the muscle was in any given mechanical state. the sample subscript i is omitted for brevity in this section, since the state-observation model is independent of the sample number. each state in s is composed of state components, where each component c o corresponds to an element o of the observation o, and non corresponding components and elements are considered independent. the components quiet, pos, and neg correspond to the d˙ and p˙ velocity elements. the quiet component corresponds to a value of the velocity element close to and pos and neg represent the positive and negative values. the components occ, dis, and any correspond to the diameter d, where occ represents an occluded diameter, dis a distended diameter, and any if the diameter is irrelevent. for example, the state dipd is composed of dis, quietd˙, and negp˙, where the subscripts disambiguate the corresponding velocity elements. the states in s can be considered a vector of state components, where cd∈{any,dis,occ} cd˙∈{quietd˙,posd˙,negd˙} cp˙∈{quietp˙,posp˙,negp˙} given a velocity observation v∈{d˙,p˙}, the probability of the corresponding state component being quiet is modelled on the basis of a normal distribution located at with width free parameters σd˙ and σp˙. the normal distribution is the most common way to model noise and errors, justified by the central limit theorem. since very low speeds are considered quiescent, slow tonic muscle activity will be absorbed into passive states, with only phasic contractions exposed as active states. the probability of the state component being pos or neg is modelled on the basis of normal cumulative distribution functions with the same parameters. probability mass functions are normalised to ensure f+f+f= see – for the formulae, and figure for a visual example. given an observation of diameter d, the probability of the corresponding state component being occ or dis is modelled on the basis of a normal cumulative distribution function and its complement, located at μ d +min d with width σ d, where min d is the value of the minimum recorded diameter. the value d−min d is referred to as “dilation”, and μ d represents the amount of dilation that separates occluded and distended states. the probability of the state being any given d is a constant. the probability mass functions are normalised to ensure f+f+f= see – for the formulae, and figure for a visual example. the probability mass functions f are given by f=zvexp−v22σv f=zvΦvσv f=zvΦ−vσv zv=exp−v22σv2+1−1f=zd f=zdΦd−mind−μdσd f=zdΦμd−d+mindσd zd= where Φ is the cumulative standard normal distribution function, v is an alias for either d˙ or p˙, and z v and z d are normalisation constants ensuring the probabilities sum to for any given observation and all corresponding states. the probability density function of the model emitting a particular observation element o∈{d,d˙,p˙} given a corresponding state component c o, is known as the emission pdf, which can be obtained from bayes’ theorem f=fff the emission pdf is used to determine the distribution of observations that can be made assuming an underlying muscle mechanical state. since only the relative sizes of emission pdfs are required for calculating the optimal state sequence, the observation prior density f can be removed which is independent of state and so does not change which state is most likely to have produced a given observation. in a similar way, if we approximate the state component prior distribution f with a constant, then it can also be removed resulting in the following practical approximation f≈f note that under this approximation, f no longer represents a pdf, that is, ∫fdo≠ this approximation isn’t necessary for performance, since finding the priors numerically is straight forward with gaussian kernel density estimation of f and the marginalization f=∫ffdo, which resulted in priors of f = ± for our data. rather it is our desire to keep the emission pdfs free of any other data-based attributes besides the few parameters that were chosen by hand. this allows for the consistent interpretation of results by having a homogeneous muscle mechanics model which is comparable among different preparations and recordings. assuming independence of the variables d, d˙, and p˙, the joint emission pdf can be factorized into f=f=fff where the model of the state s=cd,cd˙,cp˙ subtends the following specific factorisation associations oimc=oimr=dipi=dipd=itc=itr=atc=atr=ps=pd=oq=dq= with implicit substitutions of – and – to be made in due the approximation. the independence assumption is a model simplification rather than an observed independence in the data, and allows for the factorization of the joint emission pdf into component emission pdfs. making such an independence assumption, where none exists in reality, is common practice in machine learning for simplifying models and algorithms used to make inference. in practice, inference algorithms are often robust despite such assumptions, and we observe that inferences obtained by our technique remain consistent with expected states. optimal state sequence given an observation sequence o1:n, our goal is to find the optimal sequence of states s1:n that explains the observations. the joint pdf of the observation and state sequences is given by a hidden markov model, which subsumes the following factorisation f=ff∏i=2nff to keep the number of free parameters small, we choose the state transition probabilities to be independent of state for non self-transitions, given by f=γ,ifsi=si−11−γ|s|− otherwise where γ ∈ is a free parameter that represents a penalty for changing states between samples. such a penalty allows the inferred state sequence to be desensitised to noisy observations, resulting in practical smoothing of the sequence. it is important to include this implicit smoothing so that linear segments of orbits containing undulations are not subdivided, which may result in incorrect state inferences based on arbitrary angles of small subsegments of the undulated linear segment. a value of γ=1|s| would result in modelling the states in adjacent samples as independent, effectively eliminating the links in the markov chain. due to the difficulty in quantifying and translating physically realistic dynamics into transition probabilities under our model, state-dependent transition probabilities were not used. however, by plotting all of the transition occurrences from our complete data set we have been able to demonstrate that qualitatively unlikely transitions were either not observed or rarely observed in the inference results. for example we did not have a single example of a mechanical state moving from occluded quiescence to a distended isometric pressure increase. thus we are confident that state-independent transition probabilities are sufficient. the probability of the initial state is modelled with the discrete uniform distribution f=1|s| the solution to the most likely sequence of states for a given sequence of observations is obtained by performing the following maximisation argmaxs1:nf where f is proportional over s1:n to, and the solution can be found by applying the viterbi algorithm. the viterbi algorithm works by calculating the most likely sequence of states based on a sequence of discrete observations. to handle continuous observations we used the value of the emission pdf at each observation as a substitute for the probability of making that observation. parameters through an iterative trial-and-error approach we manually selected and tuned parameter values, checking selected areas of data where we could verify whether the inference resulted in states consistent with existing domain knowledge of the expected muscular activity. for example, when the gut contracts and squeezes the catheter we expect the pressure to rise. for this approach, data was drawn from a total of rabbits, each with to minutes of recording. the values for parameters are given in the middle column of table μ d σ d to test the classification sensitivity of different parameter values to the ones selected manually, parameters were varied one at a time through a range of values. one reference classification, considered as ground-truth, was performed with the manually selected parameter values. the reference classification was compared to many comparison classifications with the varied parameter values. a ratio ε of the number of incorrect active-state classifications to the total number of states which were active in both reference and comparison classification over the entire spatiotemporal map was given by the equation ε=1∑j,iαji∑j,iαjiŝji≠ŝji′ αji=1{ac,ar}1{ac,ar} where the square brackets denote iverson bracketsa, is the indicator functionb, i and j denote the sample and sensor number respectively. a simplified state ŝj,i∈{ac,ar,ps} is one of: active contraction ac = {oimr, itc, act}, active relaxation ar = {itr, atr}, or passive states ps = {oimr, dipi, dipd, ps, pd, oq, dq}. a simplified state in the comparison classification is denoted with a prime ŝj,i′. results on the error ε as parameter values vary shows that the model is adequately robust to variations in the parameters, as the errors are qualitatively considered small. the test was performed on a 10-minute recording with sensors of a single isolated rabbit colon which exhibited typical activity.  the optimal state sequence for each of the sensor locations was independently inferred. when visualising, each state sequence was placed according to the location of the corresponding sensor in the colon, resulting in a 2d map where horizontal sequence strips are vertically stacked, shown in figure –. parameters of the hidden markov model were chosen manually, giving robust results with respect to variations in the parameters, shown in figure the γ parameter specifying transition probabilities should be adjusted to account for variations in time sampling frequency, which was not required here as our data consisted entirely of hz sampling. the states inferred by our method coincided with hypothesised states based on manual observation of orbital plots and the expected mechanical function of the colon. this allowed qualitative analysis of colon dynamics as given in the description of figure 6–. a more detailed description of these finding can be found in our previous paper.  the use of the hidden markov model to discriminate mechanical states of the intestinal muscle in an isolated preparation of the rabbit colon has given experimental neurogastroenterologists a novel powerful tool to identify the active and passive states of the intestinal muscle. the graphic representation of where the active contractions and relaxations occur in the intestine at any particular time will allow for the testing of many hypotheses currently proposed but not validated on the mechanisms responsible for the appropriate mixing and propulsive movements. at the present the parameters described here have been shown to work with the rabbit distal colon. whether or not the same criteria could be applied to different species with different sized diameters is still to be determined. it is likely that the parameter will need to be adjusted for each species. we are currently setting up studies with different animal species to test this hypothesis. endnotes a = if p is true, if p is false. b1 a = if x ∈ a, and otherwise. competing interests the authors declare that they have no competing interests. authors’ contributions lw, mc, and pd - study concept and design, drafting of the manuscript; critical revision of the manuscript for important intellectual content. pd - recorded the data. lw - software development and analysis. all authors read and approved the final manuscript. 
utilising an in vitro technique that allows for the simultaneous recording of intraluminal pressure and gut diameter in an isolated section of rabbit colon, we developed a technique to help define the mechanical states of the muscle at any point in space and time during actual peristaltic movements. then qualitative mechanical states of the muscle activity were defined as combinations of these state components. a hidden markov model was used to correlate adjacent-in-time samples, and the viterbi algorithm was used to infer the most likely sequence of mechanical states based on the observed data. from this a spatiotemporal map of the mechanical states was produced, showing the regions of active contractions, active relaxations, or passive states along the length of the gut throughout the entire recording period. the identification of mechanical muscles states based on gut diameter and intraluminal pressure was possible by modelling muscle activation with a hidden markov model. defining these complex relationships is a fundamental step for neurogastroenterologists to be able define normal and abnormal gut motility. for each individual measure of pressure or diameter, dynamic state components were identified; increasing or decreasing changes or a stable period. two additional static state components, fully contracted and fully distended, were defined for the diameter.
 contractions and relaxations of the muscle layers within the digestive tract alter the external diameter and the internal pressures. these changes in diameter and pressure move digesting food and waste products. defining these complex relationships is a fundamental step for neurogastroenterologists to be able define normal and abnormal gut motility.  utilising an in vitro technique that allows for the simultaneous recording of intraluminal pressure and gut diameter in an isolated section of rabbit colon, we developed a technique to help define the mechanical states of the muscle at any point in space and time during actual peristaltic movements. this was achieved by directly relating the changes in pressure to the changes in diameter along the length of the gut studied. for each individual measure of pressure or diameter, dynamic state components were identified; increasing or decreasing changes or a stable period. two additional static state components, fully contracted and fully distended, were defined for the diameter. then qualitative mechanical states of the muscle activity were defined as combinations of these state components. a hidden markov model was used to correlate adjacent-in-time samples, and the viterbi algorithm was used to infer the most likely sequence of mechanical states based on the observed data. from this a spatiotemporal map of the mechanical states was produced, showing the regions of active contractions, active relaxations, or passive states along the length of the gut throughout the entire recording period.  the identification of mechanical muscles states based on gut diameter and intraluminal pressure was possible by modelling muscle activation with a hidden markov model. manometryperistalsistime-series analysismuscle mechanics 