Consider a set of probes, called “agents”, who sample, based on opportunistic contacts, a population moving between a set of discrete locations. An example of such agents are Bluetooth probes that sample the visible Bluetooth devices in a population. Based on the obtained measurements, we construct a parametric statistical model to jointly estimate the total population size (e.g., the number of visible Bluetooth devices) and their spatial density. We evaluate the performance of our estimators by using Bluetooth traces obtained during an open-air event and Wi-Fi traces obtained on a university campus.

In what follows, we explain how to execute the code accompanying the paper *Opportunistic Sampling for Joint Population Size and Density Estimation* to performing population size and density estimation. The files `test1.m`

and `test3.m`

can be used as starting points for applying the implemented algorithms on your datasets. The datasets used in the paper are not publicly available.

`test1.m`

: This file generates**Figures 2**and**3**in the paper and demonstrates the population size estimation model described in the paper. Traces are first generated and then the contact matrix is computed. Afterward population size is estimated by using the arrival/departure times of the individuals, the arrival/departure time distribution of the individuals, and the approximated arrival/departure time distribution of individuals.`test2.m`

: Demonstrates the population size estimation model described in the paper.. Traces are first generated and then the contact matrix is computed. Afterwards population size is estimated by varying the amount of information in the traces: the number of agents and observation window are changed.`test3.m`

: Demonstrates the joint population size and density estimation model described in the paper.. Traces are first generated and then the contact matrix is computed. Afterwards population size and density is jointly estimated by using the actual arrival/departure times of the individuals, the actual arrival/departure time distribution of the individuals, and the approximated arrival/departure time distribution of individuals.`PopEstLogLikeKnownTimes`

: Computes the negative loglikelihood function for the population size estimation model as stated in Equation (13) of the paper for a given set of parameters and measurements. For this function we assume that the actual arrival/departure times of the discovered individuals are known; the likelihood function computed is given in Section I-B of the*supplementary materials*(separate file to the paper).`PopEstLogLikeKnownDistribution`

: Computes the negative loglikelihood function for the population size estimation model as stated in Equation (13) of the paper for a given set of parameters and measurements. For this function we assume that the individuals' arrival/departure time distribution (actual or approximate) are known, but not the actual times.`JointPopDensEstLogLikeKnownTimes`

: Computes the negative loglikelihood function for the joint population size and density estimation model as stated in Equation (17) of the paper for a given set of parameters and measurements. For this function we assume that the actual arrival/departure times of the discovered individuals are known; the likelihood function computed is given in Section II-A of*supplementary materials*(separate file to the paper).`JointPopDensEstLogLikeKnownDistribution`

: Computes the negative loglikelihood function for the joint population size and density estimation model as stated in Equation (17) of the paper for a given set of parameters and measurements. For this function we assume that the individuals' arrival/departure time distribution (actual or approximate) are known, but not the actual times.

- Microsoft Windows 8, with MATLAV R2014b

Copyright (c) 2015, Farid Movahedi Naini, Olivier Dousse, Patrick Thiran and Martin Vetterli

This code is free to reuse for non-commercial purpose such as academic or educational. For any other use, please contact the authors.

This code is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

For any questions, suggestions or comments, please contact Farid M. Naini