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.
Metadata
Release files for instinto 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| instinto-0.2.0.tar.gz | 9.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| instinto-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.9 kB
Release files / instinto-0.2.0.tar.gz
| Download URL | instinto-0.2.0.tar.gz |
|---|---|
| Size | 9.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ccba6346ecf34649b3842f73d4c6338f3de51750aec3eba4fc92591b3733d4d3
|
|
BLAKE2b-256 checksum How to use checksums |
4458675f46e9ee91138593a2c8ccb906bfba74bc652ca722eafc92ce470523ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / instinto-0.2.0-py3-none-any.whl
| Download URL | instinto-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
883c5697736c31b6eb7556d021b22f07bda7bd8f4572a3a9fbb0116ce0efbd54
|
|
BLAKE2b-256 checksum How to use checksums |
5d86bd8382a237c2d315416a843913982321ca0f973f574ff4fed2d5c1474ba5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|