Пример #1
0
  public final Row extractDenseRow(double[] vals, Row row) {
    row.bad = false;
    row.rid = 0;
    row.cid = 0;
    if (row.weight == 0) return row;

    if (_skipMissing)
      for (double d : vals)
        if (Double.isNaN(d)) {
          row.bad = true;
          return row;
        }
    int nbins = 0;
    for (int i = 0; i < _cats; ++i) {
      int c = getCategoricalId(i, Double.isNaN(vals[i]) ? _catModes[i] : (int) vals[i]);
      if (c >= 0) row.binIds[nbins++] = c;
    }
    row.nBins = nbins;
    final int n = _nums;
    int numValsIdx = 0;
    for (int i = 0; i < n; ++i) {
      if (isInteractionVec(i)) {
        int offset;
        InteractionWrappedVec iwv = ((InteractionWrappedVec) _adaptedFrame.vec(_cats + i));
        int v1 = _adaptedFrame.find(iwv.v1());
        int v2 = _adaptedFrame.find(iwv.v2());
        if (v1 < _cats)
          offset = getCategoricalId(v1, Double.isNaN(vals[v1]) ? _catModes[v1] : (int) vals[v1]);
        else if (v2 < _cats)
          offset = getCategoricalId(v2, Double.isNaN(vals[v2]) ? _catModes[v1] : (int) vals[v2]);
        else offset = 0;
        row.numVals[numValsIdx + offset] = vals[_cats + i]; // essentially: vals[v1] * vals[v2])
        numValsIdx += nextNumericIdx(i);
      } else {
        double d = vals[_cats + i]; // can be NA if skipMissing() == false
        if (Double.isNaN(d)) d = _numMeans[numValsIdx];
        if (_normMul != null && _normSub != null)
          d = (d - _normSub[numValsIdx]) * _normMul[numValsIdx];
        row.numVals[numValsIdx++] = d;
      }
    }
    int off = responseChunkId(0);
    for (int i = off; i < Math.min(vals.length, off + _responses); ++i) {
      try {
        row.response[i] = vals[responseChunkId(i)];
      } catch (Throwable t) {
        throw new RuntimeException(t);
      }
      if (_normRespMul != null)
        row.response[i] = (row.response[i] - _normRespSub[i]) * _normRespMul[i];
      if (Double.isNaN(row.response[i])) {
        row.bad = true;
        return row;
      }
    }
    return row;
  }
Пример #2
0
 public final int getCategoricalIdFromInteraction(int cid, int val) {
   InteractionWrappedVec v;
   if ((v = (InteractionWrappedVec) _adaptedFrame.vec(cid)).isCategorical())
     return getCategoricalId(cid, val);
   assert v.domains() != null
       : "No domain levels found for interactions! cid: " + cid + " val: " + val;
   if (val >= _numOffsets[cid + 1]) { // previously unseen interaction (aka new domain level)
     assert _valid
         : "interaction value out of bounds, got "
             + val
             + ", next cat starts at "
             + _numOffsets[cid + 1];
     val = v.mode();
   }
   return val < 0 ? -1 : val + _numOffsets[cid];
 }
Пример #3
0
 public int getInteractionOffset(Chunk[] chunks, int cid, int rid) {
   int v1 = -1, v2 = -1;
   if (_adaptedFrame == null) {
     Vec vec1 = ((InteractionWrappedVec) chunks[cid].vec()).v1();
     Vec vec2 = ((InteractionWrappedVec) chunks[cid].vec()).v2();
     for (int i = 0; i < chunks.length; ++i) {
       if (v1 >= 0 && v2 >= 0) break; // found both vecs already
       if (v1 == -1 && chunks[i].vec() == vec1) v1 = i;
       if (v2 == -1 && chunks[i].vec() == vec2) v2 = i;
     }
   } else {
     InteractionWrappedVec iwv = ((InteractionWrappedVec) _adaptedFrame.vec(cid));
     v1 = _adaptedFrame.find(iwv.v1());
     v2 = _adaptedFrame.find(iwv.v2());
   }
   if (v1 < _cats) return (int) chunks[v1].at8(rid); // v1 is some categorical column
   else if (v2 < _cats) return (int) chunks[v2].at8(rid); // or v2 is some categorical column
   return 0; // or neither is categorical
 }
Пример #4
0
  public final String[] coefNames() {
    if (_coefNames != null) return _coefNames; // already computed
    int k = 0;
    final int n = fullN(); // total number of columns to compute
    String[] res = new String[n];
    final Vec[] vecs = _adaptedFrame.vecs();

    // first do all of the expanded categorical names
    for (int i = 0; i < _cats; ++i) {
      for (int j = (_useAllFactorLevels || vecs[i] instanceof InteractionWrappedVec) ? 0 : 1;
          j < vecs[i].domain().length;
          ++j) {
        int jj = getCategoricalId(i, j);
        if (jj < 0) continue;
        res[k++] = _adaptedFrame._names[i] + "." + vecs[i].domain()[j];
      }
      if (_catMissing[i] && getCategoricalId(i, _catModes[i]) >= 0)
        res[k++] = _adaptedFrame._names[i] + ".missing(NA)";
    }
    // now loop over the numerical columns, collecting up any expanded InteractionVec names
    if (_interactions == null) {
      final int nums = n - k;
      System.arraycopy(_adaptedFrame._names, _cats, res, k, nums);
    } else {
      for (int i = _cats; i < _nums; ++i) {
        InteractionWrappedVec v;
        if (vecs[i] instanceof InteractionWrappedVec
            && ((v = (InteractionWrappedVec) vecs[i]).domains()
                != null)) { // in this case, get the categoricalOffset
          for (int j = 0; k < v.domains().length; ++j) {
            if (getCategoricalIdFromInteraction(i, j) < 0) continue;
            res[k++] = _adaptedFrame._names[i] + "." + v.domains()[j];
          }
        } else res[k++] = _adaptedFrame._names[i];
      }
    }
    _coefNames = res;
    return res;
  }