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

predictive-memory

v1.3.1

Published

Generates predictions and classifications using a hierarchical sequence/object cache

Downloads

4

Readme

predictive memory

predictive memory generates predictions and classifications using a hierarchical sequence/object cache.

Why

Prediction and classification can be implemented in low level neural networks (i.e. Numenta HTM). The goal of this module is to provide similar features, but do it faster while using less resources.

The long term goal is to expand and use this module in order to research cognition and perhaps consciousness.

How

This module provides a Predictor class that can process historical objects. It uses a Comparator to compare individual objects and sequences of those objects to other previously recorded sequences. The cache that is used to record sequences uses an internal hierarchy to quickly find similar key/value pairs in large amounts of historical data. In order to get balanced & weighted predictions, the second (or more) most similar cache result is used to weigh cache results whenever possible.

This module also provides support for text classification by providing a Classifier class. It uses the same type of hierarchical cache as the Predictor.

Installation

Via npm:

npm install predictive-memory

Usage

This module can be used both server and client side. Client side implementation can be done by loading predictive-memory.js as provided the root of the module. Please note that all class names in the client side implementation have been prefixed with 'Pm'.

Prediction

Server side example

See the example implementation in test/e2e/rec-center-hourly.js.

const { PredictorConfig, Predictor, PredictorAnalyzer } = require('predictive-memory');

const pc = new PredictorConfig();
const predictor = new Predictor(pc);

let prediction = null;
// Pass in any name and number of value properties
// Predictions will be generated when a minimal number of records have been processed
prediction = predictor.process({ dayOfWeek: 1, hourOfDay: 22, measuredValue: 5.5 });
prediction = predictor.process({ dayOfWeek: 1, hourOfDay: 23, measuredValue: 6.5 });
predictor.setPredict(true);
prediction = predictor.process({ dayOfWeek: 2, hourOfDay: 0, measuredValue: 1.5 });

// Optional methods to obtain predictor results (see PredictorConfig.maxPredictionHistorySize)
// const latestPrediction = predictor.predictions.get([0])[0];
// const results = predictor.getResults('measuredValue');

const analyzer = new PredictorAnalyzer();
const analysis = analyzer.analyze(predictor, ['measuredValue']);
console.log(analysis);

const predictionsForNext24Steps = predictor.generatePredictions(24);
console.log(predictionsForNext24Steps);

Client side example

See the example implementation in test/e2e/test.html.

<html>
    <head>
        <script src="predictive-memory.js"></script>
        <script type="text/javascript">
            const onload = () => {
                const pc = new PmPredictorConfig();
                const predictor = new PmPredictor(pc);
                for (let i = 0; i < 200; i++) {
                    predictor.process({k: i % 5, v: i % 10});
                    if (i > 10) {
                        predictor.setPredict(true);
                    }
                }
                const analyzer = new PmPredictorAnalyzer();
                const analysis = analyzer.analyze(predictor, ['v']);
                let str = JSON.stringify(analysis, null, 2);
                str = str.replace(/ /g, '&nbsp;');
                str = str.replace(/\n/g, '<br />');
                document.getElementById('analysis').innerHTML = str;
            };
        </script>
    </head>
    <body onload="onload()">
        <div id="analysis" />
    </body>
</html>

Classification

Server side example

See the example implementation in test/e2e/text-classification.js.

const { ClasifierConfig, Classifier, ClassifierAnalyzer } = require('predictive-memory');

const config = new ClassifierConfig();
const classifier = new Classifier(config);
// Record input for analyzer
classifier.setRecordInput(true);

classifier.put('String to associate1','Class to associate1');
classifier.put('String to associate2','Class to associate2');

const result classifier.classify('String to classify');
console.log(result.classifications);

const analyzer = new ClassifierAnalyzer();
const analysis = analyzer.analyze(classifier);
console.log(analysis);