org.apache.commons.math3.random.RandomAdaptor Java Examples
The following examples show how to use
org.apache.commons.math3.random.RandomAdaptor.
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: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeCircles(int samples, boolean shuffle, double noise, double factor, final RandomGenerator random) { if (factor < 0 || factor > 1) { throw new IllegalArgumentException(); } NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); List<Vector2D> points = new ArrayList<Vector2D>(); double range = 2.0 * FastMath.PI; double step = range / (samples / 2.0 + 1); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); Vector2D innerCircle = outerCircle.scalarMultiply(factor); points.add(outerCircle.add(generateNoiseVector(dist))); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #2
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeMoons(int samples, boolean shuffle, double noise, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); int nSamplesOut = samples / 2; int nSamplesIn = samples - nSamplesOut; List<Vector2D> points = new ArrayList<Vector2D>(); double range = FastMath.PI; double step = range / (nSamplesOut / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); points.add(outerCircle.add(generateNoiseVector(dist))); } step = range / (nSamplesIn / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D innerCircle = new Vector2D(1 - FastMath.cos(angle), 1 - FastMath.sin(angle) - 0.5); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #3
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeCircles(int samples, boolean shuffle, double noise, double factor, final RandomGenerator random) { if (factor < 0 || factor > 1) { throw new IllegalArgumentException(); } NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); List<Vector2D> points = new ArrayList<Vector2D>(); double range = 2.0 * FastMath.PI; double step = range / (samples / 2.0 + 1); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); Vector2D innerCircle = outerCircle.scalarMultiply(factor); points.add(outerCircle.add(generateNoiseVector(dist))); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #4
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeMoons(int samples, boolean shuffle, double noise, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); int nSamplesOut = samples / 2; int nSamplesIn = samples - nSamplesOut; List<Vector2D> points = new ArrayList<Vector2D>(); double range = FastMath.PI; double step = range / (nSamplesOut / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); points.add(outerCircle.add(generateNoiseVector(dist))); } step = range / (nSamplesIn / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D innerCircle = new Vector2D(1 - FastMath.cos(angle), 1 - FastMath.sin(angle) - 0.5); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #5
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeCircles(int samples, boolean shuffle, double noise, double factor, final RandomGenerator random) { if (factor < 0 || factor > 1) { throw new IllegalArgumentException(); } NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); List<Vector2D> points = new ArrayList<Vector2D>(); double range = 2.0 * FastMath.PI; double step = range / (samples / 2.0 + 1); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); Vector2D innerCircle = outerCircle.scalarMultiply(factor); points.add(outerCircle.add(generateNoiseVector(dist))); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #6
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeMoons(int samples, boolean shuffle, double noise, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); int nSamplesOut = samples / 2; int nSamplesIn = samples - nSamplesOut; List<Vector2D> points = new ArrayList<Vector2D>(); double range = FastMath.PI; double step = range / (nSamplesOut / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); points.add(outerCircle.add(generateNoiseVector(dist))); } step = range / (nSamplesIn / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D innerCircle = new Vector2D(1 - FastMath.cos(angle), 1 - FastMath.sin(angle) - 0.5); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #7
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeCircles(int samples, boolean shuffle, double noise, double factor, final RandomGenerator random) { if (factor < 0 || factor > 1) { throw new IllegalArgumentException(); } NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); List<Vector2D> points = new ArrayList<Vector2D>(); double range = 2.0 * FastMath.PI; double step = range / (samples / 2.0 + 1); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); Vector2D innerCircle = outerCircle.scalarMultiply(factor); points.add(outerCircle.add(generateNoiseVector(dist))); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #8
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 6 votes |
public static List<Vector2D> makeMoons(int samples, boolean shuffle, double noise, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, noise, 1e-9); int nSamplesOut = samples / 2; int nSamplesIn = samples - nSamplesOut; List<Vector2D> points = new ArrayList<Vector2D>(); double range = FastMath.PI; double step = range / (nSamplesOut / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D outerCircle = new Vector2D(FastMath.cos(angle), FastMath.sin(angle)); points.add(outerCircle.add(generateNoiseVector(dist))); } step = range / (nSamplesIn / 2.0); for (double angle = 0; angle < range; angle += step) { Vector2D innerCircle = new Vector2D(1 - FastMath.cos(angle), 1 - FastMath.sin(angle) - 0.5); points.add(innerCircle.add(generateNoiseVector(dist))); } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #9
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 5 votes |
public static List<Vector2D> makeBlobs(int samples, int centers, double clusterStd, double min, double max, boolean shuffle, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, clusterStd, 1e-9); double range = max - min; Vector2D[] centerPoints = new Vector2D[centers]; for (int i = 0; i < centers; i++) { double x = random.nextDouble() * range + min; double y = random.nextDouble() * range + min; centerPoints[i] = new Vector2D(x, y); } int[] nSamplesPerCenter = new int[centers]; int count = samples / centers; Arrays.fill(nSamplesPerCenter, count); for (int i = 0; i < samples % centers; i++) { nSamplesPerCenter[i]++; } List<Vector2D> points = new ArrayList<Vector2D>(); for (int i = 0; i < centers; i++) { for (int j = 0; j < nSamplesPerCenter[i]; j++) { Vector2D point = new Vector2D(dist.sample(), dist.sample()); points.add(point.add(centerPoints[i])); } } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #10
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 5 votes |
public static List<Vector2D> makeBlobs(int samples, int centers, double clusterStd, double min, double max, boolean shuffle, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, clusterStd, 1e-9); double range = max - min; Vector2D[] centerPoints = new Vector2D[centers]; for (int i = 0; i < centers; i++) { double x = random.nextDouble() * range + min; double y = random.nextDouble() * range + min; centerPoints[i] = new Vector2D(x, y); } int[] nSamplesPerCenter = new int[centers]; int count = samples / centers; Arrays.fill(nSamplesPerCenter, count); for (int i = 0; i < samples % centers; i++) { nSamplesPerCenter[i]++; } List<Vector2D> points = new ArrayList<Vector2D>(); for (int i = 0; i < centers; i++) { for (int j = 0; j < nSamplesPerCenter[i]; j++) { Vector2D point = new Vector2D(dist.sample(), dist.sample()); points.add(point.add(centerPoints[i])); } } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #11
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 5 votes |
public static List<Vector2D> makeBlobs(int samples, int centers, double clusterStd, double min, double max, boolean shuffle, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, clusterStd, 1e-9); double range = max - min; Vector2D[] centerPoints = new Vector2D[centers]; for (int i = 0; i < centers; i++) { double x = random.nextDouble() * range + min; double y = random.nextDouble() * range + min; centerPoints[i] = new Vector2D(x, y); } int[] nSamplesPerCenter = new int[centers]; int count = samples / centers; Arrays.fill(nSamplesPerCenter, count); for (int i = 0; i < samples % centers; i++) { nSamplesPerCenter[i]++; } List<Vector2D> points = new ArrayList<Vector2D>(); for (int i = 0; i < centers; i++) { for (int j = 0; j < nSamplesPerCenter[i]; j++) { Vector2D point = new Vector2D(dist.sample(), dist.sample()); points.add(point.add(centerPoints[i])); } } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #12
Source File: ClusterAlgorithmComparison.java From astor with GNU General Public License v2.0 | 5 votes |
public static List<Vector2D> makeBlobs(int samples, int centers, double clusterStd, double min, double max, boolean shuffle, RandomGenerator random) { NormalDistribution dist = new NormalDistribution(random, 0.0, clusterStd, 1e-9); double range = max - min; Vector2D[] centerPoints = new Vector2D[centers]; for (int i = 0; i < centers; i++) { double x = random.nextDouble() * range + min; double y = random.nextDouble() * range + min; centerPoints[i] = new Vector2D(x, y); } int[] nSamplesPerCenter = new int[centers]; int count = samples / centers; Arrays.fill(nSamplesPerCenter, count); for (int i = 0; i < samples % centers; i++) { nSamplesPerCenter[i]++; } List<Vector2D> points = new ArrayList<Vector2D>(); for (int i = 0; i < centers; i++) { for (int j = 0; j < nSamplesPerCenter[i]; j++) { Vector2D point = new Vector2D(dist.sample(), dist.sample()); points.add(point.add(centerPoints[i])); } } if (shuffle) { Collections.shuffle(points, new RandomAdaptor(random)); } return points; }
Example #13
Source File: GridSearchCandidateGenerator.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Override protected void initialize() { super.initialize(); List<ParameterSpace> leaves = LeafUtils.getUniqueObjects(parameterSpace.collectLeaves()); int nParams = leaves.size(); //Work out for each parameter: is it continuous or discrete? // for grid search: discrete values are grid-searchable as-is // continuous values: discretize using 'discretizationCount' bins // integer values: use min(max-min+1, discretizationCount) values. i.e., discretize if necessary numValuesPerParam = new int[nParams]; long searchSize = 1; for (int i = 0; i < nParams; i++) { ParameterSpace ps = leaves.get(i); if (ps instanceof DiscreteParameterSpace) { DiscreteParameterSpace dps = (DiscreteParameterSpace) ps; numValuesPerParam[i] = dps.numValues(); } else if (ps instanceof IntegerParameterSpace) { IntegerParameterSpace ips = (IntegerParameterSpace) ps; int min = ips.getMin(); int max = ips.getMax(); //Discretize, as some integer ranges are much too large to search (i.e., num. neural network units, between 100 and 1000) numValuesPerParam[i] = Math.min(max - min + 1, discretizationCount); } else if (ps instanceof FixedValue){ numValuesPerParam[i] = 1; } else { numValuesPerParam[i] = discretizationCount; } searchSize *= numValuesPerParam[i]; } if (searchSize >= Integer.MAX_VALUE) throw new IllegalStateException("Invalid search: cannot process search with " + searchSize + " candidates > Integer.MAX_VALUE"); //TODO find a more reasonable upper bound? order = new ConcurrentLinkedQueue<>(); totalNumCandidates = (int) searchSize; switch (mode) { case Sequential: for (int i = 0; i < totalNumCandidates; i++) { order.add(i); } break; case RandomOrder: List<Integer> tempList = new ArrayList<>(totalNumCandidates); for (int i = 0; i < totalNumCandidates; i++) { tempList.add(i); } Collections.shuffle(tempList, new RandomAdaptor(rng)); order.addAll(tempList); break; default: throw new RuntimeException(); } }