-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a22e056
commit a17f279
Showing
6 changed files
with
647 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
"brenth", | ||
"proportion", | ||
"nullproportion", | ||
"ospp" | ||
"ospp", | ||
"unpooled" | ||
] | ||
} |
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,8 @@ | ||
from pystatpower.basic import * | ||
|
||
|
||
class TestEnum(Enum): | ||
Test1 = 1 | ||
|
||
|
||
Alternative(TestEnum.Test1) |
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,148 @@ | ||
from abc import ABC, abstractmethod | ||
from enum import Enum | ||
from math import inf | ||
from numbers import Real | ||
|
||
from pystatpower.interval import Interval | ||
|
||
|
||
class Param(ABC): | ||
"""抽象参数基类""" | ||
|
||
domain = None | ||
|
||
@abstractmethod | ||
def __init__(self, value): | ||
pass | ||
|
||
@classmethod | ||
@abstractmethod | ||
def _check(cls, domain, value): | ||
pass | ||
|
||
|
||
class NumericParam(Param): | ||
"""数值参数基类""" | ||
|
||
domain = Interval(-inf, inf) | ||
|
||
def __init__(self, value: Real): | ||
cls = type(self) | ||
cls._check(value) | ||
self._value = value | ||
|
||
@property | ||
def value(self): | ||
return self._value | ||
|
||
@classmethod | ||
def _check(cls, value: Real): | ||
domain = cls.domain | ||
if not isinstance(value, Real): | ||
raise TypeError(f"{value} is not a real number") | ||
if value not in domain: | ||
raise ValueError(f"{value} is not in {domain}") | ||
|
||
|
||
class OptionalParam(Param): | ||
"""选项参数基类""" | ||
|
||
class EmptyEnum(Enum): | ||
pass | ||
|
||
domain = EmptyEnum | ||
|
||
def __init__(self, value: Enum | str): | ||
cls = type(self) | ||
self._value = cls._check(value) | ||
|
||
@property | ||
def value(self): | ||
return self._value | ||
|
||
@classmethod | ||
def _check(cls, value: Enum | str) -> Enum: | ||
domain = cls.domain | ||
|
||
if isinstance(value, str): | ||
try: | ||
value = domain[value.upper()] | ||
except KeyError: | ||
raise ValueError(f"No such option '{value}' in {domain.__name__}") | ||
elif not isinstance(value, domain): | ||
raise TypeError(f"{value} is not a {domain.__name__}") | ||
|
||
return value | ||
|
||
|
||
class Alpha(NumericParam): | ||
"""显著性水平""" | ||
|
||
domain = Interval(0, 1) | ||
|
||
|
||
class Power(NumericParam): | ||
"""检验效能""" | ||
|
||
domain = Interval(0, 1) | ||
|
||
|
||
class Mean(NumericParam): | ||
"""均值""" | ||
|
||
domain = Interval(-inf, inf) | ||
|
||
|
||
class STD(NumericParam): | ||
"""标准差""" | ||
|
||
domain = Interval(0, inf) | ||
|
||
|
||
class Proportion(NumericParam): | ||
"""率""" | ||
|
||
domain = Interval(0, 1) | ||
|
||
|
||
class Percent(NumericParam): | ||
"""百分比""" | ||
|
||
domain = Interval(0, 1) | ||
|
||
|
||
class Ratio(NumericParam): | ||
"""比例""" | ||
|
||
domain = Interval(0, inf) | ||
|
||
|
||
class Size(NumericParam): | ||
"""样本量""" | ||
|
||
domain = Interval(0, inf) | ||
|
||
|
||
class DropOutRate(NumericParam): | ||
"""脱落率""" | ||
|
||
domain = Interval(0, 1, lower_inclusive=True) | ||
|
||
|
||
class Alternative(OptionalParam): | ||
"""备择假设类型 | ||
Attributes | ||
---------- | ||
TWO_SIDED : (int) | ||
双侧检验 | ||
ONE_SIDED : (int) | ||
单侧检验 | ||
""" | ||
|
||
class AlternativeEnum(Enum): | ||
|
||
TWO_SIDED = 1 | ||
ONE_SIDED = 2 | ||
|
||
domain = AlternativeEnum |
Oops, something went wrong.