How to estimate parameters of a (almost) linear model from unpaired observations? I have this model:
$a_i=mod(\lfloor i\cdot T+Normal(0,\sigma_a)\rfloor,Q)$
$b_i=mod(\lfloor a_i+D+Normal(0,\sigma_b)\rfloor,Q)$
with
$i=1..N$
$N\in\mathbb{N}$
$Q\in\mathbb{N}$
$T\in\mathbb{R}, T\gt0$
$D\in\mathbb{R}, D\gt0$
$D\gt T$
$Normal(\mu,\sigma)$ is a random number drawn from a Normal distribution with mean $\mu$ and variance $\sigma^2$.
$mod(x,y)$ is the modulo operator, in some programming language it is x % y.
$\lfloor x \rfloor$ is the floor function.
Given the $N$ paired observations $(a_i,b_i)$ and $Q$, I need to find $T$ and $D$ and I would like to have an idea about $\sigma_a$ and $\sigma_b$.
My naïve solution is:


*

*Ignore $\sigma_a$ and $\sigma_b$ setting them to $0$;

*an estimate for $T$ is the median of the list composed by the $N-1$ values $a_i-a_{i-1}$;

*an estimate for $D$ is the median of the list composed by the $N$ values $b_i-a_{i}$.


This R code:
N=1000
T=200
D=3000
Q=2^16
sigma_a=1
sigma_b=2

i=seq(1,N)

a=floor(i*T+rnorm(N,0,sigma_a))%%Q

b=floor(a+D+rnorm(N,0,sigma_b))%%Q

print(sprintf("Estimate for T: %f",median(diff(a))))
print(sprintf("Estimate for D: %f",median(b-a)))

gives this output:
[1] "Estimate for T: 200.000000"
[1] "Estimate for D: 2999.000000"

Now, I would like to remove the assumption that the observations are paired, i.e., I will just have all the $a_j$ and all the $b_k$ but I will ignore the correspondences between them, so for example, with $N=3$, $T=200$, $D=3000$, $\sigma_a=0$ and $\sigma_b=0$ I will have $a=\{200,400,600\}$ and $b=\{3400,3600,3200\}$.
Is the problem still solvable? How?
Edit
A more difficult problem is when I have less $b_i$ than $a_i$, i.e.
b=floor(a+D+rnorm(N,0,sigma_b))%%Q
b=sample(x = b,size = .95*length(b),replace = FALSE)

 A: Simplifying the problem
Given the plausible ranges of the parameters you're working with, the probability that
floor(i*T+rnorm(0,sigma_a))

differs from
floor(i*T+rnorm(0,sigma_a))%%Q

is essentially zero. So, you can assume
a=floor(i*T+rnorm(0,sigma_a))

b=floor(a+D+rnorm(0,sigma_b))

.
Crude estimates
For crude estimates, you can ignore the flooring and take $D \approx \Sigma_i a_i - \Sigma_i b_i$, $T\approx N^{-1}\Sigma a_i/i$. Neither estimate depends on the order of the observations.
For a slight refinement, you can account for the fact that the variance of $a_i/i$ decreases quadratically in $i$. You could do this by using a differently weighted average, $T \approx (\Sigma i)^{-1}\Sigma a_i$; this achieves minimum variance out of all possible weighted averages. Incidentally, if you convert the median you used to an equivalent mean, it telescopes to become $(a_n - a_1)/(N-1)$. So, yours is probably pretty far from the minimum variance estimator.
These refinements have the drawback that the require knowledge of the order of the observations.
Full treatment
To deal with the floors, I can't think of anything craftier than writing out the likelihood and either 1) optimizing it or 2) feeding it into an MCMC routine. Optimization is probably easier. But, MCMC would have the advantage that you could include steps where the ordering of the observations is swapped. This could give you exact inference, accounting for the flooring, even without knowing the order of the observations.
The PMF of a "floormal" random variable $X$ (floored normal) is $Pr(X=x_i) = Pr(x_i < Z < x_i+1) = F(x_i+1, \mu_z, \sigma_z) - F(x_i, \mu_z, \sigma_z)$ where $Z$ is the normal before flooring, $\mu_z, \sigma_z$ are its parameters, $F$ is a normal CDF, and the PMF is evaluated at $x_i$. Your likelihood is a product of terms like that one.
$$L(T, D, \sigma_a, \sigma_b) = \\ \Pi_i F(a_i+1, i*T, \sigma_a) - F(a_i, i*T, \sigma_a) \\ \times \\ \Pi_i F(b_i+1, D+a_i, \sigma_b) - F(b_i, D+a_i, \sigma_b)$$.
One way to cook up an MCMC routine with the right target distribution:

*

*Initialize at a sensible place such as the crude estimates discussed above.

*Propose a new set of parameters in a reversible manner, such that $Pr(new | old) = Pr(old | new)$. For example, add a small Normal draw to $log(\sigma_a)$ or flip a pair of adjacent $b_i$'s (to explore various plausible orderings).

*Accept the new proposal with probability $p_{acc} = \pi(new)L(new) / \pi(old)L(old)$, where $\pi$ is your judiciously chosen prior distribution over the parameters. (If $p_{acc}>1$, then accept with probability 1.) If you don't accept, then repeat the current value and try again.

I haven't worked with MCMC in about a year, so I'll check again, but please comment if I have made any errors here.
