List of usage examples for org.apache.commons.math.random JDKRandomGenerator JDKRandomGenerator
JDKRandomGenerator
From source file:com.tomgibara.cluster.CreateGaussianMouse.java
public static void main(String[] args) throws IOException { GaussianRandomGenerator gen = new GaussianRandomGenerator(new JDKRandomGenerator()); FileWriter writer = new FileWriter("R/gmouse.txt"); try {/*from ww w. j a v a 2 s . c om*/ writeCluster(gen, new double[] { 0, 0 }, new double[] { 4, 4 }, 100, writer); writeCluster(gen, new double[] { -4, 4 }, new double[] { 2, 2 }, 50, writer); writeCluster(gen, new double[] { 4, 4 }, new double[] { 2, 2 }, 50, writer); } finally { writer.close(); } }
From source file:com.tomgibara.cluster.CreateGaussianCross.java
public static void main(String[] args) throws IOException { GaussianRandomGenerator gen = new GaussianRandomGenerator(new JDKRandomGenerator()); final double[] center = new double[] { 0, 0 }; int clusterSize = 300; FileWriter writer = new FileWriter("R/cross.txt"); try {//from w ww . java2s .c o m writeCluster(gen, center, new double[] { 6, 1 }, clusterSize, writer); writeCluster(gen, center, new double[] { 1, 6 }, clusterSize, writer); } finally { writer.close(); } }
From source file:com.tomgibara.cluster.CreateUniformMouse.java
public static void main(String[] args) throws IOException { UniformRandomGenerator gen = new UniformRandomGenerator(new JDKRandomGenerator()); FileWriter writer = new FileWriter("R/umouse.txt"); try {/* w ww .jav a 2s .c o m*/ writeCluster(gen, new double[] { 0, 0 }, new double[] { 4, 4 }, 300, writer); writeCluster(gen, new double[] { -4, 4 }, new double[] { 2, 2 }, 100, writer); writeCluster(gen, new double[] { 4, 4 }, new double[] { 2, 2 }, 100, writer); } finally { writer.close(); } }
From source file:com.tomgibara.cluster.CreateUniformCircles.java
public static void main(String[] args) throws IOException { UniformRandomGenerator gen = new UniformRandomGenerator(new JDKRandomGenerator()); FileWriter writer = new FileWriter("R/circles.txt"); int size = 400; try {/* ww w . java2s . c o m*/ for (int y = 4; y >= -4; y--) { for (int x = -4; x <= 4; x++) { writeCluster(gen, new double[] { x, y }, new double[] { 0.3, 0.3 }, size, writer); } } } finally { writer.close(); } }
From source file:datafu.pig.hash.lsh.interfaces.LSHCreator.java
public RandomGenerator createGenerator() { RandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(seed); return rg; }
From source file:lfsom.visualization.clustering.LFSKMeans.java
/** * Calculate random centroids for each cluster. */// w w w . j av a2s .c o m private void initClustersRandomly() { RandomGenerator rg = new JDKRandomGenerator(); // FIXME: this is for testing purposes only rg.setSeed(RANDOM_SEED); // for each cluster for (int clusterIndex = 0; clusterIndex < k; clusterIndex++) { // for each of its attributes double[] centroid = new double[numberOfAttributes]; for (int attributeIndex = 0; attributeIndex < numberOfAttributes; attributeIndex++) { centroid[attributeIndex] = differences[attributeIndex] * rg.nextDouble() + minValues[attributeIndex]; } clusters[clusterIndex] = new LFSCluster(centroid); } System.out.println("initial centroids: "); // printCentroids(); }
From source file:lfsom.visualization.clustering.LFSKMeans.java
/** * cluster centres are initialised by equally sized random chunks of the * input data when there's 150 instances, we assign 50 chosen randomly to * each cluster and calculate its centre from these (the last cluster might * be larger if numInstances mod k < 0) *//*from w w w. j a v a 2 s .c om*/ private void initClustersEqualNumbers() { HashSet<Integer> usedIndices = new HashSet<Integer>(); int limit = numberOfInstances / k; // FIXME: Test clustering with new permutation generator! // int[] randPermIndices = RandomTools.permutation(new // Random(RANDOM_SEED), this.numberOfInstances); JDKRandomGenerator rg = new JDKRandomGenerator(); rg.setSeed(RANDOM_SEED); int[] randPermIndices = new RandomDataImpl(rg).nextPermutation(this.numberOfInstances, this.numberOfInstances); for (int clusterIndex = 0; clusterIndex < k; clusterIndex++) { LFSCluster c = new LFSCluster(new double[data[0].length]); // System.out.println("cluster: " + clusterIndex); for (int randPermIndice : randPermIndices) { int currentIndex = randPermIndice; if ((c.getNumberOfInstances() < limit || clusterIndex == k - 1) && !usedIndices.contains(currentIndex)) { c.addIndex(currentIndex); usedIndices.add(currentIndex); // System.out.print(" " + currentIndex); } } // System.out.println(); c.calculateCentroid(data); // clusters[clusterIndex] = c; clusters[clusterIndex] = new LFSCluster(c.getCentroid()); } }
From source file:lfsom.visualization.clustering.LFSKMeans.java
/** Take random points from the input data as centroids. */ private void initClustersRandomlyOnInstances() { ArrayList<double[]> usedInstances = new ArrayList<double[]>(); RandomGenerator rg = new JDKRandomGenerator(); // FIXME: this is for testing purposes only rg.setSeed(RANDOM_SEED);/* w w w. ja v a 2 s . c o m*/ // for each cluster for (int clusterIndex = 0; clusterIndex < k; clusterIndex++) { // draw a random input double[] centroid = data[rg.nextInt(data.length - 1)].clone(); while (usedInstances.contains(centroid)) { centroid = data[rg.nextInt(data.length - 1)].clone(); } usedInstances.add(centroid); clusters[clusterIndex] = new LFSCluster(centroid); } }
From source file:org.dishevelled.analysis.GraphGenerators.java
/** * Connect the specified graph randomly with the specified value on all added edges. * * @param <N> graph node type//from ww w . ja v a 2 s. co m * @param <E> graph edge type * @param graph graph to connect, must not be null * @param edgeCount edge count, must be at least zero * @param edgeValues edge values, must not be null * @return the specified graph connected randomly with the specified value on all added edges */ public static <N, E> Graph<N, E> connectRandomly(final Graph<N, E> graph, final int edgeCount, final BinaryFunction<N, N, E> edgeValues) { return connectRandomly(graph, edgeCount, edgeValues, new JDKRandomGenerator()); }
From source file:org.dishevelled.analysis.GraphGenerators.java
/** * Create and return a new randomly connected graph with the specified nodes values * on nodes and values provided by the specified function on edges. * * @param <N> graph node type//w w w. j a va 2s . co m * @param <E> graph edge type * @param nodeValues list of node values, must not be null * @param edgeCount edge count, must be at least zero * @param edgeValues edge values, must not be null * @return a new randomly connected graph with the specified nodes values * on nodes and the specified edge value on all added edges */ public static <N, E> Graph<N, E> connectRandomly(final List<N> nodeValues, final int edgeCount, final BinaryFunction<N, N, E> edgeValues) { return connectRandomly(nodeValues, edgeCount, edgeValues, new JDKRandomGenerator()); }