Package cern.colt.matrix

Examples of cern.colt.matrix.DoubleMatrix2D


* @param distanceFunction (EUCLID, CANBERRA, ..., or any user defined distance function operating on two vectors).
* @return the distance matrix (<tt>n x n, n=matrix.columns</tt>).
*/
public static DoubleMatrix2D distance(DoubleMatrix2D matrix, VectorVectorFunction distanceFunction) {
  int columns = matrix.columns();
  DoubleMatrix2D distance = new cern.colt.matrix.impl.DenseDoubleMatrix2D(columns,columns);

  // cache views
  DoubleMatrix1D[] cols = new DoubleMatrix1D[columns];
  for (int i=columns; --i >= 0; ) {
    cols[i] = matrix.viewColumn(i);
  }

  // work out all permutations
  for (int i=columns; --i >= 0; ) {
    for (int j=i; --j >= 0; ) {
      double d = distanceFunction.apply(cols[i], cols[j]);
      distance.setQuick(i,j,d);
      distance.setQuick(j,i,d); // symmetric
    }
  }
  return distance;
}
View Full Code Here


String[] formats =         {"%G", "%1.10G", "%f", "%1.2f", "%0.2e", null};


// now the processing
int size = formats.length;
DoubleMatrix2D matrix = cern.colt.matrix.DoubleFactory2D.dense.make(values);
String[] strings = new String[size];
String[] sourceCodes = new String[size];
String[] htmlStrings = new String[size];
String[] htmlSourceCodes = new String[size];
View Full Code Here

*/
public static void demo3(int size, double value) {
  cern.colt.Timer timer = new cern.colt.Timer();
  String s;
  StringBuffer buf;
  DoubleMatrix2D matrix = cern.colt.matrix.DoubleFactory2D.dense.make(size,size, value);

  timer.reset().start();
  buf = new StringBuffer();
  for (int i=size; --i >= 0; ) {
    for (int j=size; --j >= 0; ) {
      buf.append(matrix.getQuick(i,j));
    }
  }
  buf = null;
  timer.stop().display();

  timer.reset().start();
  cern.colt.matrix.impl.Former format = new cern.colt.matrix.impl.FormerFactory().create("%G");
  buf = new StringBuffer();
  for (int i=size; --i >= 0; ) {
    for (int j=size; --j >= 0; ) {
      buf.append(format.form(matrix.getQuick(i,j)));
    }
  }
  buf = null;
  timer.stop().display();

View Full Code Here

String[] columnNames = { "0.1", "0.3", "0.5", "0.7" };
String[] rowNames = { "SunJDK1.2.2 classic", "IBMJDK1.1.8", "SunJDK1.3 Hotspot", "other1", "other2" };
//String[] columnNames = { "0.1", "0.3" };
//String[] rowNames = { "SunJDK1.2.2 classic", "IBMJDK1.1.8"};

DoubleMatrix2D matrix = cern.colt.matrix.DoubleFactory2D.dense.make(values);
System.out.println("\n\n"+new Formatter("%G").toTitleString(matrix,rowNames,columnNames,"rowAxis","colAxis","VM Performance: Provider vs. matrix density"));
}
View Full Code Here

/**
* Returns a string representation of the given matrix.
* @param matrix the matrix to convert.
*/
public String toString(DoubleMatrix1D matrix) {
  DoubleMatrix2D easy = matrix.like2D(1,matrix.size());
  easy.viewRow(0).assign(matrix);
  return toString(easy);
}
View Full Code Here

