Ejemplo n.º 1
0
 // Slow-path append data
 private void append2slow() {
   if (_len > Vec.CHUNK_SZ) throw new ArrayIndexOutOfBoundsException(_len);
   assert _ds == null;
   if (_len2 == _len) { // Check for sparse-ness now & then
     int nzcnt = 0;
     for (int i = 0; i < _len; i++) {
       if (_ls[i] != 0) nzcnt++;
       if (_xs[i] != 0) {
         nzcnt = Vec.CHUNK_SZ;
         break;
       } // Only non-specials sparse
     }
     if (_len >= 32 && nzcnt * 8 <= _len) { // Heuristic for sparseness
       _len = 0;
       for (int i = 0; i < _len2; i++)
         if (_ls[i] != 0) {
           _xs[_len] = i; // Row number in xs
           _ls[_len++] = _ls[i]; // Sparse value in ls
         }
       return; // Compressed, so lots of room now
     }
   }
   _xs = _ls == null ? MemoryManager.malloc4(4) : MemoryManager.arrayCopyOf(_xs, _len << 1);
   _ls = _ls == null ? MemoryManager.malloc8(4) : MemoryManager.arrayCopyOf(_ls, _len << 1);
 }
Ejemplo n.º 2
0
 protected void cancel_sparse() {
   if (sparseLen() != _len) {
     if (_is != null) {
       int[] is = MemoryManager.malloc4(_len);
       for (int i = 0; i < _len; i++) is[i] = -1;
       for (int i = 0; i < sparseLen(); i++) is[_id[i]] = _is[i];
       _is = is;
     } else if (_ds == null) {
       int[] xs = MemoryManager.malloc4(_len);
       long[] ls = MemoryManager.malloc8(_len);
       for (int i = 0; i < sparseLen(); ++i) {
         xs[_id[i]] = _xs[i];
         ls[_id[i]] = _ls[i];
       }
       _xs = xs;
       _ls = ls;
     } else {
       double[] ds = MemoryManager.malloc8d(_len);
       for (int i = 0; i < sparseLen(); ++i) ds[_id[i]] = _ds[i];
       _ds = ds;
     }
     set_sparseLen(_len);
   }
   _id = null;
 }
Ejemplo n.º 3
0
 private void cancel_sparse() {
   long ls[] = MemoryManager.malloc8(_len2 + 1);
   for (int i = 0; i < _len; i++) // Inflate ls to hold values
   ls[_xs[i]] = _ls[i];
   _ls = ls;
   _xs = MemoryManager.malloc4(_len2 + 1);
   _len = _len2; // Not compressed now!
 }
Ejemplo n.º 4
0
 @Override
 NewChunk inflate_impl(NewChunk nc) {
   double dx = Math.log10(_scale);
   assert DParseTask.fitsIntoInt(dx);
   Arrays.fill(nc._xs = MemoryManager.malloc4(_len), (int) dx);
   nc._ls = MemoryManager.malloc8(_len);
   for (int i = 0; i < _len; i++) {
     int res = UDP.get2(_mem, (i << 1) + OFF);
     if (res == C2Chunk._NA) nc.setNA_impl2(i);
     else nc._ls[i] = res + _bias;
   }
   return nc;
 }
Ejemplo n.º 5
0
 @Override
 protected boolean chunkInit() {
   final int n_coef = _beta.length;
   sumWeightedCatX = MemoryManager.malloc8d(n_coef - (_dinfo._nums - _n_offsets));
   sumWeightedNumX = MemoryManager.malloc8d(_dinfo._nums);
   sizeRiskSet = MemoryManager.malloc8d(_n_time);
   sizeCensored = MemoryManager.malloc8d(_n_time);
   sizeEvents = MemoryManager.malloc8d(_n_time);
   countEvents = MemoryManager.malloc8(_n_time);
   sumRiskEvents = MemoryManager.malloc8d(_n_time);
   sumLogRiskEvents = MemoryManager.malloc8d(_n_time);
   rcumsumRisk = MemoryManager.malloc8d(_n_time);
   sumXEvents = malloc2DArray(_n_time, n_coef);
   sumXRiskEvents = malloc2DArray(_n_time, n_coef);
   rcumsumXRisk = malloc2DArray(_n_time, n_coef);
   sumXXRiskEvents = malloc3DArray(_n_time, n_coef, n_coef);
   rcumsumXXRisk = malloc3DArray(_n_time, n_coef, n_coef);
   return true;
 }
