Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
088429a16a | ||
|
b6145223c8 | ||
|
09256956f3 | ||
|
0ca90fdcee | ||
|
be21412f8a | ||
|
ae6bc47f87 |
@@ -1,5 +1,5 @@
|
|||||||
[bumpversion]
|
[bumpversion]
|
||||||
current_version = 0.4.2
|
current_version = 0.4.4
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
|
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)
|
||||||
|
@@ -23,7 +23,7 @@ author = "Jensun Ravichandran"
|
|||||||
|
|
||||||
# The full version, including alpha/beta/rc tags
|
# The full version, including alpha/beta/rc tags
|
||||||
#
|
#
|
||||||
release = "0.4.2"
|
release = "0.4.4"
|
||||||
|
|
||||||
# -- General configuration ---------------------------------------------------
|
# -- General configuration ---------------------------------------------------
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
"""ProtoTorch package."""
|
"""ProtoTorch package."""
|
||||||
|
|
||||||
# Core Setup
|
# Core Setup
|
||||||
__version__ = "0.4.2"
|
__version__ = "0.4.4"
|
||||||
|
|
||||||
__all_core__ = [
|
__all_core__ = [
|
||||||
"datasets",
|
"datasets",
|
||||||
|
@@ -67,8 +67,9 @@ class LabeledComponents(Components):
|
|||||||
*,
|
*,
|
||||||
initialized_components=None):
|
initialized_components=None):
|
||||||
if initialized_components is not None:
|
if initialized_components is not None:
|
||||||
super().__init__(initialized_components=initialized_components[0])
|
components, component_labels = initialized_components
|
||||||
self._labels = initialized_components[1]
|
super().__init__(initialized_components=components)
|
||||||
|
self._labels = component_labels
|
||||||
else:
|
else:
|
||||||
self._initialize_labels(distribution)
|
self._initialize_labels(distribution)
|
||||||
super().__init__(number_of_components=len(self._labels),
|
super().__init__(number_of_components=len(self._labels),
|
||||||
|
@@ -1,11 +1,6 @@
|
|||||||
"""ProtoTorch datasets."""
|
"""ProtoTorch datasets."""
|
||||||
|
|
||||||
from .abstract import NumpyDataset
|
from .abstract import NumpyDataset
|
||||||
|
from .iris import Iris
|
||||||
from .spiral import Spiral
|
from .spiral import Spiral
|
||||||
from .tecator import Tecator
|
from .tecator import Tecator
|
||||||
|
|
||||||
__all__ = [
|
|
||||||
"NumpyDataset",
|
|
||||||
"Spiral",
|
|
||||||
"Tecator",
|
|
||||||
]
|
|
||||||
|
15
prototorch/datasets/iris.py
Normal file
15
prototorch/datasets/iris.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
"""Thin wrapper for the Iris classification dataset from sklearn.
|
||||||
|
|
||||||
|
URL:
|
||||||
|
https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
from prototorch.datasets.abstract import NumpyDataset
|
||||||
|
from sklearn.datasets import load_iris
|
||||||
|
|
||||||
|
|
||||||
|
class Iris(NumpyDataset):
|
||||||
|
def __init__(self):
|
||||||
|
x, y = load_iris(return_X_y=True)
|
||||||
|
super().__init__(x, y)
|
@@ -3,7 +3,6 @@
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
|
|
||||||
# @torch.jit.script
|
|
||||||
def stratified_min(distances, labels):
|
def stratified_min(distances, labels):
|
||||||
clabels = torch.unique(labels, dim=0)
|
clabels = torch.unique(labels, dim=0)
|
||||||
nclasses = clabels.size()[0]
|
nclasses = clabels.size()[0]
|
||||||
@@ -31,15 +30,15 @@ def stratified_min(distances, labels):
|
|||||||
return winning_distances.T # return with `batch_size` first
|
return winning_distances.T # return with `batch_size` first
|
||||||
|
|
||||||
|
|
||||||
# @torch.jit.script
|
|
||||||
def wtac(distances, labels):
|
def wtac(distances, labels):
|
||||||
winning_indices = torch.min(distances, dim=1).indices
|
winning_indices = torch.min(distances, dim=1).indices
|
||||||
winning_labels = labels[winning_indices].squeeze()
|
winning_labels = labels[winning_indices].squeeze()
|
||||||
return winning_labels
|
return winning_labels
|
||||||
|
|
||||||
|
|
||||||
# @torch.jit.script
|
def knnc(distances, labels, k=1):
|
||||||
def knnc(distances, labels, k):
|
winning_indices = torch.topk(-distances, k=k, dim=1).indices
|
||||||
winning_indices = torch.topk(-distances, k=k.item(), dim=1).indices
|
# winning_labels = torch.mode(labels[winning_indices].squeeze(),
|
||||||
winning_labels = labels[winning_indices].squeeze()
|
# dim=1).values
|
||||||
|
winning_labels = torch.mode(labels[winning_indices], dim=1).values
|
||||||
return winning_labels
|
return winning_labels
|
||||||
|
3
setup.py
3
setup.py
@@ -23,6 +23,7 @@ INSTALL_REQUIRES = [
|
|||||||
]
|
]
|
||||||
DATASETS = [
|
DATASETS = [
|
||||||
"requests",
|
"requests",
|
||||||
|
"sklearn",
|
||||||
"tqdm",
|
"tqdm",
|
||||||
]
|
]
|
||||||
DEV = ["bumpversion"]
|
DEV = ["bumpversion"]
|
||||||
@@ -42,7 +43,7 @@ ALL = DATASETS + DEV + DOCS + EXAMPLES + TESTS
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="prototorch",
|
name="prototorch",
|
||||||
version="0.4.2",
|
version="0.4.4",
|
||||||
description="Highly extensible, GPU-supported "
|
description="Highly extensible, GPU-supported "
|
||||||
"Learning Vector Quantization (LVQ) toolbox "
|
"Learning Vector Quantization (LVQ) toolbox "
|
||||||
"built using PyTorch and its nn API.",
|
"built using PyTorch and its nn API.",
|
||||||
|
@@ -4,7 +4,6 @@ import unittest
|
|||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import torch
|
import torch
|
||||||
|
|
||||||
from prototorch.functions import (activations, competitions, distances,
|
from prototorch.functions import (activations, competitions, distances,
|
||||||
initializers, losses)
|
initializers, losses)
|
||||||
|
|
||||||
@@ -139,7 +138,7 @@ class TestCompetitions(unittest.TestCase):
|
|||||||
def test_knnc_k1(self):
|
def test_knnc_k1(self):
|
||||||
d = torch.tensor([[2.0, 3.0, 1.99, 3.01], [2.0, 3.0, 2.01, 3.0]])
|
d = torch.tensor([[2.0, 3.0, 1.99, 3.01], [2.0, 3.0, 2.01, 3.0]])
|
||||||
labels = torch.tensor([0, 1, 2, 3])
|
labels = torch.tensor([0, 1, 2, 3])
|
||||||
actual = competitions.knnc(d, labels, k=torch.tensor([1]))
|
actual = competitions.knnc(d, labels, k=1)
|
||||||
desired = torch.tensor([2, 0])
|
desired = torch.tensor([2, 0])
|
||||||
mismatch = np.testing.assert_array_almost_equal(actual,
|
mismatch = np.testing.assert_array_almost_equal(actual,
|
||||||
desired,
|
desired,
|
||||||
|
Reference in New Issue
Block a user