-
Notifications
You must be signed in to change notification settings - Fork 2k
GH-16678 GLM: Control variables - Multinomial, Ordinal #16690
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
Open
maurever
wants to merge
12
commits into
rel-3.46.0
Choose a base branch
from
maurever_GH-16524_glm_control_variables_multinomial
base: rel-3.46.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
48c0744
Implement multinomial case for control variables.
maurever abe358b
Fix junit test for multinomial control variables
maurever d1b2c0f
Add pyunit, runit, fix bugs.
maurever 8388b6b
Implement ordinal distribution, add tests
maurever 48634c9
Update h2o-algos/src/main/java/hex/glm/GLM.java
maurever a49cabb
Update h2o-algos/src/main/java/hex/glm/GLMModel.java
maurever 644638f
Update h2o-r/tests/testdir_algos/glm/runit_GLM_control_variables_ordi…
maurever e4b310b
Update h2o-r/tests/testdir_algos/glm/runit_GLM_control_variables_mult…
maurever b78bf38
Update h2o-r/tests/testdir_algos/glm/runit_GLM_control_variables_ordi…
maurever 70d9250
Update h2o-algos/src/test/java/hex/glm/GLMControlVariablesTest.java
maurever 005c0aa
Improve tests
maurever 5cd1a8e
Improve tests
maurever 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
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
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 |
|---|---|---|
|
|
@@ -1646,6 +1646,28 @@ public double[] getControlValBeta(double[] beta){ | |
| } | ||
| return beta; | ||
| } | ||
|
|
||
| public double[][] getControlValBetaMultinomial(double[][] beta) { | ||
| if (_control_values_idxs_in_adapted_frame == null) { | ||
| mapControlVariables(); | ||
| } | ||
| assert _control_values_idxs_in_adapted_frame != null; | ||
| for (int featureIdx : _control_values_idxs_in_adapted_frame) { | ||
| if (featureIdx < _dinfo._catOffsets.length - 1 && _column_types[featureIdx].equals("Enum")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this part really necessary or is it just to be really really sure? |
||
| for (int i = _dinfo._catOffsets[featureIdx]; i < _dinfo._catOffsets[featureIdx + 1]; i++) { | ||
| for (int c = 0; c < beta.length; ++c) { | ||
| beta[c][i] = 0; | ||
| } | ||
| } | ||
| } else { | ||
| for (int c = 0; c < beta.length; ++c) { | ||
| featureIdx += _dinfo._numOffsets[0] - _dinfo._catOffsets.length + 1; | ||
| beta[c][featureIdx] = 0; | ||
|
maurever marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
| } | ||
| return beta; | ||
| } | ||
|
|
||
| public double[] stdErr() { | ||
| return calculateStdErrFromZValues(_zvalues, _global_beta); | ||
|
|
@@ -1797,7 +1819,6 @@ public GLMOutput(DataInfo dinfo, String[] column_names, String[] column_types, S | |
| mapControlVariables(); | ||
| } | ||
|
|
||
|
|
||
| public GLMOutput() { | ||
| _isSupervised = true; | ||
| _nclasses = -1; | ||
|
|
@@ -2020,9 +2041,13 @@ public VarImp calculateVarimp(boolean contrVal) { | |
| float[] magnitudesSort = new float[len]; // stored sorted coefficient magnitudes | ||
| String[] namesSort = new String[len]; | ||
|
|
||
| if (contrVal) | ||
| calculateVarimpBase(magnitudes, indices, getControlValBeta(getNormBeta())); | ||
| else if (_nclasses > 2) | ||
| if (contrVal) { | ||
| if(_nclasses > 2) { | ||
| calculateVarimpMultinomial(magnitudes, indices, getControlValBetaMultinomial(getNormBetaMultinomial())); | ||
| } else { | ||
| calculateVarimpBase(magnitudes, indices, getControlValBeta(getNormBeta())); | ||
| } | ||
| } else if (_nclasses > 2) | ||
| calculateVarimpMultinomial(magnitudes, indices, getNormBetaMultinomial()); | ||
| else | ||
| calculateVarimpBase(magnitudes, indices, getNormBeta()); | ||
|
|
@@ -2147,9 +2172,13 @@ else if (_output.bestSubmodel().alpha_value == 1) | |
| int icptInd = bm[0].length-1; | ||
| if (_parms._family == Family.ordinal) // only need one eta for all classes | ||
| classInd -= 1; // last class all zeros | ||
| double[][] bmcv = bm.clone(); | ||
| if(_useControlVariables){ | ||
| bmcv = _output.getControlValBetaMultinomial(bm); | ||
| } | ||
| for (int c = 0; c < classInd; ++c) { | ||
| double e = bm[c][icptInd]; // grab the intercept, replace the bm[0].length-1 | ||
| double [] b = bm[c]; | ||
| double e = bmcv[c][icptInd]; // grab the intercept, replace the bm[0].length-1 | ||
| double [] b = bmcv[c]; | ||
| for(int i = 0; i < _output._dinfo._cats; ++i) { | ||
| int l = _output._dinfo.getCategoricalId(i, data[i]); | ||
| if (l >= 0) e += b[l]; | ||
|
|
@@ -2203,7 +2232,6 @@ else if (_output.bestSubmodel().alpha_value == 1) | |
| double[] bcv = b.clone(); | ||
| if (this._useControlVariables) | ||
| bcv = _output.getControlValBeta(bcv); // make beta connected to control variables zero | ||
|
|
||
| for (int i = 0; i < _output._dinfo._cats && !Double.isNaN(eta); ++i) { | ||
| int l = _output._dinfo.getCategoricalId(i, data[i]); | ||
| if (l >= 0) eta += bcv[l]; | ||
|
|
||
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
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.