Skip to content

Commit

Permalink
[MINOR][SYSTEMDS-43] Cleanup scale builtin function (readability)
Browse files Browse the repository at this point in the history
  • Loading branch information
mboehm7 committed Jun 7, 2019
1 parent 66a68de commit f4fa565
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
2 changes: 2 additions & 0 deletions docs/Tasks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ SYSTEMDS-40 Preprocessing builtins
* 43 Add new scale builtin function OK
* 44 SotA normalization primitives
* 45 SotA outlier detection primitives
* 46 Generalization of quantiles


SYSTEMDS-50 I/O Formats
* 51 Support for homogeneous JSON (local/distributed)
Expand Down
20 changes: 8 additions & 12 deletions scripts/builtin/scale.dml
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,19 @@
m_scale = function(Matrix[Double] X, Boolean center, Boolean scale) return (Matrix[Double] Y) {
# This function centers scales and performs z-score on the input matrix X

if (center) {
cm = colMeans(X);
X = X - cm;
}
if( center )
X = X - colMeans(X);

if (scale) {
N = nrow(X);
cvars = (colSums(X^2));
if (center == TRUE) {
cm = colMeans(X);
cvars = (cvars - N*(cm^2))/(N-1);
}
if( center )
cvars = (colSums(X^2) - N*(colMeans(X)^2))/(N-1);
else
cvars = cvars/(N-1);
cvars = colSums(X^2)/(N-1);

X = X/sqrt(cvars);
X = replace(target=X, pattern=NaN, replacement=0); #replace NaNs with 0's
#scale by std-dev and replace NaNs with 0's
X = replace(target=X/sqrt(cvars),
pattern=NaN, replacement=0);
}
Y = X;
}

0 comments on commit f4fa565

Please sign in to comment.