new MDS([arg])

Multidimensional Scaling

Example

// import analytics module
var analytics = require('qminer').analytics;
// construct a MDS instance
var mds = new analytics.MDS({ maxStep: 300, distType: 'Cos' });
// create the multidimensional matrix
var mat = new la.Matrix({ rows: 50, cols: 10, random: true });
// get the 2d representation of mat
var mat2d = mds.fitTransform(mat);

Parameter

Name Type Optional Description

arg

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

Yes

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

Methods

fitTransform(mat[, callback]) → module:la.Matrix

Get the MDS of the given matrix.

Examples

Asynchronous function

// import the modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a MDS instance
var mds = new analytics.MDS();
// create the multidimensional matrix
var mat = new la.Matrix({ rows: 50, cols: 10, random: true });
// get the 2d representation of mat 
mds.fitTransformAsync(mat, function (err, res) {
   if (err) throw err;
   // successful calculation
   var mat2d = res;
}); 

Synchronous function

// import the modules
var analytics = require('qminer').analytics;
var la = require('qminer').la;
// create a MDS instance
var mds = new analytics.MDS();
// create the multidimensional matrix
var mat = new la.Matrix({ rows: 50, cols: 10, random: true });
// get the 2d representation of mat 
var mat2d = mds.fitTransform(mat); 

Parameters

Name Type Optional Description

mat

(module:la.Matrix or module:la.SparseMatrix)

 

The multidimensional matrix.

callback

function()

Yes

The callback function receiving the error parameter (err) and the result parameter (res). Only for the asynchronous function.

Returns

module:la.Matrix The matrix of dimensions mat.cols x 2, where the i-th row of the matrix is the 2D representation of the i-th column of mat.

getParams() → module:analytics~MDSParam

Get the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a MDS instance
var mds = new analytics.MDS();
// get the (default) parameters of the instance
// returns { maxStep: 5000, maxSecs: 300, minDiff: 1e-4, distType: "Euclid" }
var params = mds.getParams();
Returns

module:analytics~MDSParam The constructor parameters.

save(fout) → module:fs.FOut

Save the MDS model.

Example

// import modules
var analytics = require('qminer').analytics;
var fs = require('qminer').fs;
// create a MDS instance
var mds = new analytics.MDS({ iter: 200, MaxStep: 10 });
// create the file output stream
var fout = new fs.openWrite('MDS.bin');
// save the MDS instance
mds.save(fout);
fout.close();
// load the MDS instance
var fin = fs.openRead('MDS.bin');
var mds2 = new analytics.MDS(fin);

Parameter

Name Type Optional Description

fout

module:fs.FOut

 

The output stream.

Returns

module:fs.FOut The output stram fout.

setParams(params) → module:analytics.MDS

Set the parameters.

Example

// import analytics module
var analytics = require('qminer').analytics;
// create a MDS instance
var mds = new analytics.MDS();
// get the (default) parameters of the instance
// returns { maxStep: 5000, maxSecs: 300, minDiff: 1e-4, distType: "Euclid" }
var params = mds.getParams();

Parameter

Name Type Optional Description

params

module:analytics~MDSParam

 

The constructor parameters.

Returns

module:analytics.MDS Self. The model parameters have been updated.