Skip to main content

SBO defines an iterative approach to translate points by a most likely distance from a given dataset

Project description

soft-brownian-offset

Soft Brownian Offset (SBO) defines an iterative approach to translate points by a most likely distance from a given dataset.

Background

The technique is described in detail within the paper TBA. For citations please see cite.

Installation

This project is hosted on PyPI and can therefore be installed easily through pip:

pip install sbo

Dependending on your setup you may need to add --user after the install.

Demonstration

demonstration

The following code creates the plot seen above:

#!/usr/bin/env python3
# Creates a plot for Soft Brownian Offset (SBO)

import numpy as np
import pylab as plt
import itertools
import sys

from matplotlib import cm
from sklearn.datasets import make_moons

from sbo import soft_brownian_offset, gaussian_hyperspheric_offset

plt.rc('text', usetex=True)

c = cm.tab10.colors

def plot_data(X, y, ax=plt):
    ax.scatter(X[:, 0], X[:, 1], marker='x', s=20, label='ID', alpha=alpha, c=[c[-1]])
    ax.scatter(y[:, 0], y[:, 1], marker='+', label='SBO', alpha=alpha, c=[c[-6]])

def plot_mindist(X, y, ax=plt):
    if len(X.shape) == 1:
        X = X[:, None]
    if len(y.shape) == 1:
        y = y[:, None]
    ax.hist(pairwise_distances(y, X).min(axis=1), bins=len(y) // 10)
    ax.set_xlabel("Minimum distance from ood to id")
    ax.set_ylabel("Count")

def plot_data_mindist(X, y):
    fig, ax = plt.subplots(1, 2)
    plot_data(X, y, ax=ax[0])
    plot_mindist(X, y, ax=ax[1])
    plt.show()


n_samples_id = 60
n_samples_ood = 150
noise = .08
show_progress = False
alpha = .6

n_colrow = 3
d_min = np.linspace(.25, .45, n_colrow)
softness = np.linspace(0, 1, n_colrow)
fig, ax = plt.subplots(n_colrow, n_colrow, sharex=True, sharey=True, figsize=(8.5, 9))

X, _ = make_moons(n_samples=n_samples_id, noise=noise)
for i, (d_min_, softness_) in enumerate(itertools.product(d_min, softness)):
    xy = i // n_colrow, i % n_colrow
    d_off_ = d_min_ * .7
    ax[xy].set_title(f"$d^- = {d_min_:.2f}\ d^+ = {d_off_:.2f}\ \sigma = {softness_}$")
    if softness_ == 0:
        softness_ = False
    y = soft_brownian_offset(X, d_min_, d_off_, n_samples=n_samples_ood, softness=softness_, show_progress=show_progress)
    plot_data(X, y, ax=ax[xy])
    if i // n_colrow == len(d_min) - 1:
        ax[xy].set_xlabel("$x_1$")
    if i % n_colrow == 0:
        ax[xy].set_ylabel("$x_2$")
ax[0, n_colrow - 1].legend(loc='upper right')

plt.tight_layout()
plt.savefig('assets/sbo-demo.svg')

Cite

Please cite SBO in your paper if it helps your research TBA:

@article{name2020sbo,
  Author = {TBA},
  Journal = {arXiv preprint arXiv:TBA},
  Title = {TBA},
  Year = {2020}
}

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

sbo-0.0.8.tar.gz (51.7 kB view details)

Uploaded Source

Built Distribution

sbo-0.0.8-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file sbo-0.0.8.tar.gz.

File metadata

  • Download URL: sbo-0.0.8.tar.gz
  • Upload date:
  • Size: 51.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7

File hashes

Hashes for sbo-0.0.8.tar.gz
Algorithm Hash digest
SHA256 df91d25e10dcc9c6e1b440e4c51429a265f2f1919a9821f1573438a980ee4eb2
MD5 89e6c5e5f38d88cbc061477316bf85f2
BLAKE2b-256 38838d0be82a46661e283e4763d63c9849863d60f68055aca42dbb6c394c408e

See more details on using hashes here.

File details

Details for the file sbo-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: sbo-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.8.7

File hashes

Hashes for sbo-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 0167f72bab992508ac1ae5dd1bc1f68b0d1821fb406a721440563bddd2642ed9
MD5 476ba505349fba08bf4f01b8ac510b9a
BLAKE2b-256 1ca154a7b3a81cbed2f1693ee9a523c95a9d14554f75559f26430ab6400a8b46

See more details on using hashes here.

Supported by

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