NeuralNetworks 0.2.4__tar.gz → 0.2.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/PKG-INFO +14 -27
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/README.md +13 -26
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Dependances/pytorch.py +3 -1
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/MLP/__init__.py +8 -21
- neuralnetworks-0.2.6/src/NeuralNetworks/MLP/inference.py +12 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/__init__.py +15 -8
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/train.py +5 -10
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/__init__.py +1 -1
- neuralnetworks-0.2.6/src/NeuralNetworks/shared/__init__.py +8 -0
- neuralnetworks-0.2.6/src/NeuralNetworks/shared/module.py +41 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/PKG-INFO +14 -27
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/SOURCES.txt +3 -1
- neuralnetworks-0.2.4/src/NeuralNetworks/MLP/inference.py +0 -26
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/LICENSE +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/pyproject.toml +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/setup.cfg +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Dependances/__init__.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Dependances/matplot.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/MLP/FourierFeatures.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/MLP/Layers.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/dynamic_learning_rate.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/sample_data.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/UI/Learnings.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/UI/Losses.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/UI/__init__.py +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/dependency_links.txt +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/requires.txt +0 -0
- {neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NeuralNetworks
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Multi-Layer Perceptrons with multi-Fourier encoding, variable learning rate, visualization and PyTorch compilation
|
|
5
5
|
Author-email: Alexandre Brun <alexandre51160@gmail.com>
|
|
6
6
|
License: GPL-3.0-or-later
|
|
@@ -46,8 +46,6 @@ Cette classe fournit :
|
|
|
46
46
|
|
|
47
47
|
---
|
|
48
48
|
|
|
49
|
-
#### **Paramètres**
|
|
50
|
-
|
|
51
49
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
52
50
|
|----------------------|--------------------------------------------------------------------------------------------------|---------------|--------------------------------------------------------------------------------|
|
|
53
51
|
| `input_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taille des données en entrée au réseau. Default: `1` |
|
|
@@ -56,47 +54,36 @@ Cette classe fournit :
|
|
|
56
54
|
| `sigmas` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Oui | Liste de sigma pour encodages RFF. Si None : passthrough. Default: `None` |
|
|
57
55
|
| `fourier_input_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | WIP. Default: `2` |
|
|
58
56
|
| `nb_fourier` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Nombre de fréquences utilisées pour les Fourier Features. Default: `8` |
|
|
59
|
-
| `norm` | [`norm`](#norms
|
|
57
|
+
| `norm` | [`norm`](#norms) | Oui | Type de normalisation / activation pour les couches cachées. Default: `'Relu'` |
|
|
60
58
|
| `name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Oui | Nom du réseau pour identification ou affichage. Default: `'Net'` |
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
| **Attributs** | **Type** | **Description** |
|
|
70
|
-
|---------------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
|
71
|
-
| `losses` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des pertes cumulées lors de l'entraînement |
|
|
72
|
-
| `learnings` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des taux d'apprentissage utilisées lors de l'entraînement |
|
|
73
|
-
| `model` | [`nn.Sequential`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Sequential.html) | MLP complet construit dynamiquement |
|
|
74
|
-
| `name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Nom du réseau |
|
|
60
|
+
| **Attributs** | **Type** | **Description** |
|
|
61
|
+
|-----------------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
|
62
|
+
| `MLP.losses` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des pertes cumulées lors de l'entraînement |
|
|
63
|
+
| `MLP.learnings` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des taux d'apprentissage utilisées lors de l'entraînement |
|
|
64
|
+
| `MLP.model` | [`nn.Sequential`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Sequential.html) | MLP complet construit dynamiquement |
|
|
65
|
+
| `MLP.name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Nom du réseau |
|
|
75
66
|
|
|
76
67
|
---
|
|
77
68
|
|
|
78
69
|
### **Trainer**
|
|
79
70
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
- Méthode pour entraîner des réseaux avec mini-batchs et [Automatic Mixed Precision](https://docs.pytorch.org/tutorials/recipes/recipes/amp_recipe.html)
|
|
83
|
-
|
|
84
|
-
#### **Paramètres**
|
|
71
|
+
Classe pour entraîner des réseaux avec mini-batchs et [Automatic Mixed Precision](https://docs.pytorch.org/tutorials/recipes/recipes/amp_recipe.html).
|
|
85
72
|
|
|
86
73
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
87
74
|
|----------------|-------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------|
|
|
88
|
-
| `*nets` | [`MLP`](#mlp
|
|
75
|
+
| `*nets` | [`MLP`](#mlp) | Non | Réseaux pour lesquels le trainer va entrainer. |
|
|
89
76
|
| `inputs` | [`numpy.array(list[float])`](https://numpy.org/doc/stable/reference/generated/numpy.array.html) | Non | Données en entrée au réseau. |
|
|
90
77
|
| `outputs` | [`numpy.array(list[float])`](https://numpy.org/doc/stable/reference/generated/numpy.array.html) | Non | Données en sortie au réseau. |
|
|
91
78
|
| `test_size` | [`float`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Proportion des données à utiliser pendant l'entrainement. Si None : utilise toutes les données. Default: `None` |
|
|
92
|
-
| `optim` | [`optim`](#optims
|
|
79
|
+
| `optim` | [`optim`](#optims) | Oui | Nom de l’optimiseur à utiliser (doit exister dans `optims()`). Default: `'Adam'` |
|
|
93
80
|
| `init_lr` | [`float`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taux d’apprentissage initial pour l’optimiseur. Default: `1e-3` |
|
|
94
|
-
| `crit` | [`crit`](#crits
|
|
81
|
+
| `crit` | [`crit`](#crits) | Oui | Fonction de perte à utiliser (doit exister dans `crits()`). Default: `MSE'` |
|
|
95
82
|
| `batch_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taille des minibatchs. Default: `1024` |
|
|
96
83
|
|
|
97
84
|
#### **Trainer.train**
|
|
98
85
|
|
|
99
|
-
Lancement d'un entrainement avec le trainer définit
|
|
86
|
+
Lancement d'un entrainement avec le trainer définit.
|
|
100
87
|
|
|
101
88
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
102
89
|
|-----------------|------------------------------------------------------------------------------------------|---------------|-----------------------------------------|
|
|
@@ -172,7 +159,7 @@ Affiche les taux d'apprentissage en fonction des époques d'entrainement des ré
|
|
|
172
159
|
|
|
173
160
|
## **device**
|
|
174
161
|
|
|
175
|
-
|
|
162
|
+
Variable principale d'allocation des performances.
|
|
176
163
|
|
|
177
164
|
### **Apple Silicon (macOS)**
|
|
178
165
|
- Si le système d'exploitation est macOS (nommé `darwin` dans `platform.system()`), la fonction vérifie si l'accélérateur **Metal Performance Shaders** (MPS) est disponible sur l'appareil.
|
|
@@ -16,8 +16,6 @@ Cette classe fournit :
|
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
|
-
#### **Paramètres**
|
|
20
|
-
|
|
21
19
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
22
20
|
|----------------------|--------------------------------------------------------------------------------------------------|---------------|--------------------------------------------------------------------------------|
|
|
23
21
|
| `input_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taille des données en entrée au réseau. Default: `1` |
|
|
@@ -26,47 +24,36 @@ Cette classe fournit :
|
|
|
26
24
|
| `sigmas` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Oui | Liste de sigma pour encodages RFF. Si None : passthrough. Default: `None` |
|
|
27
25
|
| `fourier_input_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | WIP. Default: `2` |
|
|
28
26
|
| `nb_fourier` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Nombre de fréquences utilisées pour les Fourier Features. Default: `8` |
|
|
29
|
-
| `norm` | [`norm`](#norms
|
|
27
|
+
| `norm` | [`norm`](#norms) | Oui | Type de normalisation / activation pour les couches cachées. Default: `'Relu'` |
|
|
30
28
|
| `name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Oui | Nom du réseau pour identification ou affichage. Default: `'Net'` |
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
| **Attributs** | **Type** | **Description** |
|
|
40
|
-
|---------------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
|
41
|
-
| `losses` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des pertes cumulées lors de l'entraînement |
|
|
42
|
-
| `learnings` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des taux d'apprentissage utilisées lors de l'entraînement |
|
|
43
|
-
| `model` | [`nn.Sequential`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Sequential.html) | MLP complet construit dynamiquement |
|
|
44
|
-
| `name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Nom du réseau |
|
|
30
|
+
| **Attributs** | **Type** | **Description** |
|
|
31
|
+
|-----------------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
|
32
|
+
| `MLP.losses` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des pertes cumulées lors de l'entraînement |
|
|
33
|
+
| `MLP.learnings` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des taux d'apprentissage utilisées lors de l'entraînement |
|
|
34
|
+
| `MLP.model` | [`nn.Sequential`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Sequential.html) | MLP complet construit dynamiquement |
|
|
35
|
+
| `MLP.name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Nom du réseau |
|
|
45
36
|
|
|
46
37
|
---
|
|
47
38
|
|
|
48
39
|
### **Trainer**
|
|
49
40
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
- Méthode pour entraîner des réseaux avec mini-batchs et [Automatic Mixed Precision](https://docs.pytorch.org/tutorials/recipes/recipes/amp_recipe.html)
|
|
53
|
-
|
|
54
|
-
#### **Paramètres**
|
|
41
|
+
Classe pour entraîner des réseaux avec mini-batchs et [Automatic Mixed Precision](https://docs.pytorch.org/tutorials/recipes/recipes/amp_recipe.html).
|
|
55
42
|
|
|
56
43
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
57
44
|
|----------------|-------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------|
|
|
58
|
-
| `*nets` | [`MLP`](#mlp
|
|
45
|
+
| `*nets` | [`MLP`](#mlp) | Non | Réseaux pour lesquels le trainer va entrainer. |
|
|
59
46
|
| `inputs` | [`numpy.array(list[float])`](https://numpy.org/doc/stable/reference/generated/numpy.array.html) | Non | Données en entrée au réseau. |
|
|
60
47
|
| `outputs` | [`numpy.array(list[float])`](https://numpy.org/doc/stable/reference/generated/numpy.array.html) | Non | Données en sortie au réseau. |
|
|
61
48
|
| `test_size` | [`float`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Proportion des données à utiliser pendant l'entrainement. Si None : utilise toutes les données. Default: `None` |
|
|
62
|
-
| `optim` | [`optim`](#optims
|
|
49
|
+
| `optim` | [`optim`](#optims) | Oui | Nom de l’optimiseur à utiliser (doit exister dans `optims()`). Default: `'Adam'` |
|
|
63
50
|
| `init_lr` | [`float`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taux d’apprentissage initial pour l’optimiseur. Default: `1e-3` |
|
|
64
|
-
| `crit` | [`crit`](#crits
|
|
51
|
+
| `crit` | [`crit`](#crits) | Oui | Fonction de perte à utiliser (doit exister dans `crits()`). Default: `MSE'` |
|
|
65
52
|
| `batch_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taille des minibatchs. Default: `1024` |
|
|
66
53
|
|
|
67
54
|
#### **Trainer.train**
|
|
68
55
|
|
|
69
|
-
Lancement d'un entrainement avec le trainer définit
|
|
56
|
+
Lancement d'un entrainement avec le trainer définit.
|
|
70
57
|
|
|
71
58
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
72
59
|
|-----------------|------------------------------------------------------------------------------------------|---------------|-----------------------------------------|
|
|
@@ -142,7 +129,7 @@ Affiche les taux d'apprentissage en fonction des époques d'entrainement des ré
|
|
|
142
129
|
|
|
143
130
|
## **device**
|
|
144
131
|
|
|
145
|
-
|
|
132
|
+
Variable principale d'allocation des performances.
|
|
146
133
|
|
|
147
134
|
### **Apple Silicon (macOS)**
|
|
148
135
|
- Si le système d'exploitation est macOS (nommé `darwin` dans `platform.system()`), la fonction vérifie si l'accélérateur **Metal Performance Shaders** (MPS) est disponible sur l'appareil.
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
# (at your option) any later version.
|
|
7
7
|
|
|
8
8
|
import os
|
|
9
|
-
os.environ["PYTORCH_CUDA_ALLOC_CONF"] = "expandable_segments:True"
|
|
10
9
|
|
|
11
10
|
import platform
|
|
12
11
|
|
|
@@ -20,6 +19,8 @@ from torch.utils.data import TensorDataset, DataLoader
|
|
|
20
19
|
from torchmetrics.image import PeakSignalNoiseRatio as PSNR
|
|
21
20
|
from torchvision.transforms import ToTensor, Resize, Compose
|
|
22
21
|
|
|
22
|
+
import visualtorch
|
|
23
|
+
|
|
23
24
|
torch.cuda.empty_cache()
|
|
24
25
|
def get_best_device():
|
|
25
26
|
|
|
@@ -51,6 +52,7 @@ def get_best_device():
|
|
|
51
52
|
|
|
52
53
|
# =========== Unknown OS ===========
|
|
53
54
|
return torch.device("cpu")
|
|
55
|
+
|
|
54
56
|
device = get_best_device()
|
|
55
57
|
|
|
56
58
|
# --- Optimisations CUDA ---
|
|
@@ -10,7 +10,9 @@ from .FourierFeatures import encode
|
|
|
10
10
|
from .Layers import create_layers
|
|
11
11
|
from .inference import infer
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
from ..shared import Module
|
|
14
|
+
|
|
15
|
+
class MLP (Module):
|
|
14
16
|
"""
|
|
15
17
|
Multi-Layer Perceptron avec encodage de Fourier optionnel.
|
|
16
18
|
|
|
@@ -49,18 +51,13 @@ class MLP (nn.Module):
|
|
|
49
51
|
nb_fourier = 8,
|
|
50
52
|
norm = "Relu",
|
|
51
53
|
name = "Net"):
|
|
52
|
-
super ().__init__ ()
|
|
54
|
+
super ().__init__ (name)
|
|
53
55
|
|
|
54
56
|
# --- Activation ---
|
|
55
57
|
self.norm = norm_list.get (norm)
|
|
56
58
|
if self.norm is None:
|
|
57
|
-
print (f"Warning: '{norm}' not recognized,
|
|
59
|
+
print (f"Warning: '{norm}' not recognized, fRelung back to 'm is'")
|
|
58
60
|
self.norm = norm_list.get ("Relu")
|
|
59
|
-
|
|
60
|
-
# --- Attributs ---
|
|
61
|
-
self.losses = []
|
|
62
|
-
self.learnings = []
|
|
63
|
-
self.name = name
|
|
64
61
|
|
|
65
62
|
## --- Encodage Fourier ou passthrough ---
|
|
66
63
|
self.encodings, self.f = encode (
|
|
@@ -82,18 +79,8 @@ class MLP (nn.Module):
|
|
|
82
79
|
self.norm
|
|
83
80
|
)
|
|
84
81
|
|
|
85
|
-
def
|
|
86
|
-
|
|
87
|
-
Effectue une passe avant du réseau.
|
|
88
|
-
|
|
89
|
-
Parameters
|
|
90
|
-
----------
|
|
91
|
-
x : torch.Tensor
|
|
92
|
-
Entrées du réseau de shape `(N, input_size)`.
|
|
82
|
+
def _forward (self, x):
|
|
83
|
+
return infer (self, x)
|
|
93
84
|
|
|
94
|
-
|
|
95
|
-
-------
|
|
96
|
-
torch.Tensor
|
|
97
|
-
Sortie du MLP de shape `(N, output_size)`.
|
|
98
|
-
"""
|
|
85
|
+
def train_forward (self, x):
|
|
99
86
|
return infer (self, x)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
+
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
|
|
8
|
+
from ..Dependances import torch, np, device
|
|
9
|
+
|
|
10
|
+
def infer (net, x):
|
|
11
|
+
results_list = [net.model (encoding (x)) for encoding in net.encodings]
|
|
12
|
+
return net.f (torch.cat (results_list, dim = 1))
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# the Free Software Foundation, either version 3 of the License, or
|
|
6
6
|
# (at your option) any later version.
|
|
7
7
|
|
|
8
|
-
from ..Dependances import crit_list, optim_list
|
|
8
|
+
from ..Dependances import crit_list, optim_list, np
|
|
9
9
|
from .train import train_f
|
|
10
10
|
from .sample_data import sample_data
|
|
11
11
|
|
|
@@ -15,7 +15,7 @@ class Trainer:
|
|
|
15
15
|
*nets,
|
|
16
16
|
inputs,
|
|
17
17
|
outputs,
|
|
18
|
-
|
|
18
|
+
train_size = None,
|
|
19
19
|
optim = 'Adam',
|
|
20
20
|
init_lr = 0.01,
|
|
21
21
|
crit = 'MSE',
|
|
@@ -24,12 +24,19 @@ class Trainer:
|
|
|
24
24
|
self.batch_size = batch_size
|
|
25
25
|
self.nets = nets
|
|
26
26
|
self.init_lr = init_lr
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
inputs
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
if train_size is None:
|
|
28
|
+
|
|
29
|
+
self.X_train = inputs
|
|
30
|
+
self.X_test = inputs
|
|
31
|
+
self.y_train = outputs
|
|
32
|
+
self.y_test = outputs
|
|
33
|
+
else:
|
|
34
|
+
|
|
35
|
+
self.X_train, self.X_test, self.y_train, self.y_test = sample_data (
|
|
36
|
+
inputs,
|
|
37
|
+
outputs,
|
|
38
|
+
min(1,np.abs(1 - train_size))
|
|
39
|
+
)
|
|
33
40
|
|
|
34
41
|
# --- Fonction de perte ---
|
|
35
42
|
self.crit = crit_list.get(crit)
|
|
@@ -27,7 +27,8 @@ def train_f (Trainer, num_epochs = 1, activate_tqdm = True):
|
|
|
27
27
|
pbar = tqdm (
|
|
28
28
|
range (num_epochs),
|
|
29
29
|
desc = f"train epoch",
|
|
30
|
-
disable = not (activate_tqdm)
|
|
30
|
+
disable = not (activate_tqdm),
|
|
31
|
+
mininterval=0.5
|
|
31
32
|
)
|
|
32
33
|
|
|
33
34
|
for epoch in pbar:
|
|
@@ -43,14 +44,8 @@ def train_f (Trainer, num_epochs = 1, activate_tqdm = True):
|
|
|
43
44
|
def closure ():
|
|
44
45
|
Trainer.optims [k].zero_grad (set_to_none = True)
|
|
45
46
|
with autocast (dev):
|
|
46
|
-
loss = Trainer.crit (
|
|
47
|
-
|
|
48
|
-
torch.cat (
|
|
49
|
-
[net.model (encoding (Trainer.X_train [idx]))for encoding in net.encodings],
|
|
50
|
-
dim = 1
|
|
51
|
-
)
|
|
52
|
-
),
|
|
53
|
-
Trainer.y_train[idx]
|
|
47
|
+
loss = Trainer.crit (net.train_forward (Trainer.X_train [idx]),
|
|
48
|
+
Trainer.y_train [idx]
|
|
54
49
|
)
|
|
55
50
|
scaler.scale (loss).backward ()
|
|
56
51
|
return loss
|
|
@@ -66,7 +61,7 @@ def train_f (Trainer, num_epochs = 1, activate_tqdm = True):
|
|
|
66
61
|
for param_group in Trainer.optims [k].param_groups:
|
|
67
62
|
param_group ['lr'] = net.learnings[-1]
|
|
68
63
|
|
|
69
|
-
pbar.set_postfix(loss=f"{epoch_loss:.5f}",lr=f"{net.learnings[-1]:.5f}")
|
|
64
|
+
#pbar.set_postfix(loss=f"{epoch_loss:.5f}",lr=f"{net.learnings[-1]:.5f}")
|
|
70
65
|
|
|
71
66
|
net = net.to ('cpu')
|
|
72
67
|
net.learnings.pop(-1)
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
+
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
|
|
8
|
+
from .module import Module
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
+
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
+
# (at your option) any later version.
|
|
7
|
+
|
|
8
|
+
from ..Dependances import norm_list, nn, torch, device
|
|
9
|
+
|
|
10
|
+
class Module (nn.Module):
|
|
11
|
+
|
|
12
|
+
def __init__ (self, name = "Net"):
|
|
13
|
+
super ().__init__ ()
|
|
14
|
+
|
|
15
|
+
# --- Attributs ---
|
|
16
|
+
self.losses = []
|
|
17
|
+
self.learnings = []
|
|
18
|
+
self.name = name
|
|
19
|
+
|
|
20
|
+
def _forward (self,x):
|
|
21
|
+
raise Exception ("_forward n'est pas défini dans la classe")
|
|
22
|
+
|
|
23
|
+
def train_forward (self,x):
|
|
24
|
+
raise Exception ("train_forward n'est pas défini dans la classe")
|
|
25
|
+
|
|
26
|
+
def forward (self, x):
|
|
27
|
+
|
|
28
|
+
with torch.no_grad ():
|
|
29
|
+
x = x.unsqueeze (0) if x.dim () == 1 else x
|
|
30
|
+
self = self.to (device)
|
|
31
|
+
x = x.to (device)
|
|
32
|
+
|
|
33
|
+
output = self._forward(x).cpu ().numpy ().flatten ()
|
|
34
|
+
|
|
35
|
+
x = x.to ('cpu')
|
|
36
|
+
self = self.to ('cpu')
|
|
37
|
+
|
|
38
|
+
return output
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NeuralNetworks
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Multi-Layer Perceptrons with multi-Fourier encoding, variable learning rate, visualization and PyTorch compilation
|
|
5
5
|
Author-email: Alexandre Brun <alexandre51160@gmail.com>
|
|
6
6
|
License: GPL-3.0-or-later
|
|
@@ -46,8 +46,6 @@ Cette classe fournit :
|
|
|
46
46
|
|
|
47
47
|
---
|
|
48
48
|
|
|
49
|
-
#### **Paramètres**
|
|
50
|
-
|
|
51
49
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
52
50
|
|----------------------|--------------------------------------------------------------------------------------------------|---------------|--------------------------------------------------------------------------------|
|
|
53
51
|
| `input_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taille des données en entrée au réseau. Default: `1` |
|
|
@@ -56,47 +54,36 @@ Cette classe fournit :
|
|
|
56
54
|
| `sigmas` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Oui | Liste de sigma pour encodages RFF. Si None : passthrough. Default: `None` |
|
|
57
55
|
| `fourier_input_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | WIP. Default: `2` |
|
|
58
56
|
| `nb_fourier` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Nombre de fréquences utilisées pour les Fourier Features. Default: `8` |
|
|
59
|
-
| `norm` | [`norm`](#norms
|
|
57
|
+
| `norm` | [`norm`](#norms) | Oui | Type de normalisation / activation pour les couches cachées. Default: `'Relu'` |
|
|
60
58
|
| `name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Oui | Nom du réseau pour identification ou affichage. Default: `'Net'` |
|
|
61
59
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
| **Attributs** | **Type** | **Description** |
|
|
70
|
-
|---------------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
|
71
|
-
| `losses` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des pertes cumulées lors de l'entraînement |
|
|
72
|
-
| `learnings` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des taux d'apprentissage utilisées lors de l'entraînement |
|
|
73
|
-
| `model` | [`nn.Sequential`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Sequential.html) | MLP complet construit dynamiquement |
|
|
74
|
-
| `name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Nom du réseau |
|
|
60
|
+
| **Attributs** | **Type** | **Description** |
|
|
61
|
+
|-----------------|--------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
|
|
62
|
+
| `MLP.losses` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des pertes cumulées lors de l'entraînement |
|
|
63
|
+
| `MLP.learnings` | [`list[float]`](https://docs.python.org/3/library/stdtypes.html#sequence-types-list-tuple-range) | Historique des taux d'apprentissage utilisées lors de l'entraînement |
|
|
64
|
+
| `MLP.model` | [`nn.Sequential`](https://docs.pytorch.org/docs/stable/generated/torch.nn.Sequential.html) | MLP complet construit dynamiquement |
|
|
65
|
+
| `MLP.name` | [`str`](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str) | Nom du réseau |
|
|
75
66
|
|
|
76
67
|
---
|
|
77
68
|
|
|
78
69
|
### **Trainer**
|
|
79
70
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
- Méthode pour entraîner des réseaux avec mini-batchs et [Automatic Mixed Precision](https://docs.pytorch.org/tutorials/recipes/recipes/amp_recipe.html)
|
|
83
|
-
|
|
84
|
-
#### **Paramètres**
|
|
71
|
+
Classe pour entraîner des réseaux avec mini-batchs et [Automatic Mixed Precision](https://docs.pytorch.org/tutorials/recipes/recipes/amp_recipe.html).
|
|
85
72
|
|
|
86
73
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
87
74
|
|----------------|-------------------------------------------------------------------------------------------------|---------------|-----------------------------------------------------------------------------------------------------------------|
|
|
88
|
-
| `*nets` | [`MLP`](#mlp
|
|
75
|
+
| `*nets` | [`MLP`](#mlp) | Non | Réseaux pour lesquels le trainer va entrainer. |
|
|
89
76
|
| `inputs` | [`numpy.array(list[float])`](https://numpy.org/doc/stable/reference/generated/numpy.array.html) | Non | Données en entrée au réseau. |
|
|
90
77
|
| `outputs` | [`numpy.array(list[float])`](https://numpy.org/doc/stable/reference/generated/numpy.array.html) | Non | Données en sortie au réseau. |
|
|
91
78
|
| `test_size` | [`float`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Proportion des données à utiliser pendant l'entrainement. Si None : utilise toutes les données. Default: `None` |
|
|
92
|
-
| `optim` | [`optim`](#optims
|
|
79
|
+
| `optim` | [`optim`](#optims) | Oui | Nom de l’optimiseur à utiliser (doit exister dans `optims()`). Default: `'Adam'` |
|
|
93
80
|
| `init_lr` | [`float`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taux d’apprentissage initial pour l’optimiseur. Default: `1e-3` |
|
|
94
|
-
| `crit` | [`crit`](#crits
|
|
81
|
+
| `crit` | [`crit`](#crits) | Oui | Fonction de perte à utiliser (doit exister dans `crits()`). Default: `MSE'` |
|
|
95
82
|
| `batch_size` | [`int`](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) | Oui | Taille des minibatchs. Default: `1024` |
|
|
96
83
|
|
|
97
84
|
#### **Trainer.train**
|
|
98
85
|
|
|
99
|
-
Lancement d'un entrainement avec le trainer définit
|
|
86
|
+
Lancement d'un entrainement avec le trainer définit.
|
|
100
87
|
|
|
101
88
|
| **Paramètres** | **Type** | **Optionnel** | **Description** |
|
|
102
89
|
|-----------------|------------------------------------------------------------------------------------------|---------------|-----------------------------------------|
|
|
@@ -172,7 +159,7 @@ Affiche les taux d'apprentissage en fonction des époques d'entrainement des ré
|
|
|
172
159
|
|
|
173
160
|
## **device**
|
|
174
161
|
|
|
175
|
-
|
|
162
|
+
Variable principale d'allocation des performances.
|
|
176
163
|
|
|
177
164
|
### **Apple Silicon (macOS)**
|
|
178
165
|
- Si le système d'exploitation est macOS (nommé `darwin` dans `platform.system()`), la fonction vérifie si l'accélérateur **Metal Performance Shaders** (MPS) est disponible sur l'appareil.
|
|
@@ -20,4 +20,6 @@ src/NeuralNetworks/Trainer/sample_data.py
|
|
|
20
20
|
src/NeuralNetworks/Trainer/train.py
|
|
21
21
|
src/NeuralNetworks/UI/Learnings.py
|
|
22
22
|
src/NeuralNetworks/UI/Losses.py
|
|
23
|
-
src/NeuralNetworks/UI/__init__.py
|
|
23
|
+
src/NeuralNetworks/UI/__init__.py
|
|
24
|
+
src/NeuralNetworks/shared/__init__.py
|
|
25
|
+
src/NeuralNetworks/shared/module.py
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# NeuralNetworks - Multi-Layer Perceptrons avec encodage Fourier
|
|
2
|
-
# Copyright (C) 2026 Alexandre Brun
|
|
3
|
-
# This program is free software: you can redistribute it and/or modify
|
|
4
|
-
# it under the terms of the GNU General Public License as published by
|
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
6
|
-
# (at your option) any later version.
|
|
7
|
-
|
|
8
|
-
from ..Dependances import torch, np, device
|
|
9
|
-
|
|
10
|
-
def infer (net, x):
|
|
11
|
-
with torch.no_grad ():
|
|
12
|
-
x = x.unsqueeze (0) if x.dim () == 1 else x
|
|
13
|
-
|
|
14
|
-
net = net.to (device)
|
|
15
|
-
x = x.to (device)
|
|
16
|
-
results_list = [net.model (encoding (x)) for encoding in net.encodings]
|
|
17
|
-
x = x.to ('cpu')
|
|
18
|
-
|
|
19
|
-
output = np.array (
|
|
20
|
-
net.f (
|
|
21
|
-
torch.cat (results_list, dim = 1)
|
|
22
|
-
).cpu ().numpy ().flatten ()
|
|
23
|
-
)
|
|
24
|
-
net = net.to ('cpu')
|
|
25
|
-
|
|
26
|
-
return output
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks/Trainer/dynamic_learning_rate.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{neuralnetworks-0.2.4 → neuralnetworks-0.2.6}/src/NeuralNetworks.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|