-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f8861e
commit 4ff4108
Showing
4 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
from distutils.core import setup | ||
|
||
|
||
setup( | ||
name='poprank', | ||
version='0.1', | ||
version='1.0.0', | ||
description='Rating Mechanisms', | ||
author='Manfred Diaz, Aurelien Buck-Kaeffer', | ||
author_email='', | ||
url='https://www.python.org/sigs/distutils-sig/', | ||
package_dir={'': 'src'}, | ||
packages=['poprank'], | ||
install_requires=[ | ||
'popcore @ git+ssh://git@github.com/poprl/popcore@v1.0.0-beta#egg=popcore', | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from abc import ABC, abstractmethod | ||
from typing import Any | ||
|
||
import numpy as np | ||
|
||
|
||
class Metric(ABC): | ||
|
||
def __init__(self, name: str) -> None: | ||
super().__init__() | ||
self.name = name | ||
|
||
@abstractmethod | ||
def _compute( | ||
self, x: np.ndarray, y: np.ndarray, *args, **kwargs | ||
) -> float: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def _max(self, n: int) -> int: | ||
raise NotImplementedError() | ||
|
||
def __call__( | ||
self, x: np.ndarray, y: np.ndarray, *args: Any, **kwds: Any | ||
) -> float: | ||
return self._compute(x, y, *args, **kwds) | ||
|
||
def max(self, n: int) -> int: | ||
""" | ||
Computes the upper bound value of the metric | ||
on the space of n-ranked permutations. | ||
:param n: number of alternatives. | ||
:type n: int | ||
:return: metric upper bound. | ||
:rtype: int | ||
""" | ||
return self._max(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import numpy as np | ||
from ..functional.metrics import hamming | ||
from ._base import Metric | ||
|
||
|
||
class Hamming(Metric): | ||
def __init__(self) -> None: | ||
super().__init__("hamming") | ||
|
||
def _compute( | ||
self, x: np.ndarray, y: np.ndarray, *args, **kwargs | ||
) -> float: | ||
return hamming(x, y, *args, **kwargs) | ||
|
||
def _max(self, n: int) -> int: | ||
return n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import numpy as np | ||
|
||
from ..functional.metrics import kendall | ||
from ._base import Metric | ||
|
||
|
||
class Kendall(Metric): | ||
|
||
def __init__(self) -> None: | ||
super().__init__("kendall") | ||
|
||
def _compute( | ||
self, x: np.ndarray, y: np.ndarray, *args, **kwargs | ||
) -> float: | ||
return kendall(x, y, *args, **kwargs) | ||
|
||
def _max(self, n: int) -> int: | ||
return n * (n - 1) / 2 |