Apply statistical operation to summarize a dict. The key-value looks like: {"max", "min" ,"mean", ....}. The value may contain multiple values in a list format. Then this operation will apply the operation to the list. Typically, the dict is generated by multiple `SampleOperation` a
| 104 | |
| 105 | |
| 106 | class SummaryOperations(Operations): |
| 107 | """ |
| 108 | Apply statistical operation to summarize a dict. The key-value looks like: {"max", "min" |
| 109 | ,"mean", ....}. The value may contain multiple values in a list format. Then this operation |
| 110 | will apply the operation to the list. Typically, the dict is generated by multiple |
| 111 | `SampleOperation` and `concat_multikeys_to_dict` functions. |
| 112 | |
| 113 | Examples: |
| 114 | |
| 115 | .. code-block:: python |
| 116 | |
| 117 | import numpy as np |
| 118 | data = { |
| 119 | "min": np.random.rand(4), |
| 120 | "max": np.random.rand(4), |
| 121 | "mean": np.random.rand(4), |
| 122 | "sum": np.random.rand(4), |
| 123 | } |
| 124 | op = SummaryOperations() |
| 125 | print(op.evaluate(data)) # "sum" is not registered yet, so it won't contain "sum" |
| 126 | |
| 127 | op.update({"sum", np.sum}) |
| 128 | print(op.evaluate(data)) # output has "sum" |
| 129 | """ |
| 130 | |
| 131 | def __init__(self) -> None: |
| 132 | self.data = { |
| 133 | "max": max, |
| 134 | "mean": mean, |
| 135 | "median": mean, |
| 136 | "min": min, |
| 137 | "stdev": mean, |
| 138 | "percentile_00_5": mean, |
| 139 | "percentile_10_0": mean, |
| 140 | "percentile_90_0": mean, |
| 141 | "percentile_99_5": mean, |
| 142 | } |
| 143 | |
| 144 | def evaluate(self, data: Any, **kwargs: Any) -> dict: |
| 145 | """ |
| 146 | Applies the callables to the data, and convert the numerics to list or Python |
| 147 | numeric types (int/float). |
| 148 | |
| 149 | Args: |
| 150 | data: input data |
| 151 | """ |
| 152 | return {k: v(data[k], **kwargs).tolist() for k, v in self.data.items() if (callable(v) and k in data)} |
no outgoing calls
searching dependent graphs…