Skip to content

Commit

Permalink
Add initial documentation and docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
jmyrberg committed Dec 14, 2020
1 parent 04163d4 commit 74327a9
Show file tree
Hide file tree
Showing 11 changed files with 158 additions and 31 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.1dev2
0.0.1dev3
65 changes: 50 additions & 15 deletions aakr/_aakr.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""Module for models."""
"""Module for Auto Associative Kernel Regression models."""


import numpy as np
Expand All @@ -9,15 +9,19 @@


class AAKR(TransformerMixin, BaseEstimator):
"""A template estimator to be used as a reference implementation.
"""Auto Associative Kernel Regressor.
For more information regarding how to build your own estimator, read more
in the :ref:`User Guide <user_guide>`.
Please see the :ref:`Getting started <readme.rst>` documentation for more
information.
Parameters
----------
demo_param : str, default='demo_param'
A parameter used for demonstation of how to pass and store paramters.
metric : str, default='euclidean'
Metric for calculating kernel distances.
bw : float, default=1.0
Kernel bandwith parameter.
n_jobs : int, default=-1
The number of jobs to run in parallel.
Examples
--------
Expand All @@ -26,43 +30,74 @@ class AAKR(TransformerMixin, BaseEstimator):
>>> X = np.arange(100).reshape(50, 2)
>>> aakr = AAKR()
>>> aakr.fit(X)
AAKR(metric='euclidean', bw=1, n_jobs=None)
AAKR(metric='euclidean', bw=1, n_jobs=-1)
"""
def __init__(self, metric='euclidean', bw=1, n_jobs=None):
def __init__(self, metric='euclidean', bw=1, n_jobs=-1):
self.metric = metric
self.bw = bw
self.n_jobs = n_jobs

def fit(self, X, y=None):
"""A reference implementation of a fitting function for a transformer.
"""Fit normal condition examples.
Parameters
----------
X : array-like, shape (n_samples, n_features)
X : array-like of shape (n_samples, n_features)
Training examples from normal conditions.
y : None
Not needed, exists for compability purposes.
Not required, exists only for compability purposes.
Returns
-------
self : object
Returns self.
"""
# Validation
X = check_array(X)

# Save history
self.X_ = X

return self

def partial_fit(self, X, y=None):
"""Fit more normal condition examples.
Parameters
----------
X : array-like of shape (n_samples, n_features)
Training examples from normal conditions.
y : None
Not required, exists only for compability purposes.
Returns
-------
self : object
Returns self.
"""
# Validation
X = check_array(X)

if self.X_.shape[1] != X.shape[1]:
raise ValueError('Shape of input is different from what was seen'
'in `fit`')

# Add new examples
self.X_ = np.vstack((self.X_, X))

return self

def predict(self, X, **kwargs):
""" A reference implementation of a prediction for a classifier.
def transform(self, X, **kwargs):
"""Transform given array into expected values in normal conditions.
Parameters
----------
X : array-like, shape (n_samples, n_features)
X : array-like of shape (n_samples, n_features)
The input samples.
Returns
-------
X_nc : ndarray, shape (n_samples, n_features)
X_nc : ndarray of shape (n_samples, n_features)
Expected values in normal conditions for each sample and feature.
"""
# Validation
Expand Down
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
10 changes: 10 additions & 0 deletions docs/source/aakr.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
aakr package
============

Module contents
---------------

.. automodule:: aakr
:members:
:undoc-members:
:show-inheritance:
22 changes: 14 additions & 8 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ def add_source_parser(_old_add_source_parser, self, *args, **kwargs):

# -- Project information -----------------------------------------------------

project = 'finscraper'
project = 'aakr'
copyright = '2020, Jesse Myrberg'
author = 'Jesse Myrberg'

# The full version, including alpha/beta/rc tags
with open('../../VERSION', 'r') as f:
release = f.read().strip()
version = f.read().strip()
release = version


# -- General configuration ---------------------------------------------------
Expand All @@ -56,10 +57,15 @@ def add_source_parser(_old_add_source_parser, self, *args, **kwargs):
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'm2r',
'm2r2',
'sphinxcontrib.napoleon',
'sphinx.ext.autodoc',
'sphinx_rtd_theme',
'sphinx.ext.autodoc',
'sphinx.ext.autosummary',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.viewcode',
'numpydoc'
]

# Autodoc settings
Expand Down Expand Up @@ -102,13 +108,13 @@ def add_source_parser(_old_add_source_parser, self, *args, **kwargs):

html_theme_options = {
'canonical_url': '',
#'analytics_id': 'UA-XXXXXXX-1', # Provided by Google in your dashboard
# 'analytics_id': 'UA-XXXXXXX-1', # Provided by Google in your dashboard
'logo_only': False,
'display_version': True,
'prev_next_buttons_location': 'bottom',
'style_external_links': False,
#'vcs_pageview_mode': '',
#'style_nav_header_background': 'white',
# 'vcs_pageview_mode': '',
# 'style_nav_header_background': 'white',
# Toc options
'collapse_navigation': True,
'sticky_navigation': True,
Expand All @@ -120,4 +126,4 @@ def add_source_parser(_old_add_source_parser, self, *args, **kwargs):
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ['_static']
13 changes: 13 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. include:: readme.rst

.. toctree::
:caption: Documentation
:maxdepth: 2

Getting started <readme.rst>

.. toctree::
:caption: API
:maxdepth: 4

aakr
1 change: 1 addition & 0 deletions docs/source/readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. mdinclude:: ../../README.md
8 changes: 7 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
pytest==5.4.2
twine==3.2.0
pytest-cov==2.10.1
twine==3.2.0
sphinx==3.3.1
sphinx_rtd_theme==0.5.0
numpydoc==1.1.0
m2r2==0.2.7
sphinxcontrib-napoleon==0.7
6 changes: 3 additions & 3 deletions scripts/build-documentation.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/sh

conda activate finscraper && \
conda activate aakr && \
rm -rf docs/build && \
sphinx-apidoc -f -o docs/source finscraper && \
sphinx-apidoc -f -o docs/source aakr && \
rm -rf docs/source/modules.rst && \
sphinx-build -b html docs/source docs/build
open -a /Applications/Safari.app file://~/Documents/Personal/finscraper/docs/build/index.html
open -a /Applications/Safari.app file:///Users/e103089/Documents/Personal/aakr/docs/build/index.html
7 changes: 4 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
author='Jesse Myrberg',
author_email='[email protected]',
url='https://github.com/jmyrberg/aakr',
keywords=['aakr', 'auto', 'associative', 'kernel', 'regression', 'anomaly', 'detection'],
keywords=['aakr', 'auto', 'associative', 'kernel', 'regression', 'anomaly',
'detection'],
install_requires=[
'numpy>=1.19.4',
'pandas>=1.1.5',
Expand Down Expand Up @@ -45,10 +46,10 @@
'pytest-cov'],
'docs': [
'sphinx',
'sphinx-gallery',
'sphinx_rtd_theme',
'numpydoc',
'matplotlib'
'm2r2',
'sphinxcontrib-napoleon'
]
}
)

0 comments on commit 74327a9

Please sign in to comment.