npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

quickrl.core

v0.6.20

Published

This is a simple framework for implementing and testing reinforcement learning environments and algorithms

Downloads

64

Readme

QuickRLJS-Core

Usage

QuickRLJS can be used in the frontend as well as in the backend. I recommend training in node.js and then loading and using the model in the frontend.

Example

First install the npm-package:

npm install quickrl.core

First create "training.ts" or how ever else you choose to call this file:

import { SingleAgentEnvironment, Agents, QuickRLJS } from 'quickrl.core';
// if you want to improve training performance, make shure you import this dependency
require('@tensorflow/tfjs-node-gpu');

// parameters
const randomSeed = 12;
const numTrainingEpisodes = 10000;
const logEvery = 500;
const maxIterationsPerGame = 25;

// load the environment
const env: SingleAgentEnvironment = QuickRLJS.loadEnv('Taxi', { randomSeed: randomSeed })!;

// create an agent
const agent: Agents.DQNAgent = new Agents.DQNAgent(env, {
    learningRate: 0.0001,
    discountFactor: 0.99,
    nnLayer: [128, 128, 64],
    epsilonStart: 1,
    epsilonEnd: 0.01,
    epsilonDecaySteps: 10000,
    hiddenLayerActivation: 'relu',
    batchSize: 32,
    replayMemorySize: 10000,
    replayMemoryInitSize: 1000,
    activateDoubleDQN: true,
    updateTargetEvery: 10000,
});

// set and initialize the agent for the environment
env.agent = agent;
env.initAgent();

// train the agent
await env.train(numTrainingEpisodes, logEvery, maxIterationsPerGame);

Saving Models

After you trained the model, these models can be saved. Depending on whether you train on the web or in a node.js environment you have to install the specific package. The following example will show how it is done in a node environment.

First install node quickrl.node package:

npm install quickrl.node

Now import the Filestrategies into your training script:

...
import { FileStrategies } from 'quickrl.node';
...

After the training was finished. The agent can be saved into a dedicated folder. Also make shure to save your settings so you don't lose them.

// train the agent
await env.train(numTrainingEpisodes, logEvery, maxIterationsPerGame);

await agent.save(
    new FileStrategies.NodeTFModelSaver({
        folderPath: './models/DQN/TaxiModel/',
    })
);
await agent.saveConfig(
    new FileStrategies.NodeJSONFileSaver({
        filePath: './models/DQN/TaxiModel/config.json',
    })
);

Loading models

Previously saved models can also be loaded later. This way you can train the model, save it and load it at a later point in time to continue training, or you load trained models and can run benchmarks on them to analyse the results.

This is how you can load the model into a new agent for example:

const benchmarkAgent = new Agents.DQNAgent(env);
// load configuration
benchmarkAgent.loadConfig(
    new FileStrategies.NodeJSONFileLoader({
        filePath: './models/DQN/TaxiModel/config.json',
    })
);
// load the model
benchmarkAgent.load(
    new FileStrategies.NodeTFModelLoader({
        folderPath: './models/DQN/TaxiModel/',
    })
);

Links