Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nipals loop for factorization #91

Merged
merged 10 commits into from
Jul 20, 2019
Merged

add nipals loop for factorization #91

merged 10 commits into from
Jul 20, 2019

Conversation

jwist
Copy link
Member

@jwist jwist commented Jul 15, 2019

this decomposition is needed for pca, pls and opls

@codecov
Copy link

codecov bot commented Jul 15, 2019

Codecov Report

Merging #91 into master will increase coverage by 0.83%.
The diff coverage is 96.07%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #91      +/-   ##
========================================
+ Coverage   59.16%    60%   +0.83%     
========================================
  Files          31     32       +1     
  Lines        3044   3095      +51     
  Branches      416    428      +12     
========================================
+ Hits         1801   1857      +56     
+ Misses       1140   1136       -4     
+ Partials      103    102       -1
Impacted Files Coverage Δ
src/dc/nipals.js 96.07% <96.07%> (ø)
src/matrix.js 63.11% <0%> (+0.2%) ⬆️
src/mathOperations.js 38.94% <0%> (+1.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 47ab51a...230c073. Read the comment docs.

@jwist
Copy link
Member Author

jwist commented Jul 15, 2019

with this the tests are as deep as possible...

src/dc/nipals.js Outdated
}

counter++;
if (counter > 1000) break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be an option with default value 1000. Not nice to have an hardcoded value in the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code has been modified as suggested. It is now an option.maxIterations with default value set to 1000

src/dc/nipals.js Outdated
} else {
return { t,
w,
residual: X.clone().sub(t.clone().mmul(w.transpose())) };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mmul creates always a new matrix so it it useless to clone in before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code has been modified as suggested

src/dc/nipals.js Outdated
let t, q, w, tOld;

let counter = 0;
for (var i = 0; diff > 1e-10; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should also be an options with default value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code has been updated as suggested: options.terminationCriteria has been set with default to 1e-10

src/dc/nipals.js Outdated
/**
* NIPALS
* @param {Matrix} X
* @param {*} Y
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y is a number ? Should be {number}. Small explanation of the option would be nice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y is a column vector to project onto X. If Y is passed then NIPALS works as a PLS instead of a PCA. The help has been updated accordingly.

src/dc/nipals.js Outdated
let t, q, w, tOld;

let counter = 0;
for (var i = 0; diff > 1e-10; i++) {
Copy link
Member

@targos targos Jul 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't actually use this i variable. It seems to me that you should instead increment the counter here.

for (var counter = 0; diff > 1e-10 && counter < 1000; counter++)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the conditions for the loop have been modified accordingly

@@ -0,0 +1,152 @@
[[5.1, 3.5, 1.4, 0.2, "setosa"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please remove this file and use ml-dataset-iris instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be:

npm install -D ml-dataset-iris

import { getNumbers } from 'ml-dataset-iris';
const rawData = getNumbers();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code has been modified accordingly

@Fil Fil mentioned this pull request Jul 18, 2019
@targos targos merged commit 043c8b6 into mljs:master Jul 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants