Java Code Examples for cern.colt.list.DoubleArrayList#sort()

The following examples show how to use cern.colt.list.DoubleArrayList#sort() . 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: AbstractDoubleIntMap.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by key.
 */
public String toString() {
	DoubleArrayList theKeys = keys();
	theKeys.sort();

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		double key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 2
Source File: AbstractDoubleIntMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns a string representation of the receiver, containing
 * the String representation of each key-value pair, sorted ascending by key.
 */
public String toString() {
	DoubleArrayList theKeys = keys();
	theKeys.sort();

	StringBuffer buf = new StringBuffer();
	buf.append("[");
	int maxIndex = theKeys.size() - 1;
	for (int i = 0; i <= maxIndex; i++) {
		double key = theKeys.get(i);
	    buf.append(String.valueOf(key));
		buf.append("->");
	    buf.append(String.valueOf(get(key)));
		if (i < maxIndex) buf.append(", ");
	}
	buf.append("]");
	return buf.toString();
}
 
Example 3
Source File: KernelDensityEstimator2D.java    From beast-mcmc with GNU Lesser General Public License v2.1 5 votes vote down vote up
public double bandwidthNRD(double[] in) {

        DoubleArrayList inList = new DoubleArrayList(in.length);
        for (double d : in)
            inList.add(d);
        inList.sort();

        final double h = (Descriptive.quantile(inList, 0.75) - Descriptive.quantile(inList, 0.25)) / 1.34;

        return 4 * 1.06 *
                Math.min(Math.sqrt(DiscreteStatistics.variance(in)), h) *
                Math.pow(in.length, -0.2);
    }
 
Example 4
Source File: AbstractDoubleIntMap.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fills all keys and values <i>sorted ascending by key</i> into the specified lists.
 * Fills into the lists, starting at index 0.
 * After this call returns the specified lists both have a new size that equals <tt>this.size()</tt>.
 * <p>
 * <b>Example:</b>
 * <br>
 * <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (6,7,8), valueList = (2,2,1)</tt>
 *
 * @param keyList the list to be filled with keys, can have any size.
 * @param valueList the list to be filled with values, can have any size.
 */
public void pairsSortedByKey(final DoubleArrayList keyList, final IntArrayList valueList) {
	/*
	keys(keyList); 
	values(valueList);
	
	final double[] k = keyList.elements();
	final int[] v = valueList.elements();
	cern.colt.Swapper swapper = new cern.colt.Swapper() {
		public void swap(int a, int b) {
			int t1;	double t2;
			t1 = v[a]; v[a] = v[b]; v[b] = t1;
			t2 = k[a]; k[a] = k[b];	k[b] = t2;
		}
	}; 

	cern.colt.function.IntComparator comp = new cern.colt.function.IntComparator() {
		public int compare(int a, int b) {
			return k[a]<k[b] ? -1 : k[a]==k[b] ? 0 : 1;
		}
	};
	cern.colt.MultiSorting.sort(0,keyList.size(),comp,swapper);
	*/	
	

	
	// this variant may be quicker
	//cern.colt.map.OpenDoubleIntHashMap.hashCollisions = 0;
	//System.out.println("collisions="+cern.colt.map.OpenDoubleIntHashMap.hashCollisions);
	keys(keyList);
	keyList.sort();
	valueList.setSize(keyList.size());
	for (int i=keyList.size(); --i >= 0; ) {
		valueList.setQuick(i,get(keyList.getQuick(i)));
	}
	//System.out.println("collisions="+cern.colt.map.OpenDoubleIntHashMap.hashCollisions);
	
}
 
Example 5
Source File: AbstractDoubleIntMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Fills all keys and values <i>sorted ascending by key</i> into the specified lists.
 * Fills into the lists, starting at index 0.
 * After this call returns the specified lists both have a new size that equals <tt>this.size()</tt>.
 * <p>
 * <b>Example:</b>
 * <br>
 * <tt>keys = (8,7,6), values = (1,2,2) --> keyList = (6,7,8), valueList = (2,2,1)</tt>
 *
 * @param keyList the list to be filled with keys, can have any size.
 * @param valueList the list to be filled with values, can have any size.
 */
public void pairsSortedByKey(final DoubleArrayList keyList, final IntArrayList valueList) {
	/*
	keys(keyList); 
	values(valueList);
	
	final double[] k = keyList.elements();
	final int[] v = valueList.elements();
	cern.colt.Swapper swapper = new cern.colt.Swapper() {
		public void swap(int a, int b) {
			int t1;	double t2;
			t1 = v[a]; v[a] = v[b]; v[b] = t1;
			t2 = k[a]; k[a] = k[b];	k[b] = t2;
		}
	}; 

	cern.colt.function.IntComparator comp = new cern.colt.function.IntComparator() {
		public int compare(int a, int b) {
			return k[a]<k[b] ? -1 : k[a]==k[b] ? 0 : 1;
		}
	};
	cern.colt.MultiSorting.sort(0,keyList.size(),comp,swapper);
	*/	
	

	
	// this variant may be quicker
	//cern.colt.map.OpenDoubleIntHashMap.hashCollisions = 0;
	//System.out.println("collisions="+cern.colt.map.OpenDoubleIntHashMap.hashCollisions);
	keys(keyList);
	keyList.sort();
	valueList.setSize(keyList.size());
	for (int i=keyList.size(); --i >= 0; ) {
		valueList.setQuick(i,get(keyList.getQuick(i)));
	}
	//System.out.println("collisions="+cern.colt.map.OpenDoubleIntHashMap.hashCollisions);
	
}