Skip to main content

Math Bridge 🌉

Zaawansowana biblioteka matematyczna do obliczeń z funkcjami gamma, rozkładem Poissona i Kelly Criterion.

✨ Cechy

  • ✅ Pełna kompatybilność z scipy, numpy, keras, xgboost
  • ✅ Funkcje gamma (dodatnie, ujemne, zespolone)
  • ✅ Rozkład Poissona z pełnymi statystykami
  • ✅ Kelly Criterion i zarządzanie bankrollem
  • ✅ Bezpieczne operacje matematyczne
  • ✅ Brak błędów stringowych!

📦 Instalacja

pip install math-bridge

🚀 Szybki start

from math_bridge import MathBridge

mb = MathBridge()

# Funkcja Gamma
gamma_val = mb.gamma_positive(5)
print(f"Γ(5) = {gamma_val}")  # 24.0

# Rozkład Poissona
prob = mb.poisson_probability(k=17, lmbda=12)
print(f"P(17; 12) = {prob:.6f}")

# Kelly Criterion
confidence = mb.kelly_confidence(errors=0, fraction_str='1/2')
print(f"Confidence = {confidence:.4f}")

📚 Dokumentacja

Funkcje Gamma

gamma_positive(z)

Funkcja gamma dla wartości dodatnich.

mb.gamma_positive(5)  # 24.0
mb.gamma_positive([1, 2, 3])  # array([1., 1., 2.])

gamma_negative(x)

Funkcja gamma dla wartości ujemnych.

mb.gamma_negative(-1.5)  # 2.363271801207355

gamma_complex(z_real, z_imag)

Funkcja gamma dla liczb zespolonych.

result = mb.gamma_complex(1, 2)
print(result['modulus'])    # Moduł
print(result['argument'])   # Argument

Rozkład Poissona

poisson_probability(k, lmbda)

Prawdopodobieństwo P(k; λ).

mb.poisson_probability(17, 12)  # 0.038325

poisson_full_stats(lmbda, k=None)

Pełne statystyki rozkładu.

stats = mb.poisson_full_stats(12, 17)
print(stats)
# {
#   'lambda': 12,
#   'expected_value': 12,
#   'median': 12.0,
#   'variance': 12,
#   'entropy': 2.154,
#   'probability': 0.038325,
#   'cdf': 0.937
# }

Kelly Criterion

kelly_confidence(errors, fraction_str)

Oblicza confidence % dla danej liczby błędów.

mb.kelly_confidence(0, '1/2')   # 0.66 (66%)
mb.kelly_confidence(3, '1/3')   # 0.1875 (18.75%)

combine_fractions(frac1, frac2)

Łączy zbliżone frakcje Kelly.

mb.combine_fractions('1/3', '1/2')  # '5/6'
mb.combine_fractions('1/4', '2/4')  # '3/4'

Macierz wyników

interpret_result(goals_home, goals_away)

Interpretuje wynik meczu.

result = mb.interpret_result(2, 0)
print(result['matrix_code'])  # 'A8'
print(result['result_1x2'])   # '1'

Wzory złożone

formula_3_plus(a, b, delta, gamma_val, beta_val)

Wzór 3: [B + (δ + γ)]³ / [B + γ]³

result = mb.formula_3_plus(2, 3, 1.5, 2.5, 3.0)

delta_discriminant(a, b, c)

Delta równania kwadratowego.

delta = mb.delta_discriminant(1, -3, 2)
print(delta['delta'])         # 1
print(delta['solutions'])     # 2

🔧 Funkcje pomocnicze

Bezpieczne operacje

# Bezpieczne dzielenie (nie crashuje przy dzieleniu przez 0)
mb.safe_divide(10, 0)  # nan zamiast błędu

# Bezpieczne potęgowanie
mb.safe_power(2, 1000)  # Obsługuje bardzo duże liczby

# Bezpieczny logarytm
mb.safe_log(-5)  # nan zamiast błędu

Walidacja danych

result = mb.validate_input(0.5, 'probability')
print(result['valid'])  # True

result = mb.validate_input(-0.5, 'positive')
print(result['valid'])  # False
print(result['error'])  # 'Wartość musi być dodatnia'

Konwersja danych

# String → float
mb.from_string('1/2')     # 0.5
mb.from_string('3.14')    # 3.14

# Do numpy array
mb.to_numpy_array([1, 2, 3])  # array([1., 2., 3.])

# Formatowanie wyjścia
mb.format_output(3.14159, precision=2)  # "3.14"

📊 Przykłady użycia

Przykład 1: Analiza rozkładu Poissona

from math_bridge import MathBridge

mb = MathBridge()

