List of usage examples for java.util ArrayList clear
public void clear()
From source file:edu.nyu.vida.data_polygamy.exp.NoiseExp.java
public void noiseExp(String dataFile, String graphFile, String polygonsFile, boolean is2D) throws IOException { ArrayList<TopologicalIndex> mainDataIndex = new ArrayList<>(); SpatialGraph spatialGraph = new SpatialGraph(); ArrayList<Integer[]> edges = new ArrayList<Integer[]>(); int spatialRes = 0; int nv = 1;// ww w. j a v a 2s. c o m if (is2D) { try { spatialGraph.init(polygonsFile, graphFile); } catch (IOException e) { e.printStackTrace(); return; } spatialRes = FrameworkUtils.NBHD; BufferedReader reader = new BufferedReader(new FileReader(graphFile)); String[] s = Utilities.splitString(reader.readLine().trim()); nv = Integer.parseInt(s[0].trim()); int ne = Integer.parseInt(s[1].trim()); for (int i = 0; i < ne; i++) { s = Utilities.splitString(reader.readLine().trim()); int v1 = Integer.parseInt(s[0].trim()); int v2 = Integer.parseInt(s[1].trim()); if (v1 == v2) { continue; } Integer[] arr = new Integer[2]; arr[0] = v1; arr[1] = v2; edges.add(arr); } reader.close(); } else { spatialRes = FrameworkUtils.CITY; } //long st = System.currentTimeMillis(); if (!is2D) { this.load1DData(dataFile, 2011); } else { this.load2DData(dataFile, graphFile, 2011); } //long en = System.currentTimeMillis(); //System.out.println("time to load data: " + (en - st)); for (int i = 0; i < dataAttributes.length; i++) { //System.out.println("Creating index for data " + dataAttributes[i]); TopologicalIndex index = this.createIndex(attributes, dataAttributes[i], spatialRes, nv, edges); mainDataIndex.add(index); iqr.put(dataAttributes[i], getIQR(values.get(dataAttributes[i]))); } for (int magn = 1; magn <= 10000; magn++) { System.out.println("Amplitude: " + magn); ArrayList<TopologicalIndex> noiseDataIndex = new ArrayList<>(); // adding noise to data HashMap<String, Attribute> newAttributes = addNoise((double) magn); for (int i = 0; i < dataAttributes.length; i++) { //System.out.println("Creating index for data " + dataAttributes[i]); TopologicalIndex index = this.createIndex(newAttributes, dataAttributes[i], spatialRes, nv, edges); noiseDataIndex.add(index); } boolean outlier = false; float th = 0.90f; if (!is2D) { for (int i = 0; i < dataAttributes.length; i++) { System.out.println("Attribute: " + dataAttributes[i]); ArrayList<byte[]> e1 = mainDataIndex.get(i).queryEvents(th, outlier, attributes.get(dataAttributes[i]), ""); ArrayList<byte[]> e2 = noiseDataIndex.get(i).queryEvents(th, outlier, newAttributes.get(dataAttributes[i]), ""); TopologyTimeSeriesWritable t1 = new TopologyTimeSeriesWritable(0, 0, i, e1.get(0), mainDataIndex.get(i).stTime, mainDataIndex.get(i).enTime, mainDataIndex.get(i).getNbPosEvents(0), mainDataIndex.get(i).getNbNegEvents(0), mainDataIndex.get(i).getNbNonEvents(0), outlier); TopologyTimeSeriesWritable t2 = new TopologyTimeSeriesWritable(0, 0, i, e2.get(0), noiseDataIndex.get(i).stTime, noiseDataIndex.get(i).enTime, noiseDataIndex.get(i).getNbPosEvents(0), noiseDataIndex.get(i).getNbNegEvents(0), noiseDataIndex.get(i).getNbNonEvents(0), outlier); int temporal = FrameworkUtils.HOUR; TimeSeriesStats stats = CorrelationReducer.getStats(temporal, t1, t2, false); stats.computeScores(); if (!stats.isIntersect()) return; float alignedScore = stats.getRelationshipScore(); System.out.println("Score: " + alignedScore); System.out.println("Strength: " + stats.getRelationshipStrength()); //System.out.println(stats.getMatchEvents() + " " + stats.getMatchPosEvents() + " " + stats.getMatchNegEvents()); //System.out.println(t1.getNbNegEvents() + " " + t1.getNbPosEvents()); //System.out.println(t2.getNbNegEvents() + " " + t2.getNbPosEvents()); int repetitions = 1000; float pValue = 0; for (int j = 0; j < repetitions; j++) { stats = new TimeSeriesStats(); stats.add(CorrelationReducer.getStats(FrameworkUtils.HOUR, t1, t2, true)); stats.computeScores(); float mcScore = stats.getRelationshipScore(); if (alignedScore > 0) { if (mcScore >= alignedScore) pValue += 1; } else { if (mcScore <= alignedScore) pValue += 1; } } pValue = pValue / ((float) (repetitions)); if (pValue <= alpha) { System.out.println("p-value: " + pValue); } else { System.out.println("p-value: " + pValue + " [not significant]"); } } } else { for (int i = 0; i < dataAttributes.length; i++) { System.out.println("Attribute: " + dataAttributes[i]); ArrayList<byte[]> e1 = mainDataIndex.get(i).queryEvents(th, outlier, attributes.get(dataAttributes[i]), ""); int n1 = mainDataIndex.get(i).nv; TopologyTimeSeriesWritable[] tarr1 = new TopologyTimeSeriesWritable[n1]; for (int j = 0; j < n1; j++) { tarr1[j] = new TopologyTimeSeriesWritable(j, 0, i, e1.get(j), mainDataIndex.get(i).stTime, mainDataIndex.get(i).enTime, mainDataIndex.get(i).getNbPosEvents(j), mainDataIndex.get(i).getNbNegEvents(j), mainDataIndex.get(i).getNbNonEvents(j), outlier); } int temporal = FrameworkUtils.HOUR; TimeSeriesStats stats = new TimeSeriesStats(); ArrayList<byte[]> e2 = noiseDataIndex.get(i).queryEvents(th, outlier, newAttributes.get(dataAttributes[i]), ""); int n2 = noiseDataIndex.get(i).nv; if (n1 != n2) { System.out.println("Something is wrong ..."); System.exit(0); } TopologyTimeSeriesWritable[] tarr2 = new TopologyTimeSeriesWritable[n2]; for (int j = 0; j < n2; j++) { tarr2[j] = new TopologyTimeSeriesWritable(j, 0, i, e2.get(j), noiseDataIndex.get(i).stTime, noiseDataIndex.get(i).enTime, noiseDataIndex.get(i).getNbPosEvents(j), noiseDataIndex.get(i).getNbNegEvents(j), noiseDataIndex.get(i).getNbNonEvents(j), outlier); stats.add(CorrelationReducer.getStats(temporal, tarr1[j], tarr2[j], false)); } stats.computeScores(); float alignedScore = stats.getRelationshipScore(); System.out.println("Score: " + alignedScore); System.out.println("Strength: " + stats.getRelationshipStrength()); //System.out.println(stats.getMatchEvents() + " " + stats.getMatchPosEvents() + " " + stats.getMatchNegEvents()); //System.out.println(nn1 + " " + np1); //System.out.println(nn2 + " " + np2); double pValue = 0; int repetitions = 1000; ArrayList<Integer[]> pairs = new ArrayList<Integer[]>(); for (int j = 0; j < repetitions; j++) { pairs.clear(); pairs = spatialGraph.generateRandomShift(); stats = new TimeSeriesStats(); for (int p = 0; p < pairs.size(); p++) { Integer[] pair = pairs.get(p); stats.add(CorrelationReducer.getStats(temporal, tarr1[pair[0]], tarr2[pair[1]], false)); } stats.computeScores(); float mcScore = stats.getRelationshipScore(); if (alignedScore > 0) { if (mcScore >= alignedScore) pValue += 1; } else { if (mcScore <= alignedScore) pValue += 1; } } pValue = pValue / ((float) (repetitions)); if (pValue <= alpha) { System.out.println("p-value: " + pValue); } else { System.out.println("p-value: " + pValue + " [not significant]"); } } } } }
From source file:com.yoctopuce.YoctoAPI.YTemperature.java
/** * Configure NTC thermistor parameters in order to properly compute the temperature from * the measured resistance. For increased precision, you can enter a complete mapping * table using set_thermistorResponseTable. This function can only be used with a * temperature sensor based on thermistors. * * @param res25 : thermistor resistance at 25 degrees Celsius * @param beta : Beta value//from www .j av a 2s . c om * * @return YAPI.SUCCESS if the call succeeds. * * @throws YAPI_Exception on error */ public int set_ntcParameters(double res25, double beta) throws YAPI_Exception { double t0; double t1; double res100; ArrayList<Double> tempValues = new ArrayList<Double>(); ArrayList<Double> resValues = new ArrayList<Double>(); t0 = 25.0 + 275.15; t1 = 100.0 + 275.15; res100 = res25 * java.lang.Math.exp(beta * (1.0 / t1 - 1.0 / t0)); tempValues.clear(); resValues.clear(); tempValues.add(25.0); resValues.add(res25); tempValues.add(100.0); resValues.add(res100); return set_thermistorResponseTable(tempValues, resValues); }
From source file:com.ibm.bi.dml.hops.rewrite.ProgramRewriter.java
/** * /* ww w . j a v a2s .c o m*/ * @param sbs * @return * @throws HopsException */ public ArrayList<StatementBlock> rewriteStatementBlocks(ArrayList<StatementBlock> sbs, ProgramRewriteStatus state) throws HopsException { //ensure robustness for calls from outside if (state == null) state = new ProgramRewriteStatus(); ArrayList<StatementBlock> tmp = new ArrayList<StatementBlock>(); //rewrite statement blocks (with potential expansion) for (StatementBlock sb : sbs) tmp.addAll(rewriteStatementBlock(sb, state)); //copy results into original collection sbs.clear(); sbs.addAll(tmp); return sbs; }
From source file:edu.utexas.cs.tactex.tariffoptimization.TariffOptimizerBinaryOneShot.java
/** * evaluate suggestedSpecs(index), and record result to utilToIndex * and result/*from w w w .j a va 2 s .c o m*/ * * @param index * @param utilToIndex * @param result * @param suggestedSpecs * @param consideredTariffActions * @param tariffSubscriptions * @param competingTariffs * @param costCurvesPredictor * @param currentTimeslot * @param me * @param customer2ShiftedEnergy * @param customer2RelevantTariffCharges * @param customer2NonShiftedEnergy */ private void evaluateAndRecord(int index, TreeMap<Double, Integer> utilToIndex, TreeMap<Double, TariffSpecification> result, List<TariffSpecification> suggestedSpecs, ArrayList<TariffSpecification> consideredTariffActions, HashMap<TariffSpecification, HashMap<CustomerInfo, Integer>> tariffSubscriptions, List<TariffSpecification> competingTariffs, CostCurvesPredictor costCurvesPredictor, int currentTimeslot, Broker me, HashMap<CustomerInfo, HashMap<TariffSpecification, ShiftedEnergyData>> customer2ShiftedEnergy, HashMap<CustomerInfo, ArrayRealVector> customer2NonShiftedEnergy, HashMap<CustomerInfo, HashMap<TariffSpecification, Double>> customer2RelevantTariffCharges) { TreeMap<Double, TariffSpecification> sortedTariffs; consideredTariffActions.clear(); consideredTariffActions.add(suggestedSpecs.get(index)); //log.info("computing utilities"); sortedTariffs = utilityEstimator.estimateUtilities(consideredTariffActions, tariffSubscriptions, competingTariffs, customer2RelevantTariffCharges, customer2ShiftedEnergy, customer2NonShiftedEnergy, marketPredictionManager, costCurvesPredictor, currentTimeslot, me); utilToIndex.put(sortedTariffs.lastEntry().getKey(), index); // maintain top 3 if (utilToIndex.size() > 3) { utilToIndex.remove(utilToIndex.firstKey()); } result.putAll(sortedTariffs); }
From source file:com.zhihuigu.sosoOffice.RegisterThirdActivity.java
@Override public void onClick(View v) { if (v == backBtn) { Intent intent = new Intent(this, LoginActivity.class); startActivity(intent);/* ww w. j a v a2 s. c om*/ finish(); } else if (v == submitBtn) { if (textValidate()) { new Thread(runnable).start(); } } else if (v == linearGetImage) { int height = MyApplication.getInstance(this).getScreenHeight(); if (photo_tag) { shareBtn3.setVisibility(View.VISIBLE); if (height == 1280) { chazhi = 670; } else if (height == 800) { chazhi = 340; } else if (height == 960) { chazhi = 500; } else if (height == 854) { chazhi = 400; } else if (height == 480) { chazhi = 175; } } else { shareBtn3.setVisibility(View.GONE); if (height == 1280) { chazhi = 800; } else if (height == 800) { chazhi = 440; } else if (height == 960) { chazhi = 600; } else if (height == 854) { chazhi = 492; } else if (height == 480) { chazhi = 240; } } CommonUtils.hideSoftKeyboard(this);// new Thread(runnableForShowDialog).start(); } else if (v == shareBtn1) { dismiss(); Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileName = CommonUtils.getFileName(); MyApplication.getInstance(this).setFileName(fileName); File file = new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD); if (!file.exists()) { file.mkdirs(); } if (CommonUtils.isHasSdcard()) { openCamera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(SDCARD_ROOT_PATH + SAVE_PATH_IN_SDCARD, fileName))); } startActivityForResult(openCamera, REQUEST_CODE_TAKE_PICTURE); } else if (v == shareBtn2) { dismiss(); Intent getAlbum = new Intent(Intent.ACTION_GET_CONTENT); getAlbum.setType(IMAGE_TYPE); startActivityForResult(getAlbum, IMAGE_CODE); } else if (v == shareBtn3) { dismiss(); // Intent intent = new Intent(this,ImagePreViewActivity.class); // intent.putExtra("path", path); // startActivityForResult(intent, 6); ArrayList<String> al = new ArrayList<String>(); al.clear(); al.add(path); Intent it = new Intent(this, ImageSwitcher.class); it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); it.putStringArrayListExtra("pathes", al); it.putExtra("index", 0); startActivity(it); } else if (v == cancleBtn) { dismiss(); } super.onClick(v); }
From source file:com.miz.service.TraktMoviesSyncService.java
private void updateWatchedMovies() { ArrayList<Movie> watchedMovies = new ArrayList<Movie>(); int count = mMovies.size(); for (int i = 0; i < count; i++) // Check that we're not uploading stuff that's already on Trakt if (!mWatchedMovies.contains(mMovies.get(i).getTmdbId()) && mMovies.get(i).hasWatched()) watchedMovies.add(mMovies.get(i)); if (watchedMovies.size() > 0) Trakt.markMovieAsWatched(watchedMovies, this); // Clean up/*from w w w . j a v a 2 s . co m*/ watchedMovies.clear(); watchedMovies = null; mWatchedMovies.clear(); mWatchedMovies = null; }
From source file:com.chinamobile.bcbsp.comm.RPCSingleSendSlave.java
/** Send the package of messages with RPC.*/ public void sendPacked() { IMessage msg;//from w ww. j a v a2 s . c o m int count = 0; BSPMessagesPack pack = new BSPMessagesPack(); ArrayList<IMessage> content = new ArrayList<IMessage>(); // just for test int maxSize = messageQueue.size(); while ((msg = messageQueue.poll()) != null) { content.add(msg); count++; this.messageCount++; if (count == this.packSize) { pack.setPack(content); long start = System.currentTimeMillis(); /* Clock */ this.senderProtocol.sendPackedMessage(pack); this.sendTime += (System.currentTimeMillis() - start); content.clear(); count = 0; } } if (content.size() > 0) { pack.setPack(content); long start = System.currentTimeMillis(); /* Clock */ this.senderProtocol.sendPackedMessage(pack); this.sendTime += (System.currentTimeMillis() - start); /* Clock */ content.clear(); } }
From source file:com.chinamobile.bcbsp.workermanager.WorkerAgentForJob.java
/** * To aggregate the values from the running staffs. *///from w w w . j a v a 2 s. c om @SuppressWarnings("unchecked") private void localAggregate() { // Clear the results' container before the calculation of a new super step. this.aggregateResults.clear(); // To calculate the aggregations. for (Entry<String, Class<? extends Aggregator<?>>> entry : this.nameToAggregator.entrySet()) { Aggregator<AggregateValue> aggregator = null; try { aggregator = (Aggregator<AggregateValue>) entry.getValue().newInstance(); } catch (InstantiationException e1) { // LOG.error("InstantiationException", e1); throw new RuntimeException("WorkerAgentForJob " + "InstantiationException exception", e1); } catch (IllegalAccessException e1) { // LOG.error("IllegalAccessException", e1); throw new RuntimeException("WorkerAgentForJob " + "IllegalAccessException exception", e1); } if (aggregator != null) { ArrayList<AggregateValue> aggVals = this.aggregateValues.get(entry.getKey()); AggregateValue resultValue = aggregator.aggregate(aggVals); this.aggregateResults.put(entry.getKey(), resultValue); // Clear the initial aggregate values after aggregation completed. aggVals.clear(); } } }
From source file:com.miz.service.TraktMoviesSyncService.java
private void updateMovieCollection() { int count = mMovies.size(); if (count > 0) { ArrayList<Movie> collection = new ArrayList<Movie>(); for (int i = 0; i < count; i++) { if (!mMovieCollection.contains(mMovies.get(i).getTmdbId())) { collection.add(mMovies.get(i)); }/*from w w w. ja v a 2 s . c om*/ } count = collection.size(); if (count > 0) { // Add to Trakt movie collection Trakt.addMoviesToLibrary(collection, getApplicationContext()); } // Clean up collection.clear(); collection = null; } }
From source file:com.krminc.phr.domain.User.java
public void setUserImage(java.io.InputStream userImage) { ArrayList<Byte> list = new ArrayList<Byte>(); int s;//from w w w. ja v a 2 s . co m //loop through each byte of input image try { while ((s = userImage.read()) != -1) { list.add((byte) s); } } catch (IOException e) { list.clear(); } //copy from arraylist to ORM-pleasing byte array byte[] b = new byte[list.size()]; for (int i = 0; i < b.length; i++) { b[i] = list.get(i); } if (list.size() > 0) { this.userImage = b; } else { this.userImage = null; } }