Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Facebookresearch Habitat lab AverageHelper

From Leeroopedia
Revision as of 12:34, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Facebookresearch_Habitat_lab_AverageHelper.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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

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}")

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment