analytics. MDS
Source: analyticsdoc.
Scales a higher level vectors into a 2D vector space such that the distances between vectors are preserved as well as possible.
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 |
Yes |
Construction arguments. There are two ways of constructing:
|
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 |
|
The multidimensional matrix. |
|
callback |
function() |
Yes |
The callback function receiving the error parameter ( |
- Returns
-
module:la.Matrix
B The matrix of dimensionsmat.cols
x 2, where the i-th row of the matrix is the 2D representation of the i-th column ofmat
.
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
B 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 |
|
The output stream. |
- Returns
-
module:fs.FOut
B The output stramfout
.
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 |
|
The constructor parameters. |
- Returns
-
module:analytics.MDS
B Self. The model parameters have been updated.