Interpreting Poisson distribution
=================================
The matrial in this subsection is adapted from [[1]](#references).

The poisson distribution can be viewed as an approximation to a binomial distribution. Recall that a binomial distribution with parameters *n* and *p* specifies the probability of having *k* successes in *n* trials when the probability of success in each trial is *p*:

\begin{equation}
P(X=k) = \binom{n}{k} p^k {(1-p)}^{n-k}
\end{equation}

The expected value of this distribution is *np*. 

Sometimes, *n* is extremely large and *p* is extremely small; still *np* is within a reasonable range. For example consider the particles discharged from a radioactive material in a short period of time. 


```
from IPython.display import SVG
SVG('particles.svg')
```




    

    



In this example, the number of particles is very large, and the probability for each individual particle to emit is very small. Still the product of these values is a mid-range number that shows how many particles on average are discharged in that certain period. 

Having extreme values for *n* and *p*, we can not directly use the binomial distribution. Let $\lambda = np$. We can approximate the binomial distribution as follows:

\begin{align}
P(X = k) &=  \frac{n!}{(n-k)!k!}p^k(1-p)^{n-k} \\
        &= \frac{n!}{(n-k)!k!} (\frac{\lambda}{n})^k (1-\frac{\lambda}{n})^{n-k} \\
        &= \frac{n(n-1)\ldots(n-i+1)}{n^k}.\frac{\lambda^k}{k!}\frac{(1-\lambda/n)^n}{(1-\lambda/n)^k}
\end{align}

For large *n* and moderate $\lambda$, 

\begin{align}
(1-\frac{\lambda}{n})^n &\simeq e^{-\lambda} \\
\frac{n(n-1)\ldots(n-i+1)}{n^k} &\simeq 1 \\
(1-\frac{\lambda}{n})^k &\simeq 1
\end{align}

Hence, for large $n$ and moderate $\lambda$, 
\begin{equation}
    P(X=k) = e^{-\lambda}\frac{\lambda^k}{k!}
\end{equation}


Below is an excerpt from [[1]](#references):
>In other words, if *n* independent trials, each of which results in a success with probability *p*, are performed, then, when *n* is large and *p* is small enough to make *np* moderate, the number of successes occurring is approximately a Poisson random variable with parameter $\lambda = np$. This value $\lambda$ (which will later be shown to equal the expected number of successes) will usually be determined empirically. Some examples of random variables that generally obey the Poisson probability law are as follows:
1. The number of misprints on a page (or a group of pages) of a book
2. The number of people in a community who survive to age 100
3. The number of wrong telephone numbers that are dialed in a day
4. The number of packages of dog biscuits sold in a particular store each day
5. The number of customers entering a post office on a given day
6. The number of vacancies occurring during a year in the federal judicial system
7. The number of $\alpha$-particles discharged in a fixed period of time from some radioactive material

Assumptions about the distribution of trips
===========================================

In our work, we assume that the number of trips from source **s** to destination **d** during the time period **t** follows a Poisson distribution. The meaning of this assumption in terms of the original binomial distribution is that:

**There are many individuals in area _s_. The probability for each individual to take a taxi to area _d_ during period _t_ is very small. However the product of these two values (number of individuals times the probability of trip for each individual) is a moderate number.**


```
SVG('people.svg')
```




    

    



The starting core assumption about the distribution of trips from region *s* to regoin *t* during period *t* is that $\lambda_{s,d,t} = N_{s} \times p_{s,d,t}$, where $N$ is the number of individuals residing in region $s$ in period $t$, and $p_{s,d,t}$ is the probability for each of them to take a taxi for destination $d$ in this period.

The simplest approach for estimating the $\lambda$ parameters is to directly obtain them from the data. In our work, we take a different approach, that is decomposing $\lambda$'s into basic constituents and then estimating the values for these constituents. 

The first step in decomposition is to consider the trips as a sum of independent Poisson distributions. For example, we can decompose the morning trips from area **A** to area **B** into three sets of independent trips:
- *workers*: Those who live in A and work in B
- *kids*: The children living in A who have to go to their schools in B
- *shoppers*: Individuals living in A who go to B to receive a service

## Some of the assumptions about the *working* trips

Let us now study the *worker* group a bit closer. Travels by this group follows a Poisson distribution with parameter $\lambda_w$. Based on the binomial interpretation of Poisson distribution, we have $\lambda_w = N_A \times p^w_{B}$, where $N_A$ is the number of residents of region A and $p^w_{B}$ is the probability for a resident to *have a job in regioin B and take a taxi to their job*.

A distinguishing characteristic of our approach is specification of Poisson parameters by means of logical rules. Consider the following rule that specifies a rate for working trips in the morning:

``` 
trips(From, To, Time) ~ poisson(50) :-
    morning(Time),
    residential(From),
    business(To).
```

The problem with this rule is that it treats all sources and destinations equally, as long as the source is *residential* and the destination is *business*. However, $\lambda_w$ varies for different sources and destinations. Consider our previous example ($\lambda_w = N_A \times p^w_B$). In this example, $\lambda_w$ depends on:

1. the population of region A ($N_A$).
2. the probability for a resident of A to have a job in B 

The following rule takes these factors into account (A detailed justification will follow [later](#details)):

```
trips(From, To, Time) ~ poisson(Param) :-
    morning(Time),
    residential(From, Density),
    job_ratio(From, To, Ratio),
    Param is Density*Ratio*200.
        
```
However, to exploit this rule, we need to know the distribution of workers in each source area for each target area. If we do not have sufficient data about such distributions, it is simpler to assume that the jobs in source areas are distributed according to the number of jobs in target areas:

```
trips(From, To, Time) ~ poisson(Param) :-
    morning(Time),
    residential(From, Density1),
    business(To, Density2),
    Param is Density1*Density2*150.
```

## Some of the assumptions about the *shopping* trips
Similar to the *workers*, we can have a binomial interpretation for shoppers: $\lambda_s = N_A \times p^s_{B}$, where $N_A$ is the number of residents of region A and $p^s_{B}$ is the probability for a resident to *require a service in regioin B and take a taxi to B*.
Again, the simplest model does not account for depency of $N_A$ and $p^s_B$ to characteristics of A and B:
``` 
trips(From, To, Time) ~ poisson(10) :-
    morning(Time),
    residential(From),
    business(To).
```

To incorporate these characteris, we use the *gravity model* (more details in another note). Based on this model, each source and destination is viewed as a charged mass and the probability of a movement is expressed in terms of weights of bodies and their distance:

```
trips(From, To, Time) ~ poisson(Param) :-
    morning(Time),
    residential(From, Density1),
    shopping(To, Density2),
    inv_distance(From, To, Inverse_Dist),
    Param is Density1*Density2*Inverse_Dist*80.
```

## Peripheral factors
Recall that in our interpretation of $\lambda$, the probability $p^s_{\text{dest}}$ means the probability for each individual (residing in the source area) to take a taxi to the destination area. This probability is influenced by two factors:

1. The individual has the intention to go to the destination area
2. The individual takes a taxi to reach there

In previous rules, we assumed that *densities* reflect both factors. However, sometimes peripheral factors influence one (or both) of these factors. For example, we can assume that when it rains, the probability of taking a taxi increases for a shopper increases by a constant factor:

```
    trips(From, To, Time) ~ poisson(Param) :-
        evening(Time), 
        shopping(From, Density1),
        residential(To, Density2),
        inv_distance(From, To, Inverse_Dist),
        rain_factor(From, To, Time, Rain_F),
        Param is Density1*Density2*Inverse_Dist*Rain_F*80.
        
    rain_factor(_,_,_, 1):
        not(rains_at(Time)).
    rain_factor(From, To, Time, 1.4) :-
        shopping(From, _),
        residential(To, _),
        rains_at(Time).
```
Note that by adding such rules, we have other factors to learn (e.g. the impact of rain) which might complicate our learning algorithm. 

The meaning of densities
========================
<a id='details'></a>

In previous section, instead of directly specifying the parameter for each distribution, we expressed the parameter as a product of multiple factors (e.g. *density1 $\times$ density2 $\times$ 80*). Here I will try to justify this choice. 

Let variable $X$ be the number of workers taking a taxi from area **A** to area **B** in the morning. We are assuming that $X$ is a Poisson random variable and its parameter can be obtained via this rule:
```
trips(From, To, Time) ~ poisson(Param) :-
    morning(Time),
    residential(From, Density1),
    business(To, Density2),
    Param is Density1*Density2*150.
```
Denoting this Poisson parameter by $\lambda$ and the densities by $d_A$ and $d_B$, this rule says that $\lambda = d_A \times d_B \times 150$. Recalling the binomial interpretation of Poisson distribution, this rule implies that:
\begin{equation}
    N_A \times p_{A \to B} = d_A \times d_B \times 150
\end{equation}
(Once again, $N_A$ is the number of individuals residing in *A*, and $p_{A \to B}$ is the probability for each of them to take a taxi to *B* for the purpose of shopping). 

Now we are free in our interpretation of the densities, as long as the above equality holds. For example, if we take the density of a residential area ($d_A$) equal to its population, the formula changes into:
\begin{equation}
    p = d_B \times 150
\end{equation}
So, the probability for each resident of **A** to have a job in **B**  AND take a taxi to their job is reflected by two numbers: $d_B$ which is chosen by modeler, and 150, which is learned from the data. 

But how do we choose $d_B$? It follows that by making simplifying assumptions, we can use the number of jobs in **B** as its density. Assume that for an individual, the chance of having a job is independent from where they live. Also assume that each individual is eqully likely to have any of the jobs in the city (regardless of where they live). Denoting the population of A by $P_A$ and number of jobs in B by $J_B$, we can write the $p_{A \to B}$ as $c_1 \times P_A \times c_2 \times J_B$, where $c_1$ is the probability of having a job, and $c_2$ is $\frac{1}{\text{#all jobs}}$. 

However, if we are learning the base parameter (150) from the data, we do not need to include the constants $c_1$ and $c_2$, as they will be automatically reflected in the learned parameter. Following the same kind of logic, we can further simplify the model and use areas of **A** and **B** as $d_A$ and $d_B$. 

<a id='references'></a>
### References
- [1] Ross, S. (2012). A first course in probability. Pearson.

f51297024548b6d4e045a4b55ed71a9d4a6c0a6a
ipynb
Jupyter Notebook
Hanoi/Poisson_Assumptions.ipynb
Behrouz-Babaki/notebooks
9e84263879ba17e8581b8bdee60aaf3006fa4a73
Unlicense
Hanoi/Poisson_Assumptions.ipynb
Behrouz-Babaki/notebooks
9e84263879ba17e8581b8bdee60aaf3006fa4a73
Unlicense
Hanoi/Poisson_Assumptions.ipynb
Behrouz-Babaki/notebooks
9e84263879ba17e8581b8bdee60aaf3006fa4a73
Unlicense
Qwen/Qwen-72B
1. YES
2. YES