Red neuronal zero-deps para videojuegos: neuroevolucion, imitacion, JIT por codegen y save de una linea.
Project description
instinto
Red neuronal zero-deps para videojuegos. Un archivo, solo stdlib.
Brain— MLP denso con pesos planos.think()/act().- Neuroevolución —
Populationcon elitismo, torneo y sigma autoadaptativo (regla 1/5 de Rechenberg): explora fuerte al inicio, refina solo al final. - Imitación —
learn()con backprop (SGD + momentum). Graba al jugador, entrena al NPC. - JIT por codegen —
compile()genera el forward desenrollado víaexec: 3–6× más rápido, ~120k inferencias/seg en CPython puro. - Save de una línea —
save()→ float16 + zlib + base85. Un cerebro 2-6-2 son ~116 chars: pégalo en el JSON de tu partida guardada. - Determinista — misma seed, misma evolución. Replays reproducibles.
Instalar
pip install instinto # o copia instinto.py a tu proyecto
60 segundos
from instinto import Brain, Population
# inferencia
npc = Brain(n_in=4, hidden=[8], n_out=3, out="softmax", seed=42)
accion = npc.act([dx, dy, vida, peligro], explore=0.05) # 0|1|2
# neuroevolución: el fitness ES tu juego
pop = Population(60, n_in=4, hidden=[8], n_out=3, out="softmax", seed=7)
for gen in range(100):
for brain in pop:
brain.fitness = jugar_partida(brain) # tu función
stats = pop.evolve() # {'gen','best','mean','sigma'}
mejor = pop.best
# imitación: aprende del jugador
datos = [(estado, accion_del_jugador), ...] # índice de clase si softmax
npc.learn(datos, epochs=300, lr=0.5)
# producción
mejor.compile() # JIT (se invalida solo al mutar)
blob = mejor.save() # str de una línea
npc2 = Brain.load(blob)
Demo
python demo_caza.py # agentes evolucionan a cazar comida, render ASCII
API
Brain(n_in, hidden, n_out, act, out, seed) |
acts: tanh sigmoid relu linear (+softmax en salida) |
.think(x) -> list / .act(x, explore) -> int |
inferencia / argmax con ε-greedy |
.learn(samples, epochs, lr, momentum, batch, reset) |
backprop; devuelve loss (½·MSE o CE) |
.mutate(rate, power) / .cross(other) / .clone() |
operadores evolutivos |
.compile() / .save(compact) / Brain.load(s) |
JIT / persistencia |
Population(size, ..., elite, tournament, mut_rate, sigma, noisy_fitness) |
iterable de Brains |
.evolve() -> stats / .best |
siguiente generación / hall of fame |
Sin numpy. Sin configs. Sin clases que heredar. Python ≥ 3.8.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
instinto-0.2.0.tar.gz
(9.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file instinto-0.2.0.tar.gz.
File metadata
- Download URL: instinto-0.2.0.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ccba6346ecf34649b3842f73d4c6338f3de51750aec3eba4fc92591b3733d4d3
|
|
| MD5 |
48502929330edd59c76a3714737458cc
|
|
| BLAKE2b-256 |
4458675f46e9ee91138593a2c8ccb906bfba74bc652ca722eafc92ce470523ff
|
File details
Details for the file instinto-0.2.0-py3-none-any.whl.
File metadata
- Download URL: instinto-0.2.0-py3-none-any.whl
- Upload date:
- Size: 9.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
883c5697736c31b6eb7556d021b22f07bda7bd8f4572a3a9fbb0116ce0efbd54
|
|
| MD5 |
0596ea814dec1eea2ba27549c191c8ee
|
|
| BLAKE2b-256 |
5d86bd8382a237c2d315416a843913982321ca0f973f574ff4fed2d5c1474ba5
|