cern.colt.list.DoubleArrayList Java Examples

The following examples show how to use cern.colt.list.DoubleArrayList. 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: Descriptive.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the median of a sorted data sequence.
 *
 * @param sortedData the data sequence; <b>must be sorted ascending</b>.
 */
public static double median(DoubleArrayList sortedData) {
	return quantile(sortedData, 0.5);
	/*
	double[] sortedElements = sortedData.elements();
	int n = sortedData.size();
	int lhs = (n - 1) / 2 ;
	int rhs = n / 2 ;
  
	if (n == 0) return 0.0 ;

	double median;
	if (lhs == rhs) median = sortedElements[lhs] ;
	else median = (sortedElements[lhs] + sortedElements[rhs])/2.0 ;

	return median;
	*/
}
 
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: DoubleMatrix3D.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
Fills the coordinates and values of cells having non-zero values into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists all have a new size, the number of non-zero values.
<p>
In general, fill order is <i>unspecified</i>.
This implementation fill like: <tt>for (slice = 0..slices-1) for (row = 0..rows-1) for (column = 0..colums-1) do ... </tt>.
However, subclasses are free to us any other order, even an order that may change over time as cell values are changed.
(Of course, result lists indexes are guaranteed to correspond to the same cell).
For an example, see {@link DoubleMatrix2D#getNonZeros(IntArrayList,IntArrayList,DoubleArrayList)}.

@param sliceList the list to be filled with slice indexes, can have any size.
@param rowList the list to be filled with row indexes, can have any size.
@param columnList the list to be filled with column indexes, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void getNonZeros(IntArrayList sliceList, IntArrayList rowList, IntArrayList columnList, DoubleArrayList valueList) {
	sliceList.clear(); 
	rowList.clear(); 
	columnList.clear(); 
	valueList.clear();
	int s = slices;
	int r = rows;
	int c = columns;
	for (int slice=0; slice < s; slice++) {
		for (int row=0; row < r; row++) {
			for (int column=0; column < c; column++) {
				double value = getQuick(slice,row,column);
				if (value != 0) {
					sliceList.add(slice);
					rowList.add(row);
					columnList.add(column);
					valueList.add(value);
				}
			}
		}
	}
}
 
Example #4
Source File: UnknownDoubleQuantileEstimator.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Computes the specified quantile elements over the values previously added.
 * @param phis the quantiles for which elements are to be computed. Each phi must be in the interval (0.0,1.0]. <tt>phis</tt> must be sorted ascending.
 * @return the approximate quantile elements.
 */
public DoubleArrayList quantileElements(DoubleArrayList phis) {
	if (precomputeEpsilon<=0.0) return super.quantileElements(phis);
	
	int quantilesToPrecompute = (int) Utils.epsilonCeiling(1.0 / precomputeEpsilon);
	/*
	if (phis.size() > quantilesToPrecompute) {
		// illegal use case!
		// we compute results, but loose explicit approximation guarantees.
		return super.quantileElements(phis);
	}
	*/
 
	//select that quantile from the precomputed set that corresponds to a position closest to phi.
	phis = phis.copy();
	double e = precomputeEpsilon;
	for (int index=phis.size(); --index >= 0;) {
		double phi = phis.get(index);
		int i = (int) Math.round( ((2.0*phi/e) - 1.0 ) / 2.0); // finds closest
		i = Math.min(quantilesToPrecompute-1, Math.max(0,i));
		double augmentedPhi = (e/2.0)*(1+2*i);
		phis.set(index,augmentedPhi);				
	}
	
	return super.quantileElements(phis);
}
 
Example #5
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 value.
 */
public String toStringByValue() {
	DoubleArrayList theKeys = new DoubleArrayList();
	keysSortedByValue(theKeys);

	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 #6
Source File: DoubleMatrix3D.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
Fills the coordinates and values of cells having non-zero values into the specified lists.
Fills into the lists, starting at index 0.
After this call returns the specified lists all have a new size, the number of non-zero values.
<p>
In general, fill order is <i>unspecified</i>.
This implementation fill like: <tt>for (slice = 0..slices-1) for (row = 0..rows-1) for (column = 0..colums-1) do ... </tt>.
However, subclasses are free to us any other order, even an order that may change over time as cell values are changed.
(Of course, result lists indexes are guaranteed to correspond to the same cell).
For an example, see {@link DoubleMatrix2D#getNonZeros(IntArrayList,IntArrayList,DoubleArrayList)}.

@param sliceList the list to be filled with slice indexes, can have any size.
@param rowList the list to be filled with row indexes, can have any size.
@param columnList the list to be filled with column indexes, can have any size.
@param valueList the list to be filled with values, can have any size.
*/
public void getNonZeros(IntArrayList sliceList, IntArrayList rowList, IntArrayList columnList, DoubleArrayList valueList) {
	sliceList.clear(); 
	rowList.clear(); 
	columnList.clear(); 
	valueList.clear();
	int s = slices;
	int r = rows;
	int c = columns;
	for (int slice=0; slice < s; slice++) {
		for (int row=0; row < r; row++) {
			for (int column=0; column < c; column++) {
				double value = getQuick(slice,row,column);
				if (value != 0) {
					sliceList.add(slice);
					rowList.add(row);
					columnList.add(column);
					valueList.add(value);
				}
			}
		}
	}
}
 
Example #7
Source File: Descriptive.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the covariance of two data sequences, which is 
 * <tt>cov(x,y) = (1/(size()-1)) * Sum((x[i]-mean(x)) * (y[i]-mean(y)))</tt>.
 * See the <A HREF="http://www.cquest.utoronto.ca/geog/ggr270y/notes/not05efg.html"> math definition</A>.
 */
public static double covariance(DoubleArrayList data1, DoubleArrayList data2) {
	int size = data1.size();
	if (size != data2.size() || size == 0) throw new IllegalArgumentException();
	double[] elements1 = data1.elements();
	double[] elements2 = data2.elements();
	
	double sumx=elements1[0], sumy=elements2[0], Sxy=0;
	for (int i=1; i<size; ++i) {
		double x = elements1[i];
		double y = elements2[i];
		sumx += x;
		Sxy += (x - sumx/(i+1))*(y - sumy/i);
		sumy += y;
		// Exercise for the reader: Why does this give us the right answer?
	}
	return Sxy/(size-1);
}
 
Example #8
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 #9
Source File: Descriptive.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Durbin-Watson computation.
 */
public static double durbinWatson(DoubleArrayList data) {
	int size = data.size();
	if (size < 2) throw new IllegalArgumentException("data sequence must contain at least two values.");

	double[] elements = data.elements();
	double run = 0;
	double run_sq = 0;
	run_sq = elements[0] * elements[0];
	for(int i=1; i<size; ++i) {
		double x = elements[i] - elements[i-1];
		run += x*x;
		run_sq += elements[i] * elements[i];
	}

	return run / run_sq;
}
 
Example #10
Source File: Descriptive.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the covariance of two data sequences, which is 
 * <tt>cov(x,y) = (1/(size()-1)) * Sum((x[i]-mean(x)) * (y[i]-mean(y)))</tt>.
 * See the <A HREF="http://www.cquest.utoronto.ca/geog/ggr270y/notes/not05efg.html"> math definition</A>.
 */
public static double covariance(DoubleArrayList data1, DoubleArrayList data2) {
	int size = data1.size();
	if (size != data2.size() || size == 0) throw new IllegalArgumentException();
	double[] elements1 = data1.elements();
	double[] elements2 = data2.elements();
	
	double sumx=elements1[0], sumy=elements2[0], Sxy=0;
	for (int i=1; i<size; ++i) {
		double x = elements1[i];
		double y = elements2[i];
		sumx += x;
		Sxy += (x - sumx/(i+1))*(y - sumy/i);
		sumy += y;
		// Exercise for the reader: Why does this give us the right answer?
	}
	return Sxy/(size-1);
}
 
Example #11
Source File: Benchmark.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Prints the first <tt>size</tt> random numbers generated by the distribution.
 */
public static void demo1() {
// Gamma distribution

// define distribution parameters
double mean = 5;
double variance = 1.5;
double alpha = mean*mean / variance; 
double lambda = 1 / (variance / mean); 

// for tests and debugging use a random engine with CONSTANT seed --> deterministic and reproducible results
cern.jet.random.engine.RandomEngine engine = new cern.jet.random.engine.MersenneTwister(); 

// your favourite distribution goes here
cern.jet.random.AbstractDistribution dist = new cern.jet.random.Gamma(alpha,lambda,engine);

// collect random numbers and print statistics
int size = 100000;
cern.colt.list.DoubleArrayList numbers = new cern.colt.list.DoubleArrayList(size);
for (int i=0; i < size; i++) numbers.add(dist.nextDouble());

hep.aida.bin.DynamicBin1D bin = new hep.aida.bin.DynamicBin1D();
bin.addAllOf(numbers);
System.out.println(bin);
}
 
Example #12
Source File: Descriptive.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the median of a sorted data sequence.
 *
 * @param sortedData the data sequence; <b>must be sorted ascending</b>.
 */
public static double median(DoubleArrayList sortedData) {
	return quantile(sortedData, 0.5);
	/*
	double[] sortedElements = sortedData.elements();
	int n = sortedData.size();
	int lhs = (n - 1) / 2 ;
	int rhs = n / 2 ;
  
	if (n == 0) return 0.0 ;

	double median;
	if (lhs == rhs) median = sortedElements[lhs] ;
	else median = (sortedElements[lhs] + sortedElements[rhs])/2.0 ;

	return median;
	*/
}
 
Example #13
Source File: Descriptive.java    From database with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the winsorized mean of a sorted data sequence.
 *
 * @param sortedData the data sequence; <b>must be sorted ascending</b>.
 * @param mean the mean of the (full) sorted data sequence.
 * @left the number of leading elements to trim.
 * @right the number of trailing elements to trim.
 */
public static double winsorizedMean(DoubleArrayList sortedData, double mean, int left, int right) {
	int N = sortedData.size();
	if (N==0) throw new IllegalArgumentException("Empty data.");
	if (left+right >= N) throw new IllegalArgumentException("Not enough data.");

	double[] sortedElements = sortedData.elements();

	double leftElement = sortedElements[left];
	for(int i=0; i<left; ++i)
		mean += (leftElement-sortedElements[i])/N;

	double rightElement = sortedElements[N-1-right];
	for(int i=0; i<right; ++i)
		mean += (rightElement-sortedElements[N-1-i])/N;

	return mean;
}
 
Example #14
Source File: Descriptive.java    From jAudioGIT with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Returns the <tt>phi-</tt>quantile; that is, an element <tt>elem</tt> for which holds that <tt>phi</tt> percent of data elements are less than <tt>elem</tt>.
 * The quantile need not necessarily be contained in the data sequence, it can be a linear interpolation.
 * @param sortedData the data sequence; <b>must be sorted ascending</b>.
 * @param phi the percentage; must satisfy <tt>0 &lt;= phi &lt;= 1</tt>.
 */
public static double quantile(DoubleArrayList sortedData, double phi) {
	double[] sortedElements = sortedData.elements();
	int n = sortedData.size();
	
	double index = phi * (n - 1) ;
	int lhs = (int)index ;
	double delta = index - lhs ;
	double result;

	if (n == 0) return 0.0 ;

	if (lhs == n - 1) {
		result = sortedElements[lhs] ;
	}
	else {
		result = (1 - delta) * sortedElements[lhs] + delta * sortedElements[lhs + 1] ;
	}

	return result ;
}
 
Example #15
Source File: Tools.java    From first-stories-twitter with MIT License 6 votes vote down vote up
/**
 * Computes the cosine similarity between a possible Neighbour (possibly smaller dimension vector) and a new
 * Tweet that arrives which might have a bigger vector.
 * @param possibleNeighbour The old tweet, usually located in bucket.
 * @param newTweet The new arriving tweet.
 * @return NearNeighbour The cosine similarity along with the possible neighbour
 */
public NearNeighbour computeCosineSimilarity(Tweet possibleNeighbour, Tweet newTweet) {
    SparseVector possibleNeighbourVect = possibleNeighbour.getSparseVector();
    SparseVector newTweetVect = newTweet.getSparseVector();
    IntArrayList nonZeroIndeces = new IntArrayList(possibleNeighbourVect.cardinality());
    DoubleArrayList dblZeroIndeces = new DoubleArrayList(possibleNeighbourVect.cardinality());
    possibleNeighbourVect.getNonZeros(nonZeroIndeces, dblZeroIndeces);
    double dotProductValue = newTweetVect.zDotProduct(possibleNeighbourVect, 0, possibleNeighbourVect.size(), nonZeroIndeces);

    //colt norm2 needs sqrt
    //here divide by zero will give NaN BUG if vectors are consisted ONLY of 0s !
    Double cosSim = new Double(dotProductValue / getNorm2(possibleNeighbourVect, newTweetVect));
    if (cosSim.isNaN()) {
        System.exit(1);
    }

    NearNeighbour nearN = new NearNeighbour(cosSim, possibleNeighbour);
    return nearN;

}
 
Example #16
Source File: QuantileFinderTest.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This method was created in VisualAge.
 * @return double[]
 * @param values cern.it.hepodbms.primitivearray.DoubleArrayList
 * @param phis double[]
 */
public static DoubleArrayList observedEpsilonsAtPhis(DoubleArrayList phis, ExactDoubleQuantileFinder exactFinder, DoubleQuantileFinder approxFinder, double desiredEpsilon) {
	DoubleArrayList epsilons = new DoubleArrayList(phis.size());
	
	for (int i=phis.size(); --i >=0;) {
		double epsilon = observedEpsilonAtPhi(phis.get(i), exactFinder, approxFinder);
		epsilons.add(epsilon);
		if (epsilon>desiredEpsilon) System.out.println("Real epsilon = "+epsilon+" is larger than desired by "+(epsilon-desiredEpsilon));
	}
	return epsilons;
}
 
Example #17
Source File: KnownDoubleQuantileEstimator.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 */
protected DoubleArrayList preProcessPhis(DoubleArrayList phis) {
	if (beta>1.0) {
		phis = phis.copy();
		for (int i=phis.size(); --i >=0;) {
			phis.set(i, (2*phis.get(i) + beta - 1) / (2*beta));
		}		
	}
	return phis;
}
 
Example #18
Source File: Descriptive.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static double covariance2(DoubleArrayList data1, DoubleArrayList data2) {
	int size = data1.size();
	double mean1 = Descriptive.mean(data1);
	double mean2 = Descriptive.mean(data2);
	double covariance = 0.0D;
	for (int i = 0; i < size; i++) {
		double x = data1.get(i);
		double y = data2.get(i);

		covariance += (x - mean1) * (y - mean2);
	}

	return covariance / (double) (size-1);
}
 
Example #19
Source File: AbstractIntDoubleMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Fills all values contained in the receiver into the specified list.
 * Fills the list, starting at index 0.
 * After this call returns the specified list has a new size that equals <tt>this.size()</tt>.
 * Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(IntProcedure)}.
 * <p>
 * This method can be used to iterate over the values of the receiver.
 *
 * @param list the list to be filled, can have any size.
 */
public void values(final DoubleArrayList list) {
	list.clear();
	forEachKey(
		new IntProcedure() {
			public boolean apply(int key) {
				list.add(get(key));
				return true;
			}
		}
	);
}
 
Example #20
Source File: OpenIntDoubleHashMap.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Fills all values contained in the receiver into the specified list.
 * Fills the list, starting at index 0.
 * After this call returns the specified list has a new size that equals <tt>this.size()</tt>.
 * Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(IntProcedure)}.
 * <p>
 * This method can be used to iterate over the values of the receiver.
 *
 * @param list the list to be filled, can have any size.
 */
public void values(DoubleArrayList list) {
	list.setSize(distinct);
	double[] elements = list.elements();
	
	double[] val = values;
	byte[] stat = state;
	
	int j=0;
	for (int i = stat.length ; i-- > 0 ;) {
		if (stat[i]==FULL) elements[j++]=val[i];
	}
}
 
Example #21
Source File: DistributionAggregateFunction.java    From arx with Apache License 2.0 5 votes vote down vote up
@Override
public <T> double getError(Distribution distribution) {
    
    if (!(type instanceof DataTypeWithRatioScale)) {
        return 0d;
    }
    
    @SuppressWarnings("unchecked")
    DataTypeWithRatioScale<T> rType = (DataTypeWithRatioScale<T>) this.type;
    DoubleArrayList list = new DoubleArrayList();
    Iterator<Double> it = DistributionIterator.createIteratorDouble(distribution, dictionary, rType);
    while (it.hasNext()) {
        Double value = it.next();
        value = value == null ? (ignoreMissingData ? null : 0d) : value;
        if (value != null) {
            list.add(value);
        }
    }
    
    // Determine and check mode
    int mode = getMode(distribution);
    if (mode == -1) {
        return 1d;
    }
    
    // Compute error
    return getNMSE(minimum, maximum, Arrays.copyOf(list.elements(), list.size()), 
                                     rType.toDouble(rType.parse(dictionary[mode])));
}
 
Example #22
Source File: QuantileFinderTest.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method was created in VisualAge.
 * @return double[]
 * @param values cern.it.hepodbms.primitivearray.DoubleArrayList
 * @param phis double[]
 */
public static DoubleArrayList observedEpsilonsAtPhis(DoubleArrayList phis, ExactDoubleQuantileFinder exactFinder, DoubleQuantileFinder approxFinder, double desiredEpsilon) {
	DoubleArrayList epsilons = new DoubleArrayList(phis.size());
	
	for (int i=phis.size(); --i >=0;) {
		double epsilon = observedEpsilonAtPhi(phis.get(i), exactFinder, approxFinder);
		epsilons.add(epsilon);
		if (epsilon>desiredEpsilon) System.out.println("Real epsilon = "+epsilon+" is larger than desired by "+(epsilon-desiredEpsilon));
	}
	return epsilons;
}
 
Example #23
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 #24
Source File: ExactDoubleQuantileFinder.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Computes the specified quantile elements over the values previously added.
 * @param phis the quantiles for which elements are to be computed. Each phi must be in the interval [0.0,1.0]. <tt>phis</tt> must be sorted ascending.
 * @return the exact quantile elements.
 */
public DoubleArrayList quantileElements(DoubleArrayList phis) {
	this.sort();
	return cern.jet.stat.Descriptive.quantiles(this.buffer, phis);
	/*
	int bufferSize = (int) this.size();
	double[] quantileElements = new double[phis.size()];
	for (int i=phis.size(); --i >=0;) {
		int rank=(int)Utils.epsilonCeiling(phis.get(i)*bufferSize) -1;
		quantileElements[i]=buffer.get(rank);
	}
	return new DoubleArrayList(quantileElements);
	*/
}
 
Example #25
Source File: Descriptive.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the trimmed mean of a sorted data sequence.
 *
 * @param sortedData the data sequence; <b>must be sorted ascending</b>.
 * @param mean the mean of the (full) sorted data sequence.
 * @left the number of leading elements to trim.
 * @right the number of trailing elements to trim.
 */
public static double trimmedMean(DoubleArrayList sortedData, double mean, int left, int right) {
	int N = sortedData.size();
	if (N==0) throw new IllegalArgumentException("Empty data.");
	if (left+right >= N) throw new IllegalArgumentException("Not enough data.");

	double[] sortedElements = sortedData.elements();
	int N0=N;
	for(int i=0; i<left; ++i)
		mean += (mean-sortedElements[i])/(--N);
	for(int i=0; i<right; ++i)
		mean += (mean-sortedElements[N0-1-i])/(--N);
	return mean;
}
 
Example #26
Source File: VectorBuilder.java    From first-stories-twitter with MIT License 5 votes vote down vote up
/**
 * Normalization by dividing with Euclid norm.
 * @param vector
 */
public SparseVector normalizeVector(SparseVector vector) {
    //NORMALIZE HERE with norm1 so a unit vector is produced
    IntArrayList indexes = new IntArrayList(vector.cardinality());
    DoubleArrayList dbls = new DoubleArrayList(vector.cardinality());
    double norm = vector.getEuclidNorm();
    vector.getNonZeros(indexes, dbls);
    for (int i = 0; i < indexes.size(); i++) {
        vector.setQuick(indexes.get(i), dbls.getQuick(i) / norm);
    }
    return vector;
}
 
Example #27
Source File: QuantileBin1D.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
Divides (rebins) a copy of the receiver at the given <i>interval boundaries</i> into bins and returns these bins, such that each bin <i>approximately</i> reflects the data elements of its range.

For each interval boundary of the axis (including -infinity and +infinity), computes the percentage (quantile inverse) of elements less than the boundary.
Then lets {@link #splitApproximately(DoubleArrayList,int)} do the real work.

@param axis an axis defining interval boundaries.
@param resolution a measure of accuracy; the desired number of subintervals per interval. 
*/
public synchronized MightyStaticBin1D[] splitApproximately(hep.aida.IAxis axis, int k) {
	DoubleArrayList percentages = new DoubleArrayList(new hep.aida.ref.Converter().edges(axis));
	percentages.beforeInsert(0,Double.NEGATIVE_INFINITY);
	percentages.add(Double.POSITIVE_INFINITY);
	for (int i=percentages.size(); --i >= 0; ) {
		percentages.set(i, quantileInverse(percentages.get(i)));
	}
	
	return splitApproximately(percentages,k); 
}
 
Example #28
Source File: Descriptive.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the mean deviation of a dataset.
 * That is <tt>Sum (Math.abs(data[i]-mean)) / data.size())</tt>.
 */
public static double meanDeviation(DoubleArrayList data, double mean) {
	double[] elements = data.elements();
	int size = data.size();
	double sum=0;
	for (int i=size; --i >= 0;) sum += Math.abs(elements[i]-mean);
	return sum/size;
}
 
Example #29
Source File: MightyStaticBin1D.java    From jAudioGIT with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the moment of <tt>k</tt>-th order with value <tt>c</tt>,
 * which is <tt>Sum( (x[i]-c)<sup>k</sup> ) / size()</tt>.
 *
 * @param k the order; must be greater than or equal to zero.
 * @param c any number.
 * @throws IllegalArgumentException if <tt>k < 0</tt>.
 * @return <tt>Double.NaN</tt> if <tt>!hasSumOfPower(k)</tt>.
 */
public synchronized double moment(int k, double c) {
	if (k<0) throw new IllegalArgumentException("k must be >= 0");
	//checkOrder(k);
	if (!hasSumOfPowers(k)) return Double.NaN;

	int maxOrder = Math.min(k,getMaxOrderForSumOfPowers());
	DoubleArrayList sumOfPows = new DoubleArrayList(maxOrder+1);
	sumOfPows.add(size());
	sumOfPows.add(sum());
	sumOfPows.add(sumOfSquares());
	for (int i=3; i<=maxOrder; i++) sumOfPows.add(sumOfPowers(i));
	
	return Descriptive.moment(k, c, size(), sumOfPows.elements());
}
 
Example #30
Source File: OpenDoubleIntHashMap.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fills all keys contained in the receiver into the specified list.
 * Fills the list, starting at index 0.
 * After this call returns the specified list has a new size that equals <tt>this.size()</tt>.
 * Iteration order is guaranteed to be <i>identical</i> to the order used by method {@link #forEachKey(DoubleProcedure)}.
 * <p>
 * This method can be used to iterate over the keys of the receiver.
 *
 * @param list the list to be filled, can have any size.
 */
public void keys(DoubleArrayList list) {
	list.setSize(distinct);
	double[] elements = list.elements();
	
	double[] tab = table;
	byte[] stat = state;
	
	int j=0;
	for (int i = tab.length ; i-- > 0 ;) {
		if (stat[i]==FULL) elements[j++]=tab[i];
	}
}