Repository navigation
[SYSTEMDS-3681] Add stepGLM builtin function. #2523
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
Closed
Closed
Changes from 15 commits
Commits
Show all changes
135 commits
Select commit
Hold shift + click to select a range
274f0c8
refactor StepGLM.dml from a script into a function and resolve a few …
Bruno-Ignaz 78018f9
rename builtin StepGLM.dml to stepglm.dml
Bruno-Ignaz 739c5d2
rename builtin stepglm.dml to stepGLM.dml
Bruno-Ignaz 9dc956b
fix syntax errors in stepGLM
Bruno-Ignaz e60c2dd
fix glm_fit call syntax
Bruno-Ignaz 9de039d
remove fit_glm
Bruno-Ignaz 482349c
replace glm_fit with m_glm
Bruno-Ignaz 8e24e9c
add missing glm_fit replacment
Bruno-Ignaz ca5429b
edit test script
Bruno-Ignaz 3321316
add license to TestBuiltinStepGLM.dml
Bruno-Ignaz e13e83a
rename stepGLM to m_stepGLM; register stepGLM in Builtins.java
Bruno-Ignaz c341063
add BuiltinSTEPGlmTest.java
Bruno-Ignaz 8887e5a
indent BuiltinSTEPGlmTest.java
Bruno-Ignaz 159fa87
replace spaces with tabs in BuiltinSTEPGlmTest.java
Bruno-Ignaz b7e64b8
format BuiltinSTEPGlmTest.java via jdtls
Bruno-Ignaz 59b8d88
remove print statments
Bruno-Ignaz bc4dfe2
remove comment
Bruno-Ignaz 69ccca9
rm old stepGLM.dml script
Bruno-Ignaz 8aa902b
replace misleading comments
Bruno-Ignaz 0d9e6eb
[SYSTEMDS-2651] Extend TCP port polling to federated monitoring backend
Baunsgaard a8dabe0
[SYSTEMDS-2651] Poll for async compression in federated component tes…
Baunsgaard 4fccae4
[MINOR] Upgrade Surefire to 3.5.2 and enforce fork exit timeout
Baunsgaard 9876057
[MINOR] Fix incorrect formatting of various tests
mboehm7 a221629
[SYSTEMDS-3887] Add video modality to Scuro optimizer pipeline
christinadionysio a9fd90d
[SYSTEMDS-3947] Use optuna for Scuro hyperparameter tuning
christinadionysio 35b17a9
[SYSTEMDS-3835] Improve window aggregation efficiency in Scuro
christinadionysio fd5c556
Bump codecov/codecov-action from 6.0.1 to 7.0.0 (#2477)
dependabot[bot] f0d59db
[CI] Configure GitHub workflows to use concurrency cancel-in-progress
apupier c465a3a
[MINOR] Reduce surefire per-fork test timeout from 1380s to 600s (#2485)
Baunsgaard 5653337
[MINOR][CI] Retry Maven test-compile on transient repository download…
Baunsgaard 3f44187
[MINOR] Fix CholeskyTest crash when residual is exactly zero (#2487)
Baunsgaard 3a59d44
[BWARE] Add HashMapIntToInt primitive int-to-int hash map (#2478)
Baunsgaard efe8cbd
[BWARE] Speed up frame-to-matrix conversion and harden number parsing…
Baunsgaard 503146d
[MINOR] Fix Flaky Tests from Blocking Thread Pools (#2489)
janniklinde dbe321a
[BWARE] Track more compressed-friendly ops in FederatedWorkloadAnalyz…
Baunsgaard d77096f
[MINOR][CI] Fix leaked threads hanging Java test forks (#2488)
Baunsgaard db4f60d
[BWARE] Add getCategoricalMask DML builtin (#2482)
Baunsgaard 0680df8
[MINOR] Deduplicate not-implemented logs in ColGroupTest (#2491)
Baunsgaard e71501b
[MINOR] Improve efficiency of Scuro tests
christinadionysio aa1c718
[MINOR] Fix class-init deadlock between AOffset and its subclasses (#…
Baunsgaard 9fba045
[BWARE] Tune compressed matmul fast paths and Spark execution decisio…
Baunsgaard c2ae705
[BWARE] Handle hash columns in transform decoders and tighten decode …
Baunsgaard b83f71a
[MINOR][CI] Raise federated request timeout for multitenant Spark tes…
Baunsgaard 2ba9304
[MINOR] Add ToString test for decimal-formatting in toString builtin …
Baunsgaard e177b99
[BWARE] Add removeEmpty support to compressed column groups (#2504)
Baunsgaard b36b6c7
[MINOR][CI] Make federated client and monitoring threads daemon (#2508)
Baunsgaard 51c5752
Bump actions/checkout from 6 to 7 (#2493)
dependabot[bot] 5c72d53
Bump actions/cache from 5 to 6 (#2506)
dependabot[bot] 8e235f4
[BWARE] Add sort support to compressed column groups (#2507)
Baunsgaard a8f3462
[MINOR] Bump jackson to 2.15.4 (core/databind/annotations) (#2512)
Baunsgaard ed849bb
Serialize federated monitoring and multitenant tests in CI (#2517)
Baunsgaard 6d1d218
[BWARE] Tighten MatrixBlock quantile/sort API surface (#2513)
Baunsgaard b119435
[MINOR][CI] Run component.c tests in parallel again (#2518)
Baunsgaard 8ab6b98
[MINOR] Reference-count shared Spark context to prevent concurrent sh…
Baunsgaard 35af80f
[BWARE] Restructure CLALibBinaryCellOp and decompression fallbacks (#…
Baunsgaard eb6928e
[SYSTEMDS-3949] Add native Delta Lake matrix read/write via Delta Ker…
Baunsgaard 5e476bb
[MINOR][TEST] Add Asserts to ScalarIOTest for Result Validation (#2522)
ywcb00 ef54020
[SYSTEMDS-3835] Fine grained window size parameters
christinadionysio aca41a4
[SYSTEMDS-3891] Add OOC reshape
jessicapriebe 119a7e1
[OOC] Move Old Files to Legacy Package (#2530)
janniklinde 9a4415f
[OOC] Move I/O Related Classes to cache.io Package (#2531)
janniklinde 9b419c8
[SYSTEMDS-3949] Add native Delta Lake frame read/write via Delta Kern…
Baunsgaard 9361cbc
[SYSTEMDS-3949] Add Demo for Databricks Workspace Execution (#2520)
Baunsgaard e782caa
[OOC] IO Handler Performance Improvements and Generalization (#2532)
janniklinde ddc761d
[CI] Add Java Format CI check for pull requests (#2527)
Baunsgaard c174b79
[OOC] Add OOCCache (#2533)
janniklinde 100dd9d
[OOC] Add OOCPackedCache (#2534)
janniklinde 3e184e9
[OOC] Adapt OOCStream to Forward QueueCallbacks (#2537)
janniklinde 2de79f5
Bump actions/setup-python from 5 to 6 (#2536)
dependabot[bot] f0043b6
[SYSTEMDS-3949] Column API parquet decode for Delta frame reads (#2535)
Jakob-al28 84436ab
[MINOR] Prepare Release Metadata for SystemDS 3.4.0
janniklinde 1ee76a8
[MINOR] Add Java 17 Module Access Options
janniklinde 193c261
[maven-release-plugin] prepare release 3.4.0-rc1
b49ebf5
[maven-release-plugin] prepare for next development iteration
a4642e7
[MINOR][FIX] Add SciPy as Dependency
janniklinde 1c23a16
[Minor] Update python api README.md
e-strauss 6808f5c
[maven-release-plugin] prepare release 3.4.0-rc2
5f33cd1
[maven-release-plugin] prepare for next development iteration
a060404
[SYSTEMDS-3891] Add Materialized OOC Structures
janniklinde 90d8e4e
[OOC] Add StateTable
janniklinde e9e7d1e
[SYSTEMDS-3891] OOC Memory Allowance/Broker Improvements
janniklinde 24b70f7
[SYSTEMDS-3891] Remove Unused OOC Messaging Features
janniklinde b120efb
[SYSTEMDS-3891] Add StoreBackedStream
janniklinde 91f16cd
[SYSTEMDS-3891] Add AllocatedOOCStream and ReservationBudget
janniklinde ae34b95
[SYSTEMDS-3891] Add OOCInstructionUtils
janniklinde 1e3ae35
[SYSTEMDS-3891] Add OOC Primitives
janniklinde 75c1e48
[SYSTEMDS-3922] Fix distributed (SPARK/FED) quantile pick instruction
MegaByteTron a84e865
[SYSTEMDS-3891] Add OOC Planner and First Primitive Implementations
janniklinde 43304d6
[SYSTEMDS-3891] Wire First Reworked OOC Primitives
janniklinde ce49a64
[SYSTEMDS-3891] Wire JoinOOCPrimitive (#2566)
janniklinde 0eb76ed
[SYSTEMDS-3953] Add test case for array percentiles as argument for t…
ywcb00 fe7f8f5
[SYSTEMDS-2525] Fix sparsity rewrites by switching the MNC estimator …
ywcb00 460588b
[MINOR] Fix literal parsing issue in svn promote script
j143 3c5414d
[MINOR] Downgrade Docker Action Majors
44099b3
Revert "[MINOR] Downgrade Docker Action Majors"
370b882
[SYSTEMDS-3894] Add OOC covariance and extend TSMM support
tuluyhansozen fd9c845
[SYSTEMDS-3891] OOC Bugfixes and Improved Error Propagation
janniklinde c833a3c
[SYSTEMDS-3891] OOC Add Materialized Planning Support
janniklinde e61b9d4
[SYSTEMDS-3891] Add Broadcast and Grouped Reduction Primitives
janniklinde b08de57
[SYSTEMDS-3891] Wire OOC Materialized Stores
janniklinde be8c150
[SYSTEMDS-3955] Support SSL authentication for federated network comm…
gaturchenko 391623c
[SYSTEMDS-3891] OOC Primitive Simplification and Streamable Injection…
janniklinde 3d419e3
Bump actions/setup-python from 6 to 7 (#2563)
dependabot[bot] 38e34f3
Bump docker/login-action from 4 to 4.5.2 (#2571)
dependabot[bot] 20146c1
Bump actions/setup-node from 6 to 7 (#2546)
dependabot[bot] 08249af
[SYSTEMDS-3929] Speed up Parquet frame reader/writer (#2528)
Jakob-al28 4db79bd
[SYSTEMDS-3949] Extend Delta Spark round trip tests (#2580)
Jakob-al28 5327c3b
[SYSTEMDS-3947] Introduce robustness check in hyperparameter tuning
christinadionysio 9e9902a
[SYSTEMDS-3958] Add XML options for sparsity rewrites.
ywcb00 b333755
[SYSTEMDS-3891] Wire OOC Instructions with New Primitives
janniklinde 6077976
[SYSTEMDS-3891] OOC Non-blocking Join and Primitive Simplification
janniklinde e672d4f
[SYSTEMDS-3956] Add AI Policy
janniklinde 2b6212f
[SYSTEMDS-3940] Improve Scuro Node Executor
christinadionysio 6401a62
[SYSTEMDS-3956] Extend AI Policy for IP Provenance
janniklinde e2e1f5d
[SYSTEMDS-3891] Wire OOC Aggregate Unary and Bugfix Race Condition
janniklinde e1376a0
[SYSTEMDS-3863] Add PowerTransformer built-in functions
WenliangCao b810e54
[SYSTEMDS-3891] Add Generic OOC Reduce
janniklinde 88309f0
[SYSTEMDS-3891] Add NaryJoinOOCPrimitive and Generic Join
janniklinde 9b0584c
[SYSTEMDS-3891] Add GeneralMMultOOCPrimitive
janniklinde 3f6326a
[SYSTEMDS-3960] Improve robustness against network delays in federate…
gaturchenko 781840d
[SYSTEMDS-3962] Fix memory check on recent windows11 versions
mboehm7 c32f48a
Bump docker/login-action from 4.5.2 to 4.6.0 (#2582)
dependabot[bot] 044f96f
[SYSTEMDS-3887] Improve Scuro DAGs
christinadionysio 072d50a
[SYSTEMDS-3835] Add physiological representations to Scuro
christinadionysio b8c8aa8
[SYSTEMDS-3835] Improve efficiency of Representations in Scuro
christinadionysio 3254d94
[SYSTEMDS-3967] Add a multimodal GA optimizer approach
christinadionysio b76bbd6
[SYSTEMDS-3968] Add test set evaluator - #2602
christinadionysio 55e6bf6
dev/format-changed.sh
Bruno-Ignaz 056c7f9
Revert "dev/format-changed.sh"
Bruno-Ignaz 3962ff1
dev/format-changed.sh
Bruno-Ignaz 325d24f
Revert "dev/format-changed.sh"
Bruno-Ignaz 35cb6a7
Merge branch 'main' into main
Bruno-Ignaz b0124fa
dev/format-changed.sh
Bruno-Ignaz 5e2de10
Revert "dev/format-changed.sh"
Bruno-Ignaz 54535fa
Merge remote-tracking branch 'upstream/main'
Bruno-Ignaz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,272 @@ | ||
| #------------------------------------------------------------- | ||
| # | ||
| # Licensed to the Apache Software Foundation (ASF) under one | ||
| # or more contributor license agreements. See the NOTICE file | ||
| # distributed with this work for additional information | ||
| # regarding copyright ownership. The ASF licenses this file | ||
| # to you under the Apache License, Version 2.0 (the | ||
| # "License"); you may not use this file except in compliance | ||
| # with the License. You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, | ||
| # software distributed under the License is distributed on an | ||
| # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| # KIND, either express or implied. See the License for the | ||
| # specific language governing permissions and limitations | ||
| # under the License. | ||
| # | ||
| #------------------------------------------------------------- | ||
|
|
||
| # | ||
| # THIS SCRIPT CHOOSES A GLM REGRESSION MODEL IN A STEPWISE ALGIRITHM USING AIC | ||
| # EACH GLM REGRESSION IS SOLVED USING NEWTON/FISHER SCORING WITH TRUST REGIONS | ||
| # | ||
| # INPUT PARAMETERS: | ||
| # --------------------------------------------------------------------------------------------- | ||
| # NAME TYPE DEFAULT MEANING | ||
| # --------------------------------------------------------------------------------------------- | ||
| # X Matrix --- Matrix X of feature vectors | ||
| # Y Matrix --- Response Matrix Y with 1 column | ||
| # link Int 2 Link function code: 1 = log, 2 = Logit, 3 = Probit, 4 = Cloglog | ||
| # yneg Double 0.0 Response value for Bernoulli "No" label, usually 0.0 or -1.0 | ||
| # icpt Int 0 Intercept presence, X columns shifting and rescaling: | ||
| # 0 = no intercept, no shifting, no rescaling; | ||
| # 1 = add intercept, but neither shift nor rescale X; | ||
| # 2 = add intercept, shift & rescale X columns to mean = 0, variance = 1 | ||
| # tol Double 0.000001 Tolerance (epsilon) | ||
| # disp Double 0.0 (Over-)dispersion value, or 0.0 to estimate it from data | ||
| # moi Int 200 Maximum number of outer (Newton / Fisher Scoring) iterations | ||
| # mii Int 0 Maximum number of inner (Conjugate Gradient) iterations, 0 = no maximum | ||
| # thr Double 0.01 Threshold to stop the algorithm: if the decrease in the value of AIC falls below thr | ||
| # no further features are being checked and the algorithm stops | ||
| # --------------------------------------------------------------------------------------------- | ||
| # OUTPUT: Matrix beta, whose size depends on icpt: | ||
| # icpt=0: ncol(X) x 1; icpt=1: (ncol(X) + 1) x 1; icpt=2: (ncol(X) + 1) x 2 | ||
| # | ||
| # AIC Double --- AIC value | ||
| # B Matrix --- Estimated regression parameters (betas) | ||
| # S Matrix --- The selected features ordered as computed by the algorithm | ||
| # --------------------------------------------------------------------------------------------- | ||
|
|
||
| # THE StepGLM SCRIPT CURRENTLY SUPPORTS BERNOULLI DISTRIBUTION FAMILY AND THE FOLLOWING LINK FUNCTIONS ONLY! | ||
| # - LOG | ||
| # - LOGIT | ||
| # - PROBIT | ||
| # - CLOGLOG | ||
|
|
||
| source("./scripts/builtin/glm.dml") as glm; | ||
|
|
||
| m_stepGLM = function ( | ||
| Matrix[Double] X, | ||
| Matrix[Double] Y, | ||
| Int link = 2, | ||
| Double yneg = 0.0, | ||
| Int icpt = 0, | ||
| Double tol = 0.000001, | ||
| Double disp = 0.0, | ||
| Int moi = 200, | ||
| Int mii = 0, | ||
| Double thr = 0.01 | ||
| ) return ( | ||
| Double AIC, | ||
| Matrix[Double] B, | ||
| Matrix[Double] S | ||
| ) | ||
| { | ||
| intercept_status = icpt; | ||
| bernoulli_No_label = yneg; | ||
| distribution_type = 2; | ||
|
|
||
|
|
||
| if (distribution_type == 2 & ncol(Y) == 1) { | ||
| is_Y_negative = (Y == bernoulli_No_label); | ||
| Y = cbind (1 - is_Y_negative, is_Y_negative); | ||
| count_Y_negative = sum (is_Y_negative); | ||
| if (count_Y_negative == 0) { | ||
| stop ("StepGLM Input Error: all Y-values encode Bernoulli YES-label, none encode NO-label"); | ||
| } | ||
| if (count_Y_negative == nrow(Y)) { | ||
| stop ("StepGLM Input Error: all Y-values encode Bernoulli NO-label, none encode YES-label"); | ||
| } | ||
| } | ||
|
|
||
| X_orig = X; | ||
| num_records = nrow (X_orig); | ||
| num_features = ncol (X_orig); | ||
|
|
||
| # BEGIN STEPWISE GENERALIZED LINEAR MODELS | ||
|
|
||
| continue = TRUE; | ||
| columns_fixed = matrix (0, rows = 1, cols = num_features); | ||
| columns_fixed_ordered = matrix (0, rows = 1, cols = 1); | ||
|
|
||
| # X_global stores the best model found at each step | ||
| X_global = matrix (0, rows = num_records, cols = 1); | ||
|
|
||
| if (intercept_status == 0) { | ||
| # Compute AIC of an empty model with no features and no intercept (all Ys are zero) | ||
| [AIC_best, ignore_B1, ignore_S1] = internal_glm(X=X_global, Y=Y, intercept_status=0, num_features_orig=num_features, Selected=columns_fixed_ordered, link=link, disp=disp, tol=tol, moi=moi, mii=mii); | ||
| } else { | ||
| # compute AIC of an empty model with only intercept (all Ys are constant) | ||
| all_ones = matrix (1, rows = num_records, cols = 1); | ||
| [AIC_best, ignore_beta2, ignore_S2] = internal_glm(X=all_ones, Y=Y, intercept_status=0, num_features_orig=num_features, Selected=columns_fixed_ordered, link=link, disp=disp, tol=tol, moi=moi, mii=mii); | ||
| } | ||
| #print ("Best AIC without any features: " + AIC_best); | ||
|
|
||
| # First pass to examine single features | ||
| AICs = matrix (AIC_best, rows = 1, cols = num_features); | ||
| parfor (i in 1:num_features) { | ||
| [AIC_1, ignore_beta3, ignore_S3] = internal_glm(X=X_orig[,i], Y=Y, intercept_status=intercept_status, num_features_orig=num_features, Selected=columns_fixed_ordered, link=link, disp=disp, tol=tol, moi=moi, mii=mii); | ||
| AICs[1,i] = AIC_1; | ||
| } | ||
|
|
||
| # Determine the best AIC | ||
| column_best = 0; | ||
| for (k in 1:num_features) { | ||
| AIC_cur = as.scalar (AICs[1,k]); | ||
| if ( (AIC_cur < AIC_best) & ((AIC_best - AIC_cur) > abs (thr * AIC_best)) ) { | ||
| column_best = k; | ||
| AIC_best = as.scalar(AICs[1,k]); | ||
| } | ||
| } | ||
|
|
||
| if (column_best == 0) { | ||
| #print ("AIC of an empty model is " + AIC_best + " and adding no feature achieves more than " + (thr * 100) + "% decrease in AIC!"); | ||
|
christinadionysio marked this conversation as resolved.
Resolved
|
||
| if (intercept_status == 0) { | ||
| # Compute AIC of an empty model with no features and no intercept (all Ys are zero) | ||
| [AIC_best, ignore_beta4, ignore_S4] = internal_glm(X=X_global, Y=Y, intercept_status=0, num_features_orig=num_features, Selected=columns_fixed_ordered, link=link, disp=disp, tol=tol, moi=moi, mii=mii); | ||
| } else { | ||
| # compute AIC of an empty model with only intercept (all Ys are constant) | ||
| ###all_ones = matrix (1, rows = num_records, cols = 1); | ||
|
christinadionysio marked this conversation as resolved.
Resolved
|
||
| [AIC_best, ignore_beta5, ignore_S5] = internal_glm(X=all_ones, Y=Y, intercept_status=0, num_features_orig=num_features, Selected=columns_fixed_ordered, link=link, disp=disp, tol=tol, moi=moi, mii=mii); | ||
| } | ||
| }; | ||
|
|
||
| # print ("Best AIC " + AIC_best + " achieved with feature: " + column_best); | ||
|
christinadionysio marked this conversation as resolved.
Resolved
|
||
| columns_fixed[1,column_best] = 1; | ||
| columns_fixed_ordered[1,1] = column_best; | ||
| X_global = X_orig[,column_best]; | ||
|
|
||
| while (continue) { | ||
| # Subsequent passes over the features | ||
| parfor (i in 1:num_features) { | ||
| if (as.scalar(columns_fixed[1,i]) == 0) { | ||
|
|
||
| # Construct the feature matrix | ||
| X_loop = cbind (X_global, X_orig[,i]); | ||
|
|
||
| [AIC_2, ignore_beta6, ignore_S6] = internal_glm(X=X_loop, Y=Y, intercept_status=intercept_status, num_features_orig=num_features, Selected=columns_fixed_ordered, link=link, disp=disp, tol=tol, moi=moi, mii=mii); | ||
| AICs[1,i] = AIC_2; | ||
| } | ||
| } | ||
|
|
||
| # Determine the best AIC | ||
| for (k in 1:num_features) { | ||
| AIC_cur = as.scalar (AICs[1,k]); | ||
| if ( (AIC_cur < AIC_best) & ((AIC_best - AIC_cur) > abs (thr * AIC_best)) & (as.scalar(columns_fixed[1,k]) == 0) ) { | ||
| column_best = k; | ||
| AIC_best = as.scalar(AICs[1,k]); | ||
| } | ||
| } | ||
|
|
||
| # cbind best found features (i.e., columns) to X_global | ||
| if (as.scalar(columns_fixed[1,column_best]) == 0) { # new best feature found | ||
| #print ("Best AIC " + AIC_best + " achieved with feature: " + column_best); | ||
|
christinadionysio marked this conversation as resolved.
Resolved
|
||
| columns_fixed[1,column_best] = 1; | ||
| columns_fixed_ordered = cbind (columns_fixed_ordered, as.matrix(column_best)); | ||
| if (ncol(columns_fixed_ordered) == num_features) { # all features examined | ||
| X_global = cbind (X_global, X_orig[,column_best]); | ||
| continue = FALSE; | ||
| } else { | ||
| X_global = cbind (X_global, X_orig[,column_best]); | ||
| } | ||
| } else { | ||
| continue = FALSE; | ||
| } | ||
| } | ||
|
|
||
| # run GLM with selected set of features | ||
| print ("Running GLM with selected features..."); | ||
|
christinadionysio marked this conversation as resolved.
Resolved
|
||
| [AIC, B, S] = internal_glm(X=X_global, Y=Y, intercept_status=intercept_status, num_features_orig=num_features, Selected=columns_fixed_ordered, link=link, disp=disp, tol=tol, moi=moi, mii=mii); | ||
| } | ||
|
|
||
| compute_AIC = function(Matrix[Double] X, Matrix[Double] Y, Matrix[Double] B, Int link, Int icpt) | ||
| return (Double aic) | ||
| { | ||
| # Isolate unscaled parameters; accounts for m_glm returning 2 columns when icpt=2 | ||
| beta = B[, 1]; | ||
|
|
||
| if (icpt > 0) { | ||
| ones = matrix(1, rows=nrow(X), cols=1); | ||
| X_design = cbind(X, ones); | ||
| } else { | ||
| X_design = X; | ||
| } | ||
|
|
||
| eta = X_design %*% beta; | ||
|
|
||
| # Map inverse link functions | ||
| if (link == 1) { | ||
| # log, see https://en.wikipedia.org/wiki/Generalized_linear_model#Link_function | ||
| mu = exp(eta); | ||
| } else if (link == 2) { | ||
| # logit, see https://en.wikipedia.org/wiki/Generalized_linear_model#Link_function | ||
| mu = 1 / (1 + exp(-eta)); | ||
| } else if (link == 3) { | ||
| # probit approximation, page 1487 in "Qualitative Response Models: A Survey (1981)" by Takeshi Amemiya | ||
| mu = 1 / (1 + exp(-1.6 * eta)); | ||
| } else if (link == 4) { | ||
| # cloglog, see https://search.r-project.org/CRAN/refmans/VGAM/html/clogloglink.html | ||
| mu = 1 - exp(-exp(eta)); | ||
| } else { | ||
| stop("Unsupported link function code: " + link); | ||
| mu = eta; | ||
| } | ||
|
|
||
| # Constrain to prevent numerical discontinuity in log(0) | ||
| mu = max(mu, 1e-15); | ||
| mu = min(mu, 1 - 1e-15); | ||
|
|
||
| Y_yes = Y[, 1]; | ||
| Y_neg = Y[, 2]; | ||
|
|
||
| LL = sum(Y_yes * log(mu) + Y_neg * log(1 - mu)); | ||
| k = nrow(beta); | ||
|
|
||
| aic = 2 * k - 2 * LL; | ||
| } | ||
|
|
||
| internal_glm = function ( | ||
| Matrix[Double] X, | ||
| Matrix[Double] Y, | ||
| Int intercept_status, | ||
| Double num_features_orig, | ||
| Matrix[Double] Selected, | ||
| Int link, | ||
| Double disp, | ||
| Double tol, | ||
| Int moi, | ||
| Int mii | ||
| ) return ( | ||
| Double AIC, | ||
| Matrix[Double] B, | ||
| Matrix[Double] S | ||
| ) { | ||
| # bernoulli family parameters, see table in ./scripts/builtin/m_glm.dml for details. | ||
| new_link = link; | ||
| new_lpow = 1.0; | ||
|
|
||
| if (link == 1) { | ||
| new_link = 1; | ||
| new_lpow = 0.0; | ||
| } | ||
| B = glm::m_glm(X=X, Y=Y, dfam=2, vpow=0.0, link=new_link, lpow=new_lpow, yneg=0.0, | ||
| icpt=intercept_status, disp=disp, reg=0.0, tol=tol, | ||
| moi=moi, mii=mii, verbose=FALSE); | ||
|
|
||
| AIC = compute_AIC(X, Y, B, link, intercept_status); | ||
|
|
||
| S = Selected; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
src/test/java/org/apache/sysds/test/functions/builtin/part2/BuiltinSTEPGlmTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.sysds.test.functions.builtin.part2; | ||
|
|
||
| import org.junit.Test; | ||
| import org.apache.sysds.common.Types.ExecMode; | ||
| import org.apache.sysds.common.Types.ExecType; | ||
| import org.apache.sysds.test.AutomatedTestBase; | ||
| import org.apache.sysds.test.TestConfiguration; | ||
|
|
||
| public class BuiltinSTEPGlmTest extends AutomatedTestBase { | ||
| private final static String TEST_NAME = "stepGLM"; | ||
| private final static String TEST_DIR = "functions/builtin/"; | ||
| private static final String TEST_CLASS_DIR = TEST_DIR + BuiltinSTEPGlmTest.class.getSimpleName() + "/"; | ||
|
|
||
| @Override | ||
| public void setUp() { | ||
| addTestConfiguration(TEST_NAME, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] {})); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLmMatrixDenseCPlm() { | ||
| runSTEPGlmTest(ExecType.CP); | ||
| } | ||
|
|
||
| @Test | ||
| public void testLmMatrixSparseSPlm() { | ||
| runSTEPGlmTest(ExecType.SPARK); | ||
| } | ||
|
|
||
| private void runSTEPGlmTest(ExecType instType) { | ||
| ExecMode platformOld = setExecMode(instType); | ||
|
|
||
| try { | ||
| loadTestConfiguration(getTestConfiguration(TEST_NAME)); | ||
|
|
||
| String HOME = SCRIPT_DIR + TEST_DIR; | ||
|
|
||
| // Pointing to the generated validation DML script | ||
| fullDMLScriptName = HOME + TEST_NAME + ".dml"; | ||
| programArgs = new String[] {}; | ||
|
|
||
| // runTest executes the script; fails if the DML script invokes stop() | ||
| runTest(true, false, null, -1); | ||
| } finally { | ||
| rtplatform = platformOld; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.