List of usage examples for java.util Collections shuffle
public static void shuffle(List<?> list)
From source file:br.msf.commons.util.CollectionUtils.java
public static void shuffle(final List<?> list) { Collections.shuffle(list); }
From source file:clummy.classes.DataHandlingClass.java
/** * get the total generated data for list in names files. * @return /* w w w.j ava 2s .c om*/ */ public static int getTotalPossibility() { List<String> listNames = new ArrayList<>(); ; ICombinatoricsVector<String> initialVector = Factory.createVector(readFile(AllFileList.NAMELIST)); // Create a simple combination generator to generate 3-combinations of the initial vector Generator<String> gen = Factory.createSimpleCombinationGenerator(initialVector, 2); // Print all possible combinations in vector for (ICombinatoricsVector<String> combination : gen) { //transfer vector to list and trim unessacry characters listNames.add( combination.getVector().toString().replace(",", "").replace("[", "").replace("]", "").trim()); } //shuffle the list Collections.shuffle(listNames); return listNames.size(); }
From source file:edu.cmu.tetrad.data.DataUtils.java
/** * Returns a new data sets, copying the given on but with the columns shuffled. * * @param dataSet The data set to shuffle. * @return Ibid.//from w w w .j av a 2 s. c o m */ public static DataSet shuffleColumns(DataSet dataSet) { int numVariables; numVariables = dataSet.getNumColumns(); List<Integer> indicesList = new ArrayList<Integer>(); for (int i = 0; i < numVariables; i++) indicesList.add(i); Collections.shuffle(indicesList); int[] indices = new int[numVariables]; for (int i = 0; i < numVariables; i++) { indices[i] = indicesList.get(i); } return dataSet.subsetColumns(indices); }
From source file:com.example.testtab.fragment.TwitEyesPageFragment.java
public synchronized void endIdsXML(IdsFileIO status, String resMessage, final List<CIds> messageList) { boolean isContinue = true; switch (status) { case InterruptError: toastFormThread(Table.ERROR_INTERRUPTED + " while searching friends."); isContinue = false;/* w w w . j a v a2 s .com*/ break; case HttpCodeError: if (resMessage.equalsIgnoreCase("not found")) { toastFormThread( Table.ERROR_IDS_NOT_FOUND + " while searching friends. Http Response: " + resMessage); } else { toastFormThread(Table.ERROR_HTTP_CODE + " while searching friends. Http Response: " + resMessage); } isContinue = false; break; case FileMalformedError: toastFormThread(Table.ERROR_MALFORMED_URL + " while searching friends."); isContinue = false; break; case FileStateError: toastFormThread(Table.ERROR_ILLEGAL_STATE + " while searching friends."); isContinue = false; break; case ClientProtocolError: toastFormThread(Table.ERROR_CLIENT_PROTOCOL + " while searching friends."); isContinue = false; break; case FileIOError: toastFormThread(Table.ERROR_IO + " while searching friends."); isContinue = false; break; case FileSAXError: toastFormThread(Table.ERROR_SAX + " while searching friends."); isContinue = false; break; case FileCloserror: toastFormThread(Table.ERROR_FILE_CLOSE + " while searching friends."); isContinue = false; } if (isContinue) { if (messageList == null) { toastFormThread(Table.ERROR_IDS_NULL + " (null)"); isContinue = false; } if (messageList.size() <= 0) { toastFormThread(Table.ERROR_IDS_NULL + " (0 friend)"); isContinue = false; } } if (!isContinue) { // ENABLE OPTION this.isRunnable = true; // RESET LAST KICKED TIME this.lastKickedTime = 0; return; } // SHUFFLE Collections.shuffle(messageList); this.idsLimit = messageList.size(); if (this.idsLimit > MAX_IDS) this.idsLimit = MAX_IDS; // KICK UTL REQUEST for (int i = 0; i < this.idsLimit; i++) { String id = messageList.get(i).getId(); // OFTEN ERROR ?id="+id+"&count=2" // NO IMG URL ?trim_user=true&id="+id // HUGE BUT NO ERROR ?id="+id String dstUrl; if (MODE_PROD) { // PROD if (this.isSecure) dstUrl = "https://api.twitter.com/1/statuses/user_timeline.xml?user_id=" + id + "&count=1"; else dstUrl = "http://api.twitter.com/1/statuses/user_timeline.xml?user_id=" + id + "&count=1"; } else { // DEMO if (this.isSecure) dstUrl = "https://watasama.com/twiteyes/statuses/user_timeline" + i + ".xml"; else dstUrl = "http://watasama.com/twiteyes/statuses/user_timeline" + i + ".xml"; } CUserTimelineXmlRH utlXml = new CUserTimelineXmlRH(this, dstUrl, i, id); utlXml.start(); } }
From source file:com.lineage.server.model.L1Inventory.java
/** * */ public void shuffle() { Collections.shuffle(this._items); }
From source file:edu.cmu.tetrad.search.IndTestMultiFisherZ2.java
private List<Double> getCutoff2(List<Node> aa, List<Node> bb, List<Node> cc) { Node x = new ContinuousVariable("X"); Node y = new ContinuousVariable("Y"); Node z = new ContinuousVariable("Z"); List<Node> all = new ArrayList<Node>(); for (int i = 0; i < aa.size() + bb.size() + cc.size(); i++) { all.add(new ContinuousVariable("X" + i)); }// www . j a v a 2 s .c om Graph graph = new EdgeListGraph(all); SemPm pm = new SemPm(graph); SemIm im = new SemIm(pm); for (int i = 0; i < aa.size() + bb.size() + cc.size(); i++) { double var = this.cov.getValue(i, i); Node semNode = all.get(i); im.setErrCovar(semNode, var); } DataSet data = im.simulateData(cov.getSampleSize(), false); CovarianceMatrix cov = new CovarianceMatrix(data); double[] k_ = new double[5]; for (int c = 0; c < 5; c++) { List<Integer> indices = new ArrayList<Integer>(); for (int j = 0; j < cov.getDimension(); j++) { indices.add(j); } Collections.shuffle(indices); Map<Node, List<Node>> nodeMap = new HashMap<Node, List<Node>>(); List<Node> _nodes = cov.getVariables(); int _count = 0; List<Node> nx = new ArrayList<Node>(); for (int k = 0; k < aa.size(); k++) { nx.add(_nodes.get(indices.get(_count++))); } nodeMap.put(x, nx); List<Node> ny = new ArrayList<Node>(); for (int k = 0; k < bb.size(); k++) { ny.add(_nodes.get(indices.get(_count++))); } nodeMap.put(y, ny); List<Node> nz = new ArrayList<Node>(); for (int k = 0; k < cc.size(); k++) { nz.add(_nodes.get(indices.get(_count++))); } nodeMap.put(z, nz); TetradMatrix submatrix = subMatrix(cov, nx, ny, nz); TetradMatrix inverse; int rank; try { inverse = submatrix.inverse(); rank = inverse.columns(); } catch (Exception e) { System.out.println("Couldn't invert " + submatrix.columns()); throw new IllegalArgumentException(); } List<Double> pValues = new ArrayList<Double>(); for (int i = 0; i < nx.size(); i++) { for (int m = 0; m < ny.size(); m++) { int j = nx.size() + m; double a = -1.0 * inverse.get(i, j); double v0 = inverse.get(i, i); double v1 = inverse.get(j, j); double b = Math.sqrt(v0 * v1); double r = a / b; int dof = cov.getSampleSize() - 1 - rank; if (dof < 0) { System.out.println("Negative dof: " + dof + " n = " + cov.getSampleSize() + " cols = " + inverse.columns()); dof = 0; } double _z = Math.sqrt(dof) * 0.5 * (Math.log(1.0 + r) - Math.log(1.0 - r)); double p = 2.0 * (1.0 - RandomUtil.getInstance().normalCdf(0, 1, abs(_z))); pValues.add(p); } } int k = 0; for (double p : pValues) { if (p < alpha) k++; } k_[c] = k; } double mean = StatUtils.mean(k_); double sd = StatUtils.sd(k_); List<Double> ret = new ArrayList<Double>(); ret.add(mean); ret.add(sd); return ret; }
From source file:mp.teardrop.SongTimeline.java
/** * Randomly reorder the songs in the queue. The current song will always be the first. *//* w w w .j av a2s. c o m*/ public void randomlyReorderQueue(Callback callback) { synchronized (this) { ArrayList<Song> randomizeThis = new ArrayList<Song>(); if (mCurrentPos + 1 < mSongs.size()) { randomizeThis.addAll(mSongs.subList(mCurrentPos + 1, mSongs.size())); mSongs.subList(mCurrentPos + 1, mSongs.size()).clear(); } randomizeThis.addAll(mSongs.subList(0, mCurrentPos)); mSongs.subList(0, mCurrentPos).clear(); Collections.shuffle(randomizeThis); mSongs.addAll(randomizeThis); mCurrentPos = 0; } if (mCallback != null) { mCallback.activeSongReplaced(+1, getSong(+1)); mCallback.positionInfoChanged(); } ((FullPlaybackActivity) callback).timelineShuffled(); }
From source file:edu.pitt.csb.stability.StabilitySearch.java
public static Set<Integer> subSampleIndices(int N, int subSize) { List<Integer> indices = new ArrayList<Integer>(N); for (int i = 0; i < N; i++) { indices.add(i);/*from ww w . java 2s .c o m*/ } Collections.shuffle(indices); HashSet<Integer> samp = new HashSet<Integer>(subSize); for (int i = 0; i < subSize; i++) { samp.add(indices.get(i)); } return samp; }
From source file:main.Driver.java
/** * Given a primary queue, a reference leadsheet for chords, and a corpus of queue files, construct the result leadsheet from a series of randomly weighted interpolations of the primary queue towards the set of selected queues. * @param autoencoder/*from ww w . j a v a2 s . co m*/ * @param autoencoderConnectomePath * @param primaryQueuePath * @param queueFolder * @param outputFilePath * @param chordSequence * @param numReferenceQueues * @param numCombinations * @param interpolationMagnitude */ public static void frankensteinTest(ProductCompressingAutoencoder autoencoder, String autoencoderConnectomePath, String primaryQueuePath, File queueFolder, String outputFilePath, LeadsheetDataSequence chordSequence, int numReferenceQueues, int numCombinations, double interpolationMagnitude) { LogTimer.startLog("Loading queues"); if (queueFolder.isDirectory()) { File[] queueFiles = queueFolder.listFiles(new FilenameFilter() { @Override public boolean accept(File dir, String name) { return name.contains(".q"); } }); List<File> fileList = new ArrayList<>(); for (File file : queueFiles) { fileList.add(file); } Collections.shuffle(fileList); int numSelectedFiles = (numReferenceQueues > queueFiles.length) ? queueFiles.length : numReferenceQueues; for (int i = 0; i < queueFiles.length - numSelectedFiles; i++) { fileList.remove(fileList.size() - 1); } List<FragmentedNeuralQueue> queuePopulation = new ArrayList<>(fileList.size()); String songTitle = "A mix of "; for (File file : fileList) { FragmentedNeuralQueue newQueue = new FragmentedNeuralQueue(); newQueue.initFromFile(file.getPath()); queuePopulation.add(newQueue); songTitle += file.getName().replaceAll(".q", "") + ", "; } LogTimer.endLog(); LeadsheetDataSequence outputSequence = chordSequence.copy(); LeadsheetDataSequence additionalOutput = chordSequence.copy(); for (int i = 1; i < numCombinations; i++) { outputSequence.concat(additionalOutput.copy()); } LeadsheetDataSequence decoderInputSequence = outputSequence.copy(); FragmentedNeuralQueue primaryQueue = new FragmentedNeuralQueue(); primaryQueue.initFromFile(primaryQueuePath); for (int i = 0; i < numCombinations; i++) { LogTimer.startLog("Performing queue interpolation..."); AVector combinationStrengths = Vector.createLength(queuePopulation.size()); Random vectorRand = new Random(i); for (int j = 0; j < combinationStrengths.length(); j++) { combinationStrengths.set(j, vectorRand.nextDouble()); } combinationStrengths.divide(combinationStrengths.elementSum()); FragmentedNeuralQueue currQueue = primaryQueue.copy(); for (int k = 0; k < combinationStrengths.length(); k++) { currQueue.basicInterpolate(queuePopulation.get(k), combinationStrengths.get(k) * interpolationMagnitude); } LogTimer.endLog(); autoencoder.setQueue(currQueue); refreshNetworkState(autoencoder, autoencoderConnectomePath); decodeToSequence(autoencoder, outputSequence, decoderInputSequence); } writeLeadsheetFile(outputSequence, outputFilePath, "_randomInterpSamples", songTitle); } else { throw new RuntimeException("Given queue folder is not a directory!"); } }
From source file:com.andryr.musicplayer.PlaybackService.java
private void shuffle() { boolean b = mPlayList.remove(mCurrentSong); Collections.shuffle(mPlayList); if (b) {//from w ww. jav a2 s . com Log.d(TAG, mCurrentSong.getTitle()); Log.d(TAG, "removed"); mPlayList.add(0, mCurrentSong); } setPosition(0, false); }