Skip to content

Commit

Permalink
Calculate SVD using NumericJS for now
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitrohatgi committed Jul 11, 2018
1 parent 6044fb7 commit abc1673
Show file tree
Hide file tree
Showing 14 changed files with 120 additions and 45 deletions.
14 changes: 4 additions & 10 deletions app/javascript/core/mathFunctions.js
Expand Up @@ -150,19 +150,13 @@ wpd.cspline_interp = function(cs, x) {
// Perform a Singular Value Decomposition (SVD) of a mxn matrix:
// mat = [[...], [...], ...] (2D array, row-by-row)
wpd.svd = function(mat) {
// ref: https://en.wikipedia.org/wiki/Singular-value_decomposition#Numerical_approach

let rows = mat.length;
let cols = mat[0].length;

// Step 1: Reduce to a bidiagonal matrix using Householder reflections

// Step 2: QR algorithm for computation of eigenvalues
let result = numeric.svd(mat);

return {
U: null,
D: null,
V: null
U: result.U,
D: result.S,
V: result.V
};
};

Expand Down
10 changes: 5 additions & 5 deletions app/locale/de_DE/LC_MESSAGES/messages.po
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-06 21:38-0500\n"
"POT-Creation-Date: 2018-07-10 23:12-0500\n"
"PO-Revision-Date: 2017-10-24 22:43-0500\n"
"Last-Translator: \n"
"Language: de_DE\n"
Expand All @@ -16,27 +16,27 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.3.4\n"

#: templates/_base.html:26
msgid "Web based tool to extract numerical data from plots and graph images."
msgstr ""
"Web-basiertes Werkzeug zum Extrahieren von numerischen Daten aus "
"Aufzeichnungen und Bildern."

#: templates/_base.html:47
#: templates/_base.html:48
msgid "Loading application, please wait..."
msgstr "Bitte warten, Anwendung wird geladen..."

#: templates/_base.html:50
#: templates/_base.html:51
msgid ""
"Problems loading? Make sure you have a recent version of Google Chrome, "
"Firefox, Safari or Microsoft Edge installed."
msgstr ""
"Probleme beim Laden? Bitte stellen Sie sicher, dass eine akutelle Verion "
"von Google Chrome, Firefox, Safari oder Microsoft Edge installiert ist."

#: templates/_base.html:72
#: templates/_base.html:73
msgid "Fit"
msgstr "passen"

Expand Down
10 changes: 5 additions & 5 deletions app/locale/en_US/LC_MESSAGES/messages.po
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-06 21:38-0500\n"
"POT-Creation-Date: 2018-07-10 23:12-0500\n"
"PO-Revision-Date: 2016-12-12 23:09-0600\n"
"Last-Translator: \n"
"Language: en_US\n"
Expand All @@ -16,23 +16,23 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.3.4\n"

#: templates/_base.html:26
msgid "Web based tool to extract numerical data from plots and graph images."
msgstr ""

#: templates/_base.html:47
#: templates/_base.html:48
msgid "Loading application, please wait..."
msgstr ""

#: templates/_base.html:50
#: templates/_base.html:51
msgid ""
"Problems loading? Make sure you have a recent version of Google Chrome, "
"Firefox, Safari or Microsoft Edge installed."
msgstr ""

#: templates/_base.html:72
#: templates/_base.html:73
msgid "Fit"
msgstr ""

Expand Down
10 changes: 5 additions & 5 deletions app/locale/fr_FR/LC_MESSAGES/messages.po
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-06 21:38-0500\n"
"POT-Creation-Date: 2018-07-10 23:12-0500\n"
"PO-Revision-Date: 2017-11-01 23:56-0500\n"
"Last-Translator: \n"
"Language: fr_FR\n"
Expand All @@ -16,27 +16,27 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.3.4\n"

#: templates/_base.html:26
msgid "Web based tool to extract numerical data from plots and graph images."
msgstr ""
"Outil basé sur le Web pour extraire des données numériques à partir des "
"graphes et des images graphiques."

#: templates/_base.html:47
#: templates/_base.html:48
msgid "Loading application, please wait..."
msgstr "Chargement de l'application, veuillez patienter..."

#: templates/_base.html:50
#: templates/_base.html:51
msgid ""
"Problems loading? Make sure you have a recent version of Google Chrome, "
"Firefox, Safari or Microsoft Edge installed."
msgstr ""
"Problèmes de chargement? Assurez-vous d'avoir installé une version "
"récente de Google Chrome, Firefox, Safari ou Microsoft Edge."

#: templates/_base.html:72
#: templates/_base.html:73
msgid "Fit"
msgstr "Adapter"

Expand Down
10 changes: 5 additions & 5 deletions app/locale/ja/LC_MESSAGES/messages.po
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-06 21:38-0500\n"
"POT-Creation-Date: 2018-07-10 23:12-0500\n"
"PO-Revision-Date: 2016-12-18 10:38-0600\n"
"Last-Translator: \n"
"Language: ja\n"
Expand All @@ -16,23 +16,23 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.3.4\n"

#: templates/_base.html:26
msgid "Web based tool to extract numerical data from plots and graph images."
msgstr ""

#: templates/_base.html:47
#: templates/_base.html:48
msgid "Loading application, please wait..."
msgstr ""

#: templates/_base.html:50
#: templates/_base.html:51
msgid ""
"Problems loading? Make sure you have a recent version of Google Chrome, "
"Firefox, Safari or Microsoft Edge installed."
msgstr ""

#: templates/_base.html:72
#: templates/_base.html:73
msgid "Fit"
msgstr ""

Expand Down
10 changes: 5 additions & 5 deletions app/locale/messages.pot
Expand Up @@ -8,30 +8,30 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-06 21:38-0500\n"
"POT-Creation-Date: 2018-07-10 23:12-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.3.4\n"

#: templates/_base.html:26
msgid "Web based tool to extract numerical data from plots and graph images."
msgstr ""

#: templates/_base.html:47
#: templates/_base.html:48
msgid "Loading application, please wait..."
msgstr ""

#: templates/_base.html:50
#: templates/_base.html:51
msgid ""
"Problems loading? Make sure you have a recent version of Google Chrome, "
"Firefox, Safari or Microsoft Edge installed."
msgstr ""

#: templates/_base.html:72
#: templates/_base.html:73
msgid "Fit"
msgstr ""

Expand Down
10 changes: 5 additions & 5 deletions app/locale/ru/LC_MESSAGES/messages.po
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-06 21:38-0500\n"
"POT-Creation-Date: 2018-07-10 23:12-0500\n"
"PO-Revision-Date: 2016-12-18 10:38-0600\n"
"Last-Translator: \n"
"Language: ru\n"
Expand All @@ -17,23 +17,23 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.3.4\n"

#: templates/_base.html:26
msgid "Web based tool to extract numerical data from plots and graph images."
msgstr ""

#: templates/_base.html:47
#: templates/_base.html:48
msgid "Loading application, please wait..."
msgstr ""

#: templates/_base.html:50
#: templates/_base.html:51
msgid ""
"Problems loading? Make sure you have a recent version of Google Chrome, "
"Firefox, Safari or Microsoft Edge installed."
msgstr ""

#: templates/_base.html:72
#: templates/_base.html:73
msgid "Fit"
msgstr ""

Expand Down
10 changes: 5 additions & 5 deletions app/locale/zh_CN/LC_MESSAGES/messages.po
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: WebPlotDigitizer\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-07-06 21:38-0500\n"
"POT-Creation-Date: 2018-07-10 23:12-0500\n"
"PO-Revision-Date: 2018-02-21 00:47-0600\n"
"Last-Translator: RGXGR <rgxgr@outlook.com>\n"
"Language: zh_Hans_CN\n"
Expand All @@ -16,23 +16,23 @@ msgstr ""
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.5.3\n"
"Generated-By: Babel 2.3.4\n"

#: templates/_base.html:26
msgid "Web based tool to extract numerical data from plots and graph images."
msgstr "基于Web的图片数据提取工具。"

#: templates/_base.html:47
#: templates/_base.html:48
msgid "Loading application, please wait..."
msgstr "启动中,请稍等……"

#: templates/_base.html:50
#: templates/_base.html:51
msgid ""
"Problems loading? Make sure you have a recent version of Google Chrome, "
"Firefox, Safari or Microsoft Edge installed."
msgstr "启动错误? 确认安装了最新版本的Google Chrome,Firefox,Safari 或 Microsoft Edge。"

#: templates/_base.html:72
#: templates/_base.html:73
msgid "Fit"
msgstr "还原"

Expand Down
1 change: 1 addition & 0 deletions app/templates/_base.html
Expand Up @@ -39,6 +39,7 @@
<!-- thirdparty -->
<script src="thirdparty/pdfjs/build/pdf.js"></script>
<script src="thirdparty/tarballjs/tarballjs-master/tarball.js"></script>
<script src="thirdparty/numericjs/numeric-1.2.6.min.js"></script>
</head>

<body>
Expand Down
6 changes: 6 additions & 0 deletions app/tests/index.html
Expand Up @@ -5,6 +5,11 @@
<meta name="viewport" content="width=device-width">
<title>WPD Tests</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.4.0.css">

<!-- Third Party Libraries -->
<script src="../thirdparty/numericjs/numeric-1.2.6.min.js"></script>

<!-- WPD -->
<script src="../javascript/controllers/appData.js"></script>
<script src="../javascript/controllers/autoDetection.js"></script>
<script src="../javascript/controllers/axesCalibration.js"></script>
Expand Down Expand Up @@ -75,6 +80,7 @@
<script src="date_tests.js"></script>
<script src="save_tests.js"></script>
<script src="axes_tests.js"></script>
<script src="svd_tests.js"></script>
<script src="xstep_with_interp_tests.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions app/tests/svd_tests.js
@@ -0,0 +1,26 @@
QUnit.module("SVD tests");
QUnit.test("SVD of 3x3 matrix", function (assert) {

// test matrix
let mat = [
[1, 3, 4],
[6, 9, 8],
[6, 7, 9]
];

let expectedU = [[-0.25545925, -0.60219924, 0.75637071],
[-0.69818735, 0.65607252, 0.28653669],
[-0.66878622, -0.45489001, -0.58804768]];

let expectedD = [19.19848638, 1.66555095, 1.28220936];

let expectedVtranspose = [[-0.44051914, 0.36318063, -0.82100105],
[-0.61106731, 0.54866225, 0.57058434],
[-0.65767746, -0.75304022, 0.01976841]];

let result = wpd.svd(mat);

assert.equal(wpdtest.matCompare(result.U, expectedU, 1e-5), true, "U");
assert.equal(wpdtest.vecCompare(result.D, expectedD, 1e-5), true, "D");
assert.equal(wpdtest.matCompare(result.V, expectedVtranspose, 1e-5), true, "V");
});
39 changes: 39 additions & 0 deletions app/tests/testhelpers.js
Expand Up @@ -15,3 +15,42 @@ wpdtest.fetchJSON = function(filename) {
});
});
};

