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

sirrobert-vector-hd

v1.0.0

Published

A high-definition vector library.

Downloads

5

Readme

Overview

A module for working with high-dimensionality vectors (hence "vectors-hd") in JavaScript.

I have successfully used this class in projects requiring:

  • vectors with 5,000+ dimensions
  • billions of rows of data
  • various clustering methods (k-means/medoids, etc.).

Installation

npm install sirrobert-vector-hd

Usage

Creating "degenerate" vectors

Degenerate vectors are vector objects without any dimensionality. They have lots of uses including constructing vectors piecemeal.

var vector = new Vector();

Creating populated vectors

Creating a vector with a pre-existing vector list is easy as well.

var dimensions = {x:238, y:8372, z:18};
var vector = new Vector({coords: dimensions});

Vector inspection

The module provides a set of tools for looking at the vectors. The following list of methods help understand what your vector looks like.

  • You can directly examine (or manipulate) a dimension this way:

    var vector = new Vector({coords: {"x": 2, "my-dim":3}});

    vector.coords.x == 2 // true vector.coords['my-dim'] == 4 // true

    vector.coords.x = 1238; // set .x to 1238 vector.coords['my-dim'] = 193 // set .my-dim to 193

    vector.hasDimension('my-dim') // true vector.hasDimension('fake') // false

Object accessors

get #dimensions

get #distanceMethod

set #distanceMethod

Object methods

#add()

#hasDimensions()

#removeDimension()

#removeDimensions()

#addDimension()

#addDimensions()

#reduceTo()

#reduceBy()

#is()

#toString()

#fromString()

#distanceTo()

#randomize()

Class methods

#distance()

#random()

#mean()

#dimensionalHistorgram()

#addDistanceFunction()

Creating random vectors

Random vectors are useful for things like generating clustering seeds. There are two ways to get a random vector.

In order to generate a random vector dimension, you need to give it a scale. Scales are interpreted as origin-centered. That means if you use a scale of 2000, the new value will be randomly selected between -2000 to +2000.

Randomizing an existing vector (in part or in toto)

Take an existing vector and randomize parts of it.

var dimensions = {x:238, y:8372, z:18};
var vector = new Vector({coords: dimensions});

Now randomize the "x" value.

// The new value of 'x' will be from -1000 to +1000
vector.randomize('x', -1000);

You can also randomize multiple dimensions at once.

// Randomize .y and .z between -1500 to +1500.
vector.randomize(['y','z'], 1500);

Getting a new random vector

You can also generate a new, fully random vector with the class method #random().

// Creates a 4D vector with each value from -2500 to 2500
var vector = Vector.random(['x','y','z','a'], 2500);

TO DO

Unit Tests

Right now the random functions are tested only for range validity (and definiedness). These should be enhanced with a distribution test to ensure that we're getting a good distribution within the permitted range.

Documentation

Obviously I need to finish the documentation!

A note on the module namespace (sirrobert-)

The 'sirrobert-' module prefix is a staging namespace for my modules I am testing with a small group of people. It will be moved to a general namespace (for example, the sirrobert- prefix removed).