Metadata-Version: 2.4
Name: hno-hammerstein
Version: 0.1.1
Summary: Hammerstein Neural Operator with Latent Dynamics for Magnetic Hysteresis
Author: Daniel Freitas de Jesus and Luiz Alberto Luz de Almeida
License: MIT
Project-URL: Homepage, https://github.com/seu-usuario/hno-hammerstein
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: torch>=2.0.0
Requires-Dist: numpy>=1.21.0
Dynamic: license-file

# HNO-Hammerstein

**Hammerstein Neural Operator with Latent Dynamics for Magnetic Hysteresis**

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/release/python-390/)

This package implements a Neural Operator based on the classic Hammerstein structure, designed to model non-linear dynamic systems with memory, such as magnetic hysteresis. 

Unlike traditional neural networks (DeepONet, FNO), the HNO architecture explicitly separates the static non-linearity (input) from the latent dynamics (memory), ensuring physical interpretability and generalization across different temporal resolutions.

---

## Arquitetura / Architecture

![Arquitetura HNO-Hammerstein](https://raw.githubusercontent.com/seu-usuario/hno-hammerstein/main/docs/arquitetura.png)

O fluxo de dados é:
1. **Não Linearidade Estática (Static Non-linearity):** `z(t) = N_theta(H(t))`
2. **Contexto Global (Global Context):** `c = E_phi(z(t))`
3. **Dinâmica Latente (Latent Dynamics):** `s(t) = Integrate(f_psi(s, z, c))`
4. **Saída (Output):** `B(t) = G_omega(s(t), z(t))`

---

## Instalação / Installation

```bash
pip install hno-hammerstein

#Uso Rápido / Quick Start
import torch
from hno_hammerstein import HNOHammerstein

# Instancia a rede / Instantiate the network
model = HNOHammerstein(
    nonlinear_dim=32,
    context_dim=32,
    state_dim=64,
    hidden_dim=64,
    dropout=0.05
)

# Cria uma entrada fictícia / Create a dummy input: (batch=1, Nt=198, 1)
h = torch.randn(1, 198, 1)


## Treinamento / Training

```python
import numpy as np
from hno_hammerstein import HNOHammersteinTrainer

# Carregar dados (exemplo)
H = np.random.randn(100, 198)  # 100 curvas, 198 pontos
B = np.random.randn(100, 198)

# Criar o trainer
trainer = HNOHammersteinTrainer(
    nonlinear_dim=32,
    context_dim=32,
    state_dim=64,
    hidden_dim=64,
    patience=250,
)

# Treinar
history = trainer.fit(H, B, epochs=2000, save_path="meu_modelo.pth")

# Prever
B_pred = trainer.predict(H[:5])




#Licença / License
Este projeto está sob a licença MIT. Veja o arquivo LICENSE para mais detalhes.
This project is licensed under the MIT License. See the LICENSE file for details.

#Citação / Citation
bibtex
@mastersthesis{freitas2026hno,
  title={Hammerstein Neural Operator (HNO): Um Novo Operador Neural para Modelagem de Histerese Magnética},
  authors={Freitas, Daniel,  Almeida, Luiz}
  school={Universidade Federal do ABC (UFABC)},
  year={2026}
}
