Java Code Examples for cern.colt.matrix.DoubleMatrix1D#toArray()

The following examples show how to use cern.colt.matrix.DoubleMatrix1D#toArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestMatrix2D.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Title:        Aero3D<p>
 * Description:  A Program to analyse aeroelestic evects in transonic wings<p>
 * Copyright:    Copyright (c) 1999 CERN - European Organization for Nuclear Research.
 * Company:      PIERSOL Engineering Inc.<p>
 * @author John R. Piersol
 * @version
 */
public static void doubleTest36() {
	double[] testSort = new double[5];
	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");
}
 
Example 2
Source File: Statistic.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
3-d OLAP cube operator; Fills all cells of the given vectors into the given histogram.
If you use hep.aida.ref.Converter.toString(histo) on the result, the OLAP cube of x-"column" vs. y-"column" vs. z-"column", summing the weights "column" will be printed.
For example, aggregate sales by product by region by time.
<p>
Computes the distinct values of x and y and z, yielding histogram axes that capture one distinct value per bin.
Then fills the histogram.
@return the histogram containing the cube.
@throws IllegalArgumentException if <tt>x.size() != y.size() || x.size() != z.size() || x.size() != weights.size()</tt>.
*/
public static hep.aida.IHistogram3D cube(DoubleMatrix1D x, DoubleMatrix1D y, DoubleMatrix1D z, DoubleMatrix1D weights) {
	if (x.size() != y.size() || x.size() != z.size() || x.size() != weights.size()) throw new IllegalArgumentException("vectors must have same size");
	
	double epsilon = 1.0E-9;
	cern.colt.list.DoubleArrayList distinct = new cern.colt.list.DoubleArrayList();
	double[] vals = new double[x.size()];
	cern.colt.list.DoubleArrayList sorted = new cern.colt.list.DoubleArrayList(vals);

	// compute distinct values of x
	x.toArray(vals); // copy x into vals
	sorted.sort();
	cern.jet.stat.Descriptive.frequencies(sorted, distinct, null);
	// since bins are right-open [from,to) we need an additional dummy bin so that the last distinct value does not fall into the overflow bin
	if (distinct.size()>0) distinct.add(distinct.get(distinct.size()-1) + epsilon);
	distinct.trimToSize();
	hep.aida.IAxis xaxis = new hep.aida.ref.VariableAxis(distinct.elements());

	// compute distinct values of y
	y.toArray(vals);
	sorted.sort();
	cern.jet.stat.Descriptive.frequencies(sorted, distinct, null);
	// since bins are right-open [from,to) we need an additional dummy bin so that the last distinct value does not fall into the overflow bin
	if (distinct.size()>0) distinct.add(distinct.get(distinct.size()-1) + epsilon);
	distinct.trimToSize();
	hep.aida.IAxis yaxis = new hep.aida.ref.VariableAxis(distinct.elements());

	// compute distinct values of z
	z.toArray(vals);
	sorted.sort();
	cern.jet.stat.Descriptive.frequencies(sorted, distinct, null);
	// since bins are right-open [from,to) we need an additional dummy bin so that the last distinct value does not fall into the overflow bin
	if (distinct.size()>0) distinct.add(distinct.get(distinct.size()-1) + epsilon);
	distinct.trimToSize();
	hep.aida.IAxis zaxis = new hep.aida.ref.VariableAxis(distinct.elements());

	hep.aida.IHistogram3D histo = new hep.aida.ref.Histogram3D("Cube",xaxis,yaxis,zaxis);
	return histogram(histo,x,y,z,weights);
}
 
Example 3
Source File: TestMatrix2D.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Title:        Aero3D<p>
 * Description:  A Program to analyse aeroelestic evects in transonic wings<p>
 * Copyright:    Copyright (c) 1998<p>
 * Company:      PIERSOL Engineering Inc.<p>
 * @author John R. Piersol
 * @version
 */
