All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mikera.indexz.Indexz Maven / Gradle / Ivy

Go to download

Fast double-precision vector and matrix maths library for Java, supporting N-dimensional numeric arrays.

There is a newer version: 0.67.0
Show newest version
package mikera.indexz;

import java.util.ArrayList;
import java.util.List;

import mikera.util.Rand;

/**
 * Class for static index methods
 * 
 * @author Mike
 *
 */
public class Indexz {

	private Indexz(){}
	
	public static Index create(List data) {
		int length=data.size();
		Index result=new Index(length);
		for (int i=0; i0; j--) {
			result.swap(Rand.r(j+1), j);
		}
		return result;
	}
	
	public static Index createRandomChoice(int count, int max) {
		Index result=createSequence(count);
		Rand.chooseIntegers(result.data, 0, count, max);
		assert(result.isDistinct()&&result.isSorted());
		return result;
	}
	
	public static Index createRandomChoice(int count, Index source) {
		Index result=createSequence(count);
		Rand.chooseIntegers(result.data, 0, count, source.length());
		assert(result.isDistinct()&&result.isSorted());
		result.lookupWith(source);
		return result;
	}
	
	/**
	 * Returns a random subset of an Index, including each element with the given probability
	 * @param probability
	 * @return
	 */
	public static Index createRandomSubset(AIndex index, double probability) {
		int len=index.length();
		// estimated capacity required = 3 standard deviations
		int elen=(int)(len*probability+3.0*Math.sqrt(len*probability*(1-probability)));
		ArrayList al=new ArrayList(elen);
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy