Occupancy Grid Mapping
Published:
Besides state estimation or localization, which provide a robot with knowledge of where it is, it’s equally important for a mobile robot to perceive its surrounding and form a knowledge of where is occupied, that’s where mapping comes in. This note covers a fundamental mapping algorithm, occupancy grid mapping.
Problem Statement
In occupancy grid mapping, a map is discretized into different cells, where each cell is a binary random variable that models the occupancy, and is the probability of a cell being occupied. The map is assumed to be static. The goal is to find the belief , where is the observation and is the state of the robot.
Two assumptions are made for tractability
- The robot state are known.
- The occupancy of individual cells are independent, and thus
At each timestep , the sensor performs some measurement and provide the information of whether a cell is believed to be occupied or not, in terms of , which is known as the inverse sensor model.

One simple inverse sensor model is shown in the figure above. Consider a laser beam range sensor that provides the reading , where and are the range and bearing of the -th beam. For grid , let and be the range and bearing of the grid as observed from the current robot pose , and be the beam going through that gird. Based on the relation of a grid’s position relative to the robot, we have three different cases:
- If or , then return , the sensor has no information about this grid.
- Else if and , then return , the sensor think the grid is occupied.
- Else if and , then return , the sensor think the grid is free.
where is a sensor-specific parameter representing the maximum detectable range, is the grid size and is the width of each beam.
Mapping Algorithm
Following the Bayes filtering framework, a general algorithm can be derived for the occupancy grid mapping [2]. Starting from equation 1,
Further notice that the map is independent of the robot state , we obtain
Similarly, for the negation
Compute the ratio of equation (2) and (3), we get
Then, change to log odds form by defining
and the product chain turns into a sum
Bayes Inference using Conjugate Prior
The previous section derived an equation for updating the belief of the map under the Bayes framework, however, it lacks the notion of uncertainty (i.e., how confident we are about the map). With the notion of conjugate prior, a proper selection of the underlying distribution function for can both simplifies the updating rule and provide a closed form formula for uncertainty.
Recall that from Bayes rule
Bernoulli Likelihood and Beta Prior
First consider the case where the occupancy of a grid is binary, i.e., . Let be the unknown occupancy probability. From the inverse sensor model described above, we know that each sensor measurement provide a binary result, denoted as , where
Then, the likelihood is modeled as a Bernoulli with parameter , i.e.,
Furthermore, if we model the prior as a Beta distribution, i.e.,
where is the beta function.
Then, it follows from the Bayes rule that the posterior is
which still follows a Beta distribution, , where
In this case, we call beta distribution the conjugate prior for the Bernoulli likelihood.
Conjugate Distribution and Conjugate Prior [2]
- If the posterior distributions are in the same probability distribution family as the prior probability distribution, the prior and posterior are then called conjugate distributions.
- The prior is called a conjugate prior for the likelihood function.
Note that the choice of modeling the prior as a Beta distribution here is an algebraic convenience, which provides a closed-form expression for the posterior. Then the mean and covariance can be easily obtained
Given the simple update rule in Equation (4), the recursive Bayes framework becomes a simple counting problem: when the sensor model returns “occupied”, increment by 1, if the sensor model returns “free”, increment by 1.
Categorical Likelihood and Dirichlet Prior
Next, we can generalize the above binary occupancy mapping into a multi-categorical case using the categorical likelihood and the Dirichlet prior.
Suppose we have different categories and each grid can be belongs to exactly one category or empty, i.e., . Let be a vector where , and . Further let the measurement be a one-hot-encoded tuple with and , indicating which category the sensor believes cell belongs to.
Similarly, the likelihood can be modeled as a categorical distribution
Then, we apply a Dirichlet distribution with parameter on the prior
The posterior then follows another Dirichlet distribution with parameter ,
Thus, the update rule is
which is simply adding 1 to the of the category to which the sensor believes the cell belongs.
For the multi-categorical case, the mean and covariance can also be computed in closed-form:
Counting Sensor Models
Finally, we can write out the mapping algorithm for multi-category discrete counting sensor model
Note that if , the above algorithm reduces to the binary occupancy grid mapping.
One more generalization can be made to the above discrete CSM, which is to take into account the spatial continuity. In the algorithm listed above, an observation falling into a cell grid only updates of that cell and not any other cell. In reality, if a cell is observed to be occupied by a wall, then its nearby cells may also be occupied by that wall.
Let be the spatial support of the map (e.g., or ). Define a kernel function that operates on the spatial inputs. The kernel function determines how much an observation at a location influences our belief about location .
Specifically, the inverse sensor model is corrected as follows. For beam , we construct a set of sample points where
- is the global coordinate of the beam’s endpoint. All grids close to this endpoint is considered as occupied (or fall into some category), by a kernel-weighted factor.
- is the global coordinate of other sample points on the beam. All grids close to any of these sample points are considered as free, by a kernel-weighted factor.
Then, during the map construction, we update the Dirichlet parameter for grid with
Another benefit of continuous CSM is that we can query any point in the spatial support after the map is built, with
where is the initial prior.
Reference
[1]. https://www.mathworks.com/help/nav/ref/occupancymap.insertray.html
[2]. M. Ghaffari, ROB530 Lecture Slides — Robotic Mapping. University of Michigan, 2026.


