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.1.tar.gz (181.4 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.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nnapprox-0.3.1.tar.gz
  • Upload date:
  • Size: 181.4 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.1.tar.gz
Algorithm Hash digest
SHA256 bf1bdca85d9faaf765a908ab9f693240765018834cb67cba37f4c79027f43494
MD5 57f38b6c120893fbd8adcf52323b66eb
BLAKE2b-256 584740d315d644ac04e528eeb5c98691c99c3368cad2aca3679a73fd000dd294

See more details on using hashes here.

File details

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

File metadata

  • Download URL: nnapprox-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 17.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fccdbf589441293648018eb3ef1e5633a21ae16e4d6cea991a5d467a9347a4ca
MD5 3b488270bb94a26647da24652080daa2
BLAKE2b-256 5d4cddc04ff069870f62745909f83caa418a6b4b8e112eb5b9917204734983b7

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