{"_id":"compute-cosine-similarity","_rev":"6-00d616284a691230d49e6b364dfbaf64","name":"compute-cosine-similarity","description":"Computes the cosine similarity between two arrays.","dist-tags":{"latest":"1.1.0"},"versions":{"1.0.0":{"name":"compute-cosine-similarity","version":"1.0.0","description":"Computes the cosine similarity between two arrays.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"},{"name":"Philipp Burckhardt","email":"pburckhardt@outlook.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/compute-io/cosine-similarity.git"},"keywords":["compute.io","compute","computation","similarity","information theory","distance","dist","array","vector","mathematics","math","geometry","algebra","linear algebra","cosine"],"bugs":{"url":"https://github.com/compute-io/cosine-similarity/issues"},"dependencies":{"compute-dot":"^1.1.0","compute-l2norm":"^1.1.0","validate.io-array":"^1.0.5","validate.io-function":"^1.0.2"},"devDependencies":{"chai":"2.x.x","mocha":"2.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"2.x.x","jshint-stylish":"^1.0.0"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"cfd970bb679cf591d3f4eff6568e98590e433541","homepage":"https://github.com/compute-io/cosine-similarity#readme","_id":"compute-cosine-similarity@1.0.0","_shasum":"29f2bf2e7baefa231caba40591a31c17b19a4e95","_from":".","_npmVersion":"2.8.4","_nodeVersion":"0.10.36","_npmUser":{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},"dist":{"shasum":"29f2bf2e7baefa231caba40591a31c17b19a4e95","tarball":"https://registry.npmjs.org/compute-cosine-similarity/-/compute-cosine-similarity-1.0.0.tgz","integrity":"sha512-jPdqVMT8Im6jS+THoDBDKZlGg32g7QeXOiBXeuiMXVEV5Tg8z38Qpvg08mt2qRy9j/H0m6w/VDoKBJ7w7F/sKg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGzqnU0ZL0NxJQ0cKQFDRP/IjbSLURY/1O/5ZHSozj76AiA3/v9j/Ujnwy4c5qx+hxkexM2jcdeZmkVlLJbMBDlpzA=="}]},"maintainers":[{"name":"planeshifter","email":"pgb@andrew.cmu.edu"}],"directories":{}},"1.1.0":{"name":"compute-cosine-similarity","version":"1.1.0","description":"Computes the cosine similarity between two arrays.","author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"types":"./types/index.d.ts","contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"},{"name":"Philipp Burckhardt","email":"pburckhardt@outlook.com"}],"scripts":{"test":"mocha","test-cov":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coverage -- -R spec","coveralls":"istanbul cover ./node_modules/.bin/_mocha --dir ./reports/coveralls/coverage --report lcovonly -- -R spec && cat ./reports/coveralls/coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./reports/coveralls"},"main":"./lib","repository":{"type":"git","url":"git://github.com/compute-io/cosine-similarity.git"},"keywords":["compute.io","compute","computation","similarity","information theory","distance","dist","array","vector","mathematics","math","geometry","algebra","linear algebra","cosine"],"bugs":{"url":"https://github.com/compute-io/cosine-similarity/issues"},"dependencies":{"compute-dot":"^1.1.0","compute-l2norm":"^1.1.0","validate.io-array":"^1.0.5","validate.io-function":"^1.0.2"},"devDependencies":{"chai":"2.x.x","mocha":"2.x.x","coveralls":"^2.11.1","istanbul":"^0.3.0","jshint":"2.x.x","jshint-stylish":"^1.0.0"},"licenses":[{"type":"MIT","url":"http://www.opensource.org/licenses/MIT"}],"gitHead":"b5703d5166766ba85c3c951324fe36a14283c8ac","homepage":"https://github.com/compute-io/cosine-similarity#readme","_id":"compute-cosine-similarity@1.1.0","_nodeVersion":"20.4.0","_npmVersion":"9.7.2","dist":{"integrity":"sha512-FXhNx0ILLjGi9Z9+lglLzM12+0uoTnYkHm7GiadXDAr0HGVLm25OivUS1B/LPkbzzvlcXz/1EvWg9ZYyJSdhTw==","shasum":"0086a06b0239deb90f231f0da894efdc48884609","tarball":"https://registry.npmjs.org/compute-cosine-similarity/-/compute-cosine-similarity-1.1.0.tgz","fileCount":5,"unpackedSize":9217,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDv/3yCSWM9bNOlPkOwip+5yNU60D09E7bd25AlT6pgdAiA43ZnKd2g38L+rcY4hmXQ6w8CG7iOmLfeABYKiw+nKGA=="}]},"_npmUser":{"name":"planeshifter","email":"pgb@andrew.cmu.edu"},"directories":{},"maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/compute-cosine-similarity_1.1.0_1694819756480_0.6281243493302402"},"_hasShrinkwrap":false}},"readme":"Cosine Similarity\n===\n[![NPM version][npm-image]][npm-url] [![Coverage Status][coveralls-image]][coveralls-url]\n\n> Computes the [cosine similarity](http://en.wikipedia.org/wiki/Cosine_similarity) between two arrays.\n\n[Cosine similarity](http://en.wikipedia.org/wiki/Cosine_similarity) defines vector similarity in terms of the angle separating two vectors.\n\n<div class=\"equation\" align=\"center\" data-raw-text=\"s(\\mathbf{x},\\mathbf{y}) = {\\mathbf{x} \\cdot \\mathbf{y} \\over \\|\\mathbf{x}\\| \\|\\mathbf{y}\\|} = \\frac{ \\sum\\limits_{i=0}^{n-1}{x_i y_i} }{ \\sqrt{\\sum\\limits_{i=0}^{n-1}{(x_i)^2}} \\times \\sqrt{\\sum\\limits_{i=0}^{n-1}{(y_i)^2}} }\" data-equation=\"eq:cosine_similarity\">\n\t<img src=\"https://cdn.rawgit.com/compute-io/cosine-similarity/bdef940bf4e6d320d2652b52f54f58cf2ea5d794/docs/img/eqn_similarity.svg\" alt=\"Cosine similarity formula\">\n\t<br>\n</div>\n\n\n## Installation\n\n``` bash\n$ npm install compute-cosine-similarity\n```\n\nFor use in the browser, use [browserify](https://github.com/substack/node-browserify).\n\n\n## Usage\n\n``` javascript\nvar similarity = require( 'compute-cosine-similarity' );\n```\n\n#### similarity( x, y[, accessor] )\n\nComputes the [cosine similarity](http://en.wikipedia.org/wiki/Cosine_similarity) between two `arrays`.\n\n\n``` javascript\nvar x = [ 5, 23, 2, 5, 9 ],\n    y = [ 3, 21, 2, 5, 14 ];\n\nvar s = similarity( x, y );\n// returns ~0.975\n```\n\nFor object `arrays`, provide an accessor `function` for accessing `numeric` values.\n\n``` javascript\nvar x = [\n\t{'x':2},\n\t{'x':4},\n\t{'x':5}\n];\n\nvar y = [\n\t[1,3],\n\t[2,1],\n\t[3,5]\n];\n\nfunction getValue( d, i, j ) {\n\tif ( j === 0 ) {\n\t\treturn d.x;\n\t}\n\treturn d[ 1 ];\n}\n\nvar s = similarity( x, y, getValue );\n// returns ~0.882\n```\n\nThe accessor `function` is provided three arguments:\n\n-\t__d__: current datum.\n-\t__i__: current datum index.\n-\t__j__: array index; e.g., array `x` has index `0`, and array `y` has index `1`.\n\n\nIf provided empty `arrays`, the function returns `null`.\n\n\n\n## Examples\n\n``` javascript\nvar similarity = require( 'compute-cosine-similarity' );\n\nvar x = new Array( 100 ),\n\ty = new Array( 100 ),\n\ts;\n\nfor ( var i = 0; i < x.length; i++ ) {\n\tx[ i ] = Math.round( Math.random()*100 );\n\ty[ i ] = Math.round( Math.random()*100 );\n}\ns = similarity( x, y );\n\nconsole.log( s );\n```\n\nTo run the example code from the top-level application directory,\n\n``` bash\n$ node ./examples/index.js\n```\n\n\n## Tests\n\n### Unit\n\nUnit tests use the [Mocha](http://mochajs.org/) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:\n\n``` bash\n$ make test\n```\n\nAll new feature development should have corresponding unit tests to validate correct functionality.\n\n\n### Test Coverage\n\nThis repository uses [Istanbul](https://github.com/gotwarlost/istanbul) as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:\n\n``` bash\n$ make test-cov\n```\n\nIstanbul creates a `./reports/coverage` directory. To access an HTML version of the report,\n\n``` bash\n$ make view-cov\n```\n\n\n---\n## License\n\n[MIT license](http://opensource.org/licenses/MIT). \n\n\n## Copyright\n\nCopyright &copy; 2015. The Compute.io Authors. All rights reserved.\n\n\n[npm-image]: http://img.shields.io/npm/v/compute-cosine-similarity.svg\n[npm-url]: https://npmjs.org/package/compute-cosine-similarity\n\n[coveralls-image]: https://img.shields.io/coveralls/compute-io/cosine-similarity/master.svg\n[coveralls-url]: https://coveralls.io/r/compute-io/cosine-similarity?branch=master\n\n[github-issues-image]: http://img.shields.io/github/issues/compute-io/cosine-similarity.svg\n[github-issues-url]: https://github.com/compute-io/cosine-similarity/issues\n","maintainers":[{"name":"kgryte","email":"kgryte@gmail.com"},{"name":"planeshifter","email":"pgb@andrew.cmu.edu"}],"time":{"modified":"2023-09-15T23:15:56.874Z","created":"2015-05-12T03:29:55.725Z","1.0.0":"2015-05-12T03:29:55.725Z","1.1.0":"2023-09-15T23:15:56.693Z"},"homepage":"https://github.com/compute-io/cosine-similarity#readme","keywords":["compute.io","compute","computation","similarity","information theory","distance","dist","array","vector","mathematics","math","geometry","algebra","linear algebra","cosine"],"repository":{"type":"git","url":"git://github.com/compute-io/cosine-similarity.git"},"contributors":[{"name":"Athan Reines","email":"kgryte@gmail.com"},{"name":"Philipp Burckhardt","email":"pburckhardt@outlook.com"}],"author":{"name":"Athan Reines","email":"kgryte@gmail.com"},"bugs":{"url":"https://github.com/compute-io/cosine-similarity/issues"},"readmeFilename":"README.md","users":{"ninozhang":true}}