{"name":"hidden-markov-model-tf","version":"3.0.0","license":"Apache-2.0","_id":"hidden-markov-model-tf@3.0.0","maintainers":[{"name":"addaleax","email":"anna@addaleax.net"},{"name":"admataz","email":"adam@admataz.com"},{"name":"alan.slater","email":"alan.slater@nearform.com"},{"name":"andreasmadsen","email":"amwebdk@gmail.com"},{"name":"chrisdwheatley","email":"chriswheatley87@gmail.com"},{"name":"cianfoley_nearform","email":"cian.foley@nearform.com"},{"name":"ckiss","email":"kissdevel@gmail.com"},{"name":"conoro","email":"conor@conoroneill.com"},{"name":"cuginoale","email":"alessio.carnevale@gmail.com"},{"name":"damianberesford","email":"dberesford@gmail.com"},{"name":"dancork-nf","email":"dan.cork@nearform.com"},{"name":"davidefiorello","email":"davide@codeflyer.com"},{"name":"davidmarkclements","email":"huperekchuno@googlemail.com"},{"name":"donovanhutchinson","email":"donovan.hutchinson@nearform.com"},{"name":"filippo.desantis","email":"filippo.desantis@gmail.com"},{"name":"goto-bus-stop","email":"renee@kooi.me"},{"name":"iamsw","email":"sjwilson89@gmail.com"},{"name":"jackdclark","email":"jack@jackdc.com"},{"name":"jasnell","email":"jasnell@gmail.com"},{"name":"jh3y","email":"jh3yyy@gmail.com"},{"name":"jimmymintzer","email":"jimmymintzer@gmail.com"},{"name":"joezo","email":"joezo156@googlemail.com"},{"name":"kamil-mech","email":"kamil.mech@nearform.com"},{"name":"lpww","email":"thomas.treffry@nearform.com"},{"name":"mafintosh","email":"mathiasbuus@gmail.com"},{"name":"matteo.collina","email":"hello@matteocollina.com"},{"name":"mattrobinson","email":"matt.robinson@nearform.com"},{"name":"mcdonnelldean","email":"mcdonnelldean@outlook.com"},{"name":"nearformer","email":"david.clements@nearform.com"},{"name":"ovhemert","email":"osmond@vanhemert.nu"},{"name":"shaunjbaker","email":"shaun@schb.co.uk"},{"name":"shogun_panda","email":"paolo@cowtech.it"},{"name":"simoneb","email":"simone.busoli@gmail.com"},{"name":"thekemkid","email":"glenkeane.94@gmail.com"},{"name":"wprl","email":"william@Kun.io"}],"homepage":"https://github.com/nearform/node-hidden-markov-model-tf#readme","bugs":{"url":"https://github.com/nearform/node-hidden-markov-model-tf/issues"},"dist":{"shasum":"4be9210df7d9a5a6f2bf03e847298777c82c53b9","tarball":"http://registry-npm.ywwl.com/hidden-markov-model-tf/download/hidden-markov-model-tf-3.0.0.tgz","fileCount":40,"integrity":"sha512-HvnuphQ21Q2zd0vhCuus3pZVCiIvarLbmWlz4tH0scjCOykYv11MKYu4gT7scwMxnvyAUNVgT6psWWwC0R/DXQ==","signatures":[{"sig":"MEUCIQD697q0RATOyFQHh792/ZsW0V5u9YOPu7uc/9DO6xuMPgIgWdg9NKCfGYU5JdC8GgmLScW4BXZblDxHHR40ESOOJOo=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":146521,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdDJ+yCRA9TVsSAnZWagAAAtgP/jZJCwI/+f55JB0ASMNK\njCv0zSoyoiH2cqoaj/s/P/XoIflGb9Ptir/76Wo11Z85Mfs2uIUV+c2nUMfG\nqVmmEYguuPv4zqy4rxY4ibmEKhsf2TAq2+NsW7To27syEnc5PyXEIWzJ8NhF\nGD5AK5IM3E/Okxwc4YLBx7eEGgwNMkc7l6l3vTv8pE/FIJs2DwUka42xUR1e\ngnqM5f8Ca7puOgUTuwqBhgirMWXAL8xwXy9S8jzsjbSXCsHy66WPtuXgzzpX\n3c/sSVhZlGYsK7H8kA/4MlFC1EjTHfNzpVdGLox/kRm4fM3+CbSYrqyGMQD+\nxzc8/jIn8ZMLXR6mxEBWcGGh9hAOSHpOM5KUoq/jhhth/20GaoqYe9FJd5Y1\n2YYgugwq8xC5t+RUiiI0onNQ7l6RF5DVp79/pH70rRqIm2g2wO7lVCh4q72P\nsL4V9ilxSk0y8ocopQE3s6IWZpOwnNf681rvsS69Nc7ldA/QjJJeaY/bML1q\nEmBd1rMPNqPsK+2aTzJh7hUs67nmpZBmI55SYmKc0GqLv2lNalJ79lA6FDAK\nvG1+fCfwLp2jjFBXJQmmb2/sp7LZXCJf+vw4YhHEnGwI3mueX3wlkFtXXKaJ\n2ssTYBlNVkT4IF46D5ziMUWnih/QzWGAMrRkYIlOb2Mmr3KLl9eJVLLKXfiQ\nOGwr\r\n=2I/c\r\n-----END PGP SIGNATURE-----\r\n","size":46420,"noattachment":false,"key":"/hidden-markov-model-tf/-/hidden-markov-model-tf-3.0.0.tgz"},"main":"index.js","gitHead":"814323d151debc2dd19dccf6ba99397044841508","scripts":{"lint":"standardx --fix","test":"tap test/*.test.js","test-ci":"tap --100 test/*.test.js"},"_npmUser":{"name":"andreasmadsen","email":"amwebdk@gmail.com"},"repository":{"url":"git+https://github.com/nearform/node-hidden-markov-model-tf.git","type":"git"},"_npmVersion":"6.9.0","description":"A trainable Hidden Markov Model with Gaussian emissions using TensorFlow.js","directories":{},"_nodeVersion":"13.0.0-pre","dependencies":{"semver":"^6.1.1","ndarray":"^1.0.18","ml-kmeans":"^4.0.1","seedrandom":"^3.0.1","ndarray-inv":"^0.2.0","ndarray-determinant":"^1.0.0","ndarray-cholesky-factorization":"^1.0.2"},"eslintConfig":{"rules":{"semi":["error","always"],"camelcase":0}},"_hasShrinkwrap":false,"devDependencies":{"tap":"^14.2.4","isndarray":"^1.0.0","standardx":"^3.0.0","ndarray-pack":"^1.2.1","test-allclose":"^1.1.0","ndarray-unpack":"^1.0.0","@tensorflow/tfjs-core":"^1.2.1","@tensorflow/tfjs-node":"^1.2.1"},"peerDependencies":{"@tensorflow/tfjs-core":"^1.2.1"},"_npmOperationalInternal":{"tmp":"tmp/hidden-markov-model-tf_3.0.0_1561108401988_0.07607813884401082","host":"s3://npm-registry-packages"},"readme":"# hidden-markov-model-tf\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/nearform/node-hidden-markov-model-tf.svg)](https://greenkeeper.io/)\n\n**A trainable Hidden Markov Model with Gaussian emissions using TensorFlow.js**\n\n## Install\n\n```\n$ npm install hidden-markov-model-tf\n```\n\nRequire: Node v12+\n\n## Usage\n\n```js\nconst assert = require('assert'):\nrequire('@tensorflow/tfjs-node'); // Optional, enable native TensorFlow backend\nconst tf = require('@tensorflow/tfjs');\nconst HMM = require('hidden-markov-model-tf');\n\nconst [observations, time, states, dimensions] = [5, 7, 3, 2];\n\n// Configure model\nconst hmm = new HMM({\n  states: states,\n  dimensions: dimensions\n});\n\n// Set parameters\nawait hmm.setParameters({\n  pi: tf.tensor([0.15, 0.20, 0.65]),\n  A: tf.tensor([\n    [0.55, 0.15, 0.30],\n    [0.45, 0.45, 0.10],\n    [0.15, 0.20, 0.65]\n  ]),\n  mu: tf.tensor([\n    [-7.0, -8.0],\n    [-1.5,  3.7],\n    [-1.7,  1.2]\n  ]),\n  Sigma: tf.tensor([\n    [[ 0.12, -0.01],\n     [-0.01,  0.50]],\n    [[ 0.21,  0.05],\n     [ 0.05,  0.03]],\n    [[ 0.37,  0.35],\n     [ 0.35,  0.44]]\n  ])\n});\n\n// Sample data\nconst sample = hmm.sample({observations, time});\nassert.deepEqual(sample.states.shape, [observations, time]);\nassert.deepEqual(sample.emissions.shape, [observations, time, dimensions]);\n\n// Your data must be a tf.tensor with shape [observations, time, dimensions]\nconst data = sample.emissions;\n\n// Fit model with data\nconst results = await hmm.fit(data);\nassert(results.converged);\n\n// Predict hidden state indices\nconst inference = hmm.inference(data);\nassert.deepEqual(inference.shape, [observations, time]);\nstates.print();\n\n// Compute log-likelihood\nconst logLikelihood = hmm.logLikelihood(data);\nassert.deepEqual(logLikelihood.shape, [observations]);\nlogLikelihood.print();\n\n// Get parameters\nconst {pi, A, mu, Sigma} = hmm.getParameters();\npi.print();\nA.print();\nmu.print();\nSigma.print();\n```\n\n## Documentation\n\n`hidden-markov-model-tf` is TensorFlow.js based, therefore your input must\nbe povided as a `tf.tensor`. Likewise most outputs are also provided as a\n`tf.tensor`. You can always get a `TypedArray` with `await tensor.data()`.\n\n### hmm = new HMM({states, dimensions})\n\nThe constructor takes two integer arguments. The number of hidden `states` and\nthe number of `dimensions` in the Gaussian emissions.\n\n### result = await hmm.fit(tensor, {maxIterations = 100, tolerance = 0.001, seed})\n\nThe `fit` method, takes an required `tf.tensor` object. That must have the\nshape `[observations, time, dimensions]`. If you only have one observation\nit should have the shape `[1, time, dimensions]`.\n\nThe `fit` method, returns a `Promise` for the `results`. The `results` is\nan object with the following properties:\n\n```js\nconst {\n   // the number of iterations used, will at most be `maxIterations`\n  iterations,\n\n   // if the training coverged, given the `tolerance`,\n   // before `maxIterations` was reached\n  converged,\n\n  // The achived tolerance, after the number of iterations. This can be\n  // useful if the optimizer did not converge, but you want to know how\n  // good the fit is.\n  tolerance\n} = await hmm.fit(tensor);\n```\n\nThe `fit` method uses a KMeans initialization. This initialization algorithm is\nrandom but can be seeded with the optional `seed` parameter.\n\nAfter initialization, the model is optimized using an EM-algorithm called\nthe [Baum–Welch algorithm](https://en.wikipedia.org/wiki/Baum%E2%80%93Welch_algorithm).\n\n### states = hmm.inference(tensor)\n\nThe `inference` method, takes an required `tf.tensor` object. That must have\nthe shape `[observations, time, dimensions]`.\n\nIt uses the [Viterbi algorithm](https://en.wikipedia.org/wiki/Viterbi_algorithm)\nfor infering the hidden state. Which is returned as `tf.tensor` with the\nshape `[observations, time]`.\n\n```js\nconst states = hmm.inference(tensor);\nstates.print();\nconsole.log(await states.data());\n```\n\n### logLikelihood = hmm.logLikelihood(tensor)\n\nThe `inference` method, takes an required `tf.tensor` object. That must have\nthe shape `[observations, time, dimensions]`.\n\nIt uses the forward procedure of the\n[Baum–Welch algorithm](https://en.wikipedia.org/wiki/Baum%E2%80%93Welch_algorithm)\nto compute the logLikelihood for each observation. This is returned as a\n`tf.tensor` with the shape `[observations]`.\n\n### {states, emissions} = hmm.sample({ observations, time, seed })\n\nThe `sample` method, samples data from the Hidden Markov Model distribution\nand returns both the sampled states and Gaussian emissions, as two `tf.tensor`\nobjects.\n\nthe `states` tensor has the shape `[observations, time]`. While the `emissions`\ntensor has the `shape` [observations, time, dimensions].\n\nThe sampling can be seed with the optional `seed` parameter.\n\n### {pi, A, mu, Sigma} = hmm.getParameters()\n\nReturn the underlying parameters:\n\n* `pi`: the hidden state prior distribution. `shape = [states]`\n* `A`: the hidden state transfer distribution. `shape = [states, states]`\n* `mu`: the mean of the Gaussian emission distribution. `shape = [states, dimensions]`\n* `Sigma`: the covariance matrix of the Gaussian emission distribution. `shape = [states, dimensions,  dimensions]`\n\n### await hmm.setParameters({pi, A, mu, Sigma})\n\nSet the underlying parameters of the Hidden Markov Model. Note that some\ninternal properties related to the Gaussian distribution will be precomputed.\nTherefore this returns a `Promise`. Be sure to wait for the promise to\nresolve before calling any other method.\n","publish_time":1561108402259,"_cnpm_publish_time":1561108402259,"dist-tags":{"latest":"4.0.0"}}