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

impulse-ts

v0.0.9

Published

TypeScript Neural Network.

Downloads

4

Readme

impulse-ts

This project is under heavy development and there is no stable version yet.

Documentation

Full API documentation available at https://houdini22.github.io/impulse-ts/.

Supported learning optimizers:

OptimizerGradientDescent
OptimizerMomentum
OptimizerAdam
OptimizerRMSProp

Supported dataset modifiers:

MinMaxScalingDatasetModifier
MissingDataScalingDatasetModifier
ShuffleDatasetModifier

Supported network builders:

NetworkBuilder1D

Supported network builder sources

DatasetBuilderSourceCSV::fromFile

Supported layers:

LogisticLayer
PurelinLayer
ReluLayer

Supported trainers:

Trainer
MiniBatchTrainer

Supported Networks

Network1D

Supported Computations

ComputationCPU

There are no errors using above.

Examples

Exports

const {
    NetworkBuilder: {
        NetworkBuilder1D,
        NetworkBuilder3D
    },
    Math: {
        Matrix
    },
    Layer: {
        LogisticLayer,
        ConvLayer,
        FullyConnectedLayer,
        MaxPoolLayer,
        PurelinLayer,
        ReluLayer,
        SoftmaxLayer,
        TanhLayer,
    },
    Dataset: {
        Dataset
    },
    DatasetBuilder: {
        DatasetBuilder
    },
    DatasetBuilderSource: {
        DatasetBuilderSourceCSV
    },
    Optimizer: {
        OptimizerGradientDescent,
        OptimizerAdam,
        OptimizerAdagrad
    },
    Trainer: {
        MiniBatchTrainer,
        Trainer
    },
    DatasetModifier: {
        MinMaxScalingDatasetModifier,
        MissingDataScalingDatasetModifier,
        ShuffleDatasetModifier,
    },
    Computation: {
        ComputationCPU,
        ComputationGPU,
        setComputation,
        getComputation,
    },
} = require("impulse-ts");

Create network, train network and save.

const {
    NetworkBuilder: { NetworkBuilder1D },
    Layer: { LogisticLayer, ReluLayer },
    DatasetBuilder: { DatasetBuilder },
    Optimizer: { OptimizerGradientDescent, OptimizerAdam, OptimizerMomentum, OptimizerRMSProp },
    Trainer: { MiniBatchTrainer, Trainer },
    Computation: { ComputationCPU, setComputation },
    DatasetModifier: { MinMaxScalingDatabaseModifier, MissingDataScalingDatabaseModifier },
    DatasetBuilderSource: { DatasetBuilderSourceCSV },
} = require("impulse-ts");
const path = require("path");

setComputation(new ComputationCPU());

const builder = new NetworkBuilder1D([400]);
builder
    .createLayer(ReluLayer, (layer) => {
        layer.setSize(100);
    })
    .createLayer(LogisticLayer, (layer) => {
        layer.setSize(10);
    });

const network = builder.getNetwork();

DatasetBuilder.fromSource(
    DatasetBuilderSourceCSV.fromLocalFile(path.resolve(__dirname, "./data/mnist_20x20_x.csv"))
).then(async (inputDataset) => {
    console.log("Loaded mnist_20x20_x.csv");
    DatasetBuilder.fromSource(
        DatasetBuilderSourceCSV.fromLocalFile(path.resolve(__dirname, "./data/mnist_20x20_y.csv"))
    ).then(async (outputDataset) => {
        console.log("Loaded mnist_20x20_y.csv");

        inputDataset = new MissingDataScalingDatabaseModifier(inputDataset).apply();
        inputDataset = new MinMaxScalingDatabaseModifier(inputDataset).apply();

        const trainer = new Trainer(network, new OptimizerAdam());

        const result = network.forward(inputDataset.exampleAt(0));
        console.log("forward", result);

        console.log(trainer.cost(inputDataset.data, outputDataset.data));

        trainer.setIterations(1000);
        trainer.setLearningRate(0.01);
        trainer.setRegularization(0.7);
        trainer.train(inputDataset, outputDataset);

        await network.save(path.resolve(__dirname, "./data/mnist.json"));
        console.log(trainer.cost(inputDataset.data, outputDataset.data));
        console.log(network.forward(inputDataset.exampleAt(0)), outputDataset.exampleAt(0));
    });
});

Restore network and predict

const {
    Builder: {
        NetworkBuilder1D
    },
    Dataset: {
        DatasetBuilder
    },
} = require("impulse-ts");
const path = require("path");
const timeStart = new Date().getTime();

NetworkBuilder1D.fromJSON(path.resolve(__dirname, "./data/mnist.json")).then(
    (network) => {
        DatasetBuilder.fromCSV(path.resolve(__dirname, "./data/mnist_20x20_x.csv")).then(
            (inputDataset) => {
                DatasetBuilder.fromCSV(
                    path.resolve(__dirname, "./data/mnist_20x20_y.csv")
                ).then(async (outputDataset) => {
                    const result = network.forward(inputDataset.exampleAt(0));
                    console.log("forward", result);
                });
            }
        );
    }
);