Repository: systemml Updated Branches: refs/heads/master 0aea2b531 -> 205c37fd4
[HOTFIX] Fix builtin constants (consistency w/ R, side effects) Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/205c37fd Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/205c37fd Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/205c37fd Branch: refs/heads/master Commit: 205c37fd4266f89a29b3574f3f5c415b95f3a3c6 Parents: 0aea2b5 Author: Matthias Boehm <[email protected]> Authored: Mon Apr 2 12:06:46 2018 -0700 Committer: Matthias Boehm <[email protected]> Committed: Mon Apr 2 12:08:01 2018 -0700 ---------------------------------------------------------------------- scripts/algorithms/GLM-predict.dml | 8 ++--- scripts/algorithms/GLM.dml | 34 +++++++++--------- scripts/algorithms/KM.dml | 12 +++---- scripts/algorithms/Kmeans.dml | 2 +- scripts/algorithms/StepGLM.dml | 36 +++++++++---------- scripts/staging/knn.dml | 2 +- .../apache/sysml/parser/BuiltinConstant.java | 8 ++--- .../parser/common/CommonSyntacticValidator.java | 2 +- .../applications/ctableStats/Binomial.dml | 2 +- src/test/scripts/applications/glm/GLM.pydml | 38 ++++++++++---------- .../applications/impute/imputeGaussMCMC.dml | 3 +- .../impute/imputeGaussMCMC.nogradient.dml | 1 - .../applications/impute/old/imputeGaussMCMC.dml | 1 - src/test/scripts/applications/impute/tmp.dml | 2 +- .../functions/codegenalg/Algorithm_GLM.R | 38 ++++++++++---------- .../functions/jmlc/reuse-glm-predict.dml | 8 ++--- .../functions/misc/ZeroMatrix_Aggregates.R | 4 +-- .../functions/misc/ZeroMatrix_Aggregates.dml | 4 +-- .../api/mlcontext/builtin-constants-test.dml | 6 ++-- 19 files changed, 104 insertions(+), 107 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/scripts/algorithms/GLM-predict.dml ---------------------------------------------------------------------- diff --git a/scripts/algorithms/GLM-predict.dml b/scripts/algorithms/GLM-predict.dml index 1cb571a..4b33be0 100644 --- a/scripts/algorithms/GLM-predict.dml +++ b/scripts/algorithms/GLM-predict.dml @@ -391,8 +391,8 @@ glm_means_and_vars = y_prob [, 1] = (1 - is_too_small) * (1.0 - y_prob [, 2]) + is_too_small * elt * (1.0 - elt / 2); } else if (link_type == 5) { # Binomial.cauchit atan_linear_terms = atan (linear_terms); - y_prob [, 1] = 0.5 + atan_linear_terms / PI; - y_prob [, 2] = 0.5 - atan_linear_terms / PI; + y_prob [, 1] = 0.5 + atan_linear_terms / pi; + y_prob [, 2] = 0.5 - atan_linear_terms / pi; } means = y_prob; ones_ctg = matrix (1, rows = 2, cols = 1); @@ -417,8 +417,8 @@ glm_partial_loglikelihood_for_power_dist_and_link = # Assumes: dist_type == 1 num_records = nrow (Y); if (var_power == 1.0) { # Poisson if (link_power == 0) { # Poisson.log - is_natural_parameter_log_zero = (linear_terms == -INF); - natural_parameters = replace (target = linear_terms, pattern = -INF, replacement = 0); + is_natural_parameter_log_zero = (linear_terms == -Inf); + natural_parameters = replace (target = linear_terms, pattern = -Inf, replacement = 0); b_cumulant = exp (linear_terms); } else { # Poisson.power_nonlog is_natural_parameter_log_zero = (linear_terms == 0); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/scripts/algorithms/GLM.dml ---------------------------------------------------------------------- diff --git a/scripts/algorithms/GLM.dml b/scripts/algorithms/GLM.dml index 825dc9f..d9c699a 100644 --- a/scripts/algorithms/GLM.dml +++ b/scripts/algorithms/GLM.dml @@ -638,7 +638,7 @@ return (Matrix[double] beta, double saturated_log_l, int isNaN) - log (- log (0.5)) * (is_zero_y_corr + is_one_y_corr) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr); } else if (link_type == 5) { # Binomial.cauchit - linear_terms = tan ((y_corr - 0.5) * PI) + linear_terms = tan ((y_corr - 0.5) * pi) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr); } } } @@ -741,9 +741,9 @@ glm_dist = function (Matrix[double] linear_terms, Matrix[double] Y, w = rowSums (Y) * vec1 / link_power ^ 2; } } else { - is_LT_infinite = cbind(linear_terms==INF, linear_terms==-INF); - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0); - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0); + is_LT_infinite = cbind(linear_terms==Inf, linear_terms==-Inf); + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0); + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0); if (link_type == 2) { # Binomial.logit Y_prob = cbind(exp(finite_linear_terms), ones_r); Y_prob = Y_prob / rowSums (Y_prob); @@ -771,11 +771,11 @@ glm_dist = function (Matrix[double] linear_terms, Matrix[double] Y, g_Y = (rowSums (Y) * the_exp_exp - Y [, 2]) / the_exp_ratio; w = the_exp_exp * the_exp * rowSums (Y) / the_exp_ratio; } else if (link_type == 5) { # Binomial.cauchit - Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / PI; + Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / pi; Y_prob = Y_prob * (1.0 - rowSums (is_LT_infinite)) + is_LT_infinite; y_residual = Y [, 1] * Y_prob [, 2] - Y [, 2] * Y_prob [, 1]; var_function = rowSums (Y) * Y_prob [, 1] * Y_prob [, 2]; - link_gradient_normalized = (1 + linear_terms ^ 2) * PI; + link_gradient_normalized = (1 + linear_terms ^ 2) * pi; g_Y = rowSums (Y) * y_residual / (var_function * link_gradient_normalized); w = (rowSums (Y) ^ 2) / (var_function * link_gradient_normalized ^ 2); } @@ -800,8 +800,8 @@ glm_log_likelihood_part = function (Matrix[double] linear_terms, Matrix[double] is_natural_parameter_log_zero = zeros_r; if (var_power == 1.0 & link_power == 0) { # Poisson.log b_cumulant = exp (linear_terms); - is_natural_parameter_log_zero = (linear_terms == -INF); - natural_parameters = replace (target = linear_terms, pattern = -INF, replacement = 0); + is_natural_parameter_log_zero = (linear_terms == -Inf); + natural_parameters = replace (target = linear_terms, pattern = -Inf, replacement = 0); } else if (var_power == 1.0 & link_power == 1.0) { # Poisson.id if (sum (linear_terms < 0) == 0) { b_cumulant = linear_terms; @@ -878,14 +878,14 @@ glm_log_likelihood_part = function (Matrix[double] linear_terms, Matrix[double] } } if (sum (is_natural_parameter_log_zero * abs (Y)) > 0) { - log_l = -INF; + log_l = -Inf; isNaN = 1; } if (isNaN == 0) { log_l = sum (Y * natural_parameters - b_cumulant); if (log_l != log_l | (log_l == log_l + 1.0 & log_l == log_l * 2.0)) { - log_l = -INF; + log_l = -Inf; isNaN = 1; } } } @@ -901,12 +901,12 @@ glm_log_likelihood_part = function (Matrix[double] linear_terms, Matrix[double] isNaN = 1; } } else { - log_l = -INF; + log_l = -Inf; isNaN = 1; } } } if (isNaN == 1) { - log_l = - INF; + log_l = - Inf; } } @@ -938,9 +938,9 @@ binomial_probability_two_column = isNaN = 1; } } else { # Binomial.non_power - is_LT_infinite = cbind(linear_terms==INF, linear_terms==-INF); - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0); - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0); + is_LT_infinite = cbind(linear_terms==Inf, linear_terms==-Inf); + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0); + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0); if (link_type == 2) { # Binomial.logit Y_prob = cbind(exp(finite_linear_terms), ones_r); Y_prob = Y_prob / rowSums (Y_prob); @@ -961,7 +961,7 @@ binomial_probability_two_column = Y_prob [, 1] = (1 - is_too_small) * (1 - the_exp_exp) + is_too_small * the_exp * (1 - the_exp / 2); Y_prob [, 2] = the_exp_exp; } else if (link_type == 5) { # Binomial.cauchit - Y_prob = 0.5 + cbind(atan(finite_linear_terms), -atan(finite_linear_terms)) / PI; + Y_prob = 0.5 + cbind(atan(finite_linear_terms), -atan(finite_linear_terms)) / pi; } else { isNaN = 1; } @@ -1109,7 +1109,7 @@ return (double mantissa, int eee) { mantissa = 1.0; eee = 0; - positive_infinity = INF; + positive_infinity = Inf; x = abs (x_to_truncate); if (x != x / 2.0) { log_ten = log (10.0); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/scripts/algorithms/KM.dml ---------------------------------------------------------------------- diff --git a/scripts/algorithms/KM.dml b/scripts/algorithms/KM.dml index 7659244..ba01026 100644 --- a/scripts/algorithms/KM.dml +++ b/scripts/algorithms/KM.dml @@ -186,11 +186,11 @@ if (n_group_cols > 0) { Idx[2:num_records,] = rowMaxs (X[1:(num_records - 1),3:(2 + n_group_cols)] != X[2:num_records,3:(2 + n_group_cols)]); num_groups = sum (Idx); - XG = replace (target = XG, pattern = 0, replacement = INF); + XG = replace (target = XG, pattern = 0, replacement = Inf); XG = XG * Idx; XG = replace (target = XG, pattern = NaN, replacement = 0); G_cols = removeEmpty (target = XG, margin = "rows"); - G_cols = replace (target = G_cols, pattern = INF, replacement = 0); + G_cols = replace (target = G_cols, pattern = Inf, replacement = 0); A = removeEmpty (target = diag (Idx), margin = "cols"); if (ncol (A) > 1) { @@ -226,7 +226,7 @@ if (n_stratum_cols > 0) { XS = XS * Idx; XS = replace (target = XS, pattern = NaN, replacement = 0); S_cols = removeEmpty (target = XS, margin = "rows"); - S_cols = replace (target = S_cols, pattern = INF, replacement = 0); + S_cols = replace (target = S_cols, pattern = Inf, replacement = 0); SB = removeEmpty (target = seq (1,num_records), margin = "rows", select = Idx); # indices of stratum boundaries A = removeEmpty (target = diag (Idx), margin = "cols"); @@ -317,7 +317,7 @@ parfor (s in 1:num_strata, check = 0) { time_stratum = table (seq (1, nrow (Idx1), 1), Idx1) %*% T; # distinct timestamps both censored and uncensored per stratum time_stratum_has_zero = sum (time_stratum == 0) > 0; if (time_stratum_has_zero) { - time_stratum = replace (target = time_stratum, pattern = 0, replacement = INF); + time_stratum = replace (target = time_stratum, pattern = 0, replacement = Inf); } n_time_all1 = nrow (n_event_stratum); # no. of distinct timestamps both censored and uncensored per stratum n_event_all_stratum_agg = matrix (0, rows = n_time_all1, cols = 1); @@ -351,7 +351,7 @@ parfor (s in 1:num_strata, check = 0) { if (time_stratum_has_zero) { time = replace (target = time_stratum * event_occurred, pattern = NaN, replacement = 0); time = removeEmpty (target = time, margin = "rows"); - time = replace (target = time, pattern = INF, replacement = 0); + time = replace (target = time, pattern = Inf, replacement = 0); } else { time = removeEmpty (target = time_stratum * event_occurred, margin = "rows"); } @@ -582,7 +582,7 @@ if (n_stratum_cols > 0) { M_cols = removeEmpty (target = M_cols, margin = "rows"); tab_M = table (seq (1, nrow (M_cols)), M_cols, nrow (M_cols), nrow (M)); M = tab_M %*% M; -M = replace (target = M, pattern = INF, replacement = NaN); +M = replace (target = M, pattern = Inf, replacement = NaN); # pull out non-empty rows from TEST if (n_group_cols > 0 & n_stratum_cols > 0) { http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/scripts/algorithms/Kmeans.dml ---------------------------------------------------------------------- diff --git a/scripts/algorithms/Kmeans.dml b/scripts/algorithms/Kmeans.dml index 640cc13..54bff85 100644 --- a/scripts/algorithms/Kmeans.dml +++ b/scripts/algorithms/Kmeans.dml @@ -135,7 +135,7 @@ parfor (run_index in 1 : num_runs, check = 0) C_old = C; iter_count = 0; term_code = 0; - wcss = INF + wcss = Inf while (term_code == 0) { http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/scripts/algorithms/StepGLM.dml ---------------------------------------------------------------------- diff --git a/scripts/algorithms/StepGLM.dml b/scripts/algorithms/StepGLM.dml index 34ed672..0fd02bc 100644 --- a/scripts/algorithms/StepGLM.dml +++ b/scripts/algorithms/StepGLM.dml @@ -702,7 +702,7 @@ glm_initialize = function (Matrix[double] X, Matrix[double] Y, int dist_type, do - log (- log (0.5)) * (is_zero_y_corr + is_one_y_corr) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr); } else { if (link_type == 5) { # Binomial.cauchit - linear_terms = tan ((y_corr - 0.5) * PI) + linear_terms = tan ((y_corr - 0.5) * pi) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr); }} }}}}} } @@ -815,11 +815,11 @@ glm_dist = function (Matrix[double] linear_terms, Matrix[double] Y, w = rowSums (Y) * vec1 / link_power ^ 2; } } else { - is_LT_pos_infinite = (linear_terms == INF); - is_LT_neg_infinite = (linear_terms == -INF); + is_LT_pos_infinite = (linear_terms == Inf); + is_LT_neg_infinite = (linear_terms == -Inf); is_LT_infinite = is_LT_pos_infinite %*% one_zero + is_LT_neg_infinite %*% zero_one; - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0); - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0); + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0); + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0); if (link_type == 2) { # Binomial.logit Y_prob = exp (finite_linear_terms) %*% one_zero + ones_r %*% zero_one; Y_prob = Y_prob / (rowSums (Y_prob) %*% ones_2); @@ -847,11 +847,11 @@ glm_dist = function (Matrix[double] linear_terms, Matrix[double] Y, g_Y = (rowSums (Y) * the_exp_exp - Y [, 2]) / the_exp_ratio; w = the_exp_exp * the_exp * rowSums (Y) / the_exp_ratio; } else { if (link_type == 5) { # Binomial.cauchit - Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / PI; + Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / pi; Y_prob = Y_prob * ((1.0 - rowSums (is_LT_infinite)) %*% ones_2) + is_LT_infinite; y_residual = Y [, 1] * Y_prob [, 2] - Y [, 2] * Y_prob [, 1]; var_function = rowSums (Y) * Y_prob [, 1] * Y_prob [, 2]; - link_gradient_normalized = (1 + linear_terms ^ 2) * PI; + link_gradient_normalized = (1 + linear_terms ^ 2) * pi; g_Y = rowSums (Y) * y_residual / (var_function * link_gradient_normalized); w = (rowSums (Y) ^ 2) / (var_function * link_gradient_normalized ^ 2); }}}} @@ -876,8 +876,8 @@ glm_log_likelihood_part = function (Matrix[double] linear_terms, Matrix[double] is_natural_parameter_log_zero = zeros_r; if (var_power == 1.0 & link_power == 0) { # Poisson.log b_cumulant = exp (linear_terms); - is_natural_parameter_log_zero = (linear_terms == -INF); - natural_parameters = replace (target = linear_terms, pattern = -INF, replacement = 0); + is_natural_parameter_log_zero = (linear_terms == -Inf); + natural_parameters = replace (target = linear_terms, pattern = -Inf, replacement = 0); } else { if (var_power == 1.0 & link_power == 1.0) { # Poisson.id if (sum (linear_terms < 0) == 0) { b_cumulant = linear_terms; @@ -953,14 +953,14 @@ glm_log_likelihood_part = function (Matrix[double] linear_terms, Matrix[double] }}}} }}}}} }}}}} if (sum (is_natural_parameter_log_zero * abs (Y)) > 0) { - log_l = -INF; + log_l = -Inf; isNaN = 1; } if (isNaN == 0) { log_l = sum (Y * natural_parameters - b_cumulant); if (log_l != log_l | (log_l == log_l + 1.0 & log_l == log_l * 2.0)) { - log_l = -INF; + log_l = -Inf; isNaN = 1; } } } @@ -977,12 +977,12 @@ glm_log_likelihood_part = function (Matrix[double] linear_terms, Matrix[double] isNaN = 1; } } else { - log_l = -INF; + log_l = -Inf; isNaN = 1; } } } if (isNaN == 1) { - log_l = - INF; + log_l = - Inf; } } @@ -1024,11 +1024,11 @@ binomial_probability_two_column = } else {isNaN = 1;} }} } else { # Binomial.non_power - is_LT_pos_infinite = (linear_terms == INF); - is_LT_neg_infinite = (linear_terms == -INF); + is_LT_pos_infinite = (linear_terms == Inf); + is_LT_neg_infinite = (linear_terms == -Inf); is_LT_infinite = is_LT_pos_infinite %*% one_zero + is_LT_neg_infinite %*% zero_one; - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0); - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0); + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0); + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0); if (link_type == 2) { # Binomial.logit Y_prob = exp (finite_linear_terms) %*% one_zero + ones_r %*% zero_one; Y_prob = Y_prob / (rowSums (Y_prob) %*% ones_2); @@ -1049,7 +1049,7 @@ binomial_probability_two_column = Y_prob [, 1] = (1 - is_too_small) * (1 - the_exp_exp) + is_too_small * the_exp * (1 - the_exp / 2); Y_prob [, 2] = the_exp_exp; } else { if (link_type == 5) { # Binomial.cauchit - Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / PI; + Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / pi; } else { isNaN = 1; }}}} http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/scripts/staging/knn.dml ---------------------------------------------------------------------- diff --git a/scripts/staging/knn.dml b/scripts/staging/knn.dml index bb638fe..2e49f9c 100644 --- a/scripts/staging/knn.dml +++ b/scripts/staging/knn.dml @@ -559,7 +559,7 @@ return( } d_max_err_value = ( max( in_m_data_target ) - min( in_m_data_target ) ) * 100; b_continue_main_loop = TRUE; #level 1 while loop flag - d_min_LOOCV = INF; + d_min_LOOCV = Inf; while( b_continue_main_loop ){ m_feature_selected_flag = m_main_selected_flag; m_this_model_selected_flag = TRUE; http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/main/java/org/apache/sysml/parser/BuiltinConstant.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/BuiltinConstant.java b/src/main/java/org/apache/sysml/parser/BuiltinConstant.java index 5325e80..c26fdc4 100644 --- a/src/main/java/org/apache/sysml/parser/BuiltinConstant.java +++ b/src/main/java/org/apache/sysml/parser/BuiltinConstant.java @@ -25,10 +25,10 @@ import org.apache.commons.lang3.EnumUtils; * These are the builtin constants */ public enum BuiltinConstant { - PI(Math.PI), - INF(Double.POSITIVE_INFINITY), - NaN(Double.NaN); - + Inf(Double.POSITIVE_INFINITY), + NaN(Double.NaN), + pi(Math.PI); + private DoubleIdentifier _id; private BuiltinConstant(double d) { http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java index d1b8cf6..fb25a6a 100644 --- a/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java +++ b/src/main/java/org/apache/sysml/parser/common/CommonSyntacticValidator.java @@ -333,7 +333,7 @@ public abstract class CommonSyntacticValidator { if (dataInfo.expr instanceof DataIdentifier) { DataIdentifier id = ((DataIdentifier) dataInfo.expr); if (BuiltinConstant.contains(id.getName())) { - dataInfo.expr = BuiltinConstant.valueOf(id.getName()).get(); + dataInfo.expr = new DoubleIdentifier(BuiltinConstant.valueOf(id.getName()).get(), dataInfo.expr); } } me.expr = dataInfo.expr; http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/applications/ctableStats/Binomial.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/applications/ctableStats/Binomial.dml b/src/test/scripts/applications/ctableStats/Binomial.dml index 6403a66..1946a82 100644 --- a/src/test/scripts/applications/ctableStats/Binomial.dml +++ b/src/test/scripts/applications/ctableStats/Binomial.dml @@ -164,7 +164,7 @@ logFactorial = function (Matrix[double] x) return (Matrix[double] logfact) y = y - 1.231739516140 / (x + 4); y = y + 0.001208580030 / (x + 5); y = y - 0.000005363820 / (x + 6); - logfact = log(y) + (x + 0.5) * log(x + 5.5) - (x + 5.5) + 0.91893853320467; # log(sqrt(2 * PI)); + logfact = log(y) + (x + 0.5) * log(x + 5.5) - (x + 5.5) + 0.91893853320467; # log(sqrt(2 * pi)); } http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/applications/glm/GLM.pydml ---------------------------------------------------------------------- diff --git a/src/test/scripts/applications/glm/GLM.pydml b/src/test/scripts/applications/glm/GLM.pydml index ce7e02a..373f8b1 100644 --- a/src/test/scripts/applications/glm/GLM.pydml +++ b/src/test/scripts/applications/glm/GLM.pydml @@ -729,7 +729,7 @@ def glm_initialize(X: matrix[float], Y: matrix[float], dist_type: int, var_power linear_terms = log (- log (1.0 - y_corr)) - log (- log (0.5)) * (is_zero_y_corr + is_one_y_corr) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr) else: if (link_type == 5): # Binomial.cauchit - linear_terms = tan ((y_corr - 0.5) * PI) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr) + linear_terms = tan ((y_corr - 0.5) * pi) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr) @@ -852,11 +852,11 @@ def glm_dist(linear_terms: matrix[float], Y: matrix[float], dist_type: int, var_ w = rowSums (Y) * vec1 / link_power ** 2 else: - is_LT_pos_infinite = (linear_terms == INF) - is_LT_neg_infinite = (linear_terms == -INF) + is_LT_pos_infinite = (linear_terms == Inf) + is_LT_neg_infinite = (linear_terms == -Inf) is_LT_infinite = dot(is_LT_pos_infinite, one_zero) + dot(is_LT_neg_infinite, zero_one) - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0) - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0) + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0) + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0) if (link_type == 2): # Binomial.logit Y_prob = dot(exp (finite_linear_terms), one_zero) + dot(ones_r, zero_one) Y_prob = Y_prob / (dot(rowSums (Y_prob), ones_2)) @@ -887,11 +887,11 @@ def glm_dist(linear_terms: matrix[float], Y: matrix[float], dist_type: int, var_ w = the_exp_exp * the_exp * rowSums (Y) / the_exp_ratio else: if (link_type == 5): # Binomial.cauchit - Y_prob = 0.5 + (dot(atan (finite_linear_terms), p_one_m_one)) / PI + Y_prob = 0.5 + (dot(atan (finite_linear_terms), p_one_m_one)) / pi Y_prob = Y_prob * (dot((1.0 - rowSums (is_LT_infinite)), ones_2)) + is_LT_infinite y_residual = Y [, 0] * Y_prob [, 1] - Y [, 1] * Y_prob [, 0] var_function = rowSums (Y) * Y_prob [, 0] * Y_prob [, 1] - link_gradient_normalized = (1 + linear_terms ** 2) * PI + link_gradient_normalized = (1 + linear_terms ** 2) * pi g_Y = rowSums (Y) * y_residual / (var_function * link_gradient_normalized) w = (rowSums (Y) ** 2) / (var_function * link_gradient_normalized ** 2) @@ -915,8 +915,8 @@ def glm_log_likelihood_part(linear_terms: matrix[float], Y: matrix[float], is_natural_parameter_log_zero = zeros_r if (var_power == 1.0 & link_power == 0.0): # Poisson.log b_cumulant = exp (linear_terms) - is_natural_parameter_log_zero = (linear_terms == -INF) - natural_parameters = replace (target = linear_terms, pattern = -INF, replacement = 0) + is_natural_parameter_log_zero = (linear_terms == -Inf) + natural_parameters = replace (target = linear_terms, pattern = -Inf, replacement = 0) else: if (var_power == 1.0 & link_power == 1.0): # Poisson.id if (sum (linear_terms < 0.0) == 0): @@ -1040,12 +1040,12 @@ def glm_log_likelihood_part(linear_terms: matrix[float], Y: matrix[float], if (sum (is_natural_parameter_log_zero * abs (Y)) > 0.0): - log_l = -INF + log_l = -Inf isNaN = 1 if (isNaN == 0): log_l = sum (Y * natural_parameters - b_cumulant) if (log_l != log_l | (log_l == log_l + 1.0 & log_l == log_l * 2.0)): - log_l = -INF + log_l = -Inf isNaN = 1 # end if (dist_type == 1 & link_type == 1): # POWER DISTRIBUTION @@ -1059,11 +1059,11 @@ def glm_log_likelihood_part(linear_terms: matrix[float], Y: matrix[float], if (log_l != log_l | (log_l == log_l + 1.0 & log_l == log_l * 2.0)): isNaN = 1 else: - log_l = -INF + log_l = -Inf isNaN = 1 if (isNaN == 1): - log_l = - INF + log_l = - Inf def binomial_probability_two_column(linear_terms: matrix[float], link_type: int, link_power: float) -> (Y_prob: matrix[float], isNaN: int): @@ -1100,11 +1100,11 @@ def binomial_probability_two_column(linear_terms: matrix[float], link_type: int, else: isNaN = 1 else: # Binomial.non_power - is_LT_pos_infinite = (linear_terms == INF) - is_LT_neg_infinite = (linear_terms == -INF) + is_LT_pos_infinite = (linear_terms == Inf) + is_LT_neg_infinite = (linear_terms == -Inf) is_LT_infinite = dot(is_LT_pos_infinite, one_zero) + dot(is_LT_neg_infinite, zero_one) - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0) - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0) + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0) + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0) if (link_type == 2): # Binomial.logit Y_prob = dot(exp (finite_linear_terms), one_zero) + dot(ones_r, zero_one) Y_prob = Y_prob / (dot(rowSums (Y_prob), ones_2)) @@ -1128,7 +1128,7 @@ def binomial_probability_two_column(linear_terms: matrix[float], link_type: int, Y_prob [, 1] = the_exp_exp else: if (link_type == 5): # Binomial.cauchit - Y_prob = 0.5 + (dot(atan (finite_linear_terms), p_one_m_one)) / PI + Y_prob = 0.5 + (dot(atan (finite_linear_terms), p_one_m_one)) / pi else: isNaN = 1 Y_prob = Y_prob * (dot((1.0 - rowSums (is_LT_infinite)), ones_2)) + is_LT_infinite @@ -1254,7 +1254,7 @@ def straightenX(X: matrix[float], eps: float, max_iter_CG: int) -> (w: matrix[fl def round_to_print(x_to_truncate: float) -> (mantissa: float, eee: int): mantissa = 1.0 eee = 0 - positive_infinity = INF + positive_infinity = Inf x = abs (x_to_truncate) if (x != x / 2.0): log_ten = log (10.0) http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/applications/impute/imputeGaussMCMC.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/applications/impute/imputeGaussMCMC.dml b/src/test/scripts/applications/impute/imputeGaussMCMC.dml index edd1df2..b7223d9 100644 --- a/src/test/scripts/applications/impute/imputeGaussMCMC.dml +++ b/src/test/scripts/applications/impute/imputeGaussMCMC.dml @@ -386,7 +386,7 @@ while (is_enough_gradient_descent == 0) if (acos_argument >= 0.0) { coeff_theta = acos_x; } else { - coeff_theta = PI - acos_x; + coeff_theta = pi - acos_x; } root_1 = - coeff_aa / 3.0 - 2.0 * sqrt (coeff_Q) * cos (coeff_theta / 3.0); @@ -484,7 +484,6 @@ for (swap_i in 1:num_swaps) { } } -pi = PI; zero = matrix (0.0, rows = 1, cols = 1); isVar = colSums (SampleOrder [1 : num_frees, ]); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/applications/impute/imputeGaussMCMC.nogradient.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/applications/impute/imputeGaussMCMC.nogradient.dml b/src/test/scripts/applications/impute/imputeGaussMCMC.nogradient.dml index 483b37f..617826d 100644 --- a/src/test/scripts/applications/impute/imputeGaussMCMC.nogradient.dml +++ b/src/test/scripts/applications/impute/imputeGaussMCMC.nogradient.dml @@ -247,7 +247,6 @@ for (swap_i in 1:num_swaps) { } } -pi = PI; zero = matrix (0.0, rows = 1, cols = 1); isVar = colSums (SampleOrder [1 : num_frees, ]); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/applications/impute/old/imputeGaussMCMC.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/applications/impute/old/imputeGaussMCMC.dml b/src/test/scripts/applications/impute/old/imputeGaussMCMC.dml index 58059b9..960413a 100644 --- a/src/test/scripts/applications/impute/old/imputeGaussMCMC.dml +++ b/src/test/scripts/applications/impute/old/imputeGaussMCMC.dml @@ -242,7 +242,6 @@ sum_of_observed_reports = matrix (0.0, rows = num_attrs, cols = num_terms); sum_of_observed_params = matrix (0.0, rows = num_params, cols = 1); num_of_observed_reports = 0; -pi = PI; zero = matrix (0.0, rows = 1, cols = 1); # Starting MCMC iterations http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/applications/impute/tmp.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/applications/impute/tmp.dml b/src/test/scripts/applications/impute/tmp.dml index 2e7acbe..26dd73e 100644 --- a/src/test/scripts/applications/impute/tmp.dml +++ b/src/test/scripts/applications/impute/tmp.dml @@ -73,7 +73,7 @@ coeff_d = 3.14 * (2 * (-3) * (-1.7)); if (acos_argument >= 0.0) { coeff_theta = acos_x; } else { - coeff_theta = PI - acos_x; + coeff_theta = pi - acos_x; } root_1 = - coeff_aa / 3.0 - 2.0 * sqrt (coeff_Q) * cos (coeff_theta / 3.0); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/functions/codegenalg/Algorithm_GLM.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/codegenalg/Algorithm_GLM.R b/src/test/scripts/functions/codegenalg/Algorithm_GLM.R index 8c14960..37646f3 100644 --- a/src/test/scripts/functions/codegenalg/Algorithm_GLM.R +++ b/src/test/scripts/functions/codegenalg/Algorithm_GLM.R @@ -151,7 +151,7 @@ glm_initialize <- function (X, Y, dist_type, var_power, link_type, link_power, i - log (- log (0.5)) * (is_zero_y_corr + is_one_y_corr) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr); } else { if (link_type == 5) { # Binomial.cauchit - linear_terms = tan ((y_corr - 0.5) * PI) + linear_terms = tan ((y_corr - 0.5) * pi) + is_one_y_corr / (1.0 - is_one_y_corr) - is_zero_y_corr / (1.0 - is_zero_y_corr); }} }}}}} } @@ -259,11 +259,11 @@ glm_dist <- function (linear_terms, Y, w = rowSums (Y) * vec1 / link_power ^ 2; } } else { - is_LT_pos_infinite = (linear_terms == INF); - is_LT_neg_infinite = (linear_terms == -INF); + is_LT_pos_infinite = (linear_terms == Inf); + is_LT_neg_infinite = (linear_terms == -Inf); is_LT_infinite = is_LT_pos_infinite %*% one_zero + is_LT_neg_infinite %*% zero_one; - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0); - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0); + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0); + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0); if (link_type == 2) { # Binomial.logit Y_prob = exp (finite_linear_terms) %*% one_zero + ones_r %*% zero_one; Y_prob = Y_prob / (rowSums (Y_prob) %*% ones_2); @@ -291,11 +291,11 @@ glm_dist <- function (linear_terms, Y, g_Y = (rowSums (Y) * the_exp_exp - Y [, 2]) / the_exp_ratio; w = the_exp_exp * the_exp * rowSums (Y) / the_exp_ratio; } else { if (link_type == 5) { # Binomial.cauchit - Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / PI; + Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / pi; Y_prob = Y_prob * ((1.0 - rowSums (is_LT_infinite)) %*% ones_2) + is_LT_infinite; y_residual = Y [, 1] * Y_prob [, 2] - Y [, 2] * Y_prob [, 1]; var_function = rowSums (Y) * Y_prob [, 1] * Y_prob [, 2]; - link_gradient_normalized = (1 + linear_terms ^ 2) * PI; + link_gradient_normalized = (1 + linear_terms ^ 2) * pi; g_Y = rowSums (Y) * y_residual / (var_function * link_gradient_normalized); w = (rowSums (Y) ^ 2) / (var_function * link_gradient_normalized ^ 2); }}}} @@ -321,8 +321,8 @@ glm_log_likelihood_part <- function (linear_terms, Y, is_natural_parameter_log_zero = zeros_r; if (var_power == 1.0 & link_power == 0.0) { # Poisson.log b_cumulant = exp (linear_terms); - is_natural_parameter_log_zero = (linear_terms == (-INF)); - natural_parameters = replace (target = linear_terms, pattern = -INF, replacement = 0); + is_natural_parameter_log_zero = (linear_terms == (-Inf)); + natural_parameters = replace (target = linear_terms, pattern = -Inf, replacement = 0); } else { if (var_power == 1.0 & link_power == 1.0) { # Poisson.id if (sum ((linear_terms < 0.0)) == 0) { b_cumulant = linear_terms; @@ -398,14 +398,14 @@ glm_log_likelihood_part <- function (linear_terms, Y, }}}} }}}}} }}}}} if (sum (is_natural_parameter_log_zero * abs (Y)) > 0.0) { - log_l = -INF; + log_l = -Inf; isNaN = 1; } if (isNaN == 0) { log_l = sum (Y * natural_parameters - b_cumulant); if (log_l != log_l | (log_l == log_l + 1.0 & log_l == log_l * 2.0)) { - log_l = -INF; + log_l = -Inf; isNaN = 1; } } } @@ -424,12 +424,12 @@ glm_log_likelihood_part <- function (linear_terms, Y, isNaN = 1; } } else { - log_l = -INF; + log_l = -Inf; isNaN = 1; } } } if (isNaN == 1) { - log_l = - INF; + log_l = - Inf; } } @@ -469,11 +469,11 @@ binomial_probability_two_column <- function (linear_terms, link_type, link_power } else {isNaN = 1;} }} } else { # Binomial.non_power - is_LT_pos_infinite = (linear_terms == INF); - is_LT_neg_infinite = (linear_terms == -INF); + is_LT_pos_infinite = (linear_terms == Inf); + is_LT_neg_infinite = (linear_terms == -Inf); is_LT_infinite = is_LT_pos_infinite %*% one_zero + is_LT_neg_infinite %*% zero_one; - finite_linear_terms = replace (target = linear_terms, pattern = INF, replacement = 0); - finite_linear_terms = replace (target = finite_linear_terms, pattern = -INF, replacement = 0); + finite_linear_terms = replace (target = linear_terms, pattern = Inf, replacement = 0); + finite_linear_terms = replace (target = finite_linear_terms, pattern = -Inf, replacement = 0); if (link_type == 2) { # Binomial.logit Y_prob = exp (finite_linear_terms) %*% one_zero + ones_r %*% zero_one; Y_prob = Y_prob / (rowSums (Y_prob) %*% ones_2); @@ -494,7 +494,7 @@ binomial_probability_two_column <- function (linear_terms, link_type, link_power Y_prob [, 1] = (1 - is_too_small) * (1 - the_exp_exp) + is_too_small * the_exp * (1 - the_exp / 2); Y_prob [, 2] = the_exp_exp; } else { if (link_type == 5) { # Binomial.cauchit - Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / PI; + Y_prob = 0.5 + (atan (finite_linear_terms) %*% p_one_m_one) / pi; } else { isNaN = 1; }}}} @@ -651,7 +651,7 @@ round_to_print <- function (x_to_truncate) { mantissa = 1.0; eee = 0; - positive_infinity = INF; + positive_infinity = Inf; x = abs (x_to_truncate); if (x != x / 2.0) { log_ten = log (10.0); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/functions/jmlc/reuse-glm-predict.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/jmlc/reuse-glm-predict.dml b/src/test/scripts/functions/jmlc/reuse-glm-predict.dml index 468464a..44ca778 100644 --- a/src/test/scripts/functions/jmlc/reuse-glm-predict.dml +++ b/src/test/scripts/functions/jmlc/reuse-glm-predict.dml @@ -330,8 +330,8 @@ glm_means_and_vars = y_prob [, 1] = (1 - is_too_small) * (1.0 - y_prob [, 2]) + is_too_small * elt * (1.0 - elt / 2); } else { if (link_type == 5) { # Binomial.cauchit atan_linear_terms = atan (linear_terms); - y_prob [, 1] = 0.5 + atan_linear_terms / PI; - y_prob [, 2] = 0.5 - atan_linear_terms / PI; + y_prob [, 1] = 0.5 + atan_linear_terms / pi; + y_prob [, 2] = 0.5 - atan_linear_terms / pi; }}}}}} means = y_prob; ones_ctg = matrix (1, rows = 2, cols = 1); @@ -356,8 +356,8 @@ glm_partial_loglikelihood_for_power_dist_and_link = # Assumes: dist_type == 1 num_records = nrow (Y); if (var_power == 1.0) { # Poisson if (link_power == 0.0) { # Poisson.log - is_natural_parameter_log_zero = (linear_terms == -INF); - natural_parameters = replace (target = linear_terms, pattern = -INF, replacement = 0); + is_natural_parameter_log_zero = (linear_terms == -Inf); + natural_parameters = replace (target = linear_terms, pattern = -Inf, replacement = 0); b_cumulant = exp (linear_terms); } else { # Poisson.power_nonlog is_natural_parameter_log_zero = (linear_terms == 0.0); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.R ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.R b/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.R index 128002d..6643c14 100644 --- a/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.R +++ b/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.R @@ -28,8 +28,8 @@ n = as.integer(args[1]); X = matrix(0, n, 0); R = rbind(rbind(rbind(rbind( as.matrix(sum(X)==0), - as.matrix(min(X)==INF)), - as.matrix(max(X)==-INF)), + as.matrix(min(X)==Inf)), + as.matrix(max(X)==-Inf)), as.matrix(is.nan(mean(X)))), as.matrix(is.na(sd(X)))); http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.dml b/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.dml index 7bf8cba..fbd8448 100644 --- a/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.dml +++ b/src/test/scripts/functions/misc/ZeroMatrix_Aggregates.dml @@ -24,8 +24,8 @@ X = matrix(0, $1, 0); # nary rbind not applicable because not supported in MR R = rbind(rbind(rbind(rbind( as.matrix(sum(X)==0), # 0 - as.matrix(min(X)==INF)), # INF - as.matrix(max(X)==-INF)), # -INF + as.matrix(min(X)==Inf)), # INF + as.matrix(max(X)==-Inf)), # -INF as.matrix(mean(X)!=mean(X))), # NaN as.matrix(sd(X)!=sd(X))); # NaN http://git-wip-us.apache.org/repos/asf/systemml/blob/205c37fd/src/test/scripts/org/apache/sysml/api/mlcontext/builtin-constants-test.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/org/apache/sysml/api/mlcontext/builtin-constants-test.dml b/src/test/scripts/org/apache/sysml/api/mlcontext/builtin-constants-test.dml index 05b832e..4bfcbbc 100644 --- a/src/test/scripts/org/apache/sysml/api/mlcontext/builtin-constants-test.dml +++ b/src/test/scripts/org/apache/sysml/api/mlcontext/builtin-constants-test.dml @@ -21,18 +21,18 @@ # a func using builtin constant PI f1 = function (double r) return (double res) { - res = PI * r * r + res = pi * r * r } # use builtin constant PI in main func -res = PI * 1000 +res = pi * 1000 print(res) # use builtin constant NaN print(NaN + 1) # use builtin constant INF -if (1 / 0 == INF) { +if (1 / 0 == Inf) { print("1 / 0 is an infinity.") }
