Implementation:Facebookresearch Habitat lab AverageHelper
| Knowledge Sources | |
|---|---|
| Domains | Embodied_AI, Human_in_the_Loop |
| Last Updated | 2026-02-15 00:00 GMT |
Overview
AverageHelper is a utility class that computes a moving average over a sliding window and optionally returns the average at regular output intervals.
Description
The AverageHelper class maintains a fixed-size deque (sliding window) of numeric values and provides methods to add values and compute the current moving average. The class is designed for monitoring metrics such as frame latency or performance counters. When adding a value via the add method, the helper returns the current average every output_rate calls, making it easy to log or display metrics at controlled intervals without explicit counter management in the caller.
Usage
Use AverageHelper when you need to track a running average of a numeric metric (e.g., frame latency, FPS, or any time-series measurement) and want to periodically retrieve the averaged value at a configurable rate.
Code Reference
Source Location
- Repository: Facebookresearch_Habitat_lab
- File: habitat-hitl/habitat_hitl/core/average_helper.py
- Lines: 1-34
Signature
class AverageHelper:
def __init__(self, window_size, output_rate):
...
def add(self, x):
...
def get_average(self):
...
Import
from habitat_hitl.core.average_helper import AverageHelper
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| window_size | int | Yes | Maximum number of recent values to keep in the sliding window. |
| output_rate | int | Yes | How often (in number of add calls) to return the average from the add method. |
Outputs
| Name | Type | Description |
|---|---|---|
| add() return value | Optional[float] | Returns the current average every output_rate calls; otherwise returns None. |
| get_average() return value | Optional[float] | Returns the current average over the sliding window, or None if empty. |
Usage Examples
Basic Usage
from habitat_hitl.core.average_helper import AverageHelper
# Create a helper that averages over 10 values and outputs every 5 calls
avg_helper = AverageHelper(window_size=10, output_rate=5)
for i in range(20):
result = avg_helper.add(float(i))
if result is not None:
print(f"Step {i}: average = {result}")
# You can also retrieve the average at any time
current_avg = avg_helper.get_average()
print(f"Current average: {current_avg}")