nwm-rl 1.0.0__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.
- nwm_rl-1.0.0/LICENSE +21 -0
- nwm_rl-1.0.0/PKG-INFO +158 -0
- nwm_rl-1.0.0/README.md +125 -0
- nwm_rl-1.0.0/nwm/__init__.py +45 -0
- nwm_rl-1.0.0/nwm/agents/__init__.py +5 -0
- nwm_rl-1.0.0/nwm/agents/nwm_agent.py +412 -0
- nwm_rl-1.0.0/nwm/core/__init__.py +6 -0
- nwm_rl-1.0.0/nwm/core/centroid.py +210 -0
- nwm_rl-1.0.0/nwm/core/potential_field.py +293 -0
- nwm_rl-1.0.0/nwm/utils/__init__.py +5 -0
- nwm_rl-1.0.0/nwm/utils/config.py +100 -0
- nwm_rl-1.0.0/nwm_rl.egg-info/PKG-INFO +158 -0
- nwm_rl-1.0.0/nwm_rl.egg-info/SOURCES.txt +20 -0
- nwm_rl-1.0.0/nwm_rl.egg-info/dependency_links.txt +1 -0
- nwm_rl-1.0.0/nwm_rl.egg-info/requires.txt +10 -0
- nwm_rl-1.0.0/nwm_rl.egg-info/top_level.txt +1 -0
- nwm_rl-1.0.0/pyproject.toml +54 -0
- nwm_rl-1.0.0/setup.cfg +4 -0
- nwm_rl-1.0.0/setup.py +5 -0
- nwm_rl-1.0.0/tests/test_agent.py +178 -0
- nwm_rl-1.0.0/tests/test_centroid.py +85 -0
- nwm_rl-1.0.0/tests/test_potential_field.py +119 -0
nwm_rl-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 NWM Research Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
nwm_rl-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: nwm-rl
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Negative Weight Mapping - A Reinforcement Learning framework using persistent potential fields
|
|
5
|
+
Author: CusterMustOfficial
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/nwm-research/nwm
|
|
8
|
+
Project-URL: Documentation, https://github.com/nwm-research/nwm#readme
|
|
9
|
+
Keywords: reinforcement-learning,machine-learning,ai,potential-field,exploration
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Intended Audience :: Science/Research
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
21
|
+
Requires-Python: >=3.8
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: numpy>=1.20.0
|
|
25
|
+
Requires-Dist: gymnasium>=0.26.0
|
|
26
|
+
Provides-Extra: dev
|
|
27
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
28
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
29
|
+
Provides-Extra: full
|
|
30
|
+
Requires-Dist: matplotlib>=3.5.0; extra == "full"
|
|
31
|
+
Requires-Dist: torch>=2.0.0; extra == "full"
|
|
32
|
+
Dynamic: license-file
|
|
33
|
+
|
|
34
|
+
# NWM - Negative Weight Mapping
|
|
35
|
+
|
|
36
|
+
**Apprendimento per Esclusione** - Un framework che guida l'esplorazione e la stabilita utilizzando memorie persistenti di fallimento e successo.
|
|
37
|
+
|
|
38
|
+
## Cos'e NWM?
|
|
39
|
+
|
|
40
|
+
Il **Negative Weight Mapping** trasforma l'esperienza passata in un **Campo di Forza Potenziale**. L'agente naviga lo spazio degli stati reagendo a:
|
|
41
|
+
|
|
42
|
+
- **Forze Attrattive** - Successi passati che guidano verso azioni ottimali
|
|
43
|
+
- **Forze Repulsive** - Fallimenti passati che allontanano da azioni pericolose
|
|
44
|
+
|
|
45
|
+
### Caratteristiche Principali
|
|
46
|
+
|
|
47
|
+
| Feature | Descrizione |
|
|
48
|
+
| ------------------------------ | ------------------------------------------------------- |
|
|
49
|
+
| **Dynamic Smart Lock** | Protegge automaticamente le memorie di alta qualita |
|
|
50
|
+
| **Adaptive Exploration** | Riduce l'esplorazione quando trova strategie vincenti |
|
|
51
|
+
| **Persistent Memory** | I centroidi evolvono con "stiffness" progressiva |
|
|
52
|
+
| **Fear & Greed** | Evita le azioni pericolose prima di cercare il guadagno |
|
|
53
|
+
|
|
54
|
+
## Installazione
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
cd PYTHONLIB
|
|
58
|
+
pip install -e .
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Quick Start
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
import gymnasium as gym
|
|
65
|
+
from nwm import NWM
|
|
66
|
+
|
|
67
|
+
# Crea ambiente e agente
|
|
68
|
+
env = gym.make("CartPole-v1")
|
|
69
|
+
agent = NWM(
|
|
70
|
+
state_dim=env.observation_space.shape[0],
|
|
71
|
+
num_actions=env.action_space.n
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
# Training loop
|
|
75
|
+
for episode in range(100):
|
|
76
|
+
state, _ = env.reset()
|
|
77
|
+
done = False
|
|
78
|
+
|
|
79
|
+
while not done:
|
|
80
|
+
action = agent.select_action(state)
|
|
81
|
+
next_state, reward, terminated, truncated, _ = env.step(action)
|
|
82
|
+
done = terminated or truncated
|
|
83
|
+
agent.step(state, action, reward, next_state, done)
|
|
84
|
+
state = next_state
|
|
85
|
+
|
|
86
|
+
print(f"Episode {episode + 1}: Best = {agent.best_reward:.0f}")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## API Reference
|
|
90
|
+
|
|
91
|
+
### NWM
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from nwm import NWM, NWMConfig
|
|
95
|
+
|
|
96
|
+
# Con configurazione personalizzata
|
|
97
|
+
config = NWMConfig(
|
|
98
|
+
max_centroids=500, # Massimo numero di centroidi
|
|
99
|
+
warmup_episodes=50, # Episodi di pura esplorazione
|
|
100
|
+
exploration_rate=1.0, # Tasso iniziale di esplorazione
|
|
101
|
+
exploration_decay=0.99, # Decay dell'esplorazione
|
|
102
|
+
min_exploration=0.05, # Esplorazione minima
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
agent = NWM(state_dim=4, num_actions=2, config=config)
|
|
106
|
+
|
|
107
|
+
# Metodi principali
|
|
108
|
+
action = agent.select_action(state, training=True)
|
|
109
|
+
agent.step(state, action, reward, next_state, done)
|
|
110
|
+
stats = agent.get_stats()
|
|
111
|
+
|
|
112
|
+
# Save/Load
|
|
113
|
+
agent.save("agent.pkl")
|
|
114
|
+
agent = NWM.load("agent.pkl")
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### NWMConfig
|
|
118
|
+
|
|
119
|
+
| Parametro | Default | Descrizione |
|
|
120
|
+
| --------------------- | ------- | -------------------------------------- |
|
|
121
|
+
| `max_centroids` | 500 | Numero massimo di centroidi in memoria |
|
|
122
|
+
| `warmup_episodes` | 50 | Episodi di warmup prima del learning |
|
|
123
|
+
| `exploration_rate` | 1.0 | Tasso iniziale di esplorazione |
|
|
124
|
+
| `exploration_decay` | 0.99 | Fattore di decay |
|
|
125
|
+
| `min_exploration` | 0.05 | Esplorazione minima |
|
|
126
|
+
| `merge_threshold` | 0.3 | Soglia per il merge dei centroidi |
|
|
127
|
+
| `distance_cutoff` | 2.5 | Distanza massima di influenza |
|
|
128
|
+
|
|
129
|
+
## Struttura del Package
|
|
130
|
+
|
|
131
|
+
```
|
|
132
|
+
PYTHONLIB/
|
|
133
|
+
├── nwm/ # Package principale
|
|
134
|
+
│ ├── agents/ # Implementazioni agenti
|
|
135
|
+
│ ├── core/ # Componenti core (centroid, potential_field)
|
|
136
|
+
│ └── utils/ # Utilities (config)
|
|
137
|
+
├── examples/ # Esempi di utilizzo
|
|
138
|
+
└── tests/ # Test suite
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Esempi
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
# Quick start
|
|
145
|
+
python examples/quickstart.py
|
|
146
|
+
|
|
147
|
+
# Training completo
|
|
148
|
+
python examples/cartpole_training.py --episodes 500
|
|
149
|
+
|
|
150
|
+
# Demo visuale
|
|
151
|
+
python examples/cartpole_training.py --demo
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
**Versione**: 1.0.0
|
|
157
|
+
**Licenza**: MIT
|
|
158
|
+
**Autore**: CusterMustOfficial
|
nwm_rl-1.0.0/README.md
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# NWM - Negative Weight Mapping
|
|
2
|
+
|
|
3
|
+
**Apprendimento per Esclusione** - Un framework che guida l'esplorazione e la stabilita utilizzando memorie persistenti di fallimento e successo.
|
|
4
|
+
|
|
5
|
+
## Cos'e NWM?
|
|
6
|
+
|
|
7
|
+
Il **Negative Weight Mapping** trasforma l'esperienza passata in un **Campo di Forza Potenziale**. L'agente naviga lo spazio degli stati reagendo a:
|
|
8
|
+
|
|
9
|
+
- **Forze Attrattive** - Successi passati che guidano verso azioni ottimali
|
|
10
|
+
- **Forze Repulsive** - Fallimenti passati che allontanano da azioni pericolose
|
|
11
|
+
|
|
12
|
+
### Caratteristiche Principali
|
|
13
|
+
|
|
14
|
+
| Feature | Descrizione |
|
|
15
|
+
| ------------------------------ | ------------------------------------------------------- |
|
|
16
|
+
| **Dynamic Smart Lock** | Protegge automaticamente le memorie di alta qualita |
|
|
17
|
+
| **Adaptive Exploration** | Riduce l'esplorazione quando trova strategie vincenti |
|
|
18
|
+
| **Persistent Memory** | I centroidi evolvono con "stiffness" progressiva |
|
|
19
|
+
| **Fear & Greed** | Evita le azioni pericolose prima di cercare il guadagno |
|
|
20
|
+
|
|
21
|
+
## Installazione
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
cd PYTHONLIB
|
|
25
|
+
pip install -e .
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import gymnasium as gym
|
|
32
|
+
from nwm import NWM
|
|
33
|
+
|
|
34
|
+
# Crea ambiente e agente
|
|
35
|
+
env = gym.make("CartPole-v1")
|
|
36
|
+
agent = NWM(
|
|
37
|
+
state_dim=env.observation_space.shape[0],
|
|
38
|
+
num_actions=env.action_space.n
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
# Training loop
|
|
42
|
+
for episode in range(100):
|
|
43
|
+
state, _ = env.reset()
|
|
44
|
+
done = False
|
|
45
|
+
|
|
46
|
+
while not done:
|
|
47
|
+
action = agent.select_action(state)
|
|
48
|
+
next_state, reward, terminated, truncated, _ = env.step(action)
|
|
49
|
+
done = terminated or truncated
|
|
50
|
+
agent.step(state, action, reward, next_state, done)
|
|
51
|
+
state = next_state
|
|
52
|
+
|
|
53
|
+
print(f"Episode {episode + 1}: Best = {agent.best_reward:.0f}")
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### NWM
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from nwm import NWM, NWMConfig
|
|
62
|
+
|
|
63
|
+
# Con configurazione personalizzata
|
|
64
|
+
config = NWMConfig(
|
|
65
|
+
max_centroids=500, # Massimo numero di centroidi
|
|
66
|
+
warmup_episodes=50, # Episodi di pura esplorazione
|
|
67
|
+
exploration_rate=1.0, # Tasso iniziale di esplorazione
|
|
68
|
+
exploration_decay=0.99, # Decay dell'esplorazione
|
|
69
|
+
min_exploration=0.05, # Esplorazione minima
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
agent = NWM(state_dim=4, num_actions=2, config=config)
|
|
73
|
+
|
|
74
|
+
# Metodi principali
|
|
75
|
+
action = agent.select_action(state, training=True)
|
|
76
|
+
agent.step(state, action, reward, next_state, done)
|
|
77
|
+
stats = agent.get_stats()
|
|
78
|
+
|
|
79
|
+
# Save/Load
|
|
80
|
+
agent.save("agent.pkl")
|
|
81
|
+
agent = NWM.load("agent.pkl")
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### NWMConfig
|
|
85
|
+
|
|
86
|
+
| Parametro | Default | Descrizione |
|
|
87
|
+
| --------------------- | ------- | -------------------------------------- |
|
|
88
|
+
| `max_centroids` | 500 | Numero massimo di centroidi in memoria |
|
|
89
|
+
| `warmup_episodes` | 50 | Episodi di warmup prima del learning |
|
|
90
|
+
| `exploration_rate` | 1.0 | Tasso iniziale di esplorazione |
|
|
91
|
+
| `exploration_decay` | 0.99 | Fattore di decay |
|
|
92
|
+
| `min_exploration` | 0.05 | Esplorazione minima |
|
|
93
|
+
| `merge_threshold` | 0.3 | Soglia per il merge dei centroidi |
|
|
94
|
+
| `distance_cutoff` | 2.5 | Distanza massima di influenza |
|
|
95
|
+
|
|
96
|
+
## Struttura del Package
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
PYTHONLIB/
|
|
100
|
+
├── nwm/ # Package principale
|
|
101
|
+
│ ├── agents/ # Implementazioni agenti
|
|
102
|
+
│ ├── core/ # Componenti core (centroid, potential_field)
|
|
103
|
+
│ └── utils/ # Utilities (config)
|
|
104
|
+
├── examples/ # Esempi di utilizzo
|
|
105
|
+
└── tests/ # Test suite
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Esempi
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Quick start
|
|
112
|
+
python examples/quickstart.py
|
|
113
|
+
|
|
114
|
+
# Training completo
|
|
115
|
+
python examples/cartpole_training.py --episodes 500
|
|
116
|
+
|
|
117
|
+
# Demo visuale
|
|
118
|
+
python examples/cartpole_training.py --demo
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
**Versione**: 1.0.0
|
|
124
|
+
**Licenza**: MIT
|
|
125
|
+
**Autore**: CusterMustOfficial
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NWM - Negative Weight Mapping
|
|
3
|
+
=============================
|
|
4
|
+
|
|
5
|
+
A Reinforcement Learning framework that uses persistent potential fields
|
|
6
|
+
to guide agent exploration through attractive (success) and repulsive (failure) forces.
|
|
7
|
+
|
|
8
|
+
Quick Start
|
|
9
|
+
-----------
|
|
10
|
+
>>> import gymnasium as gym
|
|
11
|
+
>>> from nwm import NWM, NWMConfig
|
|
12
|
+
>>>
|
|
13
|
+
>>> env = gym.make("CartPole-v1")
|
|
14
|
+
>>> agent = NWM(
|
|
15
|
+
... state_dim=env.observation_space.shape[0],
|
|
16
|
+
... num_actions=env.action_space.n
|
|
17
|
+
... )
|
|
18
|
+
>>>
|
|
19
|
+
>>> state, _ = env.reset()
|
|
20
|
+
>>> action = agent.select_action(state)
|
|
21
|
+
>>> next_state, reward, done, truncated, _ = env.step(action)
|
|
22
|
+
>>> agent.step(state, action, reward, next_state, done or truncated)
|
|
23
|
+
|
|
24
|
+
Main Components
|
|
25
|
+
---------------
|
|
26
|
+
- NWM: The main RL agent using potential fields
|
|
27
|
+
- NWMConfig: Configuration dataclass for agent parameters
|
|
28
|
+
- PersistentCentroid: Memory unit storing state-action experiences
|
|
29
|
+
- PersistentPotentialField: Spatial memory structure with force calculations
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
__version__ = "1.0.0"
|
|
33
|
+
__author__ = "CusterMustOfficial"
|
|
34
|
+
|
|
35
|
+
from nwm.agents.nwm_agent import NWMAgent as NWM
|
|
36
|
+
from nwm.core.centroid import PersistentCentroid
|
|
37
|
+
from nwm.core.potential_field import PersistentPotentialField
|
|
38
|
+
from nwm.utils.config import NWMConfig
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"NWM",
|
|
42
|
+
"NWMConfig",
|
|
43
|
+
"PersistentCentroid",
|
|
44
|
+
"PersistentPotentialField",
|
|
45
|
+
]
|