Skip to main content

Neural network approximation for high-dimensional functional relations

Project description

nnapprox (Neural Network Approximation)

Docs Python 3.8+ License: MIT codecov CI

Neural network function approximation using PyTorch (Future backends planned). Approximate arbitrary functions with automatic scaling, transformations, and serialization.

Full Documentation


Installation

Apple M1: Install pytorch with metal support via conda as described in the Apple Instructions

pip install nnapprox

Quick Start

import nnapprox as nna
import numpy as np

# Generate data
x = np.linspace(0, 10, 100)
y = np.sin(x) * np.exp(-x/10)

# Train
func = nna.create_approximator(
    input=['x'],
    output=['y'],
    backend='torch'
)
func.fit({'x': x, 'y': y}, epochs=5000)

# Predict
y_pred = func(x)

# Save/load
func.save('model.nna')
func2 = nna.load_approximator('model.nna', backend='torch')

Features

  • Simple API: Train in 3 lines of code
  • Flexible inputs: NumPy arrays, pandas DataFrames, scalars, or mixed types
  • Transformations: Built-in (log, sqrt) or custom transforms
  • GPU support: Automatic acceleration when available
  • Serialization: Save/load complete model state

Multi-dimensional Example

import pandas as pd

x1, x2 = np.meshgrid(np.linspace(0,10,101), np.linspace(0,10,101))
x1 = x1.flatten()
x2 = x2.flatten()
def y_true(x1, x2):
    return 2*x1 + 3*x2**2 + 1
data = pd.DataFrame({'x1': x1, 'x2': x2, 'y': y_true(x1, x2)})

func = nna.create_approximator(
    input=['x1', 'x2'],
    output=['y'],
    backend='torch'
)
func.fit(data, epochs=3000)
predictions = func(data, return_dataframe=True)

Transformations

# Predefined transforms
func.set_transform('x1', predefined='log')
func.set_transform('y', predefined='exp')

# Custom transforms
def forward_fn(x):
    return x**3
def inverse_fn(y):
    return y**(1/3)
func.set_transform('x1', forward=forward_fn, inverse=inverse_fn)

Requirements

  • Python >= 3.8
  • PyTorch >= 1.9
  • NumPy >= 1.20
  • pandas >= 1.3
  • scikit-learn >= 1.0

Optional: cloudpickle for lambda function serialization

Contributing

Contributions welcome! Please open an issue or submit a pull request.

License

MIT License - see LICENSE file.

Project details


Download files

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

Source Distribution

nnapprox-0.3.2.tar.gz (184.3 kB view details)

Uploaded Source

Built Distribution

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

nnapprox-0.3.2-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file nnapprox-0.3.2.tar.gz.

File metadata

  • Download URL: nnapprox-0.3.2.tar.gz
  • Upload date:
  • Size: 184.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for nnapprox-0.3.2.tar.gz
Algorithm Hash digest
SHA256 889a63a7b4da9dd704e54a3985819f4eb3c195470d4cba98d4a5eed992bc0d0c
MD5 5c42e61630b7feeb7c0b43976c5d9b87
BLAKE2b-256 e9c36b992cec1b1c9e312ca9533ee621bead4995f4556c96680733e01db1c798

See more details on using hashes here.

File details

Details for the file nnapprox-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: nnapprox-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for nnapprox-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 acb1f206647b3825bf38529a8905f05f8297cbccf8319c2af51f435877c811a5
MD5 e772375dc3debd5d5d2abedbe59f7277
BLAKE2b-256 7f4a044cbe4bb0a660d352583e538187cbf4df9c2e0ba0d9d3032291311e78fa

See more details on using hashes here.

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