Skip to content

Commit dc749c2

Browse files
Add utility functions for research project
This module contains utility functions such as computing the mean of a list of values and validating experiment configurations.
1 parent 42786f0 commit dc749c2

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

src/utils.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""Utility functions for the research project.
2+
3+
This module contains common utility functions used across experiments.
4+
"""
5+
6+
from typing import Any, Dict, List
7+
8+
9+
def compute_mean(values: List[float]) -> float:
10+
"""Compute the mean of a list of values.
11+
12+
Args:
13+
values: List of numerical values.
14+
15+
Returns:
16+
The arithmetic mean of the input values.
17+
18+
Raises:
19+
ValueError: If the input list is empty.
20+
21+
Example:
22+
>>> compute_mean([1.0, 2.0, 3.0, 4.0])
23+
2.5
24+
"""
25+
if not values:
26+
raise ValueError("Cannot compute mean of empty list")
27+
return sum(values) / len(values)
28+
29+
30+
def validate_config(config: Dict[str, Any]) -> bool:
31+
"""Validate experiment configuration.
32+
33+
Args:
34+
config: Configuration dictionary to validate.
35+
36+
Returns:
37+
True if configuration is valid, False otherwise.
38+
39+
Example:
40+
>>> config = {"learning_rate": 0.001, "batch_size": 32}
41+
>>> validate_config(config)
42+
True
43+
"""
44+
required_keys = ["learning_rate", "batch_size"]
45+
return all(key in config for key in required_keys)

0 commit comments

Comments
 (0)