public static void doubleTest36() {
	double[] testSort = new double[5];
	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");
}
 
Example 4
Source File: Algebra.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
Modifies the given vector <tt>A</tt> such that it is permuted as specified; Useful for pivoting.
Cell <tt>A[i]</tt> will go into cell <tt>A[indexes[i]]</tt>.
<p>
<b>Example:</b>
<pre>
Reordering
[A,B,C,D,E] with indexes [0,4,2,3,1] yields 
[A,E,C,D,B]
In other words A[0]<--A[0], A[1]<--A[4], A[2]<--A[2], A[3]<--A[3], A[4]<--A[1].

Reordering
[A,B,C,D,E] with indexes [0,4,1,2,3] yields 
[A,E,B,C,D]
In other words A[0]<--A[0], A[1]<--A[4], A[2]<--A[1], A[3]<--A[2], A[4]<--A[3].
</pre>

@param   A   the vector to permute.
@param   indexes the permutation indexes, must satisfy <tt>indexes.length==A.size() && indexes[i] >= 0 && indexes[i] < A.size()</tt>;
@param   work the working storage, must satisfy <tt>work.length >= A.size()</tt>; set <tt>work==null</tt> if you don't care about performance.
@return the modified <tt>A</tt> (for convenience only).
@throws	IndexOutOfBoundsException if <tt>indexes.length != A.size()</tt>.
*/
public DoubleMatrix1D permute(DoubleMatrix1D A, int[] indexes, double[] work) {
	// check validity
	int size = A.size();
	if (indexes.length != size) throw new IndexOutOfBoundsException("invalid permutation");

	/*
	int i=size;
	int a;
	while (--i >= 0 && (a=indexes[i])==i) if (a < 0 || a >= size) throw new IndexOutOfBoundsException("invalid permutation");
	if (i<0) return; // nothing to permute
	*/

	if (work==null || size > work.length) {
		work = A.toArray();
	}
	else {
		A.toArray(work);
	}
	for (int i=size; --i >= 0; ) A.setQuick(i, work[indexes[i]]);
	return A;
}
 
