Skip to content
Permalink
Browse files

docs: Initial Sphinx setup

  • Loading branch information...
jonnor committed Mar 10, 2019
1 parent 0bfa1df commit e431d947543eaf3cd6295be297e08ed18a3d887c
Showing with 323 additions and 4 deletions.
  1. +2 −0 LICENSE.md
  2. +2 −3 README.md
  3. +3 −0 docs/.gitignore
  4. +19 −0 docs/Makefile
  5. +7 −0 docs/bayes.rst
  6. +184 −0 docs/conf.py
  7. +30 −0 docs/index.rst
  8. +15 −0 docs/internals.rst
  9. +7 −0 docs/nets.rst
  10. +7 −0 docs/signal.rst
  11. +1 −0 docs/source/LICENSE.md
  12. +1 −0 docs/source/README.md
  13. +7 −0 docs/trees.rst
  14. +31 −0 emlearn/cgen.py
  15. +2 −0 emlearn/convert.py
  16. +2 −1 emlearn/net.py
  17. +3 −0 requirements.dev.txt
@@ -1,3 +1,5 @@
## The MIT License

Copyright 2018 Jon Nordby

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
@@ -22,7 +22,7 @@ Convenient Training
* Using Python with [scikit-learn](http://scikit-learn.org) or [Keras](https://keras.io/)
* The generated C classifier is also accessible in Python

[MIT licensed](./LICENSE.md)
[MIT licensed](https://github.com/emlearn/emlearn/blob/master/LICENSE.md)

Can be used as an open source alternative to MATLAB Classification Trees,
Decision Trees using MATLAB Coder for C/C++ code generation.
@@ -78,8 +78,7 @@ const int32_t predicted_class = sonar_predict(values, length):
```


For full example code, see [examples/digits.py](./examples/digits.py)
and [emlearn.ino](./emlearn.ino)
For full example code, see [examples/digits.py](https://github.com/emlearn/emlearn/blob/master/examples/digits.py)

## Citations

@@ -0,0 +1,3 @@
_build
_static
_templates
@@ -0,0 +1,19 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SOURCEDIR = .
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)
@@ -0,0 +1,7 @@

Gaussian Naive Bayes
==============================

.. automodule:: emlearn.bayes
:members:
@@ -0,0 +1,184 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#

import os
import sys
sys.path.insert(0, os.path.abspath('..'))


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

project = 'emlearn'
copyright = '2019, Jon Nordby'
author = 'Jon Nordby'

# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = ''


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.mathjax',
'sphinx.ext.viewcode',
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.coverage',
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
from recommonmark.parser import CommonMarkParser

source_parsers = {
'.md': CommonMarkParser,
}
source_suffix = ['.rst', '.md']

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = None


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = "sphinx_rtd_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# 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']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'emlearndoc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'emlearn.tex', 'emlearn Documentation',
'Jon Nordby', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'emlearn', 'emlearn Documentation',
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'emlearn', 'emlearn Documentation',
author, 'emlearn', 'One line description of project.',
'Miscellaneous'),
]


# -- Options for Epub output -------------------------------------------------

# Bibliographic Dublin Core info.
epub_title = project

# The unique identifier of the text. This can be a ISBN number
# or the project homepage.
#
# epub_identifier = ''

# A unique identification for the text.
#
# epub_uid = ''

# A list of files that should not be packed into the epub file.
epub_exclude_files = ['search.html']


# -- Extension configuration -------------------------------------------------
@@ -0,0 +1,30 @@
.. emlearn documentation master file, created by
sphinx-quickstart on Sun Mar 10 17:28:59 2019.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to emlearn's documentation!
===================================

.. toctree::
:maxdepth: 2
:caption: Contents:

source/README.md
trees
nets
signal
bayes
internals

source/LICENSE.md




Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
@@ -0,0 +1,15 @@

Internals
==============================


.. automodule:: emlearn.cgen
:members:
.. automodule:: emlearn.convert
:members:
.. automodule:: emlearn.common
:members:
@@ -0,0 +1,7 @@

Neural Networks
==============================

.. automodule:: emlearn.net
:members:
@@ -0,0 +1,7 @@

Signal processing
===========================

.. automodule:: emlearn.signal
:members:
@@ -0,0 +1,7 @@

Tree-based models
===========================

.. automodule:: emlearn.trees
:members:
@@ -1,10 +1,25 @@

"""Utilities to generate C code"""


def struct_init(*args):
"""Struct initializer
>>> from emlearn import cgen
>>> cgen.struct_init([ 1, 2, 3 ])
"{ 1, 2, 3 }"
"""

return '{ ' + ', '.join(str(a) for a in args) + ' }'


def constant(val, dtype='float'):
"""A literal value
>>> from emlearn import cgen
>>> cgen.constant(3.14)
"3.14f"
"""
if dtype == 'float':
return "{:f}f".format(val)
else:
@@ -13,6 +28,22 @@ def constant(val, dtype='float'):

def array_declare(name, size, dtype='float', modifiers='static const',
values=None, end='', indent=''):

"""
Declare and optionally initialize an array.
>>> from emlearn import cgen
>>> cgen.array_declare("declareonly", 10)
"static const float declareonly[10];"
Also intialize it.
>>> from emlearn import cgen
>>> cgen.array_declare("initialized", 3, dtype='int', modifiers='const')
"const float initialized[3] = { 1, 2, 3 };"
"""

init = ''
if values is not None:
init_values = ', '.join(constant(v, dtype) for v in values)
@@ -4,6 +4,8 @@
from . import bayes

def convert(estimator, kind=None, method='pymodule'):
"""Main entrypoint for converting a model"""

if kind is None:
kind = type(estimator).__name__

@@ -114,6 +114,7 @@ def init_layer(name, n_outputs, n_inputs, weigths_name, biases_name, activation_
return out

def convert_sklearn_mlp(model, method):
"""Convert sklearn.neural_network.MLPClassifier models"""

if (model.n_layers_ < 3):
raise ValueError("Model must have at least one hidden layer")
@@ -137,7 +138,7 @@ def from_tf_variable(var):
return array

def convert_keras(model, method):

"""Convert keras.Sequential models"""

activations = []
layer_weights = []
Oops, something went wrong.

0 comments on commit e431d94

Please sign in to comment.
You can’t perform that action at this time.