项目作者: petoem

项目描述 :
simple smoothing of one dimensional arrays
高级语言: JavaScript
项目地址: git://github.com/petoem/taira.git
创建时间: 2017-03-21T08:29:07Z
项目社区:https://github.com/petoem/taira

开源协议:MIT License

下载


taira

simple smoothing of one dimensional arrays

GitHub release
CI
Standard - JavaScript Style Guide
GitHub license

NPM

About

Taira enables smoothing of arrays that contain numerical values, using average (mean), median and gaussian filter.

Usage

  1. const Taira = require('taira')
  2. let arr = [1, 2, 10, 4, 5, 6]
  3. /**
  4. * Static smooth function
  5. * @param {*} array The input data array
  6. * @param {Taira.ALGORITHMS} algorithm The algorithm to use
  7. * @param {integer} size How many elements before and after (e.g. size=2, means a kernel of 2*size+1)
  8. * @param {integer} pass How often to go over the array
  9. * @param {boolean} circular Joins beginning and end of array, to make the array circular
  10. * @returns {Taira} The smooth array
  11. */
  12. let foo = Taira.smoothen(arr, Taira.ALGORITHMS.AVERAGE, 1, 1, false)
  13. console.log(foo) // [ 1, 4.333333333333333, 5.333333333333333, 6.333333333333333, 5, 6 ]
  14. // ... and the same for median filtering
  15. foo = Taira.smoothen(arr, Taira.ALGORITHMS.MEDIAN, 2, 1, false)
  16. console.log(`${arr} => ${foo}`) // [1, 2, 10, 4, 5, 6] => [ 1, 2, 4, 5, 5, 6 ]
  17. /*
  18. * ... and gaussian smoothing.
  19. * First integer is the size of the kernel that will be filled with values from a Gaussian distribution.
  20. * Last parameter is the intensity (sigma) of the distribution.
  21. */
  22. foo = Taira.smoothen(arr, Taira.ALGORITHMS.GAUSSIAN, 2, 0.65, false)
  23. console.log(`${arr} => ${foo}`) // [ 1, 2, 10, 4, 5, 6 ] => [ 1, 2, 7.294375204741146, 5.315049255808814, 5, 6 ]

Extras

Taira inherits from Array, so you can use it like a normal array.

  1. const Taira = require('taira')
  2. let foo = new Taira(1, 2, 3, 4, 5, 6)
  3. let bar = foo.smoothen(Taira.ALGORITHMS.GAUSSIAN, 2, 1.2)
  4. foo.push(10) // ... lets add some more data and recalculate.
  5. bar = foo.smoothen(Taira.ALGORITHMS.GAUSSIAN, 2, 1.2)
  6. // ... or you could do something like this.
  7. let smoothsum = Taira.from([10, 20, 10, 15, 20, 15])
  8. .smoothen(Taira.ALGORITHMS.GAUSSIAN, 2, 0.3)
  9. .reduce((acc, val) => acc + val)
  10. console.log(smoothsum) // 90.05754388528676

Contributing

If you wish to contribute to the code or documentation, feel free to fork the repository and submit a pull request.

License

MIT © Michael Petö