Skip to content

Repository refactoring #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 37 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: CI

on: [ push, pull_request ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: [ "3.11", "3.12", "3.13" ]

steps:
- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}

- name: Install poetry
run: pipx install poetry

- name: Install dependencies
run: poetry install --with dev

- name: Ruff
run: poetry run ruff check

- name: Install stubs
run: poetry run pip install types-PyYAML types-tqdm

- name: Mypy
run: poetry run mypy

- name: Pytest
run: poetry run python -m pytest tests
35 changes: 0 additions & 35 deletions .github/workflows/code_style.yml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/pylint.yml

This file was deleted.

27 changes: 0 additions & 27 deletions .github/workflows/test.yml

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ share/python-wheels/
.installed.cfg
*.egg
MANIFEST
poetry.lock

# PyInstaller
# Usually these files are written by a python script from a template
Expand Down Expand Up @@ -157,7 +158,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

#vscode
.vscode
Expand Down
16 changes: 0 additions & 16 deletions .pre-commit-config.yaml

This file was deleted.

9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
![PyLint](https://github.com/PySATL/MPEst/actions/workflows/pylint.yml/badge.svg)
![Check code style](https://github.com/PySATL/MPEst/actions/workflows/code_style.yml/badge.svg)
[![Code style](https://img.shields.io/badge/Code%20style-black-000000.svg)](https://github.com/psf/black)
![Unit Tests](https://github.com/PySATL/MPEst/actions/workflows/test.yml/badge.svg)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
![CI](https://github.com/PySATL/pysatl-mpest/actions/workflows/check.yml/badge.svg)
<a href="https://github.com/PySATL/pysatl-mpest/blob/main/LICENSE"><img alt="License: MIT" src="https://black.readthedocs.io/en/stable/_static/license.svg"></a>

## Installation

Expand Down Expand Up @@ -98,6 +97,6 @@ plt.show()
![plot](https://github.com/toxakaz/EM-algo/raw/main/examples/readme_example/example.png)

## Requirements
- python 3.11
- python >= 3.11
- numpy
- scipy
Empty file added examples/__init__.py
Empty file.
9 changes: 2 additions & 7 deletions examples/big_mono_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

counter = Clicker()

def _generate_test(
model: type[AModelWithGenerator], o_borders: list[tuple[float, float]]
) -> list[Test]:
def _generate_test(model: type[AModelWithGenerator], o_borders: list[tuple[float, float]]) -> list[Test]:
return generate_mono_test(
model_t=model,
params_borders=o_borders,
Expand All @@ -36,10 +34,7 @@ def _generate_test(
tests_per_size=8,
tests_per_cond=2,
runs_per_test=1,
solvers=[
init_solver(16, 0.1, 0.001, 3, optimizer)
for optimizer in TESTS_OPTIMIZERS
],
solvers=[init_solver(16, 0.1, 0.001, 3, optimizer) for optimizer in TESTS_OPTIMIZERS],
)

tests += _generate_test(WeibullModelExp, [(0.25, 25), (0.25, 25)])
Expand Down
6 changes: 1 addition & 5 deletions examples/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@

CPU_COUNT = os.cpu_count()
MAX_WORKERS_PERCENT = 0.75
MAX_WORKERS = (
min(round(CPU_COUNT * MAX_WORKERS_PERCENT), CPU_COUNT)
if CPU_COUNT is not None
else 1
)
MAX_WORKERS = min(round(CPU_COUNT * MAX_WORKERS_PERCENT), CPU_COUNT) if CPU_COUNT is not None else 1
# MAX_WORKERS = 4

RESULTS_FOLDER = EXAMPLES / "results"
Expand Down
36 changes: 6 additions & 30 deletions examples/diff_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
for sp in gaussian_start_params:
main_distr = list(gaussian.generate(np.array(sp), BASE_SIZE // 2, normalized=False))
for second_sp in np.linspace(sp[0] - 5, sp[0] + 5, num=8, endpoint=True):
x = main_distr + list(
gaussian.generate(
np.array((second_sp, 3.0)), BASE_SIZE // 2, normalized=False
)
)
x = main_distr + list(gaussian.generate(np.array((second_sp, 3.0)), BASE_SIZE // 2, normalized=False))
random.shuffle(x)

start_params_borders = [
Expand All @@ -45,12 +41,7 @@
samples = random.sample(x, size)
for _ in range(TESTS_PER_SIZE):
start_params = [
np.array(
[
random.uniform(border[0], border[1])
for border in start_params_borders
]
)
np.array([random.uniform(border[0], border[1]) for border in start_params_borders])
for _ in range(2)
]
tests.append(
Expand Down Expand Up @@ -81,22 +72,15 @@
]
),
),
[
init_solver(16, 0.1, 0.001, 3, optimizer)
for optimizer in TESTS_OPTIMIZERS
],
[init_solver(16, 0.1, 0.001, 3, optimizer) for optimizer in TESTS_OPTIMIZERS],
1,
)
)

for sp in weibull_start_params:
main_distr = list(weibull.generate(np.array(sp), BASE_SIZE // 2, normalized=False))
for second_sp in np.linspace(max(sp[0] - 5, 0.1), sp[0] + 5, num=8, endpoint=True):
x = main_distr + list(
weibull.generate(
np.array((second_sp, 1.0)), BASE_SIZE // 2, normalized=False
)
)
x = main_distr + list(weibull.generate(np.array((second_sp, 1.0)), BASE_SIZE // 2, normalized=False))
random.shuffle(x)

start_params_borders = [
Expand All @@ -109,12 +93,7 @@
samples = random.sample(x, size)
for _ in range(TESTS_PER_SIZE):
start_params = [
np.array(
[
random.uniform(border[0], border[1])
for border in start_params_borders
]
)
np.array([random.uniform(border[0], border[1]) for border in start_params_borders])
for _ in range(2)
]
tests.append(
Expand Down Expand Up @@ -145,10 +124,7 @@
]
),
),
[
init_solver(16, 0.1, 0.001, 3, optimizer)
for optimizer in TESTS_OPTIMIZERS
],
[init_solver(16, 0.1, 0.001, 3, optimizer) for optimizer in TESTS_OPTIMIZERS],
1,
)
)
Expand Down
23 changes: 7 additions & 16 deletions examples/mono_test_generator.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
"""Module which contains mixture distributions of single model tests generator"""

import random
from typing import Iterable
from collections.abc import Iterable

import numpy as np

from examples.utils import Clicker, Test
from mpest.distribution import Distribution
from mpest.core.distribution import Distribution
from mpest.core.mixture_distribution import MixtureDistribution
from mpest.core.problem import Problem
from mpest.em import EM
from mpest.mixture_distribution import MixtureDistribution
from mpest.models import AModel, AModelWithGenerator
from mpest.problem import Problem


def generate_mono_test(
Expand Down Expand Up @@ -42,9 +42,7 @@ def generate_mono_test(
models: list[AModel] = []

for _ in range(k):
params = np.array(
[random.uniform(border[0], border[1]) for border in params_borders]
)
params = np.array([random.uniform(border[0], border[1]) for border in params_borders])
model = model_t()
x += list(model.generate(params, per_model, normalized=False))

Expand All @@ -62,12 +60,7 @@ def generate_mono_test(
samples = random.sample(x, size)
for _ in range(tests_per_size):
start_params = [
np.array(
[
random.uniform(border[0], border[1])
for border in start_params_borders
]
)
np.array([random.uniform(border[0], border[1]) for border in start_params_borders])
for _ in range(k)
]
tests.append(
Expand All @@ -91,9 +84,7 @@ def generate_mono_test(
model,
params,
)
for model, params in zip(
models, start_params
)
for model, params in zip(models, start_params)
]
),
),
Expand Down
Loading