*/
public String toTitleString(DoubleMatrix2D matrix, String[] rowNames, String[] columnNames, String rowAxisName, String columnAxisName, String title, hep.aida.bin.BinFunction1D[] aggr) {
  if (matrix.size()==0) return "Empty matrix";
  if (aggr==null || aggr.length==0) return toTitleString(matrix,rowNames,columnNames,rowAxisName,columnAxisName,title);

  DoubleMatrix2D rowStats = matrix.like(matrix.rows(), aggr.length); // hold row aggregations
  DoubleMatrix2D colStats = matrix.like(aggr.length, matrix.columns()); // hold column aggregations

  cern.colt.matrix.doublealgo.Statistic.aggregate(matrix, aggr, colStats); // aggregate an entire column at a time
  cern.colt.matrix.doublealgo.Statistic.aggregate(matrix.viewDice(), aggr, rowStats.viewDice()); // aggregate an entire row at a time

  // turn into strings
  // tmp holds "matrix" plus "colStats" below (needed so that numbers in a columns can be decimal point aligned)
  DoubleMatrix2D tmp = matrix.like(matrix.rows()+aggr.length, matrix.columns());
  tmp.viewPart(0,0,matrix.rows(),matrix.columns()).assign(matrix);
  tmp.viewPart(matrix.rows(),0,aggr.length,matrix.columns()).assign(colStats);
  colStats = null;

  String[][] s1 = format(tmp); align(s1); tmp = null;
  String[][] s2 = format(rowStats); align(s2); rowStats = null;

View Full Code Here

@param convergenceIterations the number of iterations to pass between each convergence check.
  (Since a convergence may be expensive, you may want to do it only every 2,4 or 8 iterations.)
@return the number of iterations actually executed.
*/
public static int stencil9(DoubleMatrix2D A, cern.colt.function.Double9Function function, int maxIterations, DoubleMatrix2DProcedure hasConverged, int convergenceIterations) {
  DoubleMatrix2D B = A.copy();
  if (convergenceIterations <= 1) convergenceIterations=2;
  if (convergenceIterations%2 != 0) convergenceIterations++; // odd -> make it even

  int i=0;
  while (i<maxIterations) { // do two steps at a time for efficiency
    A.zAssign8Neighbors(B,function);
    B.zAssign8Neighbors(A,function);
    i=i+2;
    if (i%convergenceIterations == 0 && hasConverged!=null) {
      if (hasConverged.apply(A)) return i;
    }
  }
View Full Code Here

  }

    public static void main(String args[]) {

       // For COLT
       DoubleMatrix2D xmatrix,ymatrix,zmatrix;

       DoubleFactory2D myfactory;
       myfactory = DoubleFactory2D.dense;
       xmatrix = myfactory.make(8,2);
       ymatrix = myfactory.make(8,1);

       xmatrix.set(0,0,1);
       xmatrix.set(1,0,1);
       xmatrix.set(2,0,1);
       xmatrix.set(3,0,1);
       xmatrix.set(4,0,1);
       xmatrix.set(5,0,1);
       xmatrix.set(6,0,1);
       xmatrix.set(7,0,1);

       xmatrix.set(0,1,80);
       xmatrix.set(1,1,220);
       xmatrix.set(2,1,140);
       xmatrix.set(3,1,120);
       xmatrix.set(4,1,180);
       xmatrix.set(5,1,100);
       xmatrix.set(6,1,200);
       xmatrix.set(7,1,160);

       ymatrix.set(0,0,0.6);
       ymatrix.set(1,0,6.70);
       ymatrix.set(2,0,5.30);
       ymatrix.set(3,0,4.00);
View Full Code Here

*/
public DoubleMatrix2D sort(DoubleMatrix2D matrix, hep.aida.bin.BinFunction1D aggregate) {
  // precompute aggregates over rows, as defined by "aggregate"

  // a bit clumsy, because Statistic.aggregate(...) is defined on columns, so we need to transpose views
  DoubleMatrix2D tmp = matrix.like(1,matrix.rows());
  hep.aida.bin.BinFunction1D[] func = {aggregate};
  Statistic.aggregate(matrix.viewDice(), func, tmp);
  double[] aggr = tmp.viewRow(0).toArray();
  return sort(matrix,aggr);
}
View Full Code Here

* Demonstrates advanced sorting.
* Sorts by sum of row.
*/
public static void zdemo1() {
  Sorting sort = quickSort;
  DoubleMatrix2D matrix = DoubleFactory2D.dense.descending(4,3);
  DoubleMatrix1DComparator comp = new DoubleMatrix1DComparator() {
    public int compare(DoubleMatrix1D a, DoubleMatrix1D b) {
      double as = a.zSum(); double bs = b.zSum();
      return as < bs ? -1 : as == bs ? 0 : 1;
    }
View Full Code Here

TOP

Related Classes of cern.colt.matrix.DoubleMatrix2D

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.