# Parametry
lambda_param = 12
k_values = range(5, 20)

# Obliczenia
for k in k_values:
    prob = mb.poisson_probability(k, lambda_param)
    print(f"P({k}; {lambda_param}) = {prob:.6f}")

Przykład 2: Kelly Criterion dla zakładów

from math_bridge import MathBridge

mb = MathBridge()

# Sprawdź wszystkie frakcje dla 0 błędów
fractions = ['1/2', '1/3', '2/3', '1/4', '1/5']

for frac in fractions:
    confidence = mb.kelly_confidence(errors=0, fraction_str=frac)
    print(f"Frakcja {frac}: {confidence:.4f} ({confidence*100:.2f}%)")

Przykład 3: Łączenie podobnych frakcji

from math_bridge import MathBridge

mb = MathBridge()

# Sprawdź podobieństwo
similarity = mb.check_fraction_similarity(
    errors1=5, frac1='1/3',
    errors2=6, frac2='1/2',
    tolerance=0.005
)

if similarity['similar']:
    print(f"Frakcje są podobne! Łączę je:")
    print(f"Wynik: {similarity['combined']}")

Przykład 4: Analiza wyników meczów

from math_bridge import MathBridge

mb = MathBridge()

# Lista wyników
matches = [
    (3, 1),  # 3-1
    (2, 2),  # 2-2
    (0, 2),  # 0-2
]

for home, away in matches:
    result = mb.interpret_result(home, away)
    print(f"{home}-{away}: {result['matrix_code']} (typ: {result['result_1x2']})")

🧪 Testy

# Instalacja z opcją dev
pip install math-bridge[dev]

# Uruchomienie testów
pytest tests/

# Z pokryciem kodu
pytest --cov=math_bridge tests/

🤝 Integracja z innymi bibliotekami

Z NumPy

import numpy as np
from math_bridge import MathBridge

mb = MathBridge()

# Konwersja do numpy
data = [1, 2, 3, 4, 5]
np_array = mb.to_numpy_array(data)

# Obliczenia wektorowe
gammas = mb.gamma_positive(np_array)
print(gammas)  # array([  1.,   1.,   2.,   6.,  24.])

Z Pandas

import pandas as pd
from math_bridge import MathBridge

mb = MathBridge()

# DataFrame z danymi
df = pd.DataFrame({
    'k': [10, 12, 14, 16, 18],
    'lambda': [12, 12, 12, 12, 12]
})

# Oblicz prawdopodobieństwa
df['probability'] = df.apply(
    lambda row: mb.poisson_probability(row['k'], row['lambda']),
    axis=1
)

Z XGBoost/Keras

from math_bridge import MathBridge
import numpy as np

mb = MathBridge()

# Przygotuj features z matematycznych funkcji
def create_features(x):
    return np.array([
        mb.gamma_positive(x),
        mb.safe_log(x),
        mb.safe_sqrt(x)
    ])

# Użyj w modelu ML
X_train = np.array([create_features(x) for x in range(1, 100)])
# Teraz możesz użyć X_train w XGBoost/Keras!

⚠️ Uwagi

  • Brak błędów stringowych: Wszystkie funkcje zwracają np.nan zamiast crashować
  • Bezpieczne operacje: Dzielenie przez zero, logarytmy z ujemnych liczb - wszystko obsłużone
  • Kompatybilność: Działa z scipy 1.5+, numpy 1.19+, Python 3.7+

📄 Licencja

MIT License - możesz używać komercyjnie!

🐛 Zgłaszanie błędów

GitHub Issues: https://github.com/twoj-username/math-bridge/issues

👨‍💻 Autor

Twoje Imię

🌟 Wsparcie

Jeśli biblioteka Ci pomogła, zostaw ⭐ na GitHub!

Release files for math-bridge 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for math-bridge 1.0.0
File Size Uploaded
math_bridge-1.0.0.tar.gz 16.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for math-bridge 1.0.0
File Interpreter ABI Platform
math_bridge-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.6 kB

Release files / math_bridge-1.0.0.tar.gz

Download URL math_bridge-1.0.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
e2b43a6977b43c83c6ab077596ad0330ad5fe5386a9e8a660e38ccf086d09ced
BLAKE2b-256 checksum
How to use checksums
07c7beacd424d810be170288c7da275428507f68d4731f90acec9bf903312a86
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / math_bridge-1.0.0-py3-none-any.whl

Download URL math_bridge-1.0.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d27db8d127b2edc57a2b672b365679b7836d4ba0abca26982deab21fd51932da
BLAKE2b-256 checksum
How to use checksums
10925bcc63f289137319e00f8d2e92b0ac47e3506f229e9d32ef539239a836fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page