Skip to content

Commit 49ad556

Browse files
committed
Merge branch 'feature/pip'
2 parents 6877b7f + 1d18971 commit 49ad556

File tree

89 files changed

+5219
-3123
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+5219
-3123
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
*.npz
44
*.swp
55
*.pickle
6-
.notifier
6+
7+
# Ignore python cache.
78
__pycache__
9+
10+
# Ignore virtual environment.
11+
venv

Makefile

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
################################################################################
2+
# Makefile
3+
################################################################################
4+
5+
.PHONY: build testpypi pypi install-test check count coverage clean help
6+
7+
#-------------------------------------------------------------------------------
8+
# Define package names and target source files
9+
#-------------------------------------------------------------------------------
10+
11+
SOFTWARE = rfflearn
12+
PY_FILES = $(shell find rfflearn | grep \.py$$ | sort)
13+
14+
help:
15+
@echo "Usage:"
16+
@echo " make <command>"
17+
@echo ""
18+
@echo "Build commands:"
19+
@echo " build Build package"
20+
@echo " testpypi Upload package to TestPyPi"
21+
@echo " pypi Upload package to PyPi"
22+
@echo " install-test Install from TestPyPi"
23+
@echo ""
24+
@echo "Test and code check commands:"
25+
@echo " check Check the code quality"
26+
@echo " count Count the lines of code"
27+
@echo " coverage Measure code coverage"
28+
@echo ""
29+
@echo "Other commands:"
30+
@echo " clean Cleanup cache files"
31+
@echo " help Show this message"
32+
33+
#-------------------------------------------------------------------------------
34+
# Build commands
35+
#-------------------------------------------------------------------------------
36+
37+
build:
38+
python3 -m build
39+
40+
testpypi:
41+
twine upload --repository pypitest dist/*
42+
43+
pypi:
44+
twine upload --repository pypi dist/*
45+
46+
install-test:
47+
python3 -m pip install --index-url https://test.pypi.org/simple/ $(SOFTWARE)
48+
49+
#-------------------------------------------------------------------------------
50+
# Test commands
51+
#-------------------------------------------------------------------------------
52+
53+
check:
54+
pyflakes $(PY_FILES)
55+
pylint $(PY_FILES) --disable C0103,R0913,R0917,R0801
56+
57+
count:
58+
cloc --by-file $(PY_FILES)
59+
60+
coverage:
61+
rm -rf .coverage
62+
coverage erase
63+
@echo "Run tests on CPU..."
64+
coverage run --source rfflearn -a tests/cca_for_artificial_data.py
65+
coverage run --source rfflearn -a tests/feature_importances_for_california_housing.py
66+
coverage run --source rfflearn -a tests/gpc_for_mnist.py cpu --rtype rff
67+
coverage run --source rfflearn -a tests/gpc_for_mnist.py cpu --rtype orf
68+
coverage run --source rfflearn -a tests/gpc_for_mnist.py cpu --rtype qrf
69+
coverage run --source rfflearn -a tests/gpr_sparse_data.py cpu --rtype rff
70+
coverage run --source rfflearn -a tests/gpr_sparse_data.py cpu --rtype orf
71+
coverage run --source rfflearn -a tests/gpr_sparse_data.py cpu --rtype qrf
72+
coverage run --source rfflearn -a tests/least_square_regression.py --rtype rff
73+
coverage run --source rfflearn -a tests/least_square_regression.py --rtype orf
74+
coverage run --source rfflearn -a tests/least_square_regression.py --rtype qrf
75+
coverage run --source rfflearn -a tests/optuna_for_california_housing.py
76+
coverage run --source rfflearn -a tests/pca_for_swissroll.py cpu --rtype rff
77+
coverage run --source rfflearn -a tests/pca_for_swissroll.py cpu --rtype orf
78+
coverage run --source rfflearn -a tests/pca_for_swissroll.py cpu --rtype qrf
79+
coverage run --source rfflearn -a tests/svc_for_mnist.py cpu --rtype rff --skip_tune
80+
coverage run --source rfflearn -a tests/svc_for_mnist.py cpu --rtype orf --skip_tune
81+
coverage run --source rfflearn -a tests/svc_for_mnist.py cpu --rtype qrf --skip_tune
82+
coverage run --source rfflearn -a tests/svr_sparse_data.py cpu --rtype rff
83+
coverage run --source rfflearn -a tests/svr_sparse_data.py cpu --rtype orf
84+
coverage run --source rfflearn -a tests/svr_sparse_data.py cpu --rtype qrf
85+
@echo "Run tests on GPU..."
86+
coverage run --source rfflearn -a tests/gpc_for_mnist.py gpu --rtype rff
87+
coverage run --source rfflearn -a tests/gpc_for_mnist.py gpu --rtype orf
88+
coverage run --source rfflearn -a tests/gpc_for_mnist.py gpu --rtype qrf
89+
coverage run --source rfflearn -a tests/gpr_sparse_data.py gpu --rtype rff
90+
coverage run --source rfflearn -a tests/gpr_sparse_data.py gpu --rtype orf
91+
coverage run --source rfflearn -a tests/gpr_sparse_data.py gpu --rtype qrf
92+
coverage run --source rfflearn -a tests/pca_for_swissroll.py gpu --rtype rff
93+
coverage run --source rfflearn -a tests/pca_for_swissroll.py gpu --rtype orf
94+
coverage run --source rfflearn -a tests/pca_for_swissroll.py gpu --rtype qrf
95+
coverage run --source rfflearn -a tests/svc_for_mnist.py gpu --rtype rff --skip_tune
96+
coverage run --source rfflearn -a tests/svc_for_mnist.py gpu --rtype orf --skip_tune
97+
coverage run --source rfflearn -a tests/svc_for_mnist.py gpu --rtype qrf --skip_tune
98+
coverage run --source rfflearn -a tests/svc_train_cpu_predict_gpu.py
99+
coverage html
100+
101+
#-------------------------------------------------------------------------------
102+
# Other commands
103+
#-------------------------------------------------------------------------------
104+
105+
clean:
106+
rm -rf dist .coverage htmlcov scikit_learn_data `find -type d | grep __pycache__`
107+
108+
# vim: noexpandtab tabstop=4 shiftwidth=4

README.md

Lines changed: 83 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
1-
Random Fourier Features
2-
====================================================================================================
3-
41
<div align="center">
52
<img src="./figures/logo_long.svg" width="480" alt="rfflearn logo" />
63
</div>
74

5+
<div align="center">
6+
<img src="https://img.shields.io/badge/PYTHON-%3E%3D3.9-blue.svg?logo=python&logoColor=white">
7+
&nbsp;
8+
<img src="https://img.shields.io/badge/LICENSE-MIT-orange.svg">
9+
&nbsp;
10+
<img src="https://img.shields.io/badge/COVERAGE-97%25-green.svg">
11+
&nbsp;
12+
<img src="https://img.shields.io/badge/QUALITY-9.96/10.0-yellow.svg">
13+
</div>
14+
15+
16+
Random Fourier Features
17+
====================================================================================================
18+
819
This repository provides the Python module `rfflearn` which is a Python library of random Fourier
920
features (hereinafter abbreviated as RFF) [1, 2] for kernel methods, like support vector
1021
machine [3, 4] and Gaussian process model [5]. Features of this module are:
@@ -36,6 +47,34 @@ The author will provide implementations of the other algorithms soon.
3647

3748
**NOTE**: The author confirmed that the `rfflearn` module works on PyTorch 2.0! :tada:
3849

50+
51+
Installation
52+
----------------------------------------------------------------------------------------------------
53+
54+
Please install from PyPI.
55+
56+
```shell
57+
pip install rfflearn
58+
```
59+
60+
If you need GPU support, Optuna support or SHAP support,
61+
you need to install the following packages.
62+
63+
```shell
64+
# For GPU support.
65+
pip install torch
66+
67+
# For Optuna support.
68+
pip install optuna
69+
70+
# For SHAP support.
71+
pip install matplotlib shap
72+
```
73+
74+
The author recommends using [venv](https://docs.python.org/3/library/venv.html) or
75+
[Docker](https://www.docker.com/) to avoid polluting your environment.
76+
77+
3978
Minimal example
4079
----------------------------------------------------------------------------------------------------
4180

@@ -109,24 +148,55 @@ the California housing dataset, and the followings are the visualization results
109148
`rfflearn.shap_feature_importance` and `rfflearn.permutation_feature_importance`.
110149

111150
<div align="center">
112-
<img src="./examples/feature_importances_for_california_housing/figure_california_housing_shap_importance.png" width="400" alt="Permutation importances of Boston housing dataset" />
113-
<img src="./examples/feature_importances_for_california_housing/figure_california_housing_permutation_importance.png" width="400" alt="SHAP importances of Boston housing dataset" />
151+
<img src="./examples/feature_importances_for_california_housing/figures/figure_california_housing_shap_importance.png" width="450" alt="Permutation importances of Boston housing dataset" />
152+
<img src="./examples/feature_importances_for_california_housing/figures/figure_california_housing_permutation_importance.png" width="450" alt="SHAP importances of Boston housing dataset" />
114153
</div>
115154

116155

117-
Requirements and installation
156+
Quick Tutorial
118157
----------------------------------------------------------------------------------------------------
119158

120-
The author recommends using a docker image for building the environment for the `rfflearn`,
121-
however, of course, you can install the necessary packages on your environment directly.
122-
See [SETUP.md](./SETUP.md) for more details.
159+
At first, please clone the `random-fourier-features` repository from GitHub:
160+
161+
```console
162+
git clone https://github.com/tiskw/random-fourier-features.git
163+
cd random-fourier-features
164+
```
165+
166+
If you are using the docker image, enter into the docker container by the following command
167+
(not necessary to run thw following if you don't use docker):
168+
169+
```console
170+
docker run --rm -it --gpus all -v `pwd`:/work -w /work -u `id -u`:`id -g` tiskw/pytorch:latest bash
171+
```
172+
173+
Then, launch python3 and try the following minimal code that runs support vector classification
174+
with random Fourier features on an artificial tiny dataset.
175+
176+
```python
177+
>>> import numpy as np # Import Numpy
178+
>>> import rfflearn.cpu as rfflearn # Import our module
179+
>>> X = np.array([[-1, -1], [-2, -1], [1, 1], [2, 1]]) # Define input data
180+
>>> y = np.array([1, 1, 2, 2]) # Defile label data
181+
>>> svc = rfflearn.RFFSVC().fit(X, y) # Training
182+
>>> svc.score(X, y) # Inference (on CPU)
183+
1.0
184+
>>> svc.predict(np.array([[-0.8, -1]]))
185+
array([1])
186+
```
187+
188+
### Next Step
189+
190+
Now you succeeded in installing the `rfflearn` module.
191+
The author's recommendation for the next step is to see the [examples directory](/examples)
192+
and try a code you are interested in.
123193

124194

125195
Notes
126196
----------------------------------------------------------------------------------------------------
127197

128-
- The name of this module is changed from `pyrff` to `rfflearn` on Oct 2020, because the package name
129-
`pyrff` already exists in PyPI.
198+
- The name of this module is changed from `pyrff` to `rfflearn` on Oct 2020, because the package
199+
name `pyrff` already exists in PyPI.
130200
- If the number of training data is huge, an error message like `RuntimeError: The task could not be
131201
sent to the workers as it is too large for 'send_bytes'` will be raised from the joblib library.
132202
The reason for this error is that the `sklearn.svm.LinearSVC` uses `joblib` as a multiprocessing
@@ -142,7 +212,8 @@ Notes
142212
License
143213
----------------------------------------------------------------------------------------------------
144214

145-
[MIT Licence](https://opensource.org/licenses/mit-license.php)
215+
This software is distributed under the [MIT Licence](https://opensource.org/licenses/mit-license.php).
216+
See [LICENSE](./LICENSE) for more information.
146217

147218

148219
Reference

dataset/cifar10/download_and_convert_cifar10.py

Lines changed: 0 additions & 106 deletions
This file was deleted.

0 commit comments

Comments
 (0)