Skip to main content

A tiny neural network library

Project description

tinynet

A tiny neural network library

No training

This library provides no training algorithm. Use in conjunction with a black box search algorithm such as CMA-ES to train the weights in a neuroevolution framework.

Installation

pip install tinynet

Usage

from tinynet import RNN1L
import numpy as np
ninputs, noutputs = [3, 2]
net = RNN1L(ninputs, noutputs)
net.set_weights(np.random.rand(net.nweights()))
out = net.activate(np.zeros(ninputs))
assert len(out) == noutputs
assert len(net.state) == ninputs + 1 + noutputs # input, bias, recursion

Neuroevolution application

import numpy as np
from tinynet import RNN1L
import gym

# Get pre-trained weights
pre_trained_weights = raise "Check out https://gist.github.com/giuse/3d16c947259173d571cf82e28a2f7a7e"

# Environment setup
env = gym.make("BipedalWalker-v2")
# env = gym.wrappers.Monitor(env, 'video', force = True) # Uncomment to save video
nactions = env.action_space.shape[0]
ninputs = env.reset().size

# Network setup
net = RNN1L(ninputs, nactions)
net.set_weights(pre_trained_weights)

# Gameplay loop
obs = env.reset()
score = 0
done = False
while not done:
  env.render()
  action = net.activate(obs)
  obs, rew, done, info = env.step(action)
  score += rew
print(f"Fitness: {score}")
env.close()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tinynet, version 0.0.5
Filename, size File type Python version Upload date Hashes
Filename, size tinynet-0.0.5.tar.gz (4.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page