Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
yangarbiter committed Aug 22, 2021
2 parents fecc606 + 1079085 commit bce04a3
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 74 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Libact linting

on: [push, pull_request]

jobs:
build:

runs-on: ${{ matrix.os }}
continue-on-error: True
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version: [3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
- run: pylint libact
44 changes: 44 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Libact tests

on: [push, pull_request]

jobs:
build:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
python-version: [2.7, 3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
if [ "$RUNNER_OS" = "macOS" ]; then
brew update
brew install openblas
mkdir -p ~/.matplotlib
echo "backend: TkAgg" >> ~/.matplotlib/matplotlibrc
else
sudo apt-get update -qq
sudo apt-get install -y build-essential gfortran libatlas-base-dev liblapacke-dev
sudo apt-get install -y python3-dev
fi
python -m pip install --upgrade pip
pip install pylint coverage codecov
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install Libact
run: |
./setup.py build_ext --inplace
- name: Unittests
run: |
python -m unittest -v
- run: coverage run --source libact --omit */tests/* setup.py test
- run: coverage report
- run: codecov
4 changes: 2 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bad-functions=map,filter
# w, W - weight vector
# N - number of instances
# T, K - number of iterations
good-names=i,j,k,_,X,Y,x,y,P,p,qs,w,W,N,T,K
good-names=i,j,k,_,X,Y,Z,x,y,P,p,qs,w,W,N,T,K

# Regular expression matching correct attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$
Expand Down Expand Up @@ -84,7 +84,7 @@ generated-members=
[FORMAT]

# Maximum number of characters on a single line.
max-line-length=79
max-line-length=120

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
Expand Down
51 changes: 0 additions & 51 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion libact/base/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_get_labeled_entries(self):

def test_get_unlabeled_entries(self):
dataset = self.setup_dataset()
idx, X = dataset.get_unlabeled_entries()
_, X = dataset.get_unlabeled_entries()
self.assertTrue(np.array_equal(X[0], np.array([6, 7, 8])))
self.assertTrue(np.array_equal(X[1], np.array([12, 13, 14])))

Expand Down
1 change: 1 addition & 0 deletions libact/models/sklearn_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class SklearnProbaAdapter(ProbabilisticModel):
"""

def __init__(self, clf):
super().__init__()
self._model = clf

def train(self, dataset, *args, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion libact/models/tests/test_svm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUp(self):
def test_svm(self):
svc_clf = SVC(gamma="auto")
svc_clf.fit(self.X_train, self.y_train)
svm = SVM()
svm = SVM(gamma="auto")
svm.train(Dataset(self.X_train, self.y_train))

assert_array_equal(
Expand Down
2 changes: 2 additions & 0 deletions libact/query_strategies/multiclass/mdsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
# Licence: BSD

import numpy as np
import sklearn

import warnings

from sklearn.base import BaseEstimator
from sklearn.metrics import euclidean_distances
from sklearn.utils import check_random_state, check_array, check_symmetric
from joblib import Parallel, delayed

from sklearn.isotonic import IsotonicRegression


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_hs_random_selecting(self):
qseq = run_qs(ds, qs, self.y, len(self.y)-10)
assert_array_equal(
np.concatenate([qseq[:10], qseq[-10:]]),
np.array([48, 143, 13, 142, 88, 130, 29, 87, 36, 28,
58, 137, 49, 105, 76, 71, 63, 47, 64, 55])
np.array([39, 126, 66, 135, 37, 33, 118, 132, 142, 144,
71, 28, 63, 41, 140, 34, 20, 110, 136, 36])
)

def test_hs_active_selecting(self):
Expand All @@ -39,8 +39,8 @@ def test_hs_active_selecting(self):
qseq = run_qs(ds, qs, self.y, len(self.y)-10)
assert_array_equal(
np.concatenate([qseq[:10], qseq[-10:]]),
np.array([48, 143, 13, 64, 101, 108, 51, 87, 36, 28,
43, 118, 47, 25, 81, 82, 95, 40, 67, 120])
np.array([39, 126, 66, 135, 37, 33, 118, 132, 142, 144,
89, 117, 48, 67, 75, 14, 79, 62, 105, 19])
)

def test_hs_subsampling(self):
Expand All @@ -52,7 +52,7 @@ def test_hs_subsampling(self):
assert_array_equal(
np.concatenate([qseq[:10], qseq[-10:]]),
np.array([120, 50, 33, 28, 78, 133, 52, 124, 102, 109,
81, 108, 12, 10, 89, 114, 92, 126, 48, 25])
81, 108, 10, 89, 126, 114, 92, 48, 25, 13])
)

def test_hs_report_all_label(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from joblib import Parallel, delayed

from libact.base.dataset import Dataset
from libact.base.interfaces import QueryStrategy, ContinuousModel
from libact.utils import inherit_docstring_from, seed_random_state, zip
from libact.base.interfaces import QueryStrategy
from libact.utils import inherit_docstring_from, seed_random_state
from libact.models.multilabel import BinaryRelevance


Expand Down Expand Up @@ -77,12 +77,13 @@ class AdaptiveActiveLearning(QueryStrategy):

def __init__(self, dataset, base_clf, betas=None, n_jobs=1,
random_state=None):
super(AdaptiveActiveLearning, self).__init__(dataset)
super().__init__(dataset)

self.n_labels = len(self.dataset.data[0][1])

self.base_clf = copy.deepcopy(base_clf)

# pyline: disable=fixme
# TODO check beta value
self.betas = betas
if self.betas is None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_mmc(self):
qs = MMC(trn_ds, random_state=1126)
qseq = run_qs(trn_ds, qs, self.y, self.quota)
assert_array_equal(qseq,
np.array([117, 655, 1350, 909, 1003, 1116, 546, 1055, 165, 1441]))
np.array([117, 655, 234, 1419, 1350, 1224, 427, 890, 1447, 103]))

def test_multilabel_with_auxiliary_learner_hlr(self):
trn_ds = Dataset(self.X,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include <numpy/arrayobject.h>
#include <lapacke.h>

/* DGESVD prototype */
extern void LAPACK_dgesvd( char* jobu, char* jobvt, int* m, int* n, double* a,
int* lda, double* s, double* u, int* ldu, double* vt, int* ldvt,
double* work, int* lwork, int* info );

double** An(double *pi, double *x, int labs, int dims);
double** A(double **PI, double **X, int labs, int dims, int n_pool);
double** Fisher(double *pi, double *x, double sigma, int labs, int dims);
Expand Down
4 changes: 3 additions & 1 deletion libact/utils/multilabel/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Implementation of loss/score functions for multi-label evaluation."""

import numpy as np

def pairwise_rank_loss(Z, Y): #truth(Z), prediction(Y)
Expand All @@ -24,4 +26,4 @@ def pairwise_f1_score(Z, Y):
down[down==0] = 1.
up[down==0] = 1.

return up / down
return up / down
1 change: 0 additions & 1 deletion libact/utils/tests/test_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ def test_criteria(self):
[1, 0, 1, 1, 0],])
assert_array_almost_equal(pairwise_rank_loss(a, b), [-2.5, -3.5, -1])
assert_array_almost_equal(pairwise_f1_score(a, b), [0.5, 0.4, 0.8])

2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
setuptools
numpy
scipy
scikit-learn<=0.19.2
scikit-learn>=0.24
matplotlib
Cython
joblib
8 changes: 6 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@
print("Platform Detection: Mac OS X. Link to openblas...")
extra_link_args = []
libraries = ['openblas']
library_dirs = ['/opt/local/lib']
library_dirs = [
'/opt/local/lib',
'/usr/local/opt/openblas/lib', # for brew installs
]
include_dirs = (numpy.distutils.misc_util.get_numpy_include_dirs() +
['/opt/local/include'])
['/opt/local/include',
'/usr/local/opt/openblas/include']) # for brew installs
else:
# assume linux otherwise, unless we support Windows in the future...
print("Platform Detection: Linux. Link to liblapacke...")
Expand Down

0 comments on commit bce04a3

Please sign in to comment.