static double[][] malloc2DArray(final int d1, final int d2) { final double[][] array = new double[d1][]; for (int j = 0; j < d1; ++j) array[j] = MemoryManager.malloc8d(d2); return array; }
public double [] gradient(){ double [] res = MemoryManager.malloc8d(_gradient.length*_gradient[0].length); int P = _gradient.length; for(int k = 0; k < _gradient[0].length; ++k) for(int i = 0; i < _gradient.length; ++i) res[k*P + i] = _gradient[i][k]; return res; } }
static double[][][] malloc3DArray(final int d1, final int d2, final int d3) { final double[][][] array = new double[d1][d2][]; for (int j = 0; j < d1; ++j) for (int k = 0; k < d2; ++k) array[j][k] = MemoryManager.malloc8d(d3); return array; }
public ProximalGradientSolver(GradientSolver s, double[] betaStart, double[] rho, double objEps, double gradEps, GradientInfo ginfo,ProgressMonitor pm) { super(); _solver = s; _rho = rho; _objEps = objEps; _gradEps = gradEps; _pm = pm; _beta = betaStart; _betaGiven = MemoryManager.malloc8d(betaStart.length); // _ginfo = new ProximalGradientInfo(ginfo,ginfo._objVal,ginfo._gradient); }
public Gram(int N, int diag, int dense, int sparse, boolean hasIntercept) { _hasIntercept = hasIntercept; _fullN = N + (_hasIntercept?1:0); _xx = new double[_fullN - diag][]; _diag = MemoryManager.malloc8d(_diagN = diag); _denseN = dense; for( int i = 0; i < (_fullN - _diagN); ++i ) _xx[i] = MemoryManager.malloc8d(diag + i + 1); }
private static double [] extractSubRange(int N, int c, int [] ids, double [] src) { if(ids == null) return Arrays.copyOfRange(src,c*N,c*N+N); double [] res = MemoryManager.malloc8d(ids.length); int j = 0; int off = c*N; for(int i:ids) res[j++] = src[off+i]; return res; }
private static final double[] expandVec(double[] beta, final int[] activeCols, int fullN, double filler) { assert beta != null; if (activeCols == null) return beta; double[] res = MemoryManager.malloc8d(fullN); Arrays.fill(res, filler); int i = 0; for (int c : activeCols) res[c] = beta[i++]; res[res.length - 1] = beta[beta.length - 1]; return res; }
@Override public void chunkInit() { _sparseOffsets = MemoryManager.malloc8d(_nclasses); if(_sparse) for(int c = 0; c < _nclasses; ++c) _sparseOffsets[c] = GLM.sparseOffset(_beta[c],_dinfo); } @Override
public GramSolver(Gram gram, double[] xy, double lmax, double betaEps, boolean intercept) { _gram = gram; _lambda = 0; _betaEps = betaEps; _xy = xy; double[] rhos = MemoryManager.malloc8d(xy.length); computeCholesky(gram, rhos, lmax * 1e-8,intercept); _addedL2 = rhos[0] != 0; _rho = _addedL2 ? rhos : null; }
@Override protected void map(int id){ double [] cs = null; for(int i = _cidx.getAndIncrement(); i < _cids.length; i = _cidx.getAndIncrement()) { if(cs == null) cs = MemoryManager.malloc8d(_maxChunkSz); computeChunk(i,cs,_ws[i]); } }
@Override public void chunkInit() { _sparseOffsets = MemoryManager.malloc8d(_nclasses); if(_sparse) for(int c = 0; c < _nclasses; ++c) _sparseOffsets[c] = GLM.sparseOffset(_beta[c],_dinfo); } @Override
public Row(boolean sparse, int nNums, int nBins, int nresponses, int i, long start) { binIds = MemoryManager.malloc4(nBins); numVals = MemoryManager.malloc8d(nNums); response = MemoryManager.malloc8d(nresponses); if(sparse) numIds = MemoryManager.malloc4(nNums); this.nNums = sparse?0:nNums; cid = i; rid = start + i; }
public void setNonNegative() { if (_betaLB == null) { _betaLB = MemoryManager.malloc8d(_dinfo.fullN() + 1); _betaLB[_dinfo.fullN()] = Double.NEGATIVE_INFINITY; } else for (int i = 0; i < _betaLB.length - 1; ++i) _betaLB[i] = Math.max(0, _betaLB[i]); if (_betaUB == null) { _betaUB = MemoryManager.malloc8d(_dinfo.fullN() + 1); Arrays.fill(_betaUB, Double.POSITIVE_INFINITY); } }
public double [] beta_std(double lambda) { for(int i = 0 ; i < _output._submodels.length; ++i) if(_output._submodels[i].lambda_value == lambda) return _output._submodels[i].getBeta(MemoryManager.malloc8d(_output._dinfo.fullN()+1)); throw new RuntimeException("no such lambda value, lambda = " + lambda); } public String [] names(){ return _output._names;}
public double[][] getXX(boolean lowerDiag, boolean icptFist) { if(_xxCache != null && _xxCache.match(lowerDiag,icptFist)) return _xxCache.xx; final int N = _fullN; double[][] xx = new double[N][]; for( int i = 0; i < N; ++i ) xx[i] = MemoryManager.malloc8d(lowerDiag?i+1:N); return getXX(xx, lowerDiag, icptFist); }
@Override public void chunkInit() { _gram = new Gram(_dinfo.fullN(), _dinfo.largestCat(), _dinfo.numNums(), _dinfo._cats, true); _xy = MemoryManager.malloc8d(_dinfo.fullN() + 1); }
@Override public void chunkInit(){ // initialize _gram = new Gram(_dinfo.fullN(), _dinfo.largestCat(), _dinfo.numNums(), _dinfo._cats,true); _xy = MemoryManager.malloc8d(_dinfo.fullN()+1); // + 1 is for intercept if(_sparse) _sparseOffset = GLM.sparseOffset(_beta,_dinfo); } @Override