Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Iamhankai Forest of Thought Most Frequent Elements

From Leeroopedia
Knowledge Sources
Domains Ensemble_Methods, Decision_Theory
Last Updated 2026-02-14 03:00 GMT

Overview

Concrete tool for identifying the most frequent answer(s) via majority voting provided by the Forest-of-Thought repository.

Description

The most_frequent_elements function implements majority voting by counting element frequencies in a list (filtering out None values), finding the maximum frequency, and returning all elements that achieve that frequency. When a unique mode exists, this gives the majority answer. When multiple elements tie for maximum frequency, the tie is detected and escalated to the CGDM judge.

Usage

Called during early stopping checks within Monte_Carlo_Forest.mctsr_run() and during CGDM post-processing in determine_best_answer(). Also used in get_fot_final_answer() for the CGDM stopping strategy.

Code Reference

Source Location

Signature

def most_frequent_elements(lst):
    """
    Find all elements with maximum frequency in a list.

    Args:
        lst (list): Input list, may contain None values.

    Returns:
        list: All elements matching the maximum frequency.
              Empty list if input is empty or all None.
    """

Import

from utils.early_stop import most_frequent_elements

I/O Contract

Inputs

Name Type Required Description
lst list Yes List of answer strings from forest trees (may contain None)

Outputs

Name Type Description
result list All elements with maximum frequency; single-element list indicates clear majority

Usage Examples

from utils.early_stop import most_frequent_elements

# Clear majority
answers = ["42", "42", "38", "42", None]
result = most_frequent_elements(answers)
# result = ["42"]

# Tie - needs CGDM judge
answers = ["42", "38", "42", "38"]
result = most_frequent_elements(answers)
# result = ["42", "38"]

# Early stopping check
if len(result) == 1:
    final_answer = result[0]
else:
    final_answer = cgdm_judge(answers)

Related Pages

Implements Principle

Page Connections

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