Skip to content

Commit

Permalink
found new consolidations
Browse files Browse the repository at this point in the history
  • Loading branch information
e-strauss committed Feb 13, 2025
1 parent a4b4ac5 commit d60724e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
12 changes: 6 additions & 6 deletions scripts/builtin/winsorize.dml
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@
# -----------------------------------------------------------------------------------

m_winsorize = function(Matrix[Double] X, Double ql = 0.05, Double qu = 0.95, Boolean verbose)
return (Matrix[Double] Y, Matrix[Double] qLower, Matrix[Double] qUpper) {
qLower = matrix(0, rows=1, cols=ncol(X))
qUpper = matrix(0, rows=1, cols=ncol(X))
return (Matrix[Double] Y, Matrix[Double] QL, Matrix[Double] QU) {
QL = matrix(0, rows=1, cols=ncol(X))
QU = matrix(0, rows=1, cols=ncol(X))
Xtemp = replace(target=X, pattern=NaN, replacement=0)
parfor(i in 1:ncol(X), check=0) {
qLower[1,i] = quantile(Xtemp[,i], ql)
qUpper[1,i] = quantile(Xtemp[,i], qu)
QL[1,i] = quantile(Xtemp[,i], ql)
QU[1,i] = quantile(Xtemp[,i], qu)
}
Y = winsorizeApply(X, qLower, qUpper)
Y = winsorizeApply(X, QL, QU)
}

8 changes: 4 additions & 4 deletions scripts/builtin/winsorizeApply.dml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# INPUT:
# --------------------------------------------------
# X Input feature matrix
# ql row vector of upper bounds per column
# qu row vector of lower bounds per column
# QL row vector of upper bounds per column
# QU row vector of lower bounds per column
# --------------------------------------------------
#
# OUTPUT:
Expand All @@ -35,9 +35,9 @@
# ------------------------------------------------


m_winsorizeApply = function(Matrix[Double] X, Matrix[Double] ql, Matrix[Double] qu)
m_winsorizeApply = function(Matrix[Double] X, Matrix[Double] QL, Matrix[Double] QU)
return (Matrix[Double] Y)
{
# replace values outside [ql,qu] w/ ql and qu respectively
Y = min(max(X, ql), qu);
Y = min(max(X, QL), QU);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,21 @@


def winsorizeApply(X: Matrix,
ql: Matrix,
qu: Matrix):
QL: Matrix,
QU: Matrix):
"""
winsorizeApply takes the upper and lower quantile values per column, and
remove outliers by replacing them with these upper and lower bound values.
:param X: Input feature matrix
:param ql: row vector of upper bounds per column
:param qu: row vector of lower bounds per column
:param QL: row vector of upper bounds per column
:param QU: row vector of lower bounds per column
:return: Matrix without outlier values
"""

params_dict = {'X': X, 'ql': ql, 'qu': qu}
params_dict = {'X': X, 'QL': QL, 'QU': QU}
return Matrix(X.sds_context,
'winsorizeApply',
named_input_nodes=params_dict)

0 comments on commit d60724e

Please # to comment.