Statistics Calculator Examples¶
This document showcases various statistics calculator implementations available in the CALT library. These examples demonstrate how to calculate descriptive statistics for different types of mathematical problems and can be used as templates for creating your own statistics calculators.
Symbolic Problems¶
1. Polynomial Statistics Calculator¶
Purpose: Calculate comprehensive statistics for polynomial systems, providing insights into degree distributions, term complexity, and coefficient characteristics.
Key Features: - Handles both single polynomials and polynomial lists flexibly - Calculates degree statistics (min, max, sum of total degrees) - Analyzes term complexity (min, max, sum of terms across all polynomials) - Extracts coefficient statistics based on field type (QQ, RR, ZZ, finite fields) - Returns structured statistics for both problem and solution components
Please refer to scripts/dataset_generation/sagemath/polynomial_problem_generation.py
.
from calt.dataset_generator.sagemath import BaseStatisticsCalculator
class PolyStatisticsCalculator(BaseStatisticsCalculator):
def __call__(
self,
problem: list[MPolynomial_libsingular] | MPolynomial_libsingular,
solution: list[MPolynomial_libsingular] | MPolynomial_libsingular,
) -> dict[str, dict[str, int | float]]:
"""Calculate statistics for a pair of (problem, solution)"""
return {
"problem": self.poly_system_stats(
problem if isinstance(problem, list) else [problem]
),
"solution": self.poly_system_stats(
solution if isinstance(solution, list) else [solution]
),
}
def poly_system_stats(
self, polys: list[MPolynomial_libsingular]
) -> dict[str, int | float]:
"""Calculate statistics for a list of polynomials."""
pass
2. Polynomial Matrix Statistics Calculator¶
Purpose: Calculate statistics for polynomial matrix problems by flattening two-dimensional arrays and applying polynomial analysis.
Key Features: - Handles polynomial matrices (two-level nested lists) efficiently - Flattens matrices to analyze all polynomials uniformly - Leverages existing polynomial statistics methods for consistency - Provides matrix-specific problem analysis capabilities
Please refer to scripts/dataset_generation/sagemath/transposed_matrix_problem_generation.py
.
from calt.dataset_generator.sagemath import BaseStatisticsCalculator
class PolyMatrixStatsCalculator(BaseStatisticsCalculator):
def __call__(
self,
problem: list[list[MPolynomial_libsingular]],
solution: list[list[MPolynomial_libsingular]],
) -> dict[str, dict[str, int | float]]:
"""Calculate statistics for a pair of (problem, solution)"""
# Flatten the matrices to get all polynomials
flattened_problem = [poly for row in problem for poly in row]
flattened_solution = [poly for row in solution for poly in row]
# Get basic statistics using existing poly_system_stats method
problem_stats = self.poly_system_stats(flattened_problem)
solution_stats = self.poly_system_stats(flattened_solution)
return {
"problem": problem_stats,
"solution": solution_stats,
}
def poly_system_stats(
self, polys: list[MPolynomial_libsingular]
) -> dict[str, int | float]:
"""Calculate statistics for a list of polynomials."""
pass
Arithmetic Problems¶
Arithmetic Statistics Calculator¶
Purpose: Calculate descriptive statistics for arithmetic problems involving numerical data, providing comprehensive analysis of value distributions.
Key Features: - Handles both single values and lists of numerical values flexibly - Calculates comprehensive statistics (min, max, mean, standard deviation, sum) - Supports integer and float data types seamlessly - Automatically converts data to appropriate format for analysis
Please refer to scripts/dataset_generation/sagemath/arithmetic_problem_generation.py
.
from calt.dataset_generator.sagemath import BaseStatisticsCalculator
class ArithmeticStatisticsCalculator(BaseStatisticsCalculator):
def __call__(
self,
problem: list[int | float] | int | float,
solution: list[int | float] | int | float,
) -> dict[str, dict[str, int | float]]:
"""Calculate statistics for a pair of (problem, solution)"""
return {
"problem": self.numerical_stats(
problem if isinstance(problem, list) else [problem]
),
"solution": self.numerical_stats(
solution if isinstance(solution, list) else [solution]
),
}
def numerical_stats(self, data: list[int | float]) -> dict[str, int | float]:
"""Calculate statistics for a list of numbers."""
pass