Skip to main content

No project description provided

Project description

Bayes Error (Local averaging of the posterior)

Installation

To install this small tool from source code

pip install git+https://github.com/cat-claws/bayes-error-local-averaging

How to use

import bayeslap
import numpy as np
import torch
from sklearn.datasets import make_moons

# Set random seeds for reproducibility
np.random.seed(42)
torch.manual_seed(42)

# === Example 1: 2D Moons Dataset ===
def create_moons_data(n_samples=2000, noise=0.2):
    X_np, y_np = make_moons(n_samples=n_samples, noise=noise)
    X_torch = torch.tensor(X_np, dtype=torch.float32)
    y_torch = torch.tensor(y_np, dtype=torch.long)
    return X_np, y_np, X_torch, y_torch

moons_np, moons_labels_np, moons_torch, moons_labels_torch = create_moons_data()

error = bayeslap.BayesErrorRBF.apply(moons_torch, moons_labels_torch, 0.3, 10, 32)

# Alternatively
# error = bayeslap.BayesErrorLogistic.apply(moons_torch, moons_labels_torch, 10, 32)

print("Bayes error:", error.item())  # Show first few estimates

error.backward()  # Now X.grad will have the gradient of the error
print("Shape of Torch gradient:", moons_torch.grad.shape)
print("First 3 gradients (Torch):")
print(moons_torch.grad[:3])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bayeslap-0.0.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bayeslap-0.0.1-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file bayeslap-0.0.1.tar.gz.

File metadata

  • Download URL: bayeslap-0.0.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for bayeslap-0.0.1.tar.gz
Algorithm Hash digest
SHA256 316e79e0ffd632854f7121ff0644cfa194348c34bfa25a6bbb565d52f45c5328
MD5 1f5b014cc44ef6de9f1cce2b9999581c
BLAKE2b-256 308ab1c68850bf7e0d7f820185c02f462d2c46620628f276c78b47da58927f3f

See more details on using hashes here.

File details

Details for the file bayeslap-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: bayeslap-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for bayeslap-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 130e9d06ce3bc1a91104dcee234582654abeccfeb5a8966a6c82141b63301b74
MD5 a31e51a0c441ca61a368b1878637c789
BLAKE2b-256 f9cfed22d3b8a08e0bfd87f3992e75f02acc253a64742af379a80858d355443b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page