Package cern.colt.matrix

Examples of cern.colt.matrix.DoubleMatrix1D


/**
*/
public static void doubleTest31(int size) {

System.out.println("\ninit");
DoubleMatrix1D a = Factory1D.dense.descending(size);
DoubleMatrix1D b = new WrapperDoubleMatrix1D(a);
DoubleMatrix1D c = b.viewPart(2,3);
DoubleMatrix1D d = c.viewFlip();
//DoubleMatrix1D c = b.viewFlip();
//DoubleMatrix1D d = c.viewFlip();
d.set(0,99);
b = b.viewSorted();
System.out.println("a = "+a);
System.out.println("b = "+b);
System.out.println("c = "+c);
System.out.println("d = "+d);
View Full Code Here


  testSort[0] = 5;
  testSort[1] = Double.NaN;
  testSort[2] = 2;
  testSort[3] = Double.NaN;
  testSort[4] = 1;
  DoubleMatrix1D doubleDense = new DenseDoubleMatrix1D(testSort);
  System.out.println("orig = "+doubleDense);
  doubleDense = doubleDense.viewSorted();
  doubleDense.toArray(testSort);
  System.out.println("sort = "+doubleDense);
  System.out.println("done\n");
}
View Full Code Here

System.out.println("\n"+master);
master.viewPart(2,0,2,3).assign(2); // set [2,1] .. [3,3] to 2
System.out.println("\n"+master);

int[] indexes = {0,1,3,0,1,2};
DoubleMatrix1D view1 = master.viewRow(0).viewSelection(indexes);
System.out.println("view1="+view1);
DoubleMatrix1D view2 = view1.viewPart(0,3);
System.out.println("view2="+view2);

view2.viewPart(0,2).assign(-1);
System.out.println("master replaced"+master);
System.out.println("flip1 replaced"+view1);
System.out.println("flip2 replaced"+view2);

