/** C = A||B; Constructs a new matrix which is the concatenation of two other matrices. Example: <tt>0 1</tt> append <tt>3 4</tt> --> <tt>0 1 3 4</tt>. */ public DoubleMatrix1D append(DoubleMatrix1D A, DoubleMatrix1D B) { // concatenate DoubleMatrix1D matrix = make(A.size()+B.size()); matrix.viewPart(0,A.size()).assign(A); matrix.viewPart(A.size(),B.size()).assign(B); return matrix; } /**
public double getQuick(int index) { return content.get(index*_stride); } public void setQuick(int index, double value) {
/** * Sets the matrix cell at coordinate <tt>index</tt> to the specified value. * * @param index the index of the cell. * @param value the value to be filled into the specified cell. * @throws IndexOutOfBoundsException if <tt>index<0 || index>=size()</tt>. */ public void set(int index, double value) { if (index<0 || index>=size) checkIndex(index); setQuick(index,value); } /**
public MGMParams(DoubleMatrix1D vec, int p, int ltot){ int[] lens = {p*p, p, p*ltot, ltot*ltot, p, ltot}; int[] lenSums = new int[lens.length]; lenSums[0] = lens[0]; for(int i = 1; i < lenSums.length; i++){ lenSums[i] = lens[i] + lenSums[i-1]; } if(vec.size() != lenSums[5]) throw new IllegalArgumentException("Param vector dimension doesn't match: Found " + vec.size() + " need " + lenSums[5]); beta = DoubleFactory2D.dense.make(vec.viewPart(0, lens[0]).toArray(), p); betad = vec.viewPart(lenSums[0], lens[1]).copy(); theta = DoubleFactory2D.dense.make(vec.viewPart(lenSums[1], lens[2]).toArray(), ltot); phi = DoubleFactory2D.dense.make(vec.viewPart(lenSums[2], lens[3]).toArray(), ltot); alpha1 = vec.viewPart(lenSums[3], lens[4]).copy(); alpha2 = vec.viewPart(lenSums[4], lens[5]).copy(); }
protected double computeJSDivergence(DoubleMatrix1D v1, DoubleMatrix1D v2) { assert(v1.size() == v2.size()); double sum = 0.0; for(int i = 0; i < v2.size(); ++i ) { sum += v2.getQuick(i); } DoubleMatrix1D v3 = v2.copy(); for(int i = 0; i < v2.size(); ++i ) { v3.set(i, v2.getQuick(i)/sum); } double divergence = 0.0; double[] meanVector = averageDist(v1, v2); divergence = computeKLDivergence(v1, meanVector) + computeKLDivergence(v2, meanVector); return divergence; }
/** * Inequality functions gradients values at X. */ protected DoubleMatrix2D getGradFi(DoubleMatrix1D X) { DoubleMatrix2D ret = F2.make(request.getFi().length, X.size()); double[] x = X.toArray(); for(int i=0; i<request.getFi().length; i++){ ret.viewRow(i).assign(request.getFi()[i].gradient(x)); } return ret; }
/** * Replaces all cell values of the receiver with the values of another matrix. * Both matrices must have the same size. * If both matrices share the same cells (as is the case if they are views derived from the same matrix) and intersect in an ambiguous way, then replaces <i>as if</i> using an intermediate auxiliary deep copy of <tt>other</tt>. * * @param other the source matrix to copy from (may be identical to the receiver). * @return <tt>this</tt> (for convenience only). * @throws IllegalArgumentException if <tt>size() != other.size()</tt>. */ public DoubleMatrix1D assign(DoubleMatrix1D other) { if (other==this) return this; checkSize(other); if (haveSharedCells(other)) other = other.copy(); for (int i=size; --i >= 0;) { setQuick(i,other.getQuick(i)); } return this; } /**
/** * Convert discrete data (in yDat) to a matrix of dummy variables (stored in dDat) */ private void makeDummy(){ dDat = factory2D.make(n, lsum); for(int i = 0; i < q; i++){ for(int j = 0; j < l[i]; j++){ DoubleMatrix1D curCol = yDat.viewColumn(i).copy().assign(Functions.equals(j+1)); if(curCol.zSum() == 0) throw new IllegalArgumentException("Discrete data is missing a level: variable " + i + " level " + j); dDat.viewColumn(lcumsum[i]+j).assign(curCol); } } }
/** * Returns the dot product of two vectors x and y, which is <tt>Sum(x[i]*y[i])</tt>. * Where <tt>x == this</tt>. * Operates on cells at indexes <tt>0 .. Math.min(size(),y.size())</tt>. * @param y the second vector. * @return the sum of products. */ public double zDotProduct(DoubleMatrix1D y) { return zDotProduct(y,0,size); } /**