Launch Week Day 4: Introducing Data Exports.Learn More
Socket
Book a DemoSign in
Socket

association

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

association - npm Package Compare versions

Comparing version
1.0.1
to
1.0.2
+41
-27
.idea/workspace.xml

@@ -31,4 +31,4 @@ <?xml version="1.0" encoding="UTF-8"?>

<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="7.740741" vertical-offset="404" max-vertical-offset="840">
<caret line="13" column="8" selection-start-line="13" selection-start-column="8" selection-end-line="13" selection-end-column="8" />
<state vertical-scroll-proportion="-6.703704" vertical-offset="569" max-vertical-offset="1080">
<caret line="50" column="17" selection-start-line="50" selection-start-column="17" selection-end-line="50" selection-end-column="17" />
<folding />

@@ -52,4 +52,4 @@ </state>

<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.8" vertical-offset="0" max-vertical-offset="435">
<caret line="13" column="2" selection-start-line="13" selection-start-column="2" selection-end-line="13" selection-end-column="2" />
<state vertical-scroll-proportion="-4.8" vertical-offset="0" max-vertical-offset="510">
<caret line="8" column="12" selection-start-line="8" selection-start-column="12" selection-end-line="8" selection-end-column="12" />
<folding />

@@ -70,4 +70,4 @@ </state>

<list>
<option value="$PROJECT_DIR$/tester.js" />
<option value="$PROJECT_DIR$/index.js" />
<option value="$PROJECT_DIR$/tester.js" />
<option value="$PROJECT_DIR$/package.json" />

@@ -141,2 +141,3 @@ </list>

<property name="options.splitter.details.proportions" value="0.2" />
<property name="LayoutCode.rearrangeEntriesECMAScript 6" value="false" />
</component>

@@ -161,6 +162,11 @@ <component name="RunManager">

</configuration>
<configuration default="true" type="PhpUnitRemoteRunConfigurationType" factoryName="PHPUnit on Server">
<configuration default="true" type="js.build_tools.gulp" factoryName="Gulp.js">
<node-options />
<gulpfile />
<tasks />
<pass-parent-env-vars>false</pass-parent-env-vars>
<envs />
<method />
</configuration>
<configuration default="true" type="js.build_tools.gulp" factoryName="Gulp.js">
<configuration default="true" type="PhpUnitRemoteRunConfigurationType" factoryName="PHPUnit on Server">
<method />

@@ -184,22 +190,22 @@ </configuration>

<layout>
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32739726" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32739726" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Remote Host" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Remote Host" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.23263328" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
</layout>

@@ -209,3 +215,3 @@ <layout-to-restore>

<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.32876712" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.32739726" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />

@@ -224,6 +230,6 @@ <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />

<window_info id="Application Servers" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24071082" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.23263328" sideWeight="0.5" order="1" side_tool="false" content_ui="combo" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
</layout-to-restore>

@@ -254,4 +260,4 @@ </component>

<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="7.740741" vertical-offset="404" max-vertical-offset="840">
<caret line="13" column="8" selection-start-line="13" selection-start-column="8" selection-end-line="13" selection-end-column="8" />
<state vertical-scroll-proportion="0.0" vertical-offset="0" max-vertical-offset="840">
<caret line="0" column="0" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
<folding />

@@ -263,4 +269,4 @@ </state>

<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-7.8" vertical-offset="0" max-vertical-offset="435">
<caret line="13" column="2" selection-start-line="13" selection-start-column="2" selection-end-line="13" selection-end-column="2" />
<state vertical-scroll-proportion="-4.8" vertical-offset="0" max-vertical-offset="510">
<caret line="8" column="12" selection-start-line="8" selection-start-column="12" selection-end-line="8" selection-end-column="12" />
<folding />

@@ -270,2 +276,10 @@ </state>