Ejemplo n.º 6
0
    protected void initStats(final CoxPHModel model, final DataInfo dinfo) {
      CoxPHModel.CoxPHParameters p = model._parms;
      CoxPHModel.CoxPHOutput o = model._output;

      o.n = p.stop_column.length();
      o.data_info = dinfo;
      final int n_offsets = (p.offset_columns == null) ? 0 : p.offset_columns.length;
      final int n_coef = o.data_info.fullN() - n_offsets;
      final String[] coefNames = o.data_info.coefNames();
      o.coef_names = new String[n_coef];
      System.arraycopy(coefNames, 0, o.coef_names, 0, n_coef);
      o.coef = MemoryManager.malloc8d(n_coef);
      o.exp_coef = MemoryManager.malloc8d(n_coef);
      o.exp_neg_coef = MemoryManager.malloc8d(n_coef);
      o.se_coef = MemoryManager.malloc8d(n_coef);
      o.z_coef = MemoryManager.malloc8d(n_coef);
      o.gradient = MemoryManager.malloc8d(n_coef);
      o.hessian = malloc2DArray(n_coef, n_coef);
      o.var_coef = malloc2DArray(n_coef, n_coef);
      o.x_mean_cat = MemoryManager.malloc8d(n_coef - (o.data_info._nums - n_offsets));
      o.x_mean_num = MemoryManager.malloc8d(o.data_info._nums - n_offsets);
      o.mean_offset = MemoryManager.malloc8d(n_offsets);
      o.offset_names = new String[n_offsets];
      System.arraycopy(coefNames, n_coef, o.offset_names, 0, n_offsets);

      final Vec start_column = p.start_column;
      final Vec stop_column = p.stop_column;
      o.min_time =
          p.start_column == null ? (long) stop_column.min() : (long) start_column.min() + 1;
      o.max_time = (long) stop_column.max();

      final int n_time = new Vec.CollectDomain().doAll(stop_column).domain().length;
      o.time = MemoryManager.malloc8(n_time);
      o.n_risk = MemoryManager.malloc8d(n_time);
      o.n_event = MemoryManager.malloc8d(n_time);
      o.n_censor = MemoryManager.malloc8d(n_time);
      o.cumhaz_0 = MemoryManager.malloc8d(n_time);
      o.var_cumhaz_1 = MemoryManager.malloc8d(n_time);
      o.var_cumhaz_2 = malloc2DArray(n_time, n_coef);
    }
Ejemplo n.º 7
0
 protected void set_sparse(int nzeros) {
   if (sparseLen() == nzeros && _len != 0) return;
   if (_id != null) { // we have sparse representation but some 0s in it!
     int[] id = MemoryManager.malloc4(nzeros);
     int j = 0;
     if (_ds != null) {
       double[] ds = MemoryManager.malloc8d(nzeros);
       for (int i = 0; i < sparseLen(); ++i) {
         if (_ds[i] != 0) {
           ds[j] = _ds[i];
           id[j] = _id[i];
           ++j;
         }
       }
       _ds = ds;
     } else if (_is != null) {
       int[] is = MemoryManager.malloc4(nzeros);
       for (int i = 0; i < sparseLen(); i++) {
         if (_is[i] != -1) {
           is[j] = _is[i];
           id[j] = id[i];
           ++j;
         }
       }
     } else {
       long[] ls = MemoryManager.malloc8(nzeros);
       int[] xs = MemoryManager.malloc4(nzeros);
       for (int i = 0; i < sparseLen(); ++i) {
         if (_ls[i] != 0) {
           ls[j] = _ls[i];
           xs[j] = _xs[i];
           id[j] = _id[i];
           ++j;
         }
       }
       _ls = ls;
       _xs = xs;
     }
     _id = id;
     assert j == nzeros;
     set_sparseLen(nzeros);
     return;
   }
   assert sparseLen() == _len
       : "_len = " + sparseLen() + ", _len2 = " + _len + ", nzeros = " + nzeros;
   int zs = 0;
   if (_is != null) {
     assert nzeros < _is.length;
     _id = MemoryManager.malloc4(_is.length);
     for (int i = 0; i < sparseLen(); i++) {
       if (_is[i] == -1) zs++;
       else {
         _is[i - zs] = _is[i];
         _id[i - zs] = i;
       }
     }
   } else if (_ds == null) {
     if (_len == 0) {
       _ls = new long[0];
       _xs = new int[0];
       _id = new int[0];
       set_sparseLen(0);
       return;
     } else {
       assert nzeros < sparseLen();
       _id = alloc_indices(_ls.length);
       for (int i = 0; i < sparseLen(); ++i) {
         if (_ls[i] == 0 && _xs[i] == 0) ++zs;
         else {
           _ls[i - zs] = _ls[i];
           _xs[i - zs] = _xs[i];
           _id[i - zs] = i;
         }
       }
     }
   } else {
     assert nzeros < _ds.length;
     _id = alloc_indices(_ds.length);
     for (int i = 0; i < sparseLen(); ++i) {
       if (_ds[i] == 0) ++zs;
       else {
         _ds[i - zs] = _ds[i];
         _id[i - zs] = i;
       }
     }
   }
   assert zs == (sparseLen() - nzeros);
   set_sparseLen(nzeros);
 }
Ejemplo n.º 8
0
 long[] alloc_mantissa(int l) {
   return _ls = MemoryManager.malloc8(l);
 }