Example 5
Source File: BBFreeBlock.java    From OSPREY3 with GNU General Public License v2.0 4 votes vote down vote up
public void setDOFs(DoubleMatrix1D x){
    //x: free DOFs (relative to center, so can eval polys directly)
    
    int numRes = residues.size();
    
    int numDOFsFull = fullDOFPolys.length;
    double fullDOFVals[] = new double[fullDOFPolys.length];
    
    for(int fullDOF=0; fullDOF<numDOFsFull; fullDOF++)
        fullDOFVals[fullDOF] = SeriesFitter.evalSeries(fullDOFPolys[fullDOF], x, x.size(), true, polyOrder);
                
    //record current information needed for placement of sidechain
    double genChi1[] = new double[numRes];
    double SCTranslations[][] = new double[numRes][3];
    
    //now set each residue in the right place
    
    //start with the CA's and N's
    for(int resNum=0; resNum<numRes; resNum++){
        
        Residue curRes = residues.get(resNum);
        
        //the sidechain will be translated based on CA motion
        if(resNum>0 && resNum<numRes-1){//CA moves, so translate sidechain with it
            double curCACoords[] = curRes.getCoordsByAtomName("CA");
            for(int dim=0; dim<3; dim++)
                SCTranslations[resNum][dim] = fullDOFVals[6*(resNum-1)+3+dim] - curCACoords[dim];
        }
        
        genChi1[resNum] = GenChi1Calc.getGenChi1(curRes);
        
        //OK now place the backbone...
        if(resNum>0){//N or CA moves
            int CAIndex = curRes.getAtomIndexByName("CA");
            int NIndex = curRes.getAtomIndexByName("N");

            for(int dim=0; dim<3; dim++){
                if(resNum<numRes-1)//CA moves
                    curRes.coords[3*CAIndex+dim] = fullDOFVals[6*(resNum-1)+3+dim];
                
                curRes.coords[3*NIndex+dim] = fullDOFVals[6*(resNum-1)+dim];
            }
        }
    }
    
    //OK now that the CA's and N's are in place, we can finish each peptide plane
    for(int pepPlaneNum=0; pepPlaneNum<numRes-1; pepPlaneNum++){
        //set each atom based on CA and N (linear relationship)
        Residue res1 = residues.get(pepPlaneNum);//residue at start of peptide plane...
        Residue res2 = residues.get(pepPlaneNum+1);//...and at end
        
        double CA1[] = res1.getCoordsByAtomName("CA");
        double N[] = res2.getCoordsByAtomName("N");
        double CA2[] = res2.getCoordsByAtomName("CA");
                    
        res1.setCoordsByAtomName("C", pepPlanes[pepPlaneNum].calcCCoords(CA1,N,CA2,false));
        res1.setCoordsByAtomName("O", pepPlanes[pepPlaneNum].calcOCoords(CA1,N,CA2));
        res2.setCoordsByAtomName("H", pepPlanes[pepPlaneNum].calcHCoords(CA1,N,CA2));
    }
        
    
    
    //OK and now that the backbone atoms are in place, we can handle the sidechains and HA's
    for(int resNum=0; resNum<numRes; resNum++){
        //first translate into place...
        RigidBodyMotion motion = new RigidBodyMotion(new double[3], RotationMatrix.identity(), SCTranslations[resNum]);
        SidechainIdealizer.moveSidechain(residues.get(resNum), motion);
        //...now idealize
        SidechainIdealizer.idealizeSidechain(EnvironmentVars.resTemplates, residues.get(resNum));
        //and get gen chi1 to where it was before, so this BB motion commutes w/ sidechain dihedral changes
        GenChi1Calc.setGenChi1(residues.get(resNum), genChi1[resNum]);
    }
    
    curFreeDOFVals = x.toArray();
}
 
Example 6
Source File: Algebra.java    From jAudioGIT with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
Modifies the given vector <tt>A</tt> such that it is permuted as specified; Useful for pivoting.
Cell <tt>A[i]</tt> will go into cell <tt>A[indexes[i]]</tt>.
<p>
<b>Example:</b>
<pre>
Reordering
[A,B,C,D,E] with indexes [0,4,2,3,1] yields 
[A,E,C,D,B]
In other words A[0]<--A[0], A[1]<--A[4], A[2]<--A[2], A[3]<--A[3], A[4]<--A[1].

Reordering
[A,B,C,D,E] with indexes [0,4,1,2,3] yields 
[A,E,B,C,D]
In other words A[0]<--A[0], A[1]<--A[4], A[2]<--A[1], A[3]<--A[2], A[4]<--A[3].
</pre>

@param   A   the vector to permute.
@param   indexes the permutation indexes, must satisfy <tt>indexes.length==A.size() && indexes[i] >= 0 && indexes[i] < A.size()</tt>;
@param   work the working storage, must satisfy <tt>work.length >= A.size()</tt>; set <tt>work==null</tt> if you don't care about performance.
@return the modified <tt>A</tt> (for convenience only).
@throws	IndexOutOfBoundsException if <tt>indexes.length != A.size()</tt>.
*/
public DoubleMatrix1D permute(DoubleMatrix1D A, int[] indexes, double[] work) {
	// check validity
	int size = A.size();
	if (indexes.length != size) throw new IndexOutOfBoundsException("invalid permutation");

	/*
	int i=size;
	int a;
	while (--i >= 0 && (a=indexes[i])==i) if (a < 0 || a >= size) throw new IndexOutOfBoundsException("invalid permutation");
	if (i<0) return; // nothing to permute
	*/

	if (work==null || size > work.length) {
		work = A.toArray();
	}
	else {
		A.toArray(work);
	}
	for (int i=size; --i >= 0; ) A.setQuick(i, work[indexes[i]]);
	return A;
}
 
