new CountWindowGk([arg])

Example

// import modules
var qm = require('qminer');
var analytics = qm.analytics;

// create the default TDigest object
var gk = new analytics.CountWindowGk({
    windowSize: 5,
    quantileEps: 0.001,
    countEps: 0.0005
});

// create the data used for calculating quantiles
var inputs = [10, 1, 2, 8, 9, 5, 6, 4, 7, 3];

// fit the TDigest model
for (var i = 0; i < inputs.length; i++) {
    gk.partialFit(inputs[i]);
}

// make the prediction for the 0.1 quantile
var prediction = gk.predict(0.1);
// save the model
gk.save(fs.openWrite('gk.bin')).close();
// open the gk model under a new variable
var gk2 = new analytics.CountWindowGk(fs.openRead('gk.bin'));

Parameter

Name Type Optional Description

arg

(module:analytics~FixedWindowGkParam or module:fs.FIn)

Yes

Construction arguments. There are two ways of constructing:
1. Using the module:analytics~FixedWindowGkParam object,
2. using the file input stream module:fs.FIn.

Methods

static
partialFit(val) → module:analytics.CountWindowGk

Appends a new value to the sliding window. If an old value falls outside the sliding window, it is forgotten.

Example

var qm = require('qminer');

var gk = new qm.analytics.CountWindowGk();
gk.partialFit(1.0);
gk.partialFit(2.0);

Parameter

Name Type Optional Description

val

number

 

the value

Returns

module:analytics.CountWindowGk reference to self

static
save(fout) → module:fs.FOut

Saves the objects state into a binary file.

Example

var gk = new qm.analytics.CountWindowGk();

// save the model
gk.save(fs.openWrite('tdigest.bin')).close();
// open the tdigest model under a new variable
var gk = new analytics.CountWindowGk(fs.openRead('tdigest.bin'));

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

the output stream

Returns

module:fs.FOut the output stream fout

getParams() → module:analytics~FixedWindowGkParam

Returns the models' parameters as a JavaScript object (JSON). These parameters are the same as are set through the constructor.

Returns

module:analytics~FixedWindowGkParam The construction parameters.

var analytics = qm.analytics; var gk = new analytics.CountWindowGk(); var params = tdigest.getParams();

console.log(params.windowSize); console.log(params.quantileEps); console.log(params.countEps);

predict(p) → number

Given an input cumulative probability, returns a quantile associated with that probability (e.g. for input 0.5 it will return the median).

Example

var qm = require('qminer');

var gk = new qm.analytics.CountWindowGk({
    windowSize: 100    // window 100 elements long
});
gk.partialFit(1.0);
gk.partialFit(2.0);
gk.partialFit(1.0);
gk.partialFit(3.0);
gk.partialFit(2.0);

console.log(gk.predict(0.01));   // prints the first percentile
console.log(gk.predict(0.25));   // prints the first quartile
console.log(gk.predict(0.5));    // prints the median

Parameter

Name Type Optional Description

p

number

 

cumulative probability between 0 and 1 (both inclusive)

Returns

number quantile associated with p