qminer
Version:
A C++ based data analytics platform for processing large-scale real-time streams containing structured and unstructured data
1,075 lines (1,072 loc) • 61.3 kB
HTML
<!doctype html>
<html>
<head>
<meta name="generator" content="JSDoc 3">
<meta charset="utf-8">
<title>Class: FeatureSpace</title>
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Karla:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Noto+Serif:400,400i,700,700i" type="text/css">
<link rel="stylesheet" href="https://brick.a.ssl.fastly.net/Inconsolata:500" type="text/css">
<link href="css/baseline.css" rel="stylesheet">
</head>
<body onload="prettyPrint()">
<nav id="jsdoc-navbar" role="navigation" class="jsdoc-navbar">
<div id="jsdoc-navbar-container">
<div id="jsdoc-navbar-content">
<a href="index.html" class="jsdoc-navbar-package-name">QMiner JavaScript API v9.4.0</a>
</div>
</div>
</nav>
<div id="jsdoc-body-container">
<div id="jsdoc-content">
<div id="jsdoc-content-container">
<div id="jsdoc-main" role="main">
<header class="page-header">
<div class="symbol-detail-labels"><span class="label label-kind">class</span> <span class="label label-static">static</span></div>
<h1><small><a href="module-qm.html">qm</a>.<wbr></small><span class="symbol-name">FeatureSpace</span></h1>
<p class="source-link">Source: <a href="qminerdoc.js.html#source-line-2944">qminerdoc.<wbr>js:2944</a></p>
<div class="symbol-classdesc">
<p>Represents the feature space. It contains any of the <a href="module-qm.html#~FeatureExtractor">module:qm~FeatureExtractor</a> objects.</p>
</div>
<dl class="dl-compact">
</dl>
</header>
<section id="summary">
<div class="summary-callout">
<h2 class="summary-callout-heading">Properties</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.FeatureSpace.html#dim">dim</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.FeatureSpace.html#dims">dims</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
</div>
</div>
</div>
<div class="summary-callout">
<h2 class="summary-callout-heading">Methods</h2>
<div class="summary-content">
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.FeatureSpace.html#addFeatureExtractor">addFeatureExtractor(ftExt)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#clear">clear()</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#extractMatrix">extractMatrix(rs[, idx])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#extractSparseMatrix">extractSparseMatrix(rs[, idx])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#extractSparseVector">extractSparseVector(rec[, idx])</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.FeatureSpace.html#extractVector">extractVector(rec[, idx])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#filter">filter(vec, idx[, keepOffset])</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#getFeature">getFeature(idx)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#getFeatureExtractor">getFeatureExtractor(idx)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#invertFeature">invertFeature(idx, val)</a></dt>
<dd>
</dd>
</dl>
</div>
<div class="summary-column">
<dl class="dl-summary-callout">
<dt><a href="module-qm.FeatureSpace.html#invertFeatureVector">invertFeatureVector(ftr)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#save">save(fout)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#updateRecord">updateRecord(rec)</a></dt>
<dd>
</dd>
<dt><a href="module-qm.FeatureSpace.html#updateRecords">updateRecords(rs)</a></dt>
<dd>
</dd>
</dl>
</div>
</div>
</div>
</section>
<section>
<h2 id="FeatureSpace">new <span class="symbol-name">FeatureSpace</span><span class="signature"><span class="signature-params">(base, arg)</span></span></h2>
<p>Feature Space</p>
<section>
<h3>
Example
</h3>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// construct a base with the store
var base = new qm.Base({
mode: "createClean",
schema: {
name: "FtrSpace",
fields: [
{ name: "Value", type: "float" },
{ name: "Category", type: "string" },
{ name: "Categories", type: "string_v" },
],
joins: [],
keys: []
}
});
// populate the store
Store = base.store("FtrSpace");
Store.push({ Value: 1.0, Category: "a", Categories: ["a", "q"] });
Store.push({ Value: 1.1, Category: "b", Categories: ["b", "w"] });
Store.push({ Value: 1.2, Category: "c", Categories: ["c", "e"] });
Store.push({ Value: 1.3, Category: "a", Categories: ["a", "q"] });
// create a feature space
var ftr = new qm.FeatureSpace(base, { type: "numeric", source: "FtrSpace", field: "Value" });
base.close();</code></pre>
</div>
</section>
<section>
<h3>Parameters</h3>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>base</p>
</td>
<td>
<p><a href="module-qm.Base.html">module:qm.Base</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The base where the features are extracted from.</p>
</td>
</tr>
<tr>
<td>
<p>arg</p>
</td>
<td>
<p>(Array of <a href="module-qm.html#~FeatureExtractor">module:qm~FeatureExtractor</a> or <a href="module-fs.FIn.html">module:fs.FIn</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>Constructor arguments. There are two ways of constructing:
<br>1. Using an array of <a href="module-qm.html#~FeatureExtractor">module:qm~FeatureExtractor</a> objects,
<br>2. using a file input stream <a href="module-fs.FIn.html">module:fs.FIn</a>.
</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
</dl>
</section>
<section>
<h2>Properties</h2>
<section>
<h3 id="dim"><span class="symbol-name">dim</span></h3>
<p>Returns the dimension of the feature space. Type <code>number</code>.</p>
<dl class="dl-compact">
</dl>
<h3 id="dims"><span class="symbol-name">dims</span></h3>
<p>Returns an array of the dimensions of each feature extractor in the feature space. Type <code>Array of numbers</code>.</p>
<dl class="dl-compact">
</dl>
</section>
<h2>Methods</h2>
<section>
<h3 id="addFeatureExtractor"><span class="symbol-name">addFeatureExtractor</span><span class="signature"><span class="signature-params">(ftExt)</span> → <span class="signature-returns"> <a href="module-qm.FeatureSpace.html">module:qm.FeatureSpace</a></span></span></h3>
<p>Adds a new feature extractor to the feature space.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "WeatherForcast",
fields: [
{ name: "Weather", type: "string" },
{ name: "Date", type: "datetime" },
{ name: "TemperatureDegrees", type: "int" }
]
}]
});
// put some records in the "WeatherForecast" store
base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-27T11:00:00", TemperatureDegrees: 19 });
base.store("WeatherForcast").push({ Weather: "Partly Cloudy", Date: "2015-05-28T11:00:00", TemperatureDegrees: 22 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-29T11:00:00", TemperatureDegrees: 25 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-05-30T11:00:00", TemperatureDegrees: 25 });
base.store("WeatherForcast").push({ Weather: "Scattered Showers", Date: "2015-05-31T11:00:00", TemperatureDegrees: 24 });
base.store("WeatherForcast").push({ Weather: "Mostly Cloudy", Date: "2015-06-01T11:00:00", TemperatureDegrees: 27 });
// create a feature space
var ftr = new qm.FeatureSpace(base, { type: "numeric", source: "WeatherForcast", field: "TemperatureDegrees" });
// add a new feature extractor to the feature space
// it adds the new feature extractor to the pre-existing feature extractors in the feature space
ftr.addFeatureExtractor({ type: "text", source: "WeatherForcast", field: "Weather", normalize: true, weight: "tfidf" });
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>ftExt</p>
</td>
<td>
<p><a href="module-qm.html#~FeatureExtractor">module:qm~FeatureExtractor</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The added feature extractor.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.FeatureSpace.html">module:qm.FeatureSpace</a></code>B Self.</p>
</dd>
</dl>
<h3 id="clear"><span class="symbol-name">clear</span><span class="signature"><span class="signature-params">()</span> → <span class="signature-returns"> <a href="module-qm.FeatureSpace.html">module:qm.FeatureSpace</a></span></span></h3>
<p>Clears the feature space.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Runners",
fields: [
{ name: "ID", type: "int", primary: true },
{ name: "Name", type: "string" },
{ name: "BestTime", type: "float" }
]
}]
});
// put some records in the "Runners" store
base.store("Runners").push({ ID: 110020, Name: "Eric Ericsson", BestTime: 134.33 });
base.store("Runners").push({ ID: 123307, Name: "Fred Friedrich", BestTime: 101.11 });
base.store("Runners").push({ ID: 767201, Name: "Appel Banana", BestTime: 1034.56 });
// create a feature space
var ftr = new qm.FeatureSpace(base, { type: "numeric", source: "Runners", field: "BestTime" });
// update the feature space
ftr.updateRecords(base.store("Runners").allRecords);
// clear the feature space (return the feature space to it's default values)
ftr.clear();
base.close();</code></pre>
</div>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-qm.FeatureSpace.html">module:qm.FeatureSpace</a></code>B Self. Features space has been cleared.</p>
</dd>
</dl>
<h3 id="extractMatrix"><span class="symbol-name">extractMatrix</span><span class="signature"><span class="signature-params">(rs[, idx])</span> → <span class="signature-returns"> <a href="module-la.Matrix.html">module:la.Matrix</a></span></span></h3>
<p>Extracts the feature vectors from the recordset and returns them as columns of a dense matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require("qminer");
// create a base containing the store Class. Let the Name field be the primary field.
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Class",
fields: [
{ name: "Name", type: "string", primary: true },
{ name: "StudyGroups", type: "string_v" }
]
}]
});
// add some records to the store
base.store("Class").push({ Name: "Dean", StudyGroups: ["A", "D"] });
base.store("Class").push({ Name: "Chang", StudyGroups: ["B", "D"] });
base.store("Class").push({ Name: "Magnitude", StudyGroups: ["B", "C"] });
base.store("Class").push({ Name: "Leonard", StudyGroups: ["A", "B"] });
// create a feature space containing the multinomial feature extractor
var ftr = new qm.FeatureSpace(base, { type: "multinomial", source: "Class", field: "StudyGroups", values: ["A", "B", "C", "D"] });
// create a feature matrix out of the records of the store by using the feature space
// returns a sparse matrix equal to
// 1 0 0 1
// 0 1 1 1
// 0 0 1 0
// 1 1 0 0
var matrix = ftr.extractMatrix(base.store("Class").allRecords);
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rs</p>
</td>
<td>
<p><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The given record set.</p>
</td>
</tr>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>when given, only use specified feature extractor.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Matrix.html">module:la.Matrix</a></code>B The dense matrix, where the i-th column is the feature vector of the i-th record in <code>rs</code>.</p>
</dd>
</dl>
<h3 id="extractSparseMatrix"><span class="symbol-name">extractSparseMatrix</span><span class="signature"><span class="signature-params">(rs[, idx])</span> → <span class="signature-returns"> <a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a></span></span></h3>
<p>Extracts the sparse feature vectors from the record set and returns them as columns of the sparse matrix.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require("qminer");
// create a base containing the store Class. Let the Name field be the primary field.
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Class",
fields: [
{ name: "Name", type: "string", primary: true },
{ name: "StudyGroups", type: "string_v" }
]
}]
});
// add some records to the store
base.store("Class").push({ Name: "Dean", StudyGroups: ["A", "D"] });
base.store("Class").push({ Name: "Chang", StudyGroups: ["B", "D"] });
base.store("Class").push({ Name: "Magnitude", StudyGroups: ["B", "C"] });
base.store("Class").push({ Name: "Leonard", StudyGroups: ["A", "B"] });
// create a feature space containing the multinomial feature extractor
var ftr = new qm.FeatureSpace(base, { type: "multinomial", source: "Class", field: "StudyGroups", values: ["A", "B", "C", "D"] });
// create a sparse feature matrix out of the records of the store by using the feature space
// returns a sparse matrix equal to
// [[(0, 1), (3, 1)], [(1, 1), (3, 1)], [(1, 1), (2, 1)], [(0, 1), (1, 1)]]
var sparseMatrix = ftr.extractSparseMatrix(base.store("Class").allRecords);
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rs</p>
</td>
<td>
<p><a href="module-qm.RecordSet.html">module:qm.RecordSet</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The given record set.</p>
</td>
</tr>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>When given, only use specified feature extractor.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.SparseMatrix.html">module:la.SparseMatrix</a></code>B The sparse matrix, where the i-th column is the sparse feature vector of the i-th record in <code>rs</code>.</p>
</dd>
</dl>
<h3 id="extractSparseVector"><span class="symbol-name">extractSparseVector</span><span class="signature"><span class="signature-params">(rec[, idx])</span> → <span class="signature-returns"> <a href="module-la.SparseVector.html">module:la.SparseVector</a></span></span></h3>
<p>Creates a sparse feature vector from the given record.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a base containing the store Class. Let the Name field be the primary field.
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Class",
fields: [
{ name: "Name", type: "string", primary: true },
{ name: "StudyGroup", type: "string" }
]
}]
});
// add some records to the store
base.store("Class").push({ Name: "Dean", StudyGroup: "A" });
base.store("Class").push({ Name: "Chang", StudyGroup: "D" });
base.store("Class").push({ Name: "Magnitude", StudyGroup: "C" });
base.store("Class").push({ Name: "Leonard", StudyGroup: "B" });
// create a new feature space
// the feature space is of dimensions [0, 4]; 4 is the dimension of the categorical feature extractor
// and 0 is the dimension of text feature extractor (the text feature extractor doesn't have any words,
// need to be updated for use).
var ftr = new qm.FeatureSpace(base, [
{ type: "text", source: "Class", field: "Name", normalize: false },
{ type: "categorical", source: "Class", field: "StudyGroup", values: ["A", "B", "C", "D"] }
]);
// get the sparse extractor vector for the first record in store
// the sparse vector will be [(0, 1)] - uses only the categorical feature extractor. There are no
// features in the text feature extractor.
var vec = ftr.extractSparseVector(base.store("Class")[0]);
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rec</p>
</td>
<td>
<p><a href="module-qm.Record.html">module:qm.Record</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The given record.</p>
</td>
</tr>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>When given, only use specified feature extractor.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.SparseVector.html">module:la.SparseVector</a></code>B The sparse feature vector gained from <code>rec</code> and <code>idx</code>.</p>
</dd>
</dl>
<h3 id="extractVector"><span class="symbol-name">extractVector</span><span class="signature"><span class="signature-params">(rec[, idx])</span> → <span class="signature-returns"> <a href="module-la.Vector.html">module:la.Vector</a></span></span></h3>
<p>Creates a feature vector from the given record.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a base containing the store Class. Let the Name field be the primary field.
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Class",
fields: [
{ name: "Name", type: "string", primary: true },
{ name: "StudyGroup", type: "string" }
]
}]
});
// add some records to the store
base.store("Class").push({ Name: "Jeff", StudyGroup: "A" });
base.store("Class").push({ Name: "Britta", StudyGroup: "D" });
base.store("Class").push({ Name: "Abed", StudyGroup: "C" });
base.store("Class").push({ Name: "Annie", StudyGroup: "B" });
// create a new feature space
// the feature space is of dimensions [0, 4]; 4 is the dimension of the categorical feature extractor
// and 0 is the dimension of text feature extractor (the text feature extractor doesn't have any words,
// need to be updated for use).
var ftr = new qm.FeatureSpace(base, [
{ type: "text", source: "Class", field: "Name", normalize: false },
{ type: "categorical", source: "Class", field: "StudyGroup", values: ["A", "B", "C", "D"] }
]);
// get the extractor vector for the first record in store
// the sparse vector will be [1, 0, 0, 0] - uses only the categorical feature extractor. There are no
// features in the text feature extractor.
var vec = ftr.extractVector(base.store("Class")[0]);
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>rec</p>
</td>
<td>
<p><a href="module-qm.Record.html">module:qm.Record</a></p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The given record.</p>
</td>
</tr>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>when given, only use specified feature extractor.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code><a href="module-la.Vector.html">module:la.Vector</a></code>B The feature vector gained from <code>rec</code> and <code>idx</code>.</p>
</dd>
</dl>
<h3 id="filter"><span class="symbol-name">filter</span><span class="signature"><span class="signature-params">(vec, idx[, keepOffset])</span> → <span class="signature-returns"> (<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseVector.html">module:la.SparseVector</a>)</span></span></h3>
<p>Filters the vector to keep only the elements from the feature extractor.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base with one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Academics",
fields: [
{ name: "Name", type: "string" },
{ name: "Age", type: "int" },
{ name: "Gendre", type: "string" },
{ name: "Skills", type: "string_v" }
]
}]
});
// create a new feature space
var ftr = new qm.FeatureSpace(base, [
{ type: "numeric", source: "Academics", field: "Age" },
{ type: "categorical", source: "Academics", field: "Gendre", values: ["Male", "Female"] },
{ type: "multinomial", source: "Academics", field: "Skills", values: ["Mathematics", "Programming", "Philosophy", "Languages", "Politics", "Cooking"] }
]);
// create a new dense vector
var vec = new qm.la.Vector([40, 0, 1, 0, 1, 1, 1, 0, 0]);
// filter the elements from the second feature extractor
var vec2 = ftr.filter(vec, 1); // returns vector [0, 0, 1, 0, 0, 0, 0, 0, 0]
// filter the elements from the second feature extractor, without keeping the offset
var vec3 = ftr.filter(vec, 1, false); // returns vector [0, 1]
// create a new sparse vector
var spVec = new qm.la.SparseVector([[0, 40], [2, 1], [4, 1], [5, 1], [6, 1]]);
// filter the elements from the second feature extractor
var spVec2 = ftr.filter(spVec, 1); // returns sparse vector [[2, 1]]
// filter the elements from the second feature extractor, without keeping the offset
var spVec3 = ftr.filter(spVec, 1, false); // returns sparse vector [[1, 1]]
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>vec</p>
</td>
<td>
<p>(<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseVector.html">module:la.SparseVector</a>)</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The vector from where the function filters the elements.</p>
</td>
</tr>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The index of the feature extractor.</p>
</td>
</tr>
<tr>
<td>
<p>keepOffset</p>
</td>
<td>
<p>boolean</p>
</td>
<td>
<p>Yes</p>
</td>
<td>
<p>For keeping the original indexing in the new vector.</p>
<p>Defaults to <code>'true'</code>.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>(<a href="module-la.Vector.html">module:la.Vector</a> or <a href="module-la.SparseVector.html">module:la.SparseVector</a>)</code>B <br>1. <a href="module-la.Vector.html">module:la.Vector</a>, if <code>vec</code> is <a href="module-la.Vector.html">module:la.Vector</a>.
<br>2. <a href="module-la.SparseVector.html">module:la.SparseVector</a>, if <code>vec</code> is <a href="module-la.SparseVector.html">module:la.SparseVector</a>.
</p>
</dd>
</dl>
<h3 id="getFeature"><span class="symbol-name">getFeature</span><span class="signature"><span class="signature-params">(idx)</span> → <span class="signature-returns"> String</span></span></h3>
<p>Gives the name of the feature at the given position.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require("qminer");
// create a base containing the store Class. Let the Name field be the primary field.
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "Class",
fields: [
{ name: "Name", type: "string", primary: true },
{ name: "StudyGroups", type: "string_v" }
]
}]
});
// add some records to the store
base.store("Class").push({ Name: "Dean", StudyGroups: ["A", "D"] });
base.store("Class").push({ Name: "Chang", StudyGroups: ["B", "D"] });
base.store("Class").push({ Name: "Magnitude", StudyGroups: ["B", "C"] });
base.store("Class").push({ Name: "Leonard", StudyGroups: ["A", "B"] });
// create a feature space containing the multinomial feature extractor
var ftr = new qm.FeatureSpace(base, [
{ type: "text", source: "Class", field: "Name" },
{ type: "multinomial", source: "Class", field: "StudyGroups", values: ["A", "B", "C", "D"] }
]);
// get the feature at position 2
var feature = ftr.getFeature(2); // returns "C", because the text extractor has no features at the moment
// update the feature space with the records of the store; see the method updateRecords
ftr.updateRecords(base.store("Class").allRecords);
// get the feature at position 2
var feature2 = ftr.getFeature(2); // returns "magnitude"
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The index of the feature in feature space (zero based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>String</code>B The name of the feature at the position <code>idx</code>.</p>
</dd>
</dl>
<h3 id="getFeatureExtractor"><span class="symbol-name">getFeatureExtractor</span><span class="signature"><span class="signature-params">(idx)</span> → <span class="signature-returns"> String</span></span></h3>
<p>Gives the name of feature extractor at given position.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require("qminer");
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "People",
fields: [
{ name: "Name", type: "string" },
{ name: "Gendre", type: "string" },
{ name: "Age", type: "int" }
]
}]
});
// create a feature space containing a categorical and numeric feature extractor
var ftr = new qm.FeatureSpace(base, [
{ type: "numeric", source: "People", field: "Age" },
{ type: "categorical", source: "People", field: "Gendre", values: ["Male", "Female"] }
]);
// get the name of the feature extractor with index 1
var extractorName = ftr.getFeatureExtractor(1); // returns "Categorical[Gendre]"
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The index of the feature extractor in feature space (zero based).</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>String</code>B The name of the feature extractor at position <code>idx</code>.</p>
</dd>
</dl>
<h3 id="invertFeature"><span class="symbol-name">invertFeature</span><span class="signature"><span class="signature-params">(idx, val)</span> → <span class="signature-returns"> Object</span></span></h3>
<p>Calculates the inverse of a single feature using a specific feature extractor.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "TheWitcherSaga",
fields: [
{ name: "Title", type: "string" },
{ name: "YearOfRelease", type: "int" },
{ name: "EnglishEdition", type: "bool" }
]
}]
});
// put some records in the store
base.store("TheWitcherSaga").push({ Title: "Blood of Elves", YearOfRelease: 1994, EnglishEdition: true });
base.store("TheWitcherSaga").push({ Title: "Time of Contempt", YearOfRelease: 1995, EnglishEdition: true });
base.store("TheWitcherSaga").push({ Title: "Baptism of Fire", YearOfRelease: 1996, EnglishEdition: true });
base.store("TheWitcherSaga").push({ Title: "The Swallow's Tower", YearOfRelease: 1997, EnglishEdition: false });
base.store("TheWitcherSaga").push({ Title: "Lady of the Lake", YearOfRelease: 1999, EnglishEdition: false });
base.store("TheWitcherSaga").push({ Title: "Season of Storms", YearOfRelease: 2013, EnglishEdition: false });
// create a feature space with the numeric feature extractor and update the feature space with the records in store
// for update, look the method updateRecords in feature space
var ftr = new qm.FeatureSpace(base, { type: "numeric", source: "TheWitcherSaga", field: "YearOfRelease", normalize: true });
ftr.updateRecords(base.store("TheWitcherSaga").allRecords);
// because of the numeric feature extractor having normalize: true and of the records update of feature space,
// the values are not equal to those of the records
// invert the value 0 using the numeric feature extractor
var inverse = ftr.invertFeature(0, 0); // returns the value 1994
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameters</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>idx</p>
</td>
<td>
<p>number</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The index of the specific feature extractor.</p>
</td>
</tr>
<tr>
<td>
<p>val</p>
</td>
<td>
<p>Object</p>
</td>
<td>
<p> </p>
</td>
<td>
<p>The value to be inverted.</p>
</td>
</tr>
</tbody>
</table>
</section>
<dl class="dl-compact">
<dt>Returns</dt>
<dd>
<p><code>Object</code>B The inverse of <code>val</code> using the feature extractor with index <code>idx</code>.</p>
</dd>
</dl>
<h3 id="invertFeatureVector"><span class="symbol-name">invertFeatureVector</span><span class="signature"><span class="signature-params">(ftr)</span> → <span class="signature-returns"> Array of Object</span></span></h3>
<p>Performs the inverse operation of <code>ftrVec</code>. Works only for numeric feature extractors.</p>
<section>
<h4>
Example
</h4>
<div>
<pre class="prettyprint"><code>// import qm module
var qm = require('qminer');
// create a new base containing one store
var base = new qm.Base({
mode: "createClean",
schema: [{
name: "TheWitcherSaga",
fields: [
{ name: "Title", type: "string" },
{ name: "YearOfRelease", type: "int" },
{ name: "EnglishEdition", type: "bool" }
]
}]
});
// put some records in the store
base.store("TheWitcherSaga").push({ Title: "Blood of Elves", YearOfRelease: 1994, EnglishEdition: true });
base.store("TheWitcherSaga").push({ Title: "Time of Contempt", YearOfRelease: 1995, EnglishEdition: true });
base.store("TheWitcherSaga").push({ Title: "Baptism of Fire", YearOfRelease: 1996, EnglishEdition: true });
base.store("TheWitcherSaga").push({ Title: "The Swallow's Tower", YearOfRelease: 1997, EnglishEdition: false });
base.store("TheWitcherSaga").push({ Title: "Lady of the Lake", YearOfRelease: 1999, EnglishEdition: false });
base.store("TheWitcherSaga").push({ Title: "Season of Storms", YearOfRelease: 2013, EnglishEdition: false });
// create a feature space with the numeric feature extractor and update the feature space with the records in store
// for update, look the method updateRecords in feature space
var ftr = new qm.FeatureSpace(base, { type: "numeric", source: "TheWitcherSaga", field: "YearOfRelease", normalize: true });
ftr.updateRecords(base.store("TheWitcherSaga").allRecords);
// get a feature vector for the second record
// because of the numeric feature extractor having normalize: true and of the records update of feature space, the values
// are not equal to those of the records, i.e. the value 1995 is now 0.105263
var ftrVec = ftr.extractVector(base.store("TheWitcherSaga")[1]);
// get the inverse of the feature vector
// the function returns the values to their first value, i.e. 0.105263 returns to 1995
var inverse = ftr.invertFeatureVector(ftrVec); // returns a vector [1995]
base.close();</code></pre>
</div>
</section>
<section>
<h4>Parameter</h4>
<table class="jsdoc-details-table">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Optional</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<p>ftr</p>
</td>
<td>
<p>(<a href="module-la.Vector.html">module:la.Vector</a> or Array of Object)</p>
</td>
<td>
<p> </p>
</td>