New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cognitive-js

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

cognitive-js - npm Package Compare versions

Comparing version 1.0.7 to 1.1.0

__test__/fixtures/linear-regression.fixtures.js

4

__test__/base.test.js

@@ -1,4 +0,4 @@

import { compose, sFn, isSquare, swap, sFill } from "../lib/base"
import { compose, sFn, isSquare, swap, sFill } from '../lib/base'
test("base", () => {
test('base', () => {
expect(

@@ -5,0 +5,0 @@ compose(

@@ -10,3 +10,7 @@ import {

divide,
abs
abs,
zeros,
random,
dot,
fill
} from '../lib/data-frame'

@@ -94,1 +98,40 @@

})
test('zeros', () => {
expect(zeros(1, 2)).toEqual([[0, 0]])
expect(zeros(2, 3)).toEqual([
[0, 0, 0],
[0, 0, 0]
])
})
test('random', () => {
expect(random(1, 2)[0].length).toEqual(2)
expect(random(2, 3)[0].length).toEqual(3)
expect(random(2, 3).length).toEqual(2)
})
test('dot', () => {
expect(
dot(
[[0.5488135039273248], [0.7151893663724195]],
[[0.10549716166494752], [0.10549716166494752]]
)
).toEqual([[0.05789826694772729], [0.07545044820524252]])
expect(dot([3, 4, 5], [7, 8, 9])).toEqual(98)
expect(dot(2, 3)).toEqual(6)
expect(
dot([[0.5488135039273248], [0.7151893663724195]], 0.10549716166494752)
).toEqual([[0.05789826694772729], [0.07545044820524252]])
expect(
dot([[0.5488135039273248], [0.7151893663724195]], [[0.10549716166494752]])
).toEqual([[0.05789826694772729], [0.07545044820524252]])
})
test('fill', () => {
expect(fill(1, 3)).toEqual([1, 1, 1])
})

@@ -1,7 +0,6 @@

import { determinant } from "../lib/algorithms/determinant"
import { determinant } from '../lib/algorithms/determinant'
test("base", () => {
test('base', () => {
expect(
determinant([[1,2,3], [1,2,3]])
determinant([[1, 2, 3], [1, 2, 3]])
).toEqual(0)

@@ -8,0 +7,0 @@

@@ -1,7 +0,7 @@

import { sDouble, sReverse } from "../lib/series"
import { sDouble, sReverse } from '../lib/series'
test("base", () => {
test('base', () => {
expect(sDouble([1, 2])).toEqual([2, 4])
expect(sReverse([1, 2])).toEqual([2, 1])
})

@@ -23,11 +23,11 @@ import _ from 'lodash'

export const rot = _.memoize((x) =>
export const transpose = _.memoize((x) =>
_.map(_.first(x), (_v, i) => _.reverse(_.map(x, (r) => r[i])))
)
export const rotC = _.memoize((x) =>
export const inverseTranspose = _.memoize((x) =>
_.map(_.first(x), (_v, i) => _.map(x, (r) => r[_.size(r) - 1 - i]))
)
export const shape = _.memoize((x) => [_.size(x), _.size(rot(x))])
export const shape = _.memoize((x) => [_.size(x), _.size(transpose(x))])

@@ -37,1 +37,9 @@ export const isSquare = _.memoize(

)
export const isSameShape = (x, y) =>
_.get(shape(x), 0) === _.get(shape(y), 0) &&
_.get(shape(x), 1) === _.get(shape(y), 1)
export const is1d = (x) => _.get(shape(x), 0) === 1
// implement train test split random based on test size.

@@ -0,20 +1,70 @@

import _ from 'lodash'
import * as b from '../base'
import * as s from '../series'
export const mean = (x) => b.compose(b.rot, (x) => b.sFn(x, s.sMean), b.rotC)(x)
export const mean = (x) =>
b.compose(b.transpose, (x) => b.sFn(x, s.sMean), b.inverseTranspose)(x)
export const sqrt = (x) => b.compose(b.rot, (x) => b.sFn(x, s.sSqrt), b.rotC)(x)
export const sqrt = (x) =>
b.compose(b.transpose, (x) => b.sFn(x, s.sSqrt), b.inverseTranspose)(x)
export const stddev = (x) => b.compose(b.rot, (x) => b.sFn(x, s.sStd))(x)
export const stddev = (x) => b.compose(b.transpose, (x) => b.sFn(x, s.sStd))(x)
export const cumSum = (x) => b.compose(b.rotC, (x) => b.sFn(x, s.sCumSum), b.rot)(x)
export const cumSum = (x) =>
b.compose(b.inverseTranspose, (x) => b.sFn(x, s.sCumSum), b.transpose)(x)
export const add = (x) => b.compose(b.rot, (x) => b.sFn(x, s.sAdd))(x)
export const add = (x) => b.compose(b.transpose, (x) => b.sFn(x, s.sAdd))(x)
export const subtract = (x) => b.compose(b.rot, (x) => b.sFn(x, s.sSubtract))(x)
export const subtract = (x) =>
b.compose(b.transpose, (x) => b.sFn(x, s.sSubtract))(x)
export const divide = (x) => b.compose(b.rot, (x) => b.sFn(x, s.sDivide))(x)
export const divide = (x) =>
b.compose(b.transpose, (x) => b.sFn(x, s.sDivide))(x)
export const multiply = (x) => b.compose(b.rot, (x) => b.sFn(x, s.sMultiply))(x)
export const multiply = (x) =>
b.compose(b.transpose, (x) => b.sFn(x, s.sMultiply))(x)
export const abs = (x) => b.sFn(x, s.sAbs)
export const fill = (i, t) => _.fill(Array(t), i)
export const zeros = (r, c) => _.map(_.times(r, () => s.sZeros(c)))
export const random = (r, c, min, max) =>
_.map(_.times(r, () => s.sRandom(c, min, max)))
export const pow = (x, p) => b.sFn(x, (x) => s.sPow(x, p))
export const dot = (x, y) => {
if (_.isNumber(x) && _.isNumber(y)) {
return s.sMultiply([x, y])
}
if (_.get(b.shape(x), 1) === 0 && _.get(b.shape(y), 1) === 0) {
return _.sum(multiply([x, y]))
}
if (b.is1d(x) && b.is1d(y)) {
return _.sum(multiply([x[0], y[0]]))
}
if (b.isSameShape(x, y)) {
return _.map(multiply([x, y]), (xy) => [xy])
}
if (_.isNumber(y) && _.get(b.shape(x), 1) === 1) {
return _.map(
multiply([x, _.fill(Array(_.get(b.shape(x), 0)), y)]),
(xy) => [xy]
)
}
if (b.is1d(y) && _.get(b.shape(x), 1) === 1) {
return _.map(
multiply([x, _.fill(Array(_.get(b.shape(x), 0)), _.get(y, [0, 0]))]),
(xy) => [xy]
)
}
return undefined
}

@@ -11,3 +11,3 @@ import _ from 'lodash'

export const sDivide = (ns, x) => _.reduce(ns, (a, b) => a / b)
export const sDivide = (ns) => _.reduce(ns, (a, b) => a / b)

@@ -27,2 +27,6 @@ export const sMultiply = (ns) => _.reduce(ns, (a, b) => a * b)

export const sZeros = (n) => _.fill(Array(n), 0, 0)
export const sRandom = (n, min = 0, max = 1) => _.fill(Array(n), _.random(min, max, true))
export const sCumSum = (ns) =>

@@ -36,1 +40,3 @@ _.map(

)
export const sPow = (ns, p) => _.map(ns, (x) => x ** p)
{
"name": "cognitive-js",
"version": "1.0.7",
"version": "1.1.0",
"description": "",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc