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

topsis

v1.3.2

Published

This is an implementation of TOPSIS algorithm for multi-criteria decision-making and prescriptive analytics.

Downloads

44

Readme


const linearAlgebra = require('linear-algebra')();
const Matrix = linearAlgebra.Matrix; `
	
const topsis = require('topsis');

Topsis

Codacy Badge npm version build Coverage Status Known Vulnerabilities dependencies Status GitHub license Greenkeeper badge

This is the first npm library in NodeJS to implement TOPSIS (Technique for Order of Preference by Similarity to Ideal Solution). This library is fully open-source and free to use. TOPSIS is an algorithm developed in 1981 by Hwang and Yoon. It is a technique commonly utilised in the field of operations research, managerial accounting, decision science and prescriptive analytics for multi-attribute decision-making problems (MADC). Its most common use case is to select the optimal choice from an array of alternatives with conflicting criteria. (For instance, to select a celphone to buy that have the highest quality camera at the lowest price). The central idea behind the algorithm is that the most desirable solution is the one that has the highest geometric distance (euclidean distance) to the anti-ideal solution and the lowest euclidean distance to the ideal solution.

Installation

npm i topsis

Example Usage

let m = new Matrix([
                    [2, 5, 5], 
                    [60, 26, 4], 
                    [20, 20, 4],  
                    [500, 2, 4], 
                    [50, 23, 3], 
                    [25, 10, 1]
                    ]); 
// m argument is the alternative matrix. Each row is an alternative and each column is a criterion.
                    
let w = [0.27,0.33,0.40];  // This argument indicates the weights of each criteria.
let ia = ['min', 'min', 'max']; // This argument indicates if a criterion is beneficial or not.


topsis.getBest(m, w, ia);

Returns:

[2, 5, 5]

DEMO

https://runkit.com/patelotech/runkit-npm-topsis

Documentation

| Argument | Description | Mandatory | Type | Rules | |:-------------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:----------:|:-----------------------:|:----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:| | m | m argument stands for 'alternative matrix' and is a matrix that contains the data from all alternatives. Columns are criteria and rows are alternatives. | True | Matrix of numeric data | This argument MUST be a matrix object from linear-algebra module and MUST contain only numeric data. | | w | w argument stands for 'weights argument' or also known as eigenvector and this is the argument that indicates the weighting of each criterion. | True | Array of float numbers. | This argument MUST have the exact same length than the number of columns that the alternative matrix has. Each weight MUST be a number from 0 to 1 and all weights MUST sum 1. | | ia | ia argument stands for 'impact argument' and this is the argument that indicates which criteria is beneficial and which is not. So which ones we want to minimise and which ones we want to maximise. | True | Array of strings. | This argument MUST have the exact same length than the number of columns that the alternative matrix has. All of the elements of the array MUST be strings containing the string 'max' or 'min' accordingly. |

NOTE: Make sure to read through bibliography below of TOPSIS to understand how the algorithm works.

Algorithm Steps

  1. Computing normalised alternative matrix. (Alternative matrix divided by calculated norm of each column).
  2. Computing weighted normalised alternative matrix. (Alternative matrix multiplied by eigenvector).
  3. Calculating the ideal solution. (An hypothetical alternative that maximises benefits and minimises costs the most).
  4. Calculating the anti-ideal solution. (An hypothetical alternative that minimises benefits and maximises costs the most).
  5. For each alternative in the weighted normalised alternative matrix, calculate the euclidean distance to the ideal and anti-ideal solution.
  6. Calculate a performance score for each alternative. (Distance to the anti-ideal solution divided by the sum of the distance of the ideal and anti-ideal solution).
  7. Rank in descending order performance scores for each alternative.
  8. Return the top-one.

Aditional functions...

CreateRandom

topsis.createRandom(); // Creates random arguments for a topsis.getBest function.

Returns:

{ 
  m : 
    { data:
     [ [ 478, 6, 184, 1000 ],
       [ 805, 34, 703, 770 ],
       [ 216, 210, 294, 225 ],
       [ 857, 253, 396, 63 ],
       [ 244, 652, 886, 736 ],
       [ 378, 824, 948, 769 ],
       [ 298, 76, 573, 604 ] ],
      rows: 7,
      cols: 4 
    },
  w: [ 0.52, 0.26, 0.04, 0.18 ],
  ia: [ 'max', 'min', 'max', 'max' ]
}

Package roadmap

  • [x] TOPSIS.
  • [x] Support for Linear-Algebra matrices.
  • [ ] Support for MathJS matrices.
  • [ ] (FTOPSIS) Fuzzy TOPSIS
  • [ ] (IFTOPSIS) Intuisionistic Fuzzy TOPSIS
  • [ ] (NTOPSIS) Neutrosophic TOPSIS

Package Dependencies

  • linear-algebra

License

MIT

Contributing

https://github.com/patelotech/topsis

Linting

Configuration

  • Eslint v-4.19.1 // AIRBNB Configuration

Linting scripts

  • Error check: npm run check
  • Error fix: npm run lint or npm run lint -- --fix

Bibliography

  • Hwang, C. L., & Yoon, K. (1981). Methods for multiple attribute decision making. In Multiple attribute decision making (pp. 58-191).Springer, Berlin, Heidelberg. cd do cd do