Exemple #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;
  }
Exemple #2
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
 }