forked from TGSAI/mdio-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
71 lines (47 loc) · 2.5 KB
/
Copy pathstats.py
File metadata and controls
71 lines (47 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""Statistics schema for MDIO v1 arrays.
This module provides two Histogram classes (CenteredBinHistogram and
EdgeDefinedHistogram),a summary statistics class, and a summary statistics
metadata class.
SummaryStatistics: a class that represents the minimum summary statistics
of an array consisting of count, sum, sum of squares, min, max, and a histogram.
SummaryStatisticsMetadata: represents metadata for statistics, with a field
for v1 of the stats.
CenteredBinHistogram takes the center points of each bin in a histogram,
while EdgeDefinedHistogram takes the left edges and widths of each bin.
Both classes extend from the base class BaseHistogram, which represents
a histogram with count of each bin.
"""
from __future__ import annotations
from pydantic import Field
from mdio.builder.schemas.core import CamelCaseStrictModel
class BaseHistogram(CamelCaseStrictModel):
"""Represents a histogram with bin counts."""
counts: list[int] = Field(..., description="Count of each each bin.")
class CenteredBinHistogram(BaseHistogram):
"""Class representing a center bin histogram."""
bin_centers: list[float | int] = Field(..., description="List of bin centers.")
class EdgeDefinedHistogram(BaseHistogram):
"""A class representing an edge-defined histogram."""
bin_edges: list[float | int] = Field(..., description="The left edges of the histogram bins.")
bin_widths: list[float | int] = Field(..., description="The widths of the histogram bins.")
type Histogram = CenteredBinHistogram | EdgeDefinedHistogram
class SummaryStatistics(CamelCaseStrictModel):
"""Data model for some statistics in MDIO v1 arrays."""
count: int = Field(..., description="The number of data points.")
sum: float = Field(..., description="The total of all data values.")
sum_squares: float = Field(..., description="The total of all data values squared.")
min: float = Field(..., description="The smallest value in the variable.")
max: float = Field(..., description="The largest value in the variable.")
histogram: Histogram = Field(..., description="Binned frequency distribution.")
@property
def mean(self) -> float:
"""Returns the mean of the data."""
return self.sum / self.count
@property
def variance(self) -> float:
"""Returns the variance of the data."""
return (self.sum_squares / self.count) - (self.mean**2)
@property
def std(self) -> float:
"""Returns the standard deviation of the data."""
return self.variance**0.5