sicore package¶
Module contents¶
Core package for selective inference.
Installation¶
This package requires python 3.10 or higher and automatically installs any dependent packages. If you want to use tensorflow and pytorch’s tensors, please install them manually.
$ pip install sicore
- class sicore.SelectiveInference¶
Bases:
object
An abstract class conducting selective inference.
This class provides the basic structure for conducting selective inference. The user can inherit this class and implement the __init__ method.
- stat¶
Test statistic value.
- Type:
float
- a¶
Search direction vector, whose shape is same to the data.
- Type:
np.ndarray
- b¶
Search direction vector, whose shape is same to the data.
- Type:
np.ndarray
- null_rv¶
Null distribution of the unconditional test statistic.
- Type:
rv_continuous
- mode¶
Mode of the null distribution of the unconditional test statistic.
- Type:
float
- support¶
Support of the null distribution of the unconditional test statistic.
- Type:
- alternative¶
Type of the alternative hypothesis.
- Type:
Literal[“two-sided”, “less”, “greater”]
- limits¶
Limits of the search space.
- Type:
- inference(algorithm: Callable[[ndarray, ndarray, float], tuple[Any, list[list[float]] | RealSubset]], model_selector: Callable[[Any], bool], alternative: Literal['two-sided', 'less', 'greater'] | None = None, inference_mode: Literal['parametric', 'exhaustive', 'over_conditioning'] = 'parametric', search_strategy: Callable[[RealSubset], float] | Literal['pi1', 'pi2', 'pi3'] = 'pi3', termination_criterion: Callable[[RealSubset, RealSubset], bool | float] | Literal['precision', 'decision'] = 'precision', max_iter: int = 100000, n_jobs: int = 1, step: float = 1e-06, significance_level: float = 0.05, precision: float = 0.001, *, progress: bool = False) SelectiveInferenceResult ¶
Conduct selective inference.
- Parameters:
algorithm (Callable[[np.ndarray, np.ndarray, float], tuple[Any, list[list[float]] | RealSubset]]) – Callable function which takes two vectors a (np.ndarray) and b (np.ndarray), and a scalar z (float), and returns a model (Any) and intervals (list[list[float]] | RealSubset). For any point in the intervals, the same model must be selected.
model_selector (Callable[[Any], bool]) – Callable function which takes a model (Any) and returns a boolean value, indicating whether the model is the same as the selected model.
alternative (Literal["two-sided", "less", "greater"] | None, optional) – Must be one of ‘two-sided’, ‘less’, or ‘greater’ or None. If ‘two-sided’, we consider the two-tailed test. If ‘less’, we consider the right-tailed test. If ‘greater’, we consider the left-tailed test. If set to None, defaults to ‘two-sided’ for the normal distribution and ‘less’ for the chi distribution. Defaults to None.
inference_mode (Literal["parametric", "exhaustive", "over_conditioning"], optional) – Must be one of ‘parametric’, ‘exhaustive’,or ‘over_conditioning’. Defaults to ‘parametric’.
search_strategy (Callable[[RealSubset], float] | Literal["pi1", "pi2", "pi3"], optional) – Callable function which takes a searched_intervals (RealSubset) and returns next search point (float). If not callable, it must be one of ‘pi1’, ‘pi2’, ‘pi3’, or ‘parallel’. If ‘pi1’, the search strategy focuses on the truncated intervals. If ‘pi2’, the search strategy focuses on the searched intervals. If ‘pi3’, the search strategy focuses on the both of the truncated and searched intervals. This option is ignored when the inference_mode is ‘exhaustive’ or ‘over_conditioning’. Defaults to ‘pi3’.
termination_criterion (Callable[[RealSubset, RealSubset], bool | float] | Literal["precision", "decision"], optional) – Callable function which takes searched_intervals (RealSubset) and truncated_intervals (RealSubset), and returns a boolean value, indicating whether the search should be terminated or a float between 0 and 1, indicating the search completion ratio, where 1 means the search is completed. If not callable, it must be one of ‘precision’ or ‘decision’. If ‘precision’, the termination criterion is based on the precision in the computation of the p-value. If ‘decision’, the termination criterion is based on the decision result by the p-value. This option is ignored when the inference_mode is ‘exhaustive’ or ‘over_conditioning’. Defaults to ‘precision’.
max_iter (int, optional) – Maximum number of iterations. Defaults to 100_000.
n_jobs (int, optional) – Number of jobs to run in parallel. If set to other than 1, inference_mode is forced to ‘exhaustive’ and then options search_strategy and termination_criterion are ignored. If set to -1, the all available cores are used. Defaults to 1.
step (float, optional) – Step size for the search strategy. Defaults to 1e-6.
significance_level (float, optional) – Significance level only for the termination criterion ‘decision’. Defaults to 0.05.
precision (float, optional) – Precision only for the termination criterion ‘precision’. Defaults to 0.001.
progress (bool, optional) – Whether to show the progress bar. Defaults to False.
- Raises:
InfiniteLoopError – If the search falls into an infinite loop.
- Returns:
The result of the selective inference.
- Return type:
- class sicore.SelectiveInferenceNorm(data: ndarray, var: float | ndarray | csr_array, eta: ndarray, *, use_sparse: bool = False, use_tf: bool = False, use_torch: bool = False)¶
Bases:
SelectiveInference
A class conducting selective inference for the normal distribution.
- Parameters:
data (np.ndarray) – Observed data in 1D array.
var (float | np.ndarray | sparse.csr_matrix) – Known covariance matrix. If float, covariance matrix equals to the scalar times identity matrix. If 1D array, covariance matrix equals to the diagonal matrix with the given array. If 2D array, covariance matrix equals to the given array.
eta (np.ndarray) – The direction of the test statistic in 1D array.
use_sparse (bool, optional) – Whether to use sparse matrix. If True, the var must be given as a sparse matrix. Defaults to False.
use_tf (bool, optional) – Whether to use TensorFlow. If True, the data, eta, and var must be given as TensorFlow tensors. Defaults to False.
use_torch (bool, optional) – Whether to use PyTorch. If True, the data, eta, and var must be given as PyTorch tensors. Defaults to False.
- class sicore.SelectiveInferenceChi(data: ndarray, var: float, projection: ndarray, *, use_sparse: bool = False, use_tf: bool = False, use_torch: bool = False)¶
Bases:
SelectiveInference
A class conducting selective inference for the chi distribution.
- Parameters:
data (np.ndarray) – Observed data in 1D array.
var (float) – Known covariance matrix, which equals to the scalar times identity matrix.
projection (np.ndarray) – The space of the test statistic in 2D array.
use_sparse (bool, optional) – Whether to use sparse matrix. If True, the P must be given as a sparse matrix. Defaults to False.
use_tf (bool, optional) – Whether to use TensorFlow. If True, the data and P must be given as TensorFlow tensors. Defaults to False.
use_torch (bool, optional) – Whether to use PyTorch. If True, the data and P must be given as PyTorch tensors. Defaults to False.
- class sicore.SelectiveInferenceResult(stat: float, p_value: float, inf_p: float, sup_p: float, searched_intervals: list[list[float]], truncated_intervals: list[list[float]], search_count: int, detect_count: int, null_rv: rv_continuous, alternative: Literal['two-sided', 'less', 'greater'])¶
Bases:
object
A class containing the results of selective inference.
- stat¶
Test statistic value.
- Type:
float
- p_value¶
Selective p-value.
- Type:
float
- inf_p¶
Lower bound of selective p-value.
- Type:
float
- sup_p¶
Upper bound of selective p-value.
- Type:
float
- searched_intervals¶
Intervals where the search was performed.
- Type:
list[list[float]]
- truncated_intervals¶
Intervals where the selected model is obtained.
- Type:
list[list[float]]
- search_count¶
Number of times the search was performed.
- Type:
int
- detect_count¶
Number of times the selected model was obtained.
- Type:
int
- null_rv¶
Null distribution of the unconditional test statistic.
- Type:
rv_continuous
- alternative¶
Type of the alternative hypothesis.
- Type:
Literal[“two-sided”, “less”, “greater”]
- naive_p_value() float ¶
Compute the naive p-value.
- Returns:
The naive p-value.
- Return type:
float
- bonferroni_p_value(log_num_comparisons: float) float ¶
Compute the Bonferroni-corrected p-value.
- Parameters:
log_num_comparisons (float) – Logarithm of the number of comparisons.
- Returns:
The Bonferroni-corrected p-value.
- Return type:
float
- exception sicore.InfiniteLoopError(loop_type: LoopType)¶
Bases:
Exception
Exception raised when infinite loop errors occur.
- sicore.rejection_rate(results: list[SelectiveInferenceResult] | ndarray | list[float], alpha: float = 0.05, *, naive: bool = False, bonferroni: bool = False, log_num_comparisons: float = 0.0) float ¶
Compute rejection rate from list of SelectiveInferenceResult objects or p-values.
- Parameters:
results (list[SelectiveInferenceResult] | np.ndarray | list[float]) – List of SelectiveInferenceResult objects or p-values.
alpha (float, optional) – Significance level. Defaults to 0.05.
(bool (naive) – Whether to compute rejection rate of naive inference. This option is available only when results are SelectiveInferenceResult objects. Defaults to False.
optional) – Whether to compute rejection rate of naive inference. This option is available only when results are SelectiveInferenceResult objects. Defaults to False.
bonferroni (bool, optional) – Whether to compute rejection rate with Bonferroni correction. This option is available only when results are SelectiveInferenceResult objects. Defaults to False.
log_num_comparisons (float, optional) – Logarithm of the number of comparisons for the Bonferroni correction. This option is ignored when bonferroni is False. Defaults to 0.0, which means no correction.
- Returns:
Rejection rate.
- Return type:
float
- Raises:
ValueError – The naive and bonferroni option cannot be True at the same time.
- sicore.pvalues_hist(p_values: list[float] | ndarray, bins: int = 20, title: str | None = None, fname: str | None = None, figsize: tuple[float, float] = (6, 4)) None ¶
Plot histogram of p-values.
- Parameters:
p_values (list[float] | np.ndarray) – List of p-values.
bins (int, optional) – The number of bins. Defaults to 20.
title (str | None, optional) – Title of the figure. Defaults to None.
fname (str | None, optional) – File name. If fname is given, the plotted figure will be saved as a file. Defaults to None.
figsize (tuple[float, float], optional) – Size of the figure. Defaults to (6, 4).
- sicore.pvalues_qqplot(p_values: list[float] | ndarray, plot_pos: list[float] | ndarray | None = None, title: str | None = None, fname: str | None = None, figsize: tuple[float, float] = (4, 4)) None ¶
Plot uniform Q-Q plot of p-values.
- Parameters:
p_values (list[float] | np.ndarray) – List of p-values.
plot_pos (list[float] | np.ndarray | None, optional) – Plotting positions. If None, default plotting positions will be used. Defaults to None.
title (str | None, optional) – Title of the figure. Defaults to None.
fname (str | None, optional) – File name. If fname is given, the plotted figure will be saved as a file. Defaults to None.
figsize (tuple[float, float], optional) – Size of the figure. Defaults to (4, 4).
- class sicore.SummaryFigure(title: str | None = None, xlabel: str | None = None, ylabel: str | None = None)¶
Bases:
object
A class plotting a summary figure of experiments.
Examples
>>> fig = SummaryFigure(xlabel='Image Size', ylabel="Type I Error Rate") >>> fig.add_value(0.053, "proposed", "64") >>> fig.add_value(0.048, "proposed", "256") >>> fig.add_value(0.046, "proposed", "1024") >>> fig.add_value(0.052, "proposed", "4096") >>> fig.add_value(0.413, "naive", "64") >>> fig.add_value(0.821, "naive", "256") >>> fig.add_value(0.483, "naive", "1024") >>> fig.add_value(0.418, "naive", "4096") >>> fig.add_red_line(0.05, "significance level") >>> fig.plot(filepath="fpr.pdf", fontsize=16)
- add_value(value: float, label: str, xloc: str | float) None ¶
Add a value to the figure.
- Parameters:
value (float) – Value to be plotted.
label (str) – Label corresponding to the value. To note that the label well be shown in the given order.
xloc (str | float) – Location of the value. If str, it will be equally spaced in the given order. If float, it will be the exact location.
- add_results(results: list[SelectiveInferenceResult] | list[float] | ndarray, label: str, xloc: str | float, alpha: float = 0.05, confidence_level: float | None = None, *, naive: bool = False, bonferroni: bool = False, log_num_comparisons: float = 0.0) None ¶
Add rejection rate computed from the given results to the figure.
- Parameters:
results (list[SelectiveInferenceResult] | np.ndarray | list[float]) – List of SelectiveInferenceResult objects or p-values.
label (str) – Label corresponding to the results.
xloc (str | float) – Location of the results.
alpha (float, optional) – Significance level. Defaults to 0.05.
(bool (naive) – Whether to compute rejection rate of naive inference. This option is available only when results are SelectiveInferenceResult objects. Defaults to False.
optional) – Whether to compute rejection rate of naive inference. This option is available only when results are SelectiveInferenceResult objects. Defaults to False.
bonferroni (bool, optional) – Whether to compute rejection rate with Bonferroni correction. This option is available only when results are SelectiveInferenceResult objects. Defaults to False.
log_num_comparisons (float, optional) – Logarithm of the number of comparisons for the Bonferroni correction. This option is ignored when bonferroni is False. Defaults to 0.0, which means no correction.
- add_red_line(value: float = 0.05, label: str | None = None) None ¶
Add a red line at the specified value.
- Parameters:
value (float, optional) – Value to be plotted as a red line. Defaults to 0.05.
label (str | None, optional) – Label of the red line. Defaults to None.
- plot(filepath: Path | str | None = None, ylim: tuple[float, float] | None = (0.0, 1.0), yticks: list[float] | None = None, legend_loc: str | None = None, fontsize: int = 10) None ¶
Plot the figure.
- Parameters:
filepath (Path | str | None, optional) – File path. If filepath is given, the plotted figure will be saved as a file. Defaults to None.
ylim (tuple[float, float] | None, optional) – Range of y-axis. If None, range of y-axis will be automatically determined. Defaults to None.
yticks (list[float] | None, optional) – List of y-ticks. If None, y-ticks will be automatically determined. Defaults to None.
legend_loc (str | None, optional) – Location of the legend. If None, the legend will be placed at the best location. Defaults to None.
fontsize (int, optional) – Font size of the legend. Defaults to 10.
- class sicore.RealSubset(intervals: ndarray | list[list[float]] | None = None, *, is_simplify: bool = True)¶
Bases:
object
A class representing a subset of real numbers as a collection of intervals.
This class allows for various set operations on subsets of real numbers, including complement, intersection, and union. It uses numpy arrays for efficient storage and computation.
- Parameters:
intervals (np.array | list[list[int]] | None, optional) – Initial intervals to create the subset. Defaults to None, which creates an empty set.
is_simplify (bool, optional) – Whether to simplify (merge overlapping) intervals upon creation. Defaults to True.
- intervals¶
An array of shape (n, 2) representing n intervals. Each row [a, b] represents the interval [a, b].
- Type:
np.ndarray
Note
Infinite intervals can be represented using np.inf.
An empty array represents the empty set.
Examples
>>> A = RealSubset([[1.0, 3.0], [5.0, 7.0]]) >>> B = RealSubset([[2.0, 4.0], [6.0, 8.0]]) >>> print(~A) # Complement [[-inf, 1.0], [3.0, 5.0], [7.0, inf]] >>> print(A | B) # Union [[1.0, 4.0], [5.0, 8.0]] >>> print(A & B) # Intersection [[2.0, 3.0], [6.0, 7.0]]
- simplify() None ¶
Simplify the intervals of the subset.
- complement() RealSubset ¶
Take the complement.
- Returns:
Complement of the subset.
- Return type:
- union(other: RealSubset) RealSubset ¶
Take the union and can be used by the | operator.
- Parameters:
other (RealSubset) – Another subset to take union with.
- Returns:
Union of the two subsets.
- Return type:
- union_update(other: RealSubset) None ¶
Update the subset by taking the union.
- Parameters:
other (RealSubset) – Another subset to take union with.
- intersection(other: RealSubset) RealSubset ¶
Take the intersection and can be used by the & operator.
- Parameters:
other (RealSubset) – Another subset to take intersection with.
- Returns:
Intersection of the two subsets.
- Return type:
- intersection_update(other: RealSubset) None ¶
Update the subset by taking the intersection.
- Parameters:
other (RealSubset) – Another subset to take intersection with.
- difference(other: RealSubset) RealSubset ¶
Take the difference and can be used by the - operator.
- Parameters:
other (RealSubset) – Another subset to take difference with.
- Returns:
Difference of the subset with another subset.
- Return type:
- difference_update(other: RealSubset) None ¶
Update the subset by taking the difference.
- Parameters:
other (RealSubset) – Another subset to take difference with.
- symmetric_difference(other: RealSubset) RealSubset ¶
Take the symmetric difference and can be used by the ^ operator.
- Parameters:
other (RealSubset) – Another subset to take symmetric difference with.
- Returns:
Symmetric difference of the subset with another subset.
- Return type:
- symmetric_difference_update(other: RealSubset) None ¶
Update the subset by taking the symmetric difference.
- Parameters:
other (RealSubset) – Another subset to take symmetric difference with.
- is_empty() bool ¶
Check if the subset is empty.
- Returns:
True if the subset is empty, False otherwise.
- Return type:
bool
- issubset(other: RealSubset) bool ¶
Check if the subset is a subset of another subset.
- Parameters:
other (RealSubset) – Another subset to check for subset.
- Returns:
True if the subset is a subset of another subset, False otherwise.
- Return type:
bool
- issuperset(other: RealSubset) bool ¶
Check if the subset is a superset of another subset.
- Parameters:
other (RealSubset) – Another subset to check for superset.
- Returns:
True if the subset is a superset of another subset, False otherwise.
- Return type:
bool
- isdisjoint(other: RealSubset) bool ¶
Check if the subset is disjoint with another subset.
- Parameters:
other (RealSubset) – Another subset to check for disjoint.
- Returns:
True if the subset is disjoint with another subset, False otherwise.
- Return type:
bool
- find_interval_containing(z: float) list[float] ¶
Find the interval containing a real number.
- Parameters:
z (float) – Real number to find the interval containing it.
- Returns:
Interval containing z
- Return type:
list[float]
- Raises:
ValueError – If the subset is empty or no interval contains z.
- tolist() list[list[float]] ¶
Return the intervals as a list of lists.
- Returns:
Intervals as a list of lists.
- Return type:
list[list[float]]
- property measure: float¶
Return the measure of the subset.
- Returns:
Measure of the subset.
- Return type:
float
- sicore.complement(intervals: ndarray) ndarray ¶
Take the complement of intervals.
- Parameters:
intervals (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
- Returns:
Complement of the input intervals [[l1’, u1’], [l2’, u2’], …].
- Return type:
np.ndarray
- sicore.union(intervals1: ndarray, intervals2: ndarray) ndarray ¶
Take the union of two intervals.
- Parameters:
intervals1 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
intervals2 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
- Returns:
Union of the two input intervals [[l1’, u1’], [l2’, u2’], …].
- Return type:
np.ndarray
- sicore.intersection(intervals1: ndarray, intervals2: ndarray) ndarray ¶
Take the intersection of two intervals.
- Parameters:
intervals1 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
intervals2 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
- Returns:
Intersection of the two input intervals [[l1’, u1’], [l2’, u2’], …].
- Return type:
np.ndarray
- sicore.difference(intervals1: ndarray, intervals2: ndarray) ndarray ¶
Take the difference of first intervals with second intervals.
- Parameters:
intervals1 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
intervals2 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
- Returns:
Difference of the first input intervals with the second input intervals [[l1’, u1’], [l2’, u2’], …].
- Return type:
np.ndarray
- sicore.symmetric_difference(intervals1: ndarray, intervals2: ndarray) ndarray ¶
Take the symmetric difference of two intervals.
- Parameters:
intervals1 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
intervals2 (np.ndarray) – Intervals [[l1, u1], [l2, u2], …].
- Returns:
Symmetric difference of the two input intervals [[l1’, u1’], [l2’, u2’], …].
- Return type:
np.ndarray
- sicore.polynomial_iso_sign_interval(poly_or_coef: Polynomial | ndarray | list[float], z: float) list[list[float]] ¶
Compute intervals where a given polynomial is iso-sign of a given point.
This function outputs a single interval containing the point z where the given polynomial is iso-sign of z. That is, it outputs a single interval [l, u] which satisfies [l, u] contains z and [l, u] is subset of {r in R | sign(poly(z)) * poly(r) > 0}.
- Parameters:
poly_or_coef (Polynomial | np.ndarray | list[float]) – Polynomial or its coefficients e.g. [a, b, c] for a + b * z + c * z ** 2.
z (float) – Point which determines the sign of the inequality.
- Returns:
Interval where the polynomial is iso-sign.
- Return type:
list[list[float]]
- sicore.polynomial_below_zero(poly_or_coef: Polynomial | ndarray | list[float], tol: float = 1e-10) list[list[float]] ¶
Compute intervals where a given polynomial is below zero.
- Parameters:
poly_or_coef (Polynomial | np.ndarray | list[float]) – Polynomial or its coefficients e.g. [a, b, c] for a + b * z + c * z ** 2.
tol (float, optional) – Tolerance error parameter. It is recommended to set a large value (about 1e-5) for high order polynomial (>= 3) or a polynomial with multiple root. Defaults to 1e-10.
- Returns:
Intervals where the polynomial is below zero.
- Return type:
list[list[float]]
- sicore.polytope_below_zero(a_vector: ndarray, b_vector: ndarray, a: ndarray | csr_matrix | None = None, b: ndarray | None = None, c: float | None = None, *, tol: float = 1e-10, use_sparse: bool = False) list[list[float]] ¶
Compute intervals where a given polytope is below zero.
The polytope is defined as the set of z such that (a_vec+b_vec*z)^T A (a_vec+b_vec*z) + b^T (a_vec+b_vec*z) + c < 0.0.
- Parameters:
a_vector (np.ndarray) – Vector a_vec in the polytope.
b_vector (np.ndarray) – Vector b_vec in the polytope.
a (np.ndarray | sparse.csr_matrix, optional) – Matrix A in the polytope. Defaults to None.
b (np.ndarray, optional) – Vector b in the polytope. Defaults to None.
c (float, optional) – Scalar c in the polytope. Defaults to None.
tol (float, optional) – Tolerance error parameter. Defaults to 1e-10.
use_sparse (bool, optional) – Whether to use sparse matrix for computation of A matrix. Defaults to False.
- Returns:
Intervals where the polytope is below zero.
- Return type:
list[list[float]]
- sicore.linear_polynomials_below_zero(a: ndarray, b: ndarray) list[list[float]] ¶
Compute intervals where given linear polynomials are all below zero.
The linear polynomials are defined as the set of z such that a_i + b_i * z < 0.0 for all i in [len(a)].
- Parameters:
a (np.ndarray) – Constant terms of the linear polynomials.
b (np.ndarray) – Coefficients of the linear polynomials.
- Returns:
Intervals where the linear polynomials are all below zero.
- Return type:
list[list[float]]
- sicore.truncated_cdf(rv: rv_continuous, z: float, intervals: ndarray | list[list[float]] | RealSubset, *, absolute: bool = False) float ¶
Compute the cdf value of the truncated distribution.
- Parameters:
rv (rv_continuous) – The rv_continuous instance to be truncated.
z (float) – The value at which to compute the cdf of the truncated distribution.
intervals (np.ndarray | list[list[float]] | RealSubset) – The truncated intervals [[l1, u1], [l2, u2], …].
absolute (bool, optional) – Whether to compute the cdf for the distribution of the absolute value of the random variable. Defaults to False.
- Returns:
The cdf value at z.
- Return type:
float
- Raises:
ValueError – If the value z is not belong to the truncated intervals.
- sicore.generate_non_gaussian_rv(rv_name: Literal['skewnorm', 'exponnorm', 'gennormsteep', 'gennormflat', 't'], distance: float) rv_continuous ¶
Generate a random variable from the specified random variable family.
Generate a standardized random variable from the specified random variable family which has the specified Wasserstein distance from the standard gaussian distribution.
- Parameters:
rv_name (Literal["skewnorm","exponnorm", "gennormsteep", "gennormflat", "t"]) – Random variable name to be generated.
distance (float) – Wasserstein distance between the generated random variable and the standard gaussian distribution. It is strongly recommended to set a value between 0.01 and 0.15.
- Returns:
Generated standardized random variable from the specified random variable family which has the specified Wasserstein distance from the standard gaussian distribution.
- Return type:
rv_continuous
- sicore.uniformity_test(samples: ndarray | list[float], alpha: float = 0.05) UniformityTestResult ¶
Conduct 25 types of uniformity tests on the given samples.
- Parameters:
samples (np.ndarray | list[float]) – The samples to be tested. Must be 1D array.
alpha (float, optional) – The significance level. Defaults to 0.05.
- Returns:
A class containing the result of uniformity tests.
- Return type:
UniformityTestResult
- class sicore.OneVector(length: int)¶
Bases:
object
Vector whose elements from position i to j are set to 1, and 0 otherwise.
- int¶
Dimension of the vector.
- get(i: int, j: int | None = None) ndarray ¶
Get the vector.
- Parameters:
i (int) – Start index of 1 (1<=i<=`length`).
j (int, optional) – End index of 1 (1<=j<=`length`). If None, it returns a vector whose i-th element is set to 1, and 0 otherwise.
- Returns:
One-zero vector
- Return type:
np.ndarray
- sicore.construct_projection_matrix(basis: ndarray | list[list[float]], *, verify: bool = False) ndarray ¶
Construct projection matrix from basis.
- Parameters:
basis (np.ndarray | list[list[float]]) – The basis of the k-dimensional subspace to be projected. The shape of the basis should be (k, n), where n is the dimension of the data space.
verify (bool, optional) – Whether to verify the constructed projection matrix. Defaults to False.
- Raises:
ValueError: – The constructed projection matrix is not consistent with the definition.
- Returns:
The constructed projection matrix
- Return type:
np.ndarray