Skip to content

Commit

Permalink
Fix in GLM.
Browse files Browse the repository at this point in the history
1) Offset would shift ignored columns (those coming after offset in the original dataset) by -1.
2) Do not standardize the offset.
  • Loading branch information
tomasnykodym committed Mar 16, 2015
1 parent 22f9da2 commit 5617c6e
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/main/java/hex/glm/GLM2.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ private double computeIntercept(DataInfo dinfo, double ymu, Vec offset, Vec resp
int idx = Arrays.binarySearch(ignored_cols, id);
if (idx >= 0) Utils.remove(ignored_cols, idx);
String name = source2.names()[id];
source2.add(name, source2.remove(id));
// source2.add(name, source2.remove(id));
_noffsets = 1;
}
if (nlambdas == -1)
Expand Down Expand Up @@ -470,10 +470,22 @@ private double computeIntercept(DataInfo dinfo, double ymu, Vec offset, Vec resp
}
toEnum = family == Family.binomial && (!response.isEnum() && (response.min() < 0 || response.max() > 1));
Frame fr = DataInfo.prepareFrame(source2, response, ignored_cols, toEnum, true, true);
if(offset != null){ // now put the offset just before response
int id = fr.find(offset);
String offsetName = fr.names()[id];
String responseName = fr.names()[fr.numCols()-1];
Vec responseVec = fr.remove(fr.numCols()-1);
fr.add(offsetName, fr.remove(id));
fr.add(responseName,responseVec);
}
TransformType dt = TransformType.NONE;
if (standardize)
dt = intercept ? TransformType.STANDARDIZE : TransformType.DESCALE;
_srcDinfo = new DataInfo(fr, 1, intercept, use_all_factor_levels || lambda_search, dt, DataInfo.TransformType.NONE);
if(offset != null && dt != TransformType.NONE) { // do not standardize offset
_srcDinfo._normMul[_srcDinfo._normMul.length-1] = 1;
_srcDinfo._normSub[_srcDinfo._normSub.length-1] = 0;
}
if (!intercept && _srcDinfo._cats > 0)
throw new IllegalArgumentException("Models with no intercept are only supported with all-numeric predictors.");
_activeData = _srcDinfo;
Expand All @@ -499,8 +511,7 @@ private double computeIntercept(DataInfo dinfo, double ymu, Vec offset, Vec resp
final int numoff = _srcDinfo.numStart();
if((v = beta_constraints.vec("lower_bounds")) != null) {
_lbs = map == null ? Utils.asDoubles(v) : mapVec(Utils.asDoubles(v), makeAry(names.length, Double.NEGATIVE_INFINITY), map);
System.out.println("lower bounds = " + Arrays.toString(_lbs));
// for(int i = 0; i < _lbs.length; ++i)
// for(int i = 0; i < _lbs.length; ++i)
// if(_lbs[i] > 0) throw new IllegalArgumentException("lower bounds must be non-positive");
if(_srcDinfo._normMul != null) {
for (int i = numoff; i < _srcDinfo.fullN(); ++i) {
Expand Down

0 comments on commit 5617c6e

Please sign in to comment.