Skip to content

Commit

Permalink
added documentation tree.
Browse files Browse the repository at this point in the history
  • Loading branch information
saist1993 committed Aug 19, 2022
1 parent 7ccff89 commit 39afbf9
Show file tree
Hide file tree
Showing 12 changed files with 511 additions and 16 deletions.
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

%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.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

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

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

:end
popd
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
alabaster==0.7.12
Sphinx==5.1.0
sphinx-rtd-theme==1.0.0
46 changes: 46 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import os
import sys
import sphinx_rtd_theme

html_theme = "sphinx_rtd_theme"

sys.path.insert(0, os.path.abspath("../../src/"))
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]

project = "fairgrad"
copyright = "2022, Gaurav Maheshwari, Michael Perrot"
author = "Gaurav Maheshwari, Michael Perrot"
release = "0.1.1"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.coverage",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
]

templates_path = ["_templates"]
exclude_patterns = []

html_static_path = ["_static"]

intersphinx_mapping = {"python": ("http://docs.python.org/3", None)}

autodoc_typehints = "description"


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = "alabaster"
html_static_path = ["_static"]
17 changes: 17 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Welcome to fairgrad's documentation!
====================================

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

introduction.rst
reference.rst

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

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
48 changes: 48 additions & 0 deletions docs/source/introduction.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Introduction
------------

FairGrad, is an easy to use general purpose approach to enforce
fairness for gradient descent based methods. The core idea is to enforce fairness by iteratively learns
group specific weights based on whether they are advantaged or not. FairGrad is:

* Simple and easy to integrate with no significant overhead
* Supports Multiclass problems and can work with any gradient based methods
* Supports various group fairness notions including exact and approximate fairness
* Is competitive on various tasks including complex NLP and CV ones


Installation
------------

You can install FairGrad from PyPI with `pip` or your favorite package manager::

pip install fairgrad


Quick Start
------------

To use fairgrad simply replace your pytorch cross entropy loss with
fairgrad cross entropy loss. Alongside, regular pytorch cross entropy arguments,
it expects following *extra* arguments::

y_train (np.asarray[int], Tensor, optional): All train example's corresponding label
s_train (np.asarray[int], Tensor, optional): All train example's corresponding sensitive attribute. This means if there
are 2 sensitive attributes, with each of them being binary. For instance gender - (male and female) and
age (above 45, below 45). Total unique sentive attributes are 4.
fairness_measure (string): Currently we support "equal_odds", "equal_opportunity", and "accuracy_parity".
epsilon (float, optional): The slack which is allowed for the final fairness level.
fairness_rate (float, optional): Parameter which intertwines current fairness weights with sum of previous fairness rates.

Usage Example
-------------

Below is a simple example::

>>> from fairgrad.torch import CrossEntropyLoss
>>> input = torch.randn(10, 5, requires_grad=True)
>>> target = torch.empty(10, dtype=torch.long).random_(2)
>>> s = torch.empty(10, dtype=torch.long).random_(2) # protected attribute
>>> loss = CrossEntropyLoss(y_train = target, s_train = s, fairness_measure = 'equal_odds')
>>> output = loss(input, target, s, mode='train')
>>> output.backward()
9 changes: 9 additions & 0 deletions docs/source/reference.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Reference
=========

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

reference/fairness_function.rst
reference/torch/cross_entropy.rst
4 changes: 4 additions & 0 deletions docs/source/reference/fairness_function.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fairness.functions
========================
.. automodule:: fairgrad.fairness_functions
:members:
4 changes: 4 additions & 0 deletions docs/source/reference/torch/cross_entropy.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fairgrad.torch.cross_entropy
=============================
.. automodule:: fairgrad.torch.cross_entropy
:members:
Loading

0 comments on commit 39afbf9

Please sign in to comment.