View Full Code Here

  //precompute and cache some views to avoid regenerating them time and again
  DoubleMatrix1D[] LUrows = new DoubleMatrix1D[m];
  for (int i = 0; i < m; i++) LUrows[i] = LU.viewRow(i);
 
  cern.colt.list.IntArrayList nonZeroIndexes = new cern.colt.list.IntArrayList(); // sparsity
  DoubleMatrix1D LUcolj = LU.viewColumn(0).like()// blocked column j
  cern.jet.math.Mult multFunction = cern.jet.math.Mult.mult(0);

  // Outer loop.
  for (int j = 0; j < n; j++) {
    // blocking (make copy of j-th column to localize references)
    LUcolj.assign(LU.viewColumn(j));
   
    // sparsity detection
    int maxCardinality = m/CUT_OFF; // == heuristic depending on speedup
    LUcolj.getNonZeros(nonZeroIndexes,null,maxCardinality);
    int cardinality = nonZeroIndexes.size();
    boolean sparse = (cardinality < maxCardinality);

    // Apply previous transformations.
    for (int i = 0; i < m; i++) {
      int kmax = Math.min(i,j);
      double s;
      if (sparse) {
        s = LUrows[i].zDotProduct(LUcolj,0,kmax,nonZeroIndexes);
      }
      else {
        s = LUrows[i].zDotProduct(LUcolj,0,kmax);
      }
      double before = LUcolj.getQuick(i);
      double after = before -s;
      LUcolj.setQuick(i, after); // LUcolj is a copy
      LU.setQuick(i,j, after);   // this is the original
      if (sparse) {
        if (before==0 && after!=0) { // nasty bug fixed!
          int pos = nonZeroIndexes.binarySearch(i);
          pos = -pos -1;
          nonZeroIndexes.beforeInsert(pos,i);
        }
        if (before!=0 && after==0) {
          nonZeroIndexes.remove(nonZeroIndexes.binarySearch(i));
        }
      }
    }
 
    // Find pivot and exchange if necessary.
    int p = j;
    if (p < m) {
      double max = Math.abs(LUcolj.getQuick(p));
      for (int i = j+1; i < m; i++) {
        double v = Math.abs(LUcolj.getQuick(i));
        if (v > max) {
          p = i;
          max = v;
        }
      }
View Full Code Here

  // transformations
  cern.jet.math.Mult     div       = cern.jet.math.Mult.div(0);
  cern.jet.math.PlusMult minusMult = cern.jet.math.PlusMult.minusMult(0);

  cern.colt.list.IntArrayList nonZeroIndexes = new cern.colt.list.IntArrayList(); // sparsity
  DoubleMatrix1D Browk = cern.colt.matrix.DoubleFactory1D.dense.make(nx); // blocked row k

  // Solve L*Y = B(piv,:)
  for (int k = 0; k < n; k++) {
    // blocking (make copy of k-th row to localize references)
    Browk.assign(Brows[k]);

    // sparsity detection
    int maxCardinality = nx/CUT_OFF; // == heuristic depending on speedup
    Browk.getNonZeros(nonZeroIndexes,null,maxCardinality);
    int cardinality = nonZeroIndexes.size();
    boolean sparse = (cardinality < maxCardinality);

    for (int i = k+1; i < n; i++) {
      //for (int j = 0; j < nx; j++) B[i][j] -= B[k][j]*LU[i][k];
      //for (int j = 0; j < nx; j++) B.set(i,j, B.get(i,j) - B.get(k,j)*LU.get(i,k));

      minusMult.multiplicator = -LU.getQuick(i,k);
      if (minusMult.multiplicator != 0) {
        if (sparse) {
          Brows[i].assign(Browk,minusMult,nonZeroIndexes);
        }
        else {
          Brows[i].assign(Browk,minusMult);
        }
      }
    }
  }

  // Solve U*B = Y;
  for (int k = n-1; k >= 0; k--) {
    // for (int j = 0; j < nx; j++) B[k][j] /= LU[k][k];
    // for (int j = 0; j < nx; j++) B.set(k,j, B.get(k,j) / LU.get(k,k));
    div.multiplicator = 1 / LU.getQuick(k,k);
    Brows[k].assign(div);

    // blocking
    if (Browk==null) Browk = cern.colt.matrix.DoubleFactory1D.dense.make(B.columns());
    Browk.assign(Brows[k]);

    // sparsity detection
    int maxCardinality = nx/CUT_OFF; // == heuristic depending on speedup
    Browk.getNonZeros(nonZeroIndexes,null,maxCardinality);
    int cardinality = nonZeroIndexes.size();
    boolean sparse = (cardinality < maxCardinality);

    //Browk.getNonZeros(nonZeroIndexes,null);
    //boolean sparse = nonZeroIndexes.size() < nx/10;
View Full Code Here

     
      QR.setQuick(k,k, QR.getQuick(k,k) + 1);
     
      // Apply transformation to remaining columns.
      for (int j = k+1; j < n; j++) {
        DoubleMatrix1D QRcolj = QR.viewColumn(j).viewPart(k,m-k);
        double s = QRcolumnsPart[k].zDotProduct(QRcolj);
        /*
        // fixes bug reported by John Chambers
        DoubleMatrix1D QRcolj = QR.viewColumn(j).viewPart(k,m-k);
        double s = QRcolumnsPart[k].zDotProduct(QRcolumns[j]);
View Full Code Here

public DoubleMatrix2D getQ () {
  cern.jet.math.Functions F = cern.jet.math.Functions.functions;
  DoubleMatrix2D Q = QR.like();
  //double[][] Q = X.getArray();
  for (int k = n-1; k >= 0; k--) {
    DoubleMatrix1D QRcolk = QR.viewColumn(k).viewPart(k,m-k);
    Q.setQuick(k,k, 1);
    for (int j = k; j < n; j++) {
      if (QR.getQuick(k,k) != 0) {
        DoubleMatrix1D Qcolj = Q.viewColumn(j).viewPart(k,m-k);
        double s = QRcolk.zDotProduct(Qcolj);
        s = -s / QR.getQuick(k,k);
        Qcolj.assign(QRcolk, F.plusMult(s));
      }
    }
  }
  return Q;
}
View Full Code Here

public double dnrm2(DoubleMatrix1D x) {
  return Math.sqrt(Algebra.DEFAULT.norm2(x));
}
public void drot(DoubleMatrix1D x, DoubleMatrix1D y, double c, double s) {
  x.checkSize(y);
  DoubleMatrix1D tmp = x.copy();
 
  x.assign(F.mult(c));
  x.assign(y,F.plusMult(s));

  y.assign(F.mult(c));
View Full Code Here

  Property.DEFAULT.checkSquare(A);
  int size = A.rows();
  if (size != x.size() || size!=y.size()) {
    throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort() + ", " + y.toStringShort());
  }
  DoubleMatrix1D tmp = x.like();
  for (int i = 0; i < size; i++) {
    double sum = 0;
    for (int j = 0; j <= i; j++) {
      sum += A.getQuick(i,j) * x.getQuick(j);
    }
    for (int j = i + 1; j < size; j++) {
      sum += A.getQuick(j,i) * x.getQuick(j);
    }
    tmp.setQuick(i, alpha * sum + beta * y.getQuick(i));
  }
  y.assign(tmp);
}
 
View Full Code Here

  int size = A.rows();
  if (size != x.size()) {
    throw new IllegalArgumentException(A.toStringShort() + ", " + x.toStringShort());
  }
     
  DoubleMatrix1D b = x.like();
  DoubleMatrix1D y = x.like();
  if (isUnitTriangular) {
    y.assign(1);
  }
  else {
    for (int i = 0; i < size; i++) {
      y.setQuick(i, A.getQuick(i,i));
    }
  }
 
  for (int i = 0; i < size; i++) {
    double sum = 0;
    if (!isUpperTriangular) {
      for (int j = 0; j < i; j++) {
        sum += A.getQuick(i,j) * x.getQuick(j);
      }
      sum += y.getQuick(i) * x.getQuick(i);
    }
    else {
      sum += y.getQuick(i) * x.getQuick(i);
      for (int j = i + 1; j < size; j++) {
        sum += A.getQuick(i,j) * x.getQuick(j);      }
    }
    b.setQuick(i,sum);
  }
 
View Full Code Here

TOP

Related Classes of cern.colt.matrix.DoubleMatrix1D

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.