Skip to content

Commit

Permalink
Merge pull request #7 from vikdoro/devs
Browse files Browse the repository at this point in the history
Add HMM and quantizer
  • Loading branch information
Paul Varache authored Feb 19, 2018
2 parents 000e058 + 0d53ac5 commit b2ad26a
Show file tree
Hide file tree
Showing 15 changed files with 838 additions and 42 deletions.
4 changes: 2 additions & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Copyright (c) 2017 Kano Computing
Copyright (c) 2015 Fabian Canas
Author of the GRT library: Nick Gillian
Copyright (c) 2015 Fabian Canas (author of the node-native-boilerplate)
Copyright (c) 2012 Nicholas Gillian, Media Lab (MIT author of the GRT library)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
14 changes: 0 additions & 14 deletions NativeExtension.cc

This file was deleted.

4 changes: 2 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"targets": [
{
"target_name": "NativeExtension",
"target_name": "GRT",
"cflags_cc": ["-std=c++11", "-fexceptions", "-frtti"],
"sources": [ "NativeExtension.cc", "src/NodeTimeSeriesClassificationData.cc", "src/NodeDTW.cc" ],
"sources": ["src/GRT.cc", "src/NodeTimeSeriesClassificationData.cc", "src/NodeDTW.cc", "src/NodeHMM.cc", "src/NodeKMeansQuantizer.cc"],
"include_dirs" : [
"<!(node -e \"require('nan')\")",
"./include",
Expand Down
2 changes: 0 additions & 2 deletions include/NodeDTW.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include <nan.h>
#include <GRT/GRT.h>

// Example with node ObjectWrap
// Based on https://nodejs.org/api/addons.html#addons_wrapping_c_objects but using NAN
class NodeDTW : public Nan::ObjectWrap {
public:
static NAN_MODULE_INIT(Init);
Expand Down
31 changes: 31 additions & 0 deletions include/NodeHMM.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef NODE_HMM_H
#define NODE_HMM_H

#include <nan.h>
#include <GRT/GRT.h>

class NodeHMM : public Nan::ObjectWrap {
public:
static NAN_MODULE_INIT(Init);

private:
explicit NodeHMM();
~NodeHMM();

static NAN_METHOD(New);
static NAN_METHOD(Train);
static NAN_METHOD(SetHMMType);
static NAN_METHOD(SetNumStates);
static NAN_METHOD(SetNumSymbols);
static NAN_METHOD(SetModelType);
static NAN_METHOD(SetMinChange);
static NAN_METHOD(SetMaxNumEpochs);
static NAN_METHOD(SetNumRandomTrainingIterations);
static NAN_METHOD(Predict);
static NAN_METHOD(GetPredictedClassLabel);
static NAN_METHOD(GetClassLikelihoods);
static Nan::Persistent<v8::Function> constructor;
GRT::HMM *hmm;
};

#endif
26 changes: 26 additions & 0 deletions include/NodeKMeansQuantizer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef NODE_K_MEANS_QUANTIZER_H
#define NODE_K_MEANS_QUANTIZER_H

#include <nan.h>
#include <GRT/GRT.h>

class NodeKMeansQuantizer : public Nan::ObjectWrap {
public:
static NAN_MODULE_INIT(Init);

private:
explicit NodeKMeansQuantizer();
explicit NodeKMeansQuantizer(const uint numClusters);
~NodeKMeansQuantizer();

static NAN_METHOD(New);
static NAN_METHOD(Train);
static NAN_METHOD(Quantize);
static NAN_METHOD(GetFeatureVector);
static NAN_METHOD(Clear);

static Nan::Persistent<v8::Function> constructor;
GRT::KMeansQuantizer *kmeansquantizer;
};

#endif
3 changes: 1 addition & 2 deletions include/NodeTimeSeriesClassificationData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
#include <nan.h>
#include <GRT/GRT.h>

// Example with node ObjectWrap
// Based on https://nodejs.org/api/addons.html#addons_wrapping_c_objects but using NAN
class NodeTimeSeriesClassificationData : public Nan::ObjectWrap {
public:
static NAN_MODULE_INIT(Init);
GRT::TimeSeriesClassificationData* getTimeSeriesClassificationData();

private:
explicit NodeTimeSeriesClassificationData();
explicit NodeTimeSeriesClassificationData(const uint numDimensions);
~NodeTimeSeriesClassificationData();

static NAN_METHOD(New);
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,10 @@
var NativeExtension = require('bindings')('NativeExtension');
module.exports = NativeExtension;
var GRT = require('bindings')('GRT');

// HMM types to use for setHMMType method of HMM class
GRT.HMM_CONTINUOUS = 1; // default
GRT.HMM_DISCRETE = 0;

// Model types to use for setModelType method of HMM class
GRT.HMM_LEFTRIGHT = 1; // default
GRT.HMM_ERGODIC = 0;
module.exports = GRT;
Loading

0 comments on commit b2ad26a

Please sign in to comment.