List of usage examples for org.apache.commons.math.random RandomData nextInt
int nextInt(int lower, int upper);
lower
and upper
(endpoints included). From source file:com.sse.abtester.VariationAssigner.java
/** * Gets the next./* w ww . j a v a2 s . co m*/ * * @param wc the wc * @param generator the generator * @return the next */ protected IVariant<VariantBean> getNext(ArrayList<IVariant<VariantBean>> wc, RandomData generator) { if (wc == null || wc.size() == 0) return null; int random = generator.nextInt(0, wc.size() - 1); return wc.get(random); }
From source file:de.mpicbg.knime.hcs.base.utils.MutualInformation.java
private Double[] bootstrap(Double[] v, int Nboot) { Double[] boot = new Double[Nboot]; int I;/*from w w w .j a v a2s .c o m*/ int maxI = v.length - 1; RandomData rand = new RandomDataImpl(); for (int r = 0; r < Nboot; ++r) { I = rand.nextInt(0, maxI); boot[r] = v[I]; } return boot; }
From source file:br.upe.ecomp.doss.algorithm.chargedpso.ChargedPSO.java
private void chargeParticles(ChargedPSOParticle[] particles, double chargedParticlesLenght) { RandomData random = new RandomDataImpl(); List<Integer> indexes = new ArrayList<Integer>(); for (int i = 0; i < particles.length; i++) { indexes.add(i);//from w ww . ja v a 2s . c o m } int index; int randomNumber; for (int i = 0; i < chargedParticlesLenght; i++) { randomNumber = random.nextInt(0, indexes.size() - 1); index = indexes.remove(randomNumber); particles[index].setCharge(particleCharge); } }
From source file:br.upe.ecomp.doss.algorithm.apso.APSO.java
protected void doElitistLearningStrategy() { RandomData random = new RandomDataImpl(); APSOParticle[] particles = (APSOParticle[]) getParticles(); List<APSOParticle> apsoParticles = Arrays.asList(particles); APSOParticle bestParticle = Collections.max(apsoParticles, new ComparatorMaximumFitness()); // Dimension that can be changed if the best particle fitness improves after the change int dimensionChange = random.nextInt(0, getProblem().getDimensionsNumber() - 1); double[] currentBestPosition = bestParticle.getBestPosition(); // Standard Deviation of the Gaussian Distribution // TODO usar esse decaimento linear pode ser ruim para ambientes dinamicos double learningElitistRate = sigmaMax - (sigmaMax - sigmaMin) * (this.getIterations() / getMaxIterations()); // Changes position in only one dimension // if(EnumEvolutionaryState.CONVERGENCE) TODO testar com e sem esta condicao double newDimensionPosition = currentBestPosition[dimensionChange] + (getProblem().getUpperBound(dimensionChange) - getProblem().getLowerBound(dimensionChange)) * random.nextGaussian(0, learningElitistRate); // TODO verificar se nao extrapolou o limite do espaco de busca double[] newPosition = currentBestPosition.clone(); newPosition[dimensionChange] = newDimensionPosition; double currentBestFitness = bestParticle.getBestFitness(); double newFitness = getProblem().getFitness(newPosition); // If the change improves the fitness then update the best particle with the new position, // else update the worst particle with the new position. if (getProblem().isFitnessBetterThan(currentBestFitness, newFitness)) { bestParticle.updateBestPosition(newPosition.clone(), newFitness); bestParticle.updateCurrentPosition(newPosition.clone(), newFitness); } else {//from www.j ava2 s . c om PSOParticle worstParticle = Collections.min(apsoParticles, new ComparatorMaximumFitness()); worstParticle.updateCurrentPosition(newPosition.clone(), newFitness); worstParticle.updatePBest(getProblem()); } calculateGBest(bestParticle); }
From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java
@Override public void visit(State state, Environment env, Properties props) throws Exception { // reset any previous setting Object lastSetting = state.getOkIfAbsent(LAST_SETTING); if (lastSetting != null) { int choice = Integer.parseInt(lastSetting.toString()); Property property = settings[choice].property; log.debug("Setting " + property.getKey() + " back to " + property.getDefaultValue()); env.getConnector().instanceOperations().setProperty(property.getKey(), property.getDefaultValue()); }//from w ww . j ava 2 s .c o m lastSetting = state.getOkIfAbsent(LAST_TABLE_SETTING); if (lastSetting != null) { String parts[] = lastSetting.toString().split(","); String table = parts[0]; int choice = Integer.parseInt(parts[1]); Property property = tableSettings[choice].property; if (env.getConnector().tableOperations().exists(table)) { log.debug( "Setting " + property.getKey() + " on " + table + " back to " + property.getDefaultValue()); try { env.getConnector().tableOperations().setProperty(table, property.getKey(), property.getDefaultValue()); } catch (AccumuloException ex) { if (ex.getCause() instanceof ThriftTableOperationException) { ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause(); if (ttoe.type == TableOperationExceptionType.NOTFOUND) return; } throw ex; } } } lastSetting = state.getOkIfAbsent(LAST_NAMESPACE_SETTING); if (lastSetting != null) { String parts[] = lastSetting.toString().split(","); String namespace = parts[0]; int choice = Integer.parseInt(parts[1]); Property property = tableSettings[choice].property; if (env.getConnector().namespaceOperations().exists(namespace)) { log.debug("Setting " + property.getKey() + " on " + namespace + " back to " + property.getDefaultValue()); try { env.getConnector().namespaceOperations().setProperty(namespace, property.getKey(), property.getDefaultValue()); } catch (AccumuloException ex) { if (ex.getCause() instanceof ThriftTableOperationException) { ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause(); if (ttoe.type == TableOperationExceptionType.NAMESPACE_NOTFOUND) return; } throw ex; } } } state.remove(LAST_SETTING); state.remove(LAST_TABLE_SETTING); state.remove(LAST_NAMESPACE_SETTING); RandomData random = new RandomDataImpl(); int dice = random.nextInt(0, 2); if (dice == 0) { changeTableSetting(random, state, env, props); } else if (dice == 1) { changeNamespaceSetting(random, state, env, props); } else { changeSetting(random, state, env, props); } }
From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java
private void changeTableSetting(RandomData random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, tableSettings.length - 1); Setting setting = tableSettings[choice]; // pick a random table SortedSet<String> tables = env.getConnector().tableOperations().list().tailSet("ctt").headSet("ctu"); if (tables.isEmpty()) return;// ww w . j av a2s.c o m String table = random.nextSample(tables, 1)[0].toString(); // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_TABLE_SETTING, table + "," + choice); log.debug("Setting " + setting.property.getKey() + " on table " + table + " to " + newValue); try { env.getConnector().tableOperations().setProperty(table, setting.property.getKey(), "" + newValue); } catch (AccumuloException ex) { if (ex.getCause() instanceof ThriftTableOperationException) { ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause(); if (ttoe.type == TableOperationExceptionType.NOTFOUND) return; } throw ex; } }
From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java
private void changeNamespaceSetting(RandomData random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, tableSettings.length - 1); Setting setting = tableSettings[choice]; // pick a random table SortedSet<String> namespaces = env.getConnector().namespaceOperations().list().tailSet("nspc") .headSet("nspd"); if (namespaces.isEmpty()) return;/* w w w . j a v a 2 s . c o m*/ String namespace = random.nextSample(namespaces, 1)[0].toString(); // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_NAMESPACE_SETTING, namespace + "," + choice); log.debug("Setting " + setting.property.getKey() + " on namespace " + namespace + " to " + newValue); try { env.getConnector().namespaceOperations().setProperty(namespace, setting.property.getKey(), "" + newValue); } catch (AccumuloException ex) { if (ex.getCause() instanceof ThriftTableOperationException) { ThriftTableOperationException ttoe = (ThriftTableOperationException) ex.getCause(); if (ttoe.type == TableOperationExceptionType.NAMESPACE_NOTFOUND) return; } throw ex; } }
From source file:org.apache.accumulo.test.randomwalk.concurrent.Config.java
private void changeSetting(RandomData random, State state, Environment env, Properties props) throws Exception { // pick a random property int choice = random.nextInt(0, settings.length - 1); Setting setting = settings[choice];//from w ww . j a v a2 s . c o m // generate a random value long newValue = random.nextLong(setting.min, setting.max); state.set(LAST_SETTING, "" + choice); log.debug("Setting " + setting.property.getKey() + " to " + newValue); env.getConnector().instanceOperations().setProperty(setting.property.getKey(), "" + newValue); }