🤝 Contributing
Thank you for your interest in contributing to infer-ci! This guide will help you get started with contributing to the project.
Table of Contents
- Code of Conduct
- Getting Started
- Development Setup
- Running Tests
- Code Style
- Adding New Metrics
- Documentation
- Pull Request Process
- Commit Message Guidelines
- Testing Requirements
Code of Conduct
This project adheres to a code of conduct that all contributors are expected to follow. Please be respectful and constructive in all interactions.
Getting Started
- Fork the repository on GitHub
- Clone your fork locally:
- Add upstream remote:
Development Setup
Prerequisites
- Python 3.10 or higher
- pip package manager
- Git
Installation
-
Create a virtual environment:
-
Install development dependencies:
This installs the package in editable mode with all development dependencies including: - pytest (testing framework) - pytest-cov (coverage reporting) - pyright (type checking) - pre-commit (runs black, flake8 and the other checks, see Pre-commit Hooks) - mkdocs and plugins (documentation)
- Install pre-commit hooks (optional but recommended):
Running Tests
Run all tests
Run tests with coverage
View the coverage report by opening htmlcov/index.html in your browser.
Run specific test files
Run tests with verbose output
Using the test script
The project includes a convenience script for running tests:
./scripts/test.sh # Run all tests
./scripts/test.sh -c # Run with coverage
./scripts/test.sh -l # Show log output
Code Style
This project follows strict code quality standards:
Formatting
We use Black for code formatting, with its default line length (88). It runs as a pre-commit hook:
Linting
We use flake8 for linting, with a maximum line length of 120. It runs as a pre-commit hook:
Type Checking
We use pyright for static type checking:
Pre-commit Hooks
Pre-commit hooks automatically check code quality before each commit: Black, flake8, pyright, and checks such as large files (over 2.5 MB) and commits to main. If you installed them, they will run automatically. To run manually:
Adding New Metrics
Adding a new metric involves several steps. Here's a complete guide:
1. Determine the Metric Type
First, identify which category your metric belongs to: - Classification: Metrics for classification tasks (accuracy, precision, recall, F1, etc.) - Regression: Metrics for regression tasks (MAE, MSE, RMSE, R², etc.) - Detection: Metrics for object detection (mAP, precision, recall)
2. Implement the Metric Function
Create your metric function in the appropriate module:
For classification metrics: Add to src/infer_ci/binary_metrics.py (proportion-based metrics) or src/infer_ci/takahashi_methods.py (precision, recall, F1)
For regression metrics: Add to src/infer_ci/regression_metrics.py
Example template (a regression metric, using the shared helper in regression_metrics.py):
from typing import List, Tuple, Union
import numpy as np
def my_new_metric(y_true: List[float],
y_pred: List[float],
confidence_level: float = 0.95,
method: str = 'bootstrap_bca',
compute_ci: bool = True,
**kwargs) -> Union[float, Tuple[float, Tuple[float, float]]]:
"""
Compute my new metric and optionally the confidence interval.
Parameters
----------
y_true : List[float]
The ground truth target values.
y_pred : List[float]
The predicted target values.
confidence_level : float, optional
The confidence interval level, by default 0.95
method : str, optional
The bootstrap method, by default 'bootstrap_bca'
compute_ci : bool, optional
If True return the confidence interval as well as the metric value, by default True
**kwargs
Passed on to the bootstrap, for example n_resamples or random_state.
Returns
-------
Union[float, Tuple[float, Tuple[float, float]]]
The metric value, or (value, (lower, upper)) if compute_ci is True.
Examples
--------
>>> y_true = [3.0, 5.0, 2.5, 7.0]
>>> y_pred = [2.5, 5.0, 3.0, 8.0]
>>> value, (lower, upper) = my_new_metric(y_true, y_pred, random_state=0)
"""
def my_new_metric_func(y_true, y_pred):
# Calculate your metric from the two arrays
return np.mean(np.abs(np.array(y_true) - np.array(y_pred)))
return _compute_metric_with_optional_ci(
y_true=y_true,
y_pred=y_pred,
metric_func=my_new_metric_func,
confidence_level=confidence_level,
method=method,
compute_ci=compute_ci,
**kwargs
)
3. Register the Metric in MetricEvaluator
Import your metric at the top of src/infer_ci/evaluator.py and add it to the matching dictionary in MetricEvaluator.__init__ (classification_metrics, regression_metrics or detection_metrics). Without this step, evaluate_metric(..., metric='my_new_metric') raises "Unknown metric".
from .regression_metrics import (
# ... existing imports ...
my_new_metric,
)
# in MetricEvaluator.__init__
self.regression_metrics = {
# ... existing metrics ...
'my_new_metric': my_new_metric,
}
4. Export the Metric
Add your metric to src/infer_ci/__init__.py:
from .regression_metrics import (
# ... existing imports ...
my_new_metric,
)
__all__ = [
# ... existing exports ...
'my_new_metric',
]
5. Write Tests
Create comprehensive tests in the appropriate test file:
# tests/test_my_metric.py
import numpy as np
import pytest
from infer_ci import my_new_metric, evaluate_metric
def _data():
rng = np.random.RandomState(0)
y_true = rng.uniform(1, 10, size=60)
y_pred = y_true + rng.normal(0, 1, size=60) # realistic data, with noise
return y_true, y_pred
def test_my_new_metric_basic():
"""Test basic functionality."""
y_true, y_pred = _data()
value, (lower, upper) = my_new_metric(y_true, y_pred, random_state=0)
assert lower <= value <= upper
def test_my_new_metric_unified_interface():
"""evaluate_metric gives the same result as the direct call."""
y_true, y_pred = _data()
unified = evaluate_metric(y_true, y_pred, task='regression', metric='my_new_metric',
compute_ci=False)
assert unified == pytest.approx(my_new_metric(y_true, y_pred, compute_ci=False))
def test_my_new_metric_edge_cases():
"""Test edge cases."""
# Perfect predictions
y = np.array([1.0, 2.0, 3.0, 4.0])
assert my_new_metric(y, y, compute_ci=False) == 0.0
6. Add Documentation
Create API documentation in docs/api-docs/:
# my_new_metric
::: infer_ci.binary_metrics.my_new_metric
options:
show_root_heading: true
show_source: true
## Examples
[Your examples here]
## Mathematical Definition
[Your formula here]
## References
[Your citations here]
7. Update CHANGELOG.md
Add an entry to the [Unreleased] section:
Documentation
Building Documentation Locally
Then visit http://127.0.0.1:8000 in your browser.
Documentation Structure
docs/getting-started/- Tutorials and quick startsdocs/api-docs/- API reference documentationdocs/dev/- Developer documentationREADME.md- Main package documentation
Writing Documentation
- Use clear, concise language
- Include code examples
- Explain mathematical concepts when relevant
- Add references to papers/sources
Pull Request Process
-
Create a branch in your fork, starting from the latest
Don't work ondev:main, and don't create branches in thehumblebeeairepository. -
Make your changes following the code style guidelines
-
Write or update tests for your change. Every test needs at least one
assert. -
Update documentation as needed. If you change an English page that has a Korean version (
*.ko.md), update both. -
Run tests and checks:
-
Commit your changes following the commit message guidelines
-
Push to your fork:
-
Open a Pull Request to
humblebeeai/infer-ci, base branchdev(notmain). Check both on the GitHub "Open a pull request" page before you create it. Fill in the PR template with: - Clear title describing the change
- Description of what changed and why
- Reference to any related issues
-
Screenshots/examples if applicable
-
Address review feedback if requested. If a reviewer pushed commits to your branch, run
git pullbefore you push again. -
Wait for CI checks to pass before merging. CI runs only part of the test suite, so always run
python -m pytest tests/locally too.
Before you open a PR
- One issue per PR. Put unrelated work, such as a new notebook, in its own PR.
- Describe only what the diff changes.
- Don't commit large files such as model weights (the pre-commit hook blocks files over 2.5 MB).
- Put notebooks in
notebooks/, with no spaces in file names. - Read AI-generated text and code before you commit it.
- Set
random_statein examples and tests so results can be reproduced.
Commit Message Guidelines
We follow conventional commit format:
Types
feat: New featurefix: Bug fixdocs: Documentation changesstyle: Code style changes (formatting, etc.)refactor: Code refactoringtest: Adding or updating testschore: Maintenance tasks
Examples
feat(metrics): add IoU metric for regression tasks
Implemented Intersection over Union metric with bootstrap
confidence intervals for regression evaluation.
Closes #123
fix(bootstrap): correct BCa interval calculation
Fixed bias correction in bootstrap BCa method that was
causing incorrect confidence intervals for small samples.
docs(api): add examples for F1 score usage
Added comprehensive examples showing binary, macro, and
micro averaging for F1 score computation.
Testing Requirements
Coverage Standards
- Minimum coverage: 80% overall
- New code: Should have at least 90% coverage
- Critical paths: Must have 100% coverage
What to Test
- Basic functionality: Does it work as expected?
- Edge cases: Empty arrays, perfect scores, all zeros
- Invalid inputs: Wrong shapes, invalid parameters
- Integration: Works through MetricEvaluator
- Reproducibility: Random state produces consistent results
- CI methods: Different methods produce valid intervals
Test Organization
tests/test_core_api_compatibility.py- Core API checks (Wilson, scikit-learn agreement, F1 averaging, errors)tests/test_sklearn_equality.py- Metric values compared with scikit-learntests/test_delong.py- DeLong AUC methodtests/test_classification.py,tests/test_binary_classification_ci.py- Classification pipelinestests/test_regression.py,tests/test_regression_ci.py- Regression pipelinestests/test_object_detection_ci.py- Detection with a YOLO model (needsultralyticsanddatasets/coco128)tests/conftest.py- Shared settings (MatplotlibAggbackend)
Questions?
If you have questions:
- Check the documentation
- Search existing issues
- Open a new issue
License
By contributing, you agree that your contributions will be licensed under the MIT License.