wpdtest.matCompare = function(mat1, mat2, eps) {
if(mat1 == null || mat2 == null) {
return false;
}
if (mat1.length != mat2.length) {
return false;
}
let rows = mat1.length;
let cols = mat2.length;
for (let rowIdx = 0; rowIdx < rows; rowIdx++) {

if (mat1[rowIdx].length != mat2[rowIdx].length) {
return false;
}

for (let colIdx = 0; colIdx < cols; colIdx++) {
if (Math.abs(mat1[rowIdx][colIdx] - mat2[rowIdx][colIdx]) > eps) {
return false;
}
}
}
return true;
};

wpdtest.vecCompare = function(vec1, vec2, eps) {
if (vec1 == null || vec2 == null) {
return false;
}
if (vec1.length != vec2.length) {
return false;
}
for (let vIdx = 0; vIdx < vec1.length; vIdx++) {
if (Math.abs(vec1[vIdx] - vec2[vIdx]) > eps) {
return false;
}
}
return true;
};
3 changes: 3 additions & 0 deletions app/thirdparty/README.md
Expand Up @@ -15,3 +15,6 @@ Use the ./getThirdparty.sh script, or follow the following steps manually:
- Download: https://github.com/ankitrohatgi/tarballjs/archive/master.zip
- Extract to tarballjs folder

4) NumericJS:
- Download: http://www.numericjs.com/lib/numeric-1.2.6.min.js
- Extract to numericjs folder

0 comments on commit abc1673

Please sign in to comment.