</entry>
<entry file="file://$PROJECT_DIR$/index.js">
<provider selected="true" editor-type-id="text-editor">
<state vertical-scroll-proportion="-6.703704" vertical-offset="569" max-vertical-offset="1080">
<caret line="50" column="17" selection-start-line="50" selection-start-column="17" selection-end-line="50" selection-end-column="17" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/package.json">

@@ -272,0 +286,0 @@ <provider selected="true" editor-type-id="text-editor">

+45
-30

@@ -1,26 +0,40 @@

var association = function(config) {
var association = function (config) {
config = config || {}
this.sim = (config.formula === 'pearson') ? this.correlation : this.distance
};
module.exports = association;
association.prototype.distance = function(mapOne,mapTwo) {
association.prototype.compareAll = function (n, map, myMap) {
var ar = [];
for (var key in map) {
ar.push({key: key, score: this.sim(map[key], myMap)})
}
ar.sort(function (a, b) {
if (a.score > b.score) {
return 1;
}
if (a.score < b.score) {
return -1;
}
// a must be equal to b
return 0;
});
ar.reverse();
return ar.splice(0, n);
};
association.prototype.distance = function (mapOne, mapTwo) {
var sumofSq = 0;
var sim = {};
for(var key in mapOne) {
if(key in mapTwo) {
for (var key in mapOne) {
if (key in mapTwo) {
sim[key] = true;
}
}
if(Object.keys(sim).length === 0) {
if (Object.keys(sim).length === 0) {
return sumofSq;
}
for(var i in sim) {
sumofSq += Math.pow(mapOne[i] - mapTwo[i],2)
for (var i in sim) {
sumofSq += Math.pow(mapOne[i] - mapTwo[i], 2)
}
return 1/(1+Math.sqrt(sumofSq))
return 1 / (1 + Math.sqrt(sumofSq))
};
association.prototype.correlation = function(mapOne,mapTwo) {
association.prototype.correlation = function (mapOne, mapTwo) {
var sumOne = 0;

@@ -31,22 +45,23 @@ var sumTwo = 0;

var productSum = 0;
var sim = {};
for(var key in mapOne) {
if(key in mapTwo) {
for (var key in mapOne) {
if (key in mapTwo) {
sim[key] = true;
}
}
for(var k in sim) {
sumOne += mapOne[k];
sumTwo += mapTwo[k];
sum1Sq += Math.pow(mapOne[k],2);
sum2Sq += Math.pow(mapTwo[k],2);
productSum += (mapOne[k]*mapTwo[k]);
for (var k in sim) {
sumOne += mapOne[k];
sumTwo += mapTwo[k];
sum1Sq += Math.pow(mapOne[k], 2);
sum2Sq += Math.pow(mapTwo[k], 2);
productSum += (mapOne[k] * mapTwo[k]);
}
var i = Object.keys(sim).length;
var n = productSum - (sumOne*sumTwo/i);
var d = Math.sqrt((sum1Sq - Math.pow(sumOne,2)/i) * (sum2Sq - Math.pow(sumTwo,2)/i))
if(d === 0) {return 0}
return (n/d)
};
var n = productSum - (sumOne * sumTwo / i);
var d = Math.sqrt((sum1Sq - Math.pow(sumOne, 2) / i) * (sum2Sq - Math.pow(sumTwo, 2) / i))
if (d === 0) {
return 0
}
return (n / d)
};
module.exports = association;
{
"name": "association",
"version": "1.0.1",
"version": "1.0.2",
"description": "An association lib that will find an things closest associations and give helper methods to do some other interesting things",

@@ -5,0 +5,0 @@ "main": "index.js",

var blah = require('./index.js')
var a = new blah;
var a = new blah({
formula: 'pearson'
});
var jordan = {

@@ -21,4 +23,7 @@ movieOne:4.1,

};
console.log(a.correlation(randy,alec));
console.log(a.distance(randy,alec));
var obj = {
alec:alec,
randy:randy
}
console.log(a.compareAll(2,obj,jordan));