Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

⚠️ Deprecated — now a compatibility shim over mononet

As of v0.4.0a1, monotonic-nn is a thin, deprecated compatibility layer. The maintained, multi-backend implementation (PyTorch, JAX, Keras 3) lives in mononet. This package now re-exports mononet.legacy so existing airt.* imports keep working.

Breaking in 0.4.0a1: requires Keras 3 (via tensorflow>=2.16) and Python 3.11+. New code should use mononet directly. Docs: https://davorrunje.github.io/mononet/.


Constrained Monotonic Neural Networks

Summary

This package implements the Constrained Monotonic Neural Network construction described in:

Davor Runje, Sharath M. Shankaranarayana, “Constrained Monotonic Neural Networks”, in Proceedings of the 40th International Conference on Machine Learning, 2023. [PDF].

Abstract

Wider adoption of neural networks in many critical domains such as finance and healthcare is being hindered by the need to explain their predictions and to impose additional constraints on them. Monotonicity constraint is one of the most requested properties in real-world scenarios and is the focus of this paper. One of the oldest ways to construct a monotonic fully connected neural network is to constrain signs on its weights. Unfortunately, this construction does not work with popular non-saturated activation functions as it can only approximate convex functions. We show this shortcoming can be fixed by constructing two additional activation functions from a typical unsaturated monotonic activation function and employing each of them on the part of neurons. Our experiments show this approach of building monotonic neural networks has better accuracy when compared to other state-of-the-art methods, while being the simplest one in the sense of having the least number of parameters, and not requiring any modifications to the learning procedure or post-learning steps. Finally, we prove it can approximate any continuous monotone function on a compact subset of $\mathbb{R}^n$.

Status: compatibility shim

Since v0.4.0a1, this package no longer contains its own implementation. Its public API re-exports mononet.legacy, the maintained multi-backend (PyTorch / JAX / Keras 3) implementation of the same construction. The re-exported objects are the very same ones from mononet.legacy, and behaviour is numerically identical to the original TensorFlow-Keras implementation (pinned by equivalence tests in mononet).

The following continue to import, now backed by mononet and emitting a DeprecationWarning:

  • airt.keras.layers.MonoDense
  • airt.keras.layers.MonoDense.create_type_1 / create_type_2
  • the helpers in airt._components.mono_dense_layer

New projects should depend on mononet directly.

Requirements

  • Python 3.11+
  • Keras 3 — installed via tensorflow>=2.16

Install

pip install --pre monotonic-nn

--pre is required while monotonic-nn and mononet are in alpha.

Usage (compatibility)

Existing code keeps working unchanged; the imports resolve to mononet.legacy. The monotonicity_indicator uses the original three-value convention — 1 for increasingly monotonic inputs, -1 for decreasingly monotonic, 0 for non-monotonic:

import keras
from keras import Sequential
from keras.layers import Input

from airt.keras.layers import MonoDense  # re-exported from mononet.legacy

model = Sequential(
    [
        Input(shape=(3,)),
        MonoDense(128, activation="elu", monotonicity_indicator=[1, 0, -1]),
        MonoDense(128, activation="elu"),
        MonoDense(1),
    ]
)

For the create_type_1 / create_type_2 builders, benchmarks, the strictly multi-backend API, and current documentation, see the mononet docs: https://davorrunje.github.io/mononet/.

Citation

If you use this library, please cite:

@inproceedings{runje2023,
  title={Constrained Monotonic Neural Networks},
  author={Davor Runje and Sharath M. Shankaranarayana},
  booktitle={Proceedings of the 40th {International Conference on Machine Learning}},
  year={2023}
}

License

This package is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License (CC BY-NC-SA 4.0) — see LICENSE.

The underlying implementation, mononet, is available under the Apache License 2.0, which permits commercial use. If you need a permissive or commercial license, use mononet directly.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monotonic_nn-0.4.0a1.tar.gz (2.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monotonic_nn-0.4.0a1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file monotonic_nn-0.4.0a1.tar.gz.

File metadata

  • Download URL: monotonic_nn-0.4.0a1.tar.gz
  • Upload date:
  • Size: 2.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for monotonic_nn-0.4.0a1.tar.gz
Algorithm Hash digest
SHA256 56d6ceafa96f6040f0300bfd2ab4241db64711da1fb4422493aed1cc47e1046e
MD5 3707d66ddc65ef37112f583fd5531bb9
BLAKE2b-256 94939fe55b67255a1c25565b1961b86d0bfa71dd3263d33f15a6c624f0a066ae

See more details on using hashes here.

Provenance

The following attestation bundles were made for monotonic_nn-0.4.0a1.tar.gz:

Publisher: publish.yml on airtai/monotonic-nn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file monotonic_nn-0.4.0a1-py3-none-any.whl.

File metadata

  • Download URL: monotonic_nn-0.4.0a1-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for monotonic_nn-0.4.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 00f75cea6c7f53eb5f26f87f38721992481952209bf554f73d3d85feee9e69b7
MD5 a443891e8aed228835a143df6ca064ca
BLAKE2b-256 de8d1b970e7d6435e1a5394655d990be0373e141d44b99635df17d7486e5bd41

See more details on using hashes here.

Provenance

The following attestation bundles were made for monotonic_nn-0.4.0a1-py3-none-any.whl:

Publisher: publish.yml on airtai/monotonic-nn

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page