<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Basics - MLlib - Spark 1.0.0 Documentation</title>
<meta name="description" content="">
<link rel="stylesheet" href="css/bootstrap.min.css">
<style>
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" href="css/main.css">
<script src="js/vendor/modernizr-2.6.1-respond-1.1.0.min.js"></script>
<link rel="stylesheet" href="css/pygments-default.css">
<!-- Google analytics script -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-32518208-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<!--[if lt IE 7]>
<p class="chromeframe">You are using an outdated browser. <a href="http://browsehappy.com/">Upgrade your browser today</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to better experience this site.</p>
<![endif]-->
<!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->
<div class="navbar navbar-fixed-top" id="topbar">
<div class="navbar-inner">
<div class="container">
<div class="brand"><a href="index.html">
<img src="img/spark-logo-hd.png" style="height:50px;"/></a><span class="version">1.0.0</span>
</div>
<ul class="nav">
<!--TODO(andyk): Add class="active" attribute to li some how.-->
<li><a href="index.html">Overview</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Programming Guides<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="quick-start.html">Quick Start</a></li>
<li><a href="programming-guide.html">Spark Programming Guide</a></li>
<li class="divider"></li>
<li><a href="streaming-programming-guide.html">Spark Streaming</a></li>
<li><a href="sql-programming-guide.html">Spark SQL</a></li>
<li><a href="mllib-guide.html">MLlib (Machine Learning)</a></li>
<li><a href="graphx-programming-guide.html">GraphX (Graph Processing)</a></li>
<li><a href="bagel-programming-guide.html">Bagel (Pregel on Spark)</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">API Docs<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="api/scala/index.html#org.apache.spark.package">Scaladoc</a></li>
<li><a href="api/java/index.html">Javadoc</a></li>
<li><a href="api/python/index.html">Python API</a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Deploying<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="cluster-overview.html">Overview</a></li>
<li><a href="submitting-applications.html">Submitting Applications</a></li>
<li class="divider"></li>
<li><a href="ec2-scripts.html">Amazon EC2</a></li>
<li><a href="spark-standalone.html">Standalone Mode</a></li>
<li><a href="running-on-mesos.html">Mesos</a></li>
<li><a href="running-on-yarn.html">YARN</a></li>
</ul>
</li>
<li class="dropdown">
<a href="api.html" class="dropdown-toggle" data-toggle="dropdown">More<b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="configuration.html">Configuration</a></li>
<li><a href="monitoring.html">Monitoring</a></li>
<li><a href="tuning.html">Tuning Guide</a></li>
<li><a href="job-scheduling.html">Job Scheduling</a></li>
<li><a href="security.html">Security</a></li>
<li><a href="hardware-provisioning.html">Hardware Provisioning</a></li>
<li><a href="hadoop-third-party-distributions.html">3<sup>rd</sup>-Party Hadoop Distros</a></li>
<li class="divider"></li>
<li><a href="building-with-maven.html">Building Spark with Maven</a></li>
<li><a href="https://cwiki.apache.org/confluence/display/SPARK/Contributing+to+Spark">Contributing to Spark</a></li>
</ul>
</li>
</ul>
<!--<p class="navbar-text pull-right"><span class="version-text">v1.0.0</span></p>-->
</div>
</div>
</div>
<div class="container" id="content">
<h1 class="title"><a href="mllib-guide.html">MLlib</a> - Basics</h1>
<ul id="markdown-toc">
<li><a href="#local-vector">Local vector</a></li>
<li><a href="#labeled-point">Labeled point</a></li>
<li><a href="#local-matrix">Local matrix</a></li>
<li><a href="#distributed-matrix">Distributed matrix</a> <ul>
<li><a href="#rowmatrix">RowMatrix</a> <ul>
<li><a href="#multivariate-summary-statistics">Multivariate summary statistics</a></li>
</ul>
</li>
<li><a href="#indexedrowmatrix">IndexedRowMatrix</a></li>
<li><a href="#coordinatematrix">CoordinateMatrix</a></li>
</ul>
</li>
</ul>
<p>MLlib supports local vectors and matrices stored on a single machine,
as well as distributed matrices backed by one or more RDDs.
In the current implementation, local vectors and matrices are simple data models
to serve public interfaces. The underlying linear algebra operations are provided by
<a href="http://www.scalanlp.org/">Breeze</a> and <a href="http://jblas.org/">jblas</a>.
A training example used in supervised learning is called “labeled point” in MLlib.</p>
<h2 id="local-vector">Local vector</h2>
<p>A local vector has integer-typed and 0-based indices and double-typed values, stored on a single
machine. MLlib supports two types of local vectors: dense and sparse. A dense vector is backed by
a double array representing its entry values, while a sparse vector is backed by two parallel
arrays: indices and values. For example, a vector $(1.0, 0.0, 3.0)$ can be represented in dense
format as <code>[1.0, 0.0, 3.0]</code> or in sparse format as <code>(3, [0, 2], [1.0, 3.0])</code>, where <code>3</code> is the size
of the vector.</p>
<div class="codetabs">
<div data-lang="scala">
<p>The base class of local vectors is
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.Vector"><code>Vector</code></a>, and we provide two
implementations: <a href="api/scala/index.html#org.apache.spark.mllib.linalg.DenseVector"><code>DenseVector</code></a> and
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.SparseVector"><code>SparseVector</code></a>. We recommend
using the factory methods implemented in
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.Vector"><code>Vectors</code></a> to create local vectors.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.</span><span class="o">{</span><span class="nc">Vector</span><span class="o">,</span> <span class="nc">Vectors</span><span class="o">}</span>
<span class="c1">// Create a dense vector (1.0, 0.0, 3.0).</span>
<span class="k">val</span> <span class="n">dv</span><span class="k">:</span> <span class="kt">Vector</span> <span class="o">=</span> <span class="nc">Vectors</span><span class="o">.</span><span class="n">dense</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">0.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">)</span>
<span class="c1">// Create a sparse vector (1.0, 0.0, 3.0) by specifying its indices and values corresponding to nonzero entries.</span>
<span class="k">val</span> <span class="n">sv1</span><span class="k">:</span> <span class="kt">Vector</span> <span class="o">=</span> <span class="nc">Vectors</span><span class="o">.</span><span class="n">sparse</span><span class="o">(</span><span class="mi">3</span><span class="o">,</span> <span class="nc">Array</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="mi">2</span><span class="o">),</span> <span class="nc">Array</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">))</span>
<span class="c1">// Create a sparse vector (1.0, 0.0, 3.0) by specifying its nonzero entries.</span>
<span class="k">val</span> <span class="n">sv2</span><span class="k">:</span> <span class="kt">Vector</span> <span class="o">=</span> <span class="nc">Vectors</span><span class="o">.</span><span class="n">sparse</span><span class="o">(</span><span class="mi">3</span><span class="o">,</span> <span class="nc">Seq</span><span class="o">((</span><span class="mi">0</span><span class="o">,</span> <span class="mf">1.0</span><span class="o">),</span> <span class="o">(</span><span class="mi">2</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">)))</span>
</code></pre></div>
<p><strong><em>Note</em></strong></p>
<p>Scala imports <code>scala.collection.immutable.Vector</code> by default, so you have to import
<code>org.apache.spark.mllib.linalg.Vector</code> explicitly to use MLlib’s <code>Vector</code>.</p>
</div>
<div data-lang="java">
<p>The base class of local vectors is
<a href="api/java/org/apache/spark/mllib/linalg/Vector.html"><code>Vector</code></a>, and we provide two
implementations: <a href="api/java/org/apache/spark/mllib/linalg/DenseVector.html"><code>DenseVector</code></a> and
<a href="api/java/org/apache/spark/mllib/linalg/SparseVector.html"><code>SparseVector</code></a>. We recommend
using the factory methods implemented in
<a href="api/java/org/apache/spark/mllib/linalg/Vector.html"><code>Vectors</code></a> to create local vectors.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.Vector</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.Vectors</span><span class="o">;</span>
<span class="c1">// Create a dense vector (1.0, 0.0, 3.0).</span>
<span class="n">Vector</span> <span class="n">dv</span> <span class="o">=</span> <span class="n">Vectors</span><span class="o">.</span><span class="na">dense</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">0.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">);</span>
<span class="c1">// Create a sparse vector (1.0, 0.0, 3.0) by specifying its indices and values corresponding to nonzero entries.</span>
<span class="n">Vector</span> <span class="n">sv</span> <span class="o">=</span> <span class="n">Vectors</span><span class="o">.</span><span class="na">sparse</span><span class="o">(</span><span class="mi">3</span><span class="o">,</span> <span class="k">new</span> <span class="kt">int</span><span class="o">[]</span> <span class="o">{</span><span class="mi">0</span><span class="o">,</span> <span class="mi">2</span><span class="o">},</span> <span class="k">new</span> <span class="kt">double</span><span class="o">[]</span> <span class="o">{</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">});</span>
</code></pre></div>
</div>
<div data-lang="python">
<p>MLlib recognizes the following types as dense vectors:</p>
<ul>
<li>NumPy’s <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.array.html"><code>array</code></a></li>
<li>Python’s list, e.g., <code>[1, 2, 3]</code></li>
</ul>
<p>and the following as sparse vectors:</p>
<ul>
<li>MLlib’s <a href="api/python/pyspark.mllib.linalg.SparseVector-class.html"><code>SparseVector</code></a>.</li>
<li>SciPy’s
<a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.csc_matrix.html#scipy.sparse.csc_matrix"><code>csc_matrix</code></a>
with a single column</li>
</ul>
<p>We recommend using NumPy arrays over lists for efficiency, and using the factory methods implemented
in <a href="api/python/pyspark.mllib.linalg.Vectors-class.html"><code>Vectors</code></a> to create sparse vectors.</p>
<div class="highlight"><pre><code class="python"><span class="kn">import</span> <span class="nn">numpy</span> <span class="kn">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">scipy.sparse</span> <span class="kn">as</span> <span class="nn">sps</span>
<span class="kn">from</span> <span class="nn">pyspark.mllib.linalg</span> <span class="kn">import</span> <span class="n">Vectors</span>
<span class="c"># Use a NumPy array as a dense vector.</span>
<span class="n">dv1</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">])</span>
<span class="c"># Use a Python list as a dense vector.</span>
<span class="n">dv2</span> <span class="o">=</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">]</span>
<span class="c"># Create a SparseVector.</span>
<span class="n">sv1</span> <span class="o">=</span> <span class="n">Vectors</span><span class="o">.</span><span class="n">sparse</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">])</span>
<span class="c"># Use a single-column SciPy csc_matrix as a sparse vector.</span>
<span class="n">sv2</span> <span class="o">=</span> <span class="n">sps</span><span class="o">.</span><span class="n">csc_matrix</span><span class="p">((</span><span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">]),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">]),</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">])),</span> <span class="n">shape</span> <span class="o">=</span> <span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
</code></pre></div>
</div>
</div>
<h2 id="labeled-point">Labeled point</h2>
<p>A labeled point is a local vector, either dense or sparse, associated with a label/response.
In MLlib, labeled points are used in supervised learning algorithms.
We use a double to store a label, so we can use labeled points in both regression and classification.
For binary classification, label should be either $0$ (negative) or $1$ (positive).
For multiclass classification, labels should be class indices staring from zero: $0, 1, 2, \ldots$.</p>
<div class="codetabs">
<div data-lang="scala">
<p>A labeled point is represented by the case class
<a href="api/scala/index.html#org.apache.spark.mllib.regression.LabeledPoint"><code>LabeledPoint</code></a>.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.Vectors</span>
<span class="k">import</span> <span class="nn">org.apache.spark.mllib.regression.LabeledPoint</span>
<span class="c1">// Create a labeled point with a positive label and a dense feature vector.</span>
<span class="k">val</span> <span class="n">pos</span> <span class="k">=</span> <span class="nc">LabeledPoint</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="nc">Vectors</span><span class="o">.</span><span class="n">dense</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">0.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">))</span>
<span class="c1">// Create a labeled point with a negative label and a sparse feature vector.</span>
<span class="k">val</span> <span class="n">neg</span> <span class="k">=</span> <span class="nc">LabeledPoint</span><span class="o">(</span><span class="mf">0.0</span><span class="o">,</span> <span class="nc">Vectors</span><span class="o">.</span><span class="n">sparse</span><span class="o">(</span><span class="mi">3</span><span class="o">,</span> <span class="nc">Array</span><span class="o">(</span><span class="mi">0</span><span class="o">,</span> <span class="mi">2</span><span class="o">),</span> <span class="nc">Array</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">)))</span>
</code></pre></div>
</div>
<div data-lang="java">
<p>A labeled point is represented by
<a href="api/java/org/apache/spark/mllib/regression/LabeledPoint.html"><code>LabeledPoint</code></a>.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.Vectors</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.regression.LabeledPoint</span><span class="o">;</span>
<span class="c1">// Create a labeled point with a positive label and a dense feature vector.</span>
<span class="n">LabeledPoint</span> <span class="n">pos</span> <span class="o">=</span> <span class="k">new</span> <span class="n">LabeledPoint</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="n">Vectors</span><span class="o">.</span><span class="na">dense</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">0.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">));</span>
<span class="c1">// Create a labeled point with a negative label and a sparse feature vector.</span>
<span class="n">LabeledPoint</span> <span class="n">neg</span> <span class="o">=</span> <span class="k">new</span> <span class="n">LabeledPoint</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="n">Vectors</span><span class="o">.</span><span class="na">sparse</span><span class="o">(</span><span class="mi">3</span><span class="o">,</span> <span class="k">new</span> <span class="kt">int</span><span class="o">[]</span> <span class="o">{</span><span class="mi">0</span><span class="o">,</span> <span class="mi">2</span><span class="o">},</span> <span class="k">new</span> <span class="kt">double</span><span class="o">[]</span> <span class="o">{</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">}));</span>
</code></pre></div>
</div>
<div data-lang="python">
<p>A labeled point is represented by
<a href="api/python/pyspark.mllib.regression.LabeledPoint-class.html"><code>LabeledPoint</code></a>.</p>
<div class="highlight"><pre><code class="python"><span class="kn">from</span> <span class="nn">pyspark.mllib.linalg</span> <span class="kn">import</span> <span class="n">SparseVector</span>
<span class="kn">from</span> <span class="nn">pyspark.mllib.regression</span> <span class="kn">import</span> <span class="n">LabeledPoint</span>
<span class="c"># Create a labeled point with a positive label and a dense feature vector.</span>
<span class="n">pos</span> <span class="o">=</span> <span class="n">LabeledPoint</span><span class="p">(</span><span class="mf">1.0</span><span class="p">,</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">])</span>
<span class="c"># Create a labeled point with a negative label and a sparse feature vector.</span>
<span class="n">neg</span> <span class="o">=</span> <span class="n">LabeledPoint</span><span class="p">(</span><span class="mf">0.0</span><span class="p">,</span> <span class="n">SparseVector</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">],</span> <span class="p">[</span><span class="mf">1.0</span><span class="p">,</span> <span class="mf">3.0</span><span class="p">]))</span>
</code></pre></div>
</div>
</div>
<p><strong><em>Sparse data</em></strong></p>
<p>It is very common in practice to have sparse training data. MLlib supports reading training
examples stored in <code>LIBSVM</code> format, which is the default format used by
<a href="http://www.csie.ntu.edu.tw/~cjlin/libsvm/"><code>LIBSVM</code></a> and
<a href="http://www.csie.ntu.edu.tw/~cjlin/liblinear/"><code>LIBLINEAR</code></a>. It is a text format. Each line
represents a labeled sparse feature vector using the following format:</p>
<pre><code>label index1:value1 index2:value2 ...
</code></pre>
<p>where the indices are one-based and in ascending order.
After loading, the feature indices are converted to zero-based.</p>
<div class="codetabs">
<div data-lang="scala">
<p><a href="api/scala/index.html#org.apache.spark.mllib.util.MLUtils$"><code>MLUtils.loadLibSVMFile</code></a> reads training
examples stored in LIBSVM format.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.regression.LabeledPoint</span>
<span class="k">import</span> <span class="nn">org.apache.spark.mllib.util.MLUtils</span>
<span class="k">import</span> <span class="nn">org.apache.spark.rdd.RDD</span>
<span class="k">val</span> <span class="n">examples</span><span class="k">:</span> <span class="kt">RDD</span><span class="o">[</span><span class="kt">LabeledPoint</span><span class="o">]</span> <span class="k">=</span> <span class="nc">MLUtils</span><span class="o">.</span><span class="n">loadLibSVMFile</span><span class="o">(</span><span class="n">sc</span><span class="o">,</span> <span class="s">"mllib/data/sample_libsvm_data.txt"</span><span class="o">)</span>
</code></pre></div>
</div>
<div data-lang="java">
<p><a href="api/java/org/apache/spark/mllib/util/MLUtils.html"><code>MLUtils.loadLibSVMFile</code></a> reads training
examples stored in LIBSVM format.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.mllib.regression.LabeledPoint</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.util.MLUtils</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.api.java.JavaRDD</span><span class="o">;</span>
<span class="n">JavaRDD</span><span class="o"><</span><span class="n">LabeledPoint</span><span class="o">></span> <span class="n">examples</span> <span class="o">=</span>
<span class="n">MLUtils</span><span class="o">.</span><span class="na">loadLibSVMFile</span><span class="o">(</span><span class="n">jsc</span><span class="o">.</span><span class="na">sc</span><span class="o">(),</span> <span class="s">"mllib/data/sample_libsvm_data.txt"</span><span class="o">).</span><span class="na">toJavaRDD</span><span class="o">();</span>
</code></pre></div>
</div>
<div data-lang="python">
<p><a href="api/python/pyspark.mllib.util.MLUtils-class.html"><code>MLUtils.loadLibSVMFile</code></a> reads training
examples stored in LIBSVM format.</p>
<div class="highlight"><pre><code class="python"><span class="kn">from</span> <span class="nn">pyspark.mllib.util</span> <span class="kn">import</span> <span class="n">MLUtils</span>
<span class="n">examples</span> <span class="o">=</span> <span class="n">MLUtils</span><span class="o">.</span><span class="n">loadLibSVMFile</span><span class="p">(</span><span class="n">sc</span><span class="p">,</span> <span class="s">"mllib/data/sample_libsvm_data.txt"</span><span class="p">)</span>
</code></pre></div>
</div>
</div>
<h2 id="local-matrix">Local matrix</h2>
<p>A local matrix has integer-typed row and column indices and double-typed values, stored on a single
machine. MLlib supports dense matrix, whose entry values are stored in a single double array in
column major. For example, the following matrix <code>\[ \begin{pmatrix}
1.0 & 2.0 \\
3.0 & 4.0 \\
5.0 & 6.0
\end{pmatrix}
\]</code>
is stored in a one-dimensional array <code>[1.0, 3.0, 5.0, 2.0, 4.0, 6.0]</code> with the matrix size <code>(3, 2)</code>.
We are going to add sparse matrix in the next release.</p>
<div class="codetabs">
<div data-lang="scala">
<p>The base class of local matrices is
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.Matrix"><code>Matrix</code></a>, and we provide one
implementation: <a href="api/scala/index.html#org.apache.spark.mllib.linalg.DenseMatrix"><code>DenseMatrix</code></a>.
Sparse matrix will be added in the next release. We recommend using the factory methods implemented
in <a href="api/scala/index.html#org.apache.spark.mllib.linalg.Matrices"><code>Matrices</code></a> to create local
matrices.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.</span><span class="o">{</span><span class="nc">Matrix</span><span class="o">,</span> <span class="nc">Matrices</span><span class="o">}</span>
<span class="c1">// Create a dense matrix ((1.0, 2.0), (3.0, 4.0), (5.0, 6.0))</span>
<span class="k">val</span> <span class="n">dm</span><span class="k">:</span> <span class="kt">Matrix</span> <span class="o">=</span> <span class="nc">Matrices</span><span class="o">.</span><span class="n">dense</span><span class="o">(</span><span class="mi">3</span><span class="o">,</span> <span class="mi">2</span><span class="o">,</span> <span class="nc">Array</span><span class="o">(</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">,</span> <span class="mf">5.0</span><span class="o">,</span> <span class="mf">2.0</span><span class="o">,</span> <span class="mf">4.0</span><span class="o">,</span> <span class="mf">6.0</span><span class="o">))</span>
</code></pre></div>
</div>
<div data-lang="java">
<p>The base class of local matrices is
<a href="api/java/org/apache/spark/mllib/linalg/Matrix.html"><code>Matrix</code></a>, and we provide one
implementation: <a href="api/java/org/apache/spark/mllib/linalg/DenseMatrix.html"><code>DenseMatrix</code></a>.
Sparse matrix will be added in the next release. We recommend using the factory methods implemented
in <a href="api/java/org/apache/spark/mllib/linalg/Matrices.html"><code>Matrices</code></a> to create local
matrices.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.Matrix</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.Matrices</span><span class="o">;</span>
<span class="c1">// Create a dense matrix ((1.0, 2.0), (3.0, 4.0), (5.0, 6.0))</span>
<span class="n">Matrix</span> <span class="n">dm</span> <span class="o">=</span> <span class="n">Matrices</span><span class="o">.</span><span class="na">dense</span><span class="o">(</span><span class="mi">3</span><span class="o">,</span> <span class="mi">2</span><span class="o">,</span> <span class="k">new</span> <span class="kt">double</span><span class="o">[]</span> <span class="o">{</span><span class="mf">1.0</span><span class="o">,</span> <span class="mf">3.0</span><span class="o">,</span> <span class="mf">5.0</span><span class="o">,</span> <span class="mf">2.0</span><span class="o">,</span> <span class="mf">4.0</span><span class="o">,</span> <span class="mf">6.0</span><span class="o">});</span>
</code></pre></div>
</div>
</div>
<h2 id="distributed-matrix">Distributed matrix</h2>
<p>A distributed matrix has long-typed row and column indices and double-typed values, stored
distributively in one or more RDDs. It is very important to choose the right format to store large
and distributed matrices. Converting a distributed matrix to a different format may require a
global shuffle, which is quite expensive. We implemented three types of distributed matrices in
this release and will add more types in the future.</p>
<p>The basic type is called <code>RowMatrix</code>. A <code>RowMatrix</code> is a row-oriented distributed
matrix without meaningful row indices, e.g., a collection of feature vectors.
It is backed by an RDD of its rows, where each row is a local vector.
We assume that the number of columns is not huge for a <code>RowMatrix</code>.
An <code>IndexedRowMatrix</code> is similar to a <code>RowMatrix</code> but with row indices,
which can be used for identifying rows and joins.
A <code>CoordinateMatrix</code> is a distributed matrix stored in <a href="https://en.wikipedia.org/wiki/Sparse_matrix">coordinate list (COO)</a> format,
backed by an RDD of its entries.</p>
<p><strong><em>Note</em></strong></p>
<p>The underlying RDDs of a distributed matrix must be deterministic, because we cache the matrix size.
It is always error-prone to have non-deterministic RDDs.</p>
<h3 id="rowmatrix">RowMatrix</h3>
<p>A <code>RowMatrix</code> is a row-oriented distributed matrix without meaningful row indices, backed by an RDD
of its rows, where each row is a local vector. This is similar to <code>data matrix</code> in the context of
multivariate statistics. Since each row is represented by a local vector, the number of columns is
limited by the integer range but it should be much smaller in practice.</p>
<div class="codetabs">
<div data-lang="scala">
<p>A <a href="api/scala/index.html#org.apache.spark.mllib.linalg.distributed.RowMatrix"><code>RowMatrix</code></a> can be
created from an <code>RDD[Vector]</code> instance. Then we can compute its column summary statistics.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.Vector</span>
<span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.RowMatrix</span>
<span class="k">val</span> <span class="n">rows</span><span class="k">:</span> <span class="kt">RDD</span><span class="o">[</span><span class="kt">Vector</span><span class="o">]</span> <span class="k">=</span> <span class="o">...</span> <span class="c1">// an RDD of local vectors</span>
<span class="c1">// Create a RowMatrix from an RDD[Vector].</span>
<span class="k">val</span> <span class="n">mat</span><span class="k">:</span> <span class="kt">RowMatrix</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">RowMatrix</span><span class="o">(</span><span class="n">rows</span><span class="o">)</span>
<span class="c1">// Get its size.</span>
<span class="k">val</span> <span class="n">m</span> <span class="k">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">numRows</span><span class="o">()</span>
<span class="k">val</span> <span class="n">n</span> <span class="k">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">numCols</span><span class="o">()</span>
</code></pre></div>
</div>
<div data-lang="java">
<p>A <a href="api/java/org/apache/spark/mllib/linalg/distributed/RowMatrix.html"><code>RowMatrix</code></a> can be
created from a <code>JavaRDD<Vector></code> instance. Then we can compute its column summary statistics.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.api.java.JavaRDD</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.Vector</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.RowMatrix</span><span class="o">;</span>
<span class="n">JavaRDD</span><span class="o"><</span><span class="n">Vector</span><span class="o">></span> <span class="n">rows</span> <span class="o">=</span> <span class="o">...</span> <span class="c1">// a JavaRDD of local vectors</span>
<span class="c1">// Create a RowMatrix from an JavaRDD<Vector>.</span>
<span class="n">RowMatrix</span> <span class="n">mat</span> <span class="o">=</span> <span class="k">new</span> <span class="n">RowMatrix</span><span class="o">(</span><span class="n">rows</span><span class="o">.</span><span class="na">rdd</span><span class="o">());</span>
<span class="c1">// Get its size.</span>
<span class="kt">long</span> <span class="n">m</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">numRows</span><span class="o">();</span>
<span class="kt">long</span> <span class="n">n</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">numCols</span><span class="o">();</span>
</code></pre></div>
</div>
</div>
<h4 id="multivariate-summary-statistics">Multivariate summary statistics</h4>
<p>We provide column summary statistics for <code>RowMatrix</code>.
If the number of columns is not large, say, smaller than 3000, you can also compute
the covariance matrix as a local matrix, which requires $\mathcal{O}(n^2)$ storage where $n$ is the
number of columns. The total CPU time is $\mathcal{O}(m n^2)$, where $m$ is the number of rows,
which could be faster if the rows are sparse.</p>
<div class="codetabs">
<div data-lang="scala">
<p><a href="api/scala/index.html#org.apache.spark.mllib.linalg.distributed.RowMatrix"><code>RowMatrix#computeColumnSummaryStatistics</code></a> returns an instance of
<a href="api/scala/index.html#org.apache.spark.mllib.stat.MultivariateStatisticalSummary"><code>MultivariateStatisticalSummary</code></a>,
which contains the column-wise max, min, mean, variance, and number of nonzeros, as well as the
total count.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.Matrix</span>
<span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.RowMatrix</span>
<span class="k">import</span> <span class="nn">org.apache.spark.mllib.stat.MultivariateStatisticalSummary</span>
<span class="k">val</span> <span class="n">mat</span><span class="k">:</span> <span class="kt">RowMatrix</span> <span class="o">=</span> <span class="o">...</span> <span class="c1">// a RowMatrix</span>
<span class="c1">// Compute column summary statistics.</span>
<span class="k">val</span> <span class="n">summary</span><span class="k">:</span> <span class="kt">MultivariateStatisticalSummary</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">computeColumnSummaryStatistics</span><span class="o">()</span>
<span class="n">println</span><span class="o">(</span><span class="n">summary</span><span class="o">.</span><span class="n">mean</span><span class="o">)</span> <span class="c1">// a dense vector containing the mean value for each column</span>
<span class="n">println</span><span class="o">(</span><span class="n">summary</span><span class="o">.</span><span class="n">variance</span><span class="o">)</span> <span class="c1">// column-wise variance</span>
<span class="n">println</span><span class="o">(</span><span class="n">summary</span><span class="o">.</span><span class="n">numNonzeros</span><span class="o">)</span> <span class="c1">// number of nonzeros in each column</span>
<span class="c1">// Compute the covariance matrix.</span>
<span class="k">val</span> <span class="n">cov</span><span class="k">:</span> <span class="kt">Matrix</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">computeCovariance</span><span class="o">()</span>
</code></pre></div>
</div>
<div data-lang="java">
<p><a href="api/java/org/apache/spark/mllib/linalg/distributed/RowMatrix.html#computeColumnSummaryStatistics()"><code>RowMatrix#computeColumnSummaryStatistics</code></a> returns an instance of
<a href="api/java/org/apache/spark/mllib/stat/MultivariateStatisticalSummary.html"><code>MultivariateStatisticalSummary</code></a>,
which contains the column-wise max, min, mean, variance, and number of nonzeros, as well as the
total count.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.Matrix</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.RowMatrix</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.stat.MultivariateStatisticalSummary</span><span class="o">;</span>
<span class="n">RowMatrix</span> <span class="n">mat</span> <span class="o">=</span> <span class="o">...</span> <span class="c1">// a RowMatrix</span>
<span class="c1">// Compute column summary statistics.</span>
<span class="n">MultivariateStatisticalSummary</span> <span class="n">summary</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">computeColumnSummaryStatistics</span><span class="o">();</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">summary</span><span class="o">.</span><span class="na">mean</span><span class="o">());</span> <span class="c1">// a dense vector containing the mean value for each column</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">summary</span><span class="o">.</span><span class="na">variance</span><span class="o">());</span> <span class="c1">// column-wise variance</span>
<span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="n">summary</span><span class="o">.</span><span class="na">numNonzeros</span><span class="o">());</span> <span class="c1">// number of nonzeros in each column</span>
<span class="c1">// Compute the covariance matrix.</span>
<span class="n">Matrix</span> <span class="n">cov</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">computeCovariance</span><span class="o">();</span>
</code></pre></div>
</div>
</div>
<h3 id="indexedrowmatrix">IndexedRowMatrix</h3>
<p>An <code>IndexedRowMatrix</code> is similar to a <code>RowMatrix</code> but with meaningful row indices. It is backed by
an RDD of indexed rows, which each row is represented by its index (long-typed) and a local vector.</p>
<div class="codetabs">
<div data-lang="scala">
<p>An
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.distributed.IndexedRowMatrix"><code>IndexedRowMatrix</code></a>
can be created from an <code>RDD[IndexedRow]</code> instance, where
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.distributed.IndexedRow"><code>IndexedRow</code></a> is a
wrapper over <code>(Long, Vector)</code>. An <code>IndexedRowMatrix</code> can be converted to a <code>RowMatrix</code> by dropping
its row indices.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.</span><span class="o">{</span><span class="nc">IndexedRow</span><span class="o">,</span> <span class="nc">IndexedRowMatrix</span><span class="o">,</span> <span class="nc">RowMatrix</span><span class="o">}</span>
<span class="k">val</span> <span class="n">rows</span><span class="k">:</span> <span class="kt">RDD</span><span class="o">[</span><span class="kt">IndexedRow</span><span class="o">]</span> <span class="k">=</span> <span class="o">...</span> <span class="c1">// an RDD of indexed rows</span>
<span class="c1">// Create an IndexedRowMatrix from an RDD[IndexedRow].</span>
<span class="k">val</span> <span class="n">mat</span><span class="k">:</span> <span class="kt">IndexedRowMatrix</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">IndexedRowMatrix</span><span class="o">(</span><span class="n">rows</span><span class="o">)</span>
<span class="c1">// Get its size.</span>
<span class="k">val</span> <span class="n">m</span> <span class="k">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">numRows</span><span class="o">()</span>
<span class="k">val</span> <span class="n">n</span> <span class="k">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">numCols</span><span class="o">()</span>
<span class="c1">// Drop its row indices.</span>
<span class="k">val</span> <span class="n">rowMat</span><span class="k">:</span> <span class="kt">RowMatrix</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">toRowMatrix</span><span class="o">()</span>
</code></pre></div>
</div>
<div data-lang="java">
<p>An
<a href="api/java/org/apache/spark/mllib/linalg/distributed/IndexedRowMatrix.html"><code>IndexedRowMatrix</code></a>
can be created from an <code>JavaRDD<IndexedRow></code> instance, where
<a href="api/java/org/apache/spark/mllib/linalg/distributed/IndexedRow.html"><code>IndexedRow</code></a> is a
wrapper over <code>(long, Vector)</code>. An <code>IndexedRowMatrix</code> can be converted to a <code>RowMatrix</code> by dropping
its row indices.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.api.java.JavaRDD</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.IndexedRow</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.IndexedRowMatrix</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.RowMatrix</span><span class="o">;</span>
<span class="n">JavaRDD</span><span class="o"><</span><span class="n">IndexedRow</span><span class="o">></span> <span class="n">rows</span> <span class="o">=</span> <span class="o">...</span> <span class="c1">// a JavaRDD of indexed rows</span>
<span class="c1">// Create an IndexedRowMatrix from a JavaRDD<IndexedRow>.</span>
<span class="n">IndexedRowMatrix</span> <span class="n">mat</span> <span class="o">=</span> <span class="k">new</span> <span class="n">IndexedRowMatrix</span><span class="o">(</span><span class="n">rows</span><span class="o">.</span><span class="na">rdd</span><span class="o">());</span>
<span class="c1">// Get its size.</span>
<span class="kt">long</span> <span class="n">m</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">numRows</span><span class="o">();</span>
<span class="kt">long</span> <span class="n">n</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">numCols</span><span class="o">();</span>
<span class="c1">// Drop its row indices.</span>
<span class="n">RowMatrix</span> <span class="n">rowMat</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">toRowMatrix</span><span class="o">();</span>
</code></pre></div>
</div></div>
<h3 id="coordinatematrix">CoordinateMatrix</h3>
<p>A <code>CoordinateMatrix</code> is a distributed matrix backed by an RDD of its entries. Each entry is a tuple
of <code>(i: Long, j: Long, value: Double)</code>, where <code>i</code> is the row index, <code>j</code> is the column index, and
<code>value</code> is the entry value. A <code>CoordinateMatrix</code> should be used only in the case when both
dimensions of the matrix are huge and the matrix is very sparse.</p>
<div class="codetabs">
<div data-lang="scala">
<p>A
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.distributed.CoordinateMatrix"><code>CoordinateMatrix</code></a>
can be created from an <code>RDD[MatrixEntry]</code> instance, where
<a href="api/scala/index.html#org.apache.spark.mllib.linalg.distributed.MatrixEntry"><code>MatrixEntry</code></a> is a
wrapper over <code>(Long, Long, Double)</code>. A <code>CoordinateMatrix</code> can be converted to a <code>IndexedRowMatrix</code>
with sparse rows by calling <code>toIndexedRowMatrix</code>. In this release, we do not provide other
computation for <code>CoordinateMatrix</code>.</p>
<div class="highlight"><pre><code class="scala"><span class="k">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.</span><span class="o">{</span><span class="nc">CoordinateMatrix</span><span class="o">,</span> <span class="nc">MatrixEntry</span><span class="o">}</span>
<span class="k">val</span> <span class="n">entries</span><span class="k">:</span> <span class="kt">RDD</span><span class="o">[</span><span class="kt">MatrixEntry</span><span class="o">]</span> <span class="k">=</span> <span class="o">...</span> <span class="c1">// an RDD of matrix entries</span>
<span class="c1">// Create a CoordinateMatrix from an RDD[MatrixEntry].</span>
<span class="k">val</span> <span class="n">mat</span><span class="k">:</span> <span class="kt">CoordinateMatrix</span> <span class="o">=</span> <span class="k">new</span> <span class="nc">CoordinateMatrix</span><span class="o">(</span><span class="n">entries</span><span class="o">)</span>
<span class="c1">// Get its size.</span>
<span class="k">val</span> <span class="n">m</span> <span class="k">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">numRows</span><span class="o">()</span>
<span class="k">val</span> <span class="n">n</span> <span class="k">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">numCols</span><span class="o">()</span>
<span class="c1">// Convert it to an IndexRowMatrix whose rows are sparse vectors.</span>
<span class="k">val</span> <span class="n">indexedRowMatrix</span> <span class="k">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">toIndexedRowMatrix</span><span class="o">()</span>
</code></pre></div>
</div>
<div data-lang="java">
<p>A
<a href="api/java/org/apache/spark/mllib/linalg/distributed/CoordinateMatrix.html"><code>CoordinateMatrix</code></a>
can be created from a <code>JavaRDD<MatrixEntry></code> instance, where
<a href="api/java/org/apache/spark/mllib/linalg/distributed/MatrixEntry.html"><code>MatrixEntry</code></a> is a
wrapper over <code>(long, long, double)</code>. A <code>CoordinateMatrix</code> can be converted to a <code>IndexedRowMatrix</code>
with sparse rows by calling <code>toIndexedRowMatrix</code>.</p>
<div class="highlight"><pre><code class="java"><span class="kn">import</span> <span class="nn">org.apache.spark.api.java.JavaRDD</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.CoordinateMatrix</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.IndexedRowMatrix</span><span class="o">;</span>
<span class="kn">import</span> <span class="nn">org.apache.spark.mllib.linalg.distributed.MatrixEntry</span><span class="o">;</span>
<span class="n">JavaRDD</span><span class="o"><</span><span class="n">MatrixEntry</span><span class="o">></span> <span class="n">entries</span> <span class="o">=</span> <span class="o">...</span> <span class="c1">// a JavaRDD of matrix entries</span>
<span class="c1">// Create a CoordinateMatrix from a JavaRDD<MatrixEntry>.</span>
<span class="n">CoordinateMatrix</span> <span class="n">mat</span> <span class="o">=</span> <span class="k">new</span> <span class="n">CoordinateMatrix</span><span class="o">(</span><span class="n">entries</span><span class="o">.</span><span class="na">rdd</span><span class="o">());</span>
<span class="c1">// Get its size.</span>
<span class="kt">long</span> <span class="n">m</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">numRows</span><span class="o">();</span>
<span class="kt">long</span> <span class="n">n</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">numCols</span><span class="o">();</span>
<span class="c1">// Convert it to an IndexRowMatrix whose rows are sparse vectors.</span>
<span class="n">IndexedRowMatrix</span> <span class="n">indexedRowMatrix</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">toIndexedRowMatrix</span><span class="o">();</span>
</code></pre></div>
</div>
</div>
</div> <!-- /container -->
<script src="js/vendor/jquery-1.8.0.min.js"></script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/main.js"></script>
<!-- MathJax Section -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
TeX: { equationNumbers: { autoNumber: "AMS" } }
});
</script>
<script type="text/javascript"
src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<script>
MathJax.Hub.Config({
tex2jax: {
inlineMath: [ ["$", "$"], ["\\\\(","\\\\)"] ],
displayMath: [ ["$$","$$"], ["\\[", "\\]"] ],
processEscapes: true,
skipTags: ['script', 'noscript', 'style', 'textarea', 'pre']
}
});
</script>
</body>
</html>