-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from CITCOM-project/json-cate
Json cate
- Loading branch information
Showing
25 changed files
with
448 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
"""This module contains the class EnumGen, which allows us to easily create | ||
generating uniform distributions from enums.""" | ||
|
||
from enum import Enum | ||
from scipy.stats import rv_discrete | ||
import numpy as np | ||
|
||
|
||
class EnumGen(rv_discrete): | ||
"""This class allows us to easily create generating uniform distributions | ||
from enums. This is helpful for generating concrete test inputs from | ||
abstract test cases.""" | ||
|
||
def __init__(self, datatype: Enum): | ||
super().__init__() | ||
self.datatype = dict(enumerate(datatype, 1)) | ||
self.inverse_dt = {v: k for k, v in self.datatype.items()} | ||
|
||
def ppf(self, q): | ||
"""Percent point function (inverse of `cdf`) at q of the given RV. | ||
Parameters | ||
---------- | ||
q : array_like | ||
Lower tail probability. | ||
Returns | ||
------- | ||
k : array_like | ||
Quantile corresponding to the lower tail probability, q. | ||
""" | ||
return np.vectorize(self.datatype.get)(np.ceil(len(self.datatype) * q)) | ||
|
||
def cdf(self, k): | ||
""" | ||
Cumulative distribution function of the given RV. | ||
Parameters | ||
---------- | ||
k : array_like | ||
quantiles | ||
Returns | ||
------- | ||
cdf : ndarray | ||
Cumulative distribution function evaluated at `x` | ||
""" | ||
return np.vectorize(self.inverse_dt.get)(k) / len(self.datatype) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.