Skip to content

Commit

Permalink
Change naming from ordcomp to cblearn (cblearn#12)
Browse files Browse the repository at this point in the history
* Find and replace ordcomp by cblearn

* Rename module directory ordcomp to cblearn

* Set main as base branch in CI
  • Loading branch information
dekuenstle authored Feb 12, 2021
1 parent f7672ae commit 09c1317
Show file tree
Hide file tree
Showing 54 changed files with 124 additions and 126 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Tests

on:
push:
branches: [ master ]
branches: [ main ]
pull_request:
branches: [ master ]
branches: [ main ]

jobs:
build:
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
flake8 . --count --statistics
- name: Test with pytest and measure coverage
run: |
pytest ordcomp --cov=ordcomp --cov-report=xml
pytest cblearn --cov=cblearn --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand All @@ -47,4 +47,4 @@ jobs:
env_vars: OS,PYTHON
- name: Build the documentation
run: |
python setup.py build_sphinx
python setup.py build_sphinx
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2021 The ordcomp developers.
Copyright (c) 2020-2021 The cblearn developers.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# ordcomp
Machine Learning Toolkit for Comparison-based Learning in Python
# cblearn
## Comparison-based Machine Learning in Python

[![Unit tests](https://github.com/dekuenstle/ordcomp/workflows/Python%20package/badge.svg)](https://github.com/dekuenstle/ordcomp/actions)
[![Test Coverage](https://codecov.io/gh/dekuenstle/ordcomp/branch/master/graph/badge.svg?token=P9JRT6OK6O)](https://codecov.io/gh/dekuenstle/ordcomp)
[![Documentation](https://readthedocs.org/projects/ordcomp/badge/?version=latest)](https://ordcomp.readthedocs.io/en/latest/?badge=latest)
[![Unit tests](https://github.com/dekuenstle/cblearn/workflows/Python%20package/badge.svg)](https://github.com/dekuenstle/cblearn/actions)
[![Test Coverage](https://codecov.io/gh/dekuenstle/cblearn/branch/master/graph/badge.svg?token=P9JRT6OK6O)](https://codecov.io/gh/dekuenstle/cblearn)
[![Documentation](https://readthedocs.org/projects/cblearn/badge/?version=latest)](https://cblearn.readthedocs.io/en/latest/?badge=latest)

Comparison-based Learning are the Machine Learning algorithms to use, when training data
are ordinal comparisons instead of Euclidean points.
Expand All @@ -16,9 +16,9 @@ It plays hand-in-hand with scikit-learn:
from sklearn.datasets import load_iris
from sklearn.model_selection import cross_val_score

from ordcomp.datasets import make_random_triplets
from ordcomp.embedding.wrapper import SOE
from ordcomp.metrics import TripletScorer
from cblearn.datasets import make_random_triplets
from cblearn.embedding.wrapper import SOE
from cblearn.metrics import TripletScorer


X = load_iris().data
Expand All @@ -32,25 +32,25 @@ embedding = estimator.fit_transform(triplets, responses)
print(f"The embedding has shape {embedding.shape}.")
```

Please try the [Examples](https://ordcomp.readthedocs.io/en/latest/generated_examples/index.html).
Please try the [Examples](https://cblearn.readthedocs.io/en/latest/generated_examples/index.html).

## Getting Started

OrdComp required Python 3.7 or newer. The easiest way to install is using `pip`:
cblearn required Python 3.7 or newer. The easiest way to install is using `pip`:

```
pip install https://github.com/dekuenstle/ordcomp.git
pip install https://github.com/dekuenstle/cblearn.git
```
Find more details in the [installation instructions](https://ordcomp.readthedocs.io/en/latest/install.html).
Find more details in the [installation instructions](https://cblearn.readthedocs.io/en/latest/install.html).


In the [User Guide](https://ordcomp.readthedocs.io/en/latest/user_guide/index.html) you find a detailed introduction.
In the [User Guide](https://cblearn.readthedocs.io/en/latest/user_guide/index.html) you find a detailed introduction.

## Contribute

We are happy about your contributions.
Please see our [Contributor Guide](https://ordcomp.readthedocs.io/en/latest/contributor_guide/index.html).
Please see our [Contributor Guide](https://cblearn.readthedocs.io/en/latest/contributor_guide/index.html).

## License

This library is free to use under the [MIT License](https://github.com/dekuenstle/ordcomp/blob/master/LICENSE) conditions.
This library is free to use under the [MIT License](https://github.com/dekuenstle/cblearn/blob/master/LICENSE) conditions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from sklearn.metrics import pairwise
import numpy as np

from ordcomp import utils
from cblearn import utils


class NoiseTarget(enum.Enum):
Expand Down Expand Up @@ -48,7 +48,7 @@ def noisy_triplet_answers(triplets: utils.Questions, embedding: np.ndarray, resu
If return_indices is True, a tuple of indices and answers can be returned
>>> from ordcomp.datasets import noisy_triplet_answers
>>> from cblearn.datasets import noisy_triplet_answers
>>> triplets = [[0, 1, 2], [1, 2, 3]]
>>> embedding = [[0.1], [0.5], [0.9], [1.]]
>>> noisy_triplet_answers(triplets, embedding, result_format='list-order')
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def make_all_triplets(embedding: np.ndarray, result_format: str, monotonic: bool
embedding: Object coordinates or distance matrix
monotonic: Only triplets (j, i, k), such that j < i < k.
random_state: Seed for noisy answers
kwargs: Additional arguments passed to :func:`ordcomp.datasets.noisy_triplet_answers`
kwargs: Additional arguments passed to :func:`cblearn.datasets.noisy_triplet_answers`
Returns:
The triplets and answers, based on format. See :func:`ordcomp.utils.check_triplets`.
The triplets and answers, based on format. See :func:`cblearn.utils.check_triplets`.
"""
triplets = make_all_triplet_indices(len(embedding), monotonic)
return noisy_triplet_answers(triplets, embedding, result_format=result_format, **kwargs)
Expand All @@ -49,9 +49,9 @@ def make_random_triplets(embedding: np.ndarray, result_format: str, size: Union[
make_all: Choose from all triplets instead of iterative sampling,
if the difference between all triplets to the requested number is smaller than this value.
random_state: Seed for triplet sampling and noisy answers
kwargs: Additional arguments passed to :func:`ordcomp.datasets.noisy_triplet_answers`
kwargs: Additional arguments passed to :func:`cblearn.datasets.noisy_triplet_answers`
Returns:
The triplets and answers, based on format. See :func:`ordcomp.utils.check_triplets`.
The triplets and answers, based on format. See :func:`cblearn.utils.check_triplets`.
"""
triplets = make_random_triplet_indices(len(embedding), size, random_state, repeat, monotonic, make_all)
return noisy_triplet_answers(triplets, embedding, result_format=result_format, random_state=random_state, **kwargs)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Per user selection, multiple triplet constraints were created.
Dimensionality unknown
=================== =====================

This dataset can be downloaded using the :func:`ordcomp.datasets.fetch_food_similarity`.
This dataset can be downloaded using the :func:`cblearn.datasets.fetch_food_similarity`.

.. License statement from the original homepage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Such, for each user judgement multiple triplets were created with the remaining
The original dataset, published 2002-10-15, contains 224793 triplets.
We omit in this dataset the triplets with missing values for the last triplet index.
This dataset can be downloaded using the :func:`ordcomp.datasets.fetch_musician_similarity`.
This dataset can be downloaded using the :func:`cblearn.datasets.fetch_musician_similarity`.

When using these triplets, please give credit to the original authors.

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np

from ordcomp.datasets import fetch_food_similarity
from cblearn.datasets import fetch_food_similarity


def test_fetch_food(tmp_path):
data_home = tmp_path / 'ordcomp_datasets'
data_home = tmp_path / 'cblearn_datasets'
bunch = fetch_food_similarity(data_home=data_home, shuffle=False)

assert bunch.data.shape == (190376, 3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import numpy as np

from ordcomp.datasets import fetch_musician_similarity
from cblearn.datasets import fetch_musician_similarity


def test_fetch_musician_similarity(tmp_path):
data_home = tmp_path / 'ordcomp_datasets'
data_home = tmp_path / 'cblearn_datasets'
bunch = fetch_musician_similarity(data_home=data_home, shuffle=False)

assert bunch.data.shape == (213629, 3)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import numpy as np
import pytest

from ordcomp import datasets
from cblearn import datasets


def test_make_triplets_raises():
Expand Down
1 change: 1 addition & 0 deletions cblearn/embedding/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from cblearn.embedding._soe import SOE
4 changes: 2 additions & 2 deletions ordcomp/embedding/_base.py → cblearn/embedding/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from sklearn.base import TransformerMixin
from sklearn.utils.validation import check_is_fitted

from ordcomp import datasets
from ordcomp import utils
from cblearn import datasets
from cblearn import utils


class TripletEmbeddingMixin(TransformerMixin):
Expand Down
11 changes: 5 additions & 6 deletions ordcomp/embedding/_soe.py → cblearn/embedding/_soe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
from scipy.optimize import minimize
from scipy.spatial import distance_matrix

import ordcomp
from ordcomp import utils
from ordcomp.embedding._base import TripletEmbeddingMixin
from ordcomp.utils import assert_torch_is_available, torch_minimize_lbfgs
from cblearn import utils
from cblearn.embedding._base import TripletEmbeddingMixin
from cblearn.utils import assert_torch_is_available, torch_minimize_lbfgs


class SOE(BaseEstimator, TripletEmbeddingMixin):
Expand All @@ -31,7 +30,7 @@ class SOE(BaseEstimator, TripletEmbeddingMixin):
Examples:
>>> from ordcomp import datasets
>>> from cblearn import datasets
>>> true_embedding = np.random.rand(15, 2)
>>> triplets = datasets.make_random_triplets(true_embedding, result_format='list-order', size=1000)
>>> triplets.shape, np.unique(triplets).shape
Expand Down Expand Up @@ -91,7 +90,7 @@ def __init__(self, n_components=2, margin=1, max_iter=1000, verbose=False,
self.device = device

def fit(self, X: utils.Questions, y: np.ndarray = None, init: np.ndarray = None,
n_objects: Optional[int] = None) -> 'ordcomp.embedding.SOE':
n_objects: Optional[int] = None) -> 'SOE':
"""Computes the embedding.
Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
This is why we wrap the ordinal embedding estimators below
to transform featurized input to triplets.
Some checks are skipped, because ordcomp's estimators are not
Some checks are skipped, because cblearn's estimators are not
100% compatible to sklearn's estimators.
While some of the checks could be adapted to our setting,
some cannot work with triplet input.
Expand All @@ -18,9 +18,9 @@
import numpy as np
from sklearn.utils.estimator_checks import parametrize_with_checks

from ordcomp.embedding import SOE
from ordcomp.embedding import wrapper
from ordcomp.datasets import make_random_triplets
from cblearn.embedding import SOE
from cblearn.embedding import wrapper
from cblearn.datasets import make_random_triplets


# Add new estimators here:
Expand Down Expand Up @@ -81,7 +81,7 @@ def wrap_triplet_estimator(estimator):
)
def test_all_estimators(estimator, check):
if check.func.__name__ in SKIP_CHECKS:
pytest.skip("Ordcomp ordinal embedding estimator's are not fully compatible to sklearn estimators.")
pytest.skip("cblearn ordinal embedding estimator's are not fully compatible to sklearn estimators.")

with wrap_triplet_estimator(estimator) as wrapped_estimator:
check(wrapped_estimator)
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from sklearn.utils import check_random_state
import numpy as np

from ordcomp import utils
from ordcomp.embedding._base import TripletEmbeddingMixin
from ordcomp.embedding.wrapper._r_base import RWrapperMixin
from cblearn import utils
from cblearn.embedding._base import TripletEmbeddingMixin
from cblearn.embedding.wrapper._r_base import RWrapperMixin


class MLDS(BaseEstimator, TripletEmbeddingMixin, RWrapperMixin):
Expand All @@ -24,7 +24,7 @@ class MLDS(BaseEstimator, TripletEmbeddingMixin, RWrapperMixin):
embedding_: array-likeThe final embedding, shape (n_objects, 1)
log_likelihood_: The final log-likelihood of the embedding.
>>> from ordcomp import datasets
>>> from cblearn import datasets
>>> triplets = datasets.make_random_triplets(np.arange(15).reshape(-1, 1), size=400, result_format='list-order')
>>> triplets.shape, np.unique(triplets).shape
((400, 3), (15,))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def init_r(cls):
numpy2ri.activate()
except ImportError:
raise ImportError("Expects installed python package 'rpy2', could not find it. "
"Did you install ordcomp with the r_wrapper extras? "
"pip install ordcomp[r_wrapper]")
"Did you install cblearn with the r_wrapper extras? "
"pip install cblearn[r_wrapper]")

@classmethod
def import_r_package(cls, package_name, install_if_missing=True, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from sklearn.utils import check_random_state
import numpy as np

import ordcomp
from ordcomp import utils
from ordcomp.embedding._base import TripletEmbeddingMixin
from ordcomp.embedding.wrapper._r_base import RWrapperMixin
from cblearn import utils
from cblearn.embedding._base import TripletEmbeddingMixin
from cblearn.embedding.wrapper._r_base import RWrapperMixin


class SOE(BaseEstimator, TripletEmbeddingMixin, RWrapperMixin):
Expand All @@ -20,7 +19,7 @@ class SOE(BaseEstimator, TripletEmbeddingMixin, RWrapperMixin):
stress_: Final value of the SOE stress corresponding to the embedding.
Examples:
>>> from ordcomp import datasets
>>> from cblearn import datasets
>>> triplets = datasets.make_random_triplets(np.random.rand(15, 2), result_format='list-order', size=1000)
>>> triplets.shape, np.unique(triplets).shape
((1000, 3), (15,))
Expand Down Expand Up @@ -61,7 +60,7 @@ def __init__(self, n_components=2, n_init=10, margin=.1, max_iter=1000, verbose=
self.random_state = random_state

def fit(self, X: utils.Questions, y: np.ndarray = None, init: np.ndarray = None,
n_objects: Optional[int] = None) -> 'ordcomp.embedding.wrapper.SOE':
n_objects: Optional[int] = None) -> 'SOE':
"""Computes the embedding.
Args:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from sklearn.utils import check_array
from sklearn import metrics

from ordcomp import utils
from cblearn import utils
from .. import datasets


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from ordcomp import metrics
from cblearn import metrics


def test_procrustes_distance():
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import numpy as np
import pytest

from ordcomp import metrics
from ordcomp import datasets
from cblearn import metrics
from cblearn import datasets


class DummyOrdinalEmbedding():
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions ordcomp/utils/_torch.py → cblearn/utils/_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ def assert_torch_is_available() -> None:
import torch # noqa: F401 We do not use torch here on purpose
except ModuleNotFoundError as e:
raise ModuleNotFoundError(f"{e}.\n\n"
"This function of ordcomp requires the installation of the pytorch package.\n"
"This function of cblearn requires the installation of the pytorch package.\n"
"To install pytorch, visit https://pytorch.org/get-started/locally/\n"
"or run either of the following commands:\n"
" pip install ordcomp[torch]\n"
" pip install cblearn[torch]\n"
" pip install torch\n"
" conda install -c=conda-forge pytorch\n")

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import sparse

from ordcomp import utils
from cblearn import utils


triplets_numeric_undecided = [[0, 1, 2],
Expand Down
14 changes: 14 additions & 0 deletions cblearn/utils/tests/test_validate_size.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest

import cblearn.utils


def test_check_size():
assert 6 == cblearn.utils._validate_size.check_size(None, 6)
assert 3 == cblearn.utils._validate_size.check_size(3, 6)
assert 3 == cblearn.utils._validate_size.check_size(3., 6)
assert 3 == cblearn.utils._validate_size.check_size(.5, 6)
assert 15 == cblearn.utils._validate_size.check_size(15, 6)

with pytest.raises(ValueError):
cblearn.utils._validate_size.check_size(-1, 6)
Loading

0 comments on commit 09c1317

Please sign in to comment.