Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion graph_norm_experiment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import multiprocessing

from numpy import random as rd
from pysatl.criterion.normal import (
from pysatl_criterion.statistics.normal import (
GraphEdgesNumberNormalityGofStatistic,
GraphMaxDegreeNormalityGofStatistic,
KolmogorovSmirnovNormalityGofStatistic,
Expand Down
9 changes: 7 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@ dependencies = [
"python-rapidjson==1.20",
"jsonschema==4.23.0",
"rich==13.9.4",
"pysatl-criterion==0.0.1a0"
"click>=8.2.1",
"pysatl-criterion @ git+https://github.com/PySATL/pysatl-criterion.git"
]

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.poetry]
package-mode = false
package-mode = true
packages = [{include = "stattest"}]

[tool.poetry.group.dev.dependencies]
markdown = "3.7"
Expand Down Expand Up @@ -84,3 +86,6 @@ exclude = [".git", "__pycache__", ".eggs", "user_data", ".venv", ".env"]
"tests/**/*.py" = [
"S101", "S104", "S311", "S105", "S106", "S110"
]

[tool.poetry.scripts]
experiment = "stattest.cli.cli:cli"
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from dataclasses import dataclass

from stattest.configuration.experiment_config.experiment_config import ExperimentConfig


@dataclass
class CriticalValueExperimentConfig(ExperimentConfig):
"""
Critical value experiment configuration.
"""

significance_levels: list[float]
25 changes: 25 additions & 0 deletions stattest/configuration/experiment_config/experiment_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dataclasses import dataclass

from stattest.configuration.model.criterion.criterion import Criterion
from stattest.configuration.model.experiment_type.experiment_type import ExperimentType
from stattest.configuration.model.hypothesis.hypothesis import Hypothesis
from stattest.configuration.model.run_mode.run_mode import RunMode
from stattest.configuration.model.step_type.step_type import StepType


@dataclass
class ExperimentConfig:
"""
Experiment configuration.
"""

experiment_type: ExperimentType
storage_connection: str
run_mode: RunMode
hypothesis: Hypothesis
data_generator_type: StepType
executor_type: StepType
report_builder_type: StepType
sample_sizes: list[int]
monte_carlo_count: int
criteria: list[Criterion]
14 changes: 14 additions & 0 deletions stattest/configuration/experiment_config/power/power.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from dataclasses import dataclass

from stattest.configuration.experiment_config.experiment_config import ExperimentConfig
from stattest.configuration.model.alternative.alternative import Alternative


@dataclass
class PowerExperimentConfig(ExperimentConfig):
"""
Power experiment configuration.
"""

alternatives: list[Alternative]
significance_levels: list[float]
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dataclasses import dataclass

from stattest.configuration.experiment_config.experiment_config import ExperimentConfig


@dataclass
class TimeComplexityExperimentConfig(ExperimentConfig):
"""
Time complexity experiment configuration.
"""
11 changes: 11 additions & 0 deletions stattest/configuration/model/alternative/alternative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dataclasses import dataclass


@dataclass
class Alternative:
"""
Alternative configuration (generator code + parameters).
"""

generator_code: str
parameters: list[float]
11 changes: 11 additions & 0 deletions stattest/configuration/model/criterion/criterion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from dataclasses import dataclass


@dataclass
class Criterion:
"""
Criterion configuration (criterion code + parameters).
"""

criterion_code: str
parameters: list[float]
11 changes: 11 additions & 0 deletions stattest/configuration/model/experiment_type/experiment_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class ExperimentType(Enum):
"""
Experiment type.
"""

CRITICAL_VALUE = "critical_value"
POWER = "power"
TIME_COMPLEXITY = "time_complexity"
11 changes: 11 additions & 0 deletions stattest/configuration/model/hypothesis/hypothesis.py
Copy link
Contributor

@f1i3g3 f1i3g3 Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мб какой-то коммент на будущее оставить для расширения?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Для остальных перечислений так же.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не понял, Дим, что ты имеешь в виду.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class Hypothesis(Enum):
"""
Hypothesis.
"""

NORMAL = "normal"
EXPONENTIAL = "exponential"
WEIBULL = "weibull"
10 changes: 10 additions & 0 deletions stattest/configuration/model/run_mode/run_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class RunMode(Enum):
"""
Run mode (use existing data in DB or overwrite).
"""

REUSE = "reuse"
OVERWRITE = "overwrite"
10 changes: 10 additions & 0 deletions stattest/configuration/model/step_type/step_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class StepType(Enum):
"""
Step type (standard or custom).
"""

STANDARD = "standard"
CUSTOM = "custom"
2 changes: 1 addition & 1 deletion stattest/experiment/configuration/configuration.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Sequence

from pysatl.criterion import AbstractStatistic
from pysatl_criterion.statistics import AbstractStatistic

from stattest.experiment.generator import AbstractRVSGenerator
from stattest.persistence import IRvsStore
Expand Down
2 changes: 1 addition & 1 deletion stattest/experiment/test/critical_value.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np
import scipy.stats as scipy_stats
from pysatl.criterion import AbstractStatistic
from pysatl_criterion.statistics import AbstractStatistic

from stattest.experiment.hypothesis import AbstractHypothesis
from stattest.persistence.models import ICriticalValueStore
Expand Down
2 changes: 1 addition & 1 deletion stattest/experiment/test/power_calculation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pysatl.criterion import AbstractStatistic
from pysatl_criterion.statistics import AbstractStatistic

from stattest.experiment.hypothesis import AbstractHypothesis
from stattest.experiment.test.critical_value import get_or_calculate_critical_value
Expand Down
2 changes: 1 addition & 1 deletion stattest/experiment/test/test_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from multiprocessing import Queue
from multiprocessing.synchronize import Event as EventClass

from pysatl.criterion import AbstractStatistic
from pysatl_criterion.statistics import AbstractStatistic
from tqdm import tqdm

from stattest.experiment.configuration.configuration import TestConfiguration, TestWorker
Expand Down
2 changes: 1 addition & 1 deletion stattest/experiment/test/worker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pysatl.criterion import AbstractStatistic
from pysatl_criterion.statistics import AbstractStatistic
from typing_extensions import override

from stattest.experiment.configuration.configuration import TestWorker, TestWorkerResult
Expand Down
Empty file.
14 changes: 14 additions & 0 deletions stattest/experiment_new/experiment_steps/experiment_steps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from dataclasses import dataclass

from stattest.experiment_new.model.experiment_step.experiment_step import IExperimentStep


@dataclass
class ExperimentSteps:
"""
Experiment steps dataclass.
"""

generation_step: IExperimentStep
execution_step: IExperimentStep
report_building_step: IExperimentStep
31 changes: 31 additions & 0 deletions stattest/experiment_new/model/experiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from stattest.experiment_new.experiment_steps.experiment_steps import ExperimentSteps
from stattest.experiment_new.model.experiment_step.experiment_step import IExperimentStep


class Experiment:
"""
Experiment.
"""

def __init__(self, experiment_steps: ExperimentSteps):
self.experiment_steps = experiment_steps

def run_experiment(self) -> None:
"""
Run experiment.
"""
generation_step: IExperimentStep = self.experiment_steps.generation_step
execution_step: IExperimentStep = self.experiment_steps.execution_step
report_building_step: IExperimentStep = self.experiment_steps.report_building_step

print("Running generation step...")
generation_step.run()
print("Generation step finished")

print("Running execution step...")
execution_step.run()
print("Execution step finished")

print("Running report building step...")
report_building_step.run()
print("Report building step finished")
10 changes: 10 additions & 0 deletions stattest/experiment_new/model/experiment_step/experiment_step.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from typing import Protocol


class IExperimentStep(Protocol):
"""
Interface for experiment step.
"""

def run(self) -> None:
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from dataclasses import dataclass

from pysatl_criterion.statistics.goodness_of_fit import AbstractGoodnessOfFitStatistic


@dataclass
class ExecutionStepData:
"""
Data for execution step.
"""

criterion: AbstractGoodnessOfFitStatistic
sample_size: int
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from dataclasses import dataclass

from pysatl_criterion.persistence.model.limit_distribution.limit_distribution import (
ILimitDistributionStorage,
)

from stattest.experiment_new.step.execution.common.execution_step_data.execution_step_data import (
ExecutionStepData,
)
from stattest.persistence.model.random_values.random_values import IRandomValuesStorage
from stattest.worker.critical_value.critical_value import CriticalValueWorker


@dataclass
class CriticalValueStepData(ExecutionStepData):
"""
Data for execution step in critical value experiment.
"""


class CriticalValueExecutionStep:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не нужно ли добавить общий ExecutionStep?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Он есть, это IExperimentStep. Он объявлен как Protocol, в котором задан метод run() c определенной сигнатурой. CriticalValueExecutionStep реализует данный метод с такой же сигнатурой, что означает, что он является подклассом IExperimentStep (duck typing). Можно было бы явно указать, но это не требуется.

"""
Standard critical value experiment execution step.
"""

def __init__(
self,
worker: CriticalValueWorker,
step_data: list[CriticalValueStepData],
monte_carlo_count: int,
data_storage: IRandomValuesStorage,
result_storage: ILimitDistributionStorage,
):
self.worker = worker
self.step_data = step_data
self.monte_carlo_count = monte_carlo_count
self.data_storage = data_storage
self.result_storage = result_storage

def run(self) -> None:
"""
Run standard critical value execution step.
"""
raise NotImplementedError("Method is not yet implemented")
45 changes: 45 additions & 0 deletions stattest/experiment_new/step/execution/power/power.py
Copy link
Contributor

@f1i3g3 f1i3g3 Jun 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично для других шагов.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, для них работает то же самое правило.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from dataclasses import dataclass

from stattest.experiment.generator import AbstractRVSGenerator
from stattest.experiment_new.step.execution.common.execution_step_data.execution_step_data import (
ExecutionStepData,
)
from stattest.persistence.model.power.power import IPowerStorage
from stattest.persistence.model.random_values.random_values import IRandomValuesStorage
from stattest.worker.power.power import PowerWorker


@dataclass
class PowerStepData(ExecutionStepData):
"""
Data for execution step in power experiment.
"""

alternative: AbstractRVSGenerator
significance_level: float


class PowerExecutionStep:
"""
Standard power experiment execution step.
"""

def __init__(
self,
worker: PowerWorker,
step_data: list[PowerStepData],
monte_carlo_count: int,
data_storage: IRandomValuesStorage,
result_storage: IPowerStorage,
):
self.worker = worker
self.step_data = step_data
self.monte_carlo_count = monte_carlo_count
self.data_storage = data_storage
self.result_storage = result_storage

def run(self) -> None:
"""
Run standard power execution step.
"""
raise NotImplementedError("Method is not yet implemented")
Loading