Example 7
Source File: Statistic.java    From jAudioGIT with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
2-d OLAP cube operator; Fills all cells of the given vectors into the given histogram.
If you use hep.aida.ref.Converter.toString(histo) on the result, the OLAP cube of x-"column" vs. y-"column" , summing the weights "column" will be printed.
For example, aggregate sales by product by region.
<p>
Computes the distinct values of x and y, yielding histogram axes that capture one distinct value per bin.
Then fills the histogram.
<p>
Example output:
<table>
<td class="PRE"> 
<pre>
Cube:
&nbsp;&nbsp;&nbsp;Entries=5000, ExtraEntries=0
&nbsp;&nbsp;&nbsp;MeanX=4.9838, RmsX=NaN
&nbsp;&nbsp;&nbsp;MeanY=2.5304, RmsY=NaN
&nbsp;&nbsp;&nbsp;xAxis: Min=0, Max=10, Bins=11
&nbsp;&nbsp;&nbsp;yAxis: Min=0, Max=5, Bins=6
Heights:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| X
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| 0   1   2   3   4   5   6   7   8   9   10  | Sum 
----------------------------------------------------------
Y 5   |  30  53  51  52  57  39  65  61  55  49  22 |  534
&nbsp;&nbsp;4   |  43 106 112  96  92  94 107  98  98 110  47 | 1003
&nbsp;&nbsp;3   |  39 134  87  93 102 103 110  90 114  98  51 | 1021
&nbsp;&nbsp;2   |  44  81 113  96 101  86 109  83 111  93  42 |  959
&nbsp;&nbsp;1   |  54  94 103  99 115  92  98  97 103  90  44 |  989
&nbsp;&nbsp;0   |  24  54  52  44  42  56  46  47  56  53  20 |  494
----------------------------------------------------------
&nbsp;&nbsp;Sum | 234 522 518 480 509 470 535 476 537 493 226 |     
</pre>
</td>
</table>
@return the histogram containing the cube.
@throws IllegalArgumentException if <tt>x.size() != y.size() || y.size() != weights.size()</tt>.
*/
public static hep.aida.IHistogram2D cube(DoubleMatrix1D x, DoubleMatrix1D y, DoubleMatrix1D weights) {
	if (x.size() != y.size() || y.size() != weights.size()) throw new IllegalArgumentException("vectors must have same size");
	
	double epsilon = 1.0E-9;
	cern.colt.list.DoubleArrayList distinct = new cern.colt.list.DoubleArrayList();
	double[] vals = new double[x.size()];
	cern.colt.list.DoubleArrayList sorted = new cern.colt.list.DoubleArrayList(vals);

	// compute distinct values of x
	x.toArray(vals); // copy x into vals
	sorted.sort();
	cern.jet.stat.Descriptive.frequencies(sorted, distinct, null);
	// since bins are right-open [from,to) we need an additional dummy bin so that the last distinct value does not fall into the overflow bin
	if (distinct.size()>0) distinct.add(distinct.get(distinct.size()-1) + epsilon);
	distinct.trimToSize();
	hep.aida.IAxis xaxis = new hep.aida.ref.VariableAxis(distinct.elements());

	// compute distinct values of y
	y.toArray(vals);
	sorted.sort();
	cern.jet.stat.Descriptive.frequencies(sorted, distinct, null);
	// since bins are right-open [from,to) we need an additional dummy bin so that the last distinct value does not fall into the overflow bin
	if (distinct.size()>0) distinct.add(distinct.get(distinct.size()-1) + epsilon);
	distinct.trimToSize();
	hep.aida.IAxis yaxis = new hep.aida.ref.VariableAxis(distinct.elements());

	hep.aida.IHistogram2D histo = new hep.aida.ref.Histogram2D("Cube",xaxis,yaxis);
	return histogram(histo,x,y,weights);
}