List of usage examples for com.google.common.primitives Ints asList
public static List<Integer> asList(int... backingArray)
From source file:com.sop4j.SimpleStatistics.java
public static void main(String[] args) { final MersenneTwister rng = new MersenneTwister(); // used for RNG... READ THE DOCS!!! final int[] values = new int[NUM_VALUES]; final DescriptiveStatistics descriptiveStats = new DescriptiveStatistics(); // stores values final SummaryStatistics summaryStats = new SummaryStatistics(); // doesn't store values final Frequency frequency = new Frequency(); // add numbers into our stats for (int i = 0; i < NUM_VALUES; ++i) { values[i] = rng.nextInt(MAX_VALUE); descriptiveStats.addValue(values[i]); summaryStats.addValue(values[i]); frequency.addValue(values[i]);// ww w .j av a 2 s . com } // print out some standard stats System.out.println("MIN: " + summaryStats.getMin()); System.out.println("AVG: " + String.format("%.3f", summaryStats.getMean())); System.out.println("MAX: " + summaryStats.getMax()); // get some more complex stats only offered by DescriptiveStatistics System.out.println("90%: " + descriptiveStats.getPercentile(90)); System.out.println("MEDIAN: " + descriptiveStats.getPercentile(50)); System.out.println("SKEWNESS: " + String.format("%.4f", descriptiveStats.getSkewness())); System.out.println("KURTOSIS: " + String.format("%.4f", descriptiveStats.getKurtosis())); // quick and dirty stats (need a little help from Guava to convert from int[] to double[]) System.out.println("MIN: " + StatUtils.min(Doubles.toArray(Ints.asList(values)))); System.out.println("AVG: " + String.format("%.4f", StatUtils.mean(Doubles.toArray(Ints.asList(values))))); System.out.println("MAX: " + StatUtils.max(Doubles.toArray(Ints.asList(values)))); // some stats based upon frequencies System.out.println("NUM OF 7s: " + frequency.getCount(7)); System.out.println("CUMULATIVE FREQUENCY OF 7: " + frequency.getCumFreq(7)); System.out.println("PERCENTAGE OF 7s: " + frequency.getPct(7)); }
From source file:fall2015.b565.wisBreastCancer.Assignment2.java
public static void main(String[] args) throws Exception { try {/*from w ww. j ava 2s.c o m*/ parseArguments(args); FileReader fileReader = new FileReader(); if (useReplaceDataSet) { cleanedFilePath = Constants.REPLACED_DATA_FILE_PATH; } else { cleanedFilePath = Constants.REMOVED_DATA_FILE_PATH; } KMeans kMeans = new KMeans(); System.out.println("=============== Pre-Processing of Data ==============="); fileReader.cleanDataSet(); System.out.println("=============== Data Cleaned ==============="); if (correlation) { System.out.println("=============== Finding Correlation between attributes ==============="); kMeans.findAttributeCorrelations(); } if (ppv) { System.out.println("=============== Finding PPV considering all the attributes ==============="); KMeansResult kMeansResult = kMeans.findKmeansToAllAttributes(cleanedFilePath); double ppv = kMeans.calculatePPV(kMeansResult.getFinalCentroids(), kMeans.getRecords(cleanedFilePath)); System.out.println("Calculated PPV : " + ppv); } if (powerSetPPV) { System.out.println( "=============== Finding PPV considering power set of the attributes ==============="); kMeans.findKmeansToAttributePowerSet(cleanedFilePath); } if (vfoldCrossValidation) { System.out.println( "=============== Finding V Fold cross validation considering all the attribute set ==============="); KMeansResult kMeansResult = kMeans.findKmeansToAllAttributes(cleanedFilePath); HashSet<Integer> attributes = new HashSet<Integer>(Ints.asList(allAttributeHeaders)); double vPPV = kMeans.vFoldCrossValidation(kMeansResult.getInitialRecords(), attributes); System.out.println("VFold cross validation PPV : " + vPPV); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.dllearner.algorithms.qtl.experiments.Diagrams.java
public static void main(String[] args) throws Exception { File dir = new File(args[0]); dir.mkdirs();/*from w w w . j a v a 2s . c om*/ Properties config = new Properties(); config.load(Thread.currentThread().getContextClassLoader() .getResourceAsStream("org/dllearner/algorithms/qtl/qtl-eval-config.properties")); String url = config.getProperty("url"); String username = config.getProperty("username"); String password = config.getProperty("password"); Class.forName("com.mysql.jdbc.Driver").newInstance(); // url = "jdbc:mysql://address=(protocol=tcp)(host=[2001:638:902:2010:0:168:35:138])(port=3306)(user=root)/qtl"; Connection conn = DriverManager.getConnection(url, username, password); int[] nrOfExamplesIntervals = { 5, 10, // 15, 20, // 25, 30 }; double[] noiseIntervals = { 0.0, 0.1, 0.2, 0.3, // 0.4, // 0.6 }; Map<HeuristicType, String> measure2ColumnName = Maps.newHashMap(); measure2ColumnName.put(HeuristicType.FMEASURE, "avg_fscore_best_returned"); measure2ColumnName.put(HeuristicType.PRED_ACC, "avg_predacc_best_returned"); measure2ColumnName.put(HeuristicType.MATTHEWS_CORRELATION, "avg_mathcorr_best_returned"); HeuristicType[] measures = { HeuristicType.PRED_ACC, HeuristicType.FMEASURE, HeuristicType.MATTHEWS_CORRELATION }; String[] labels = { "A_1", "F_1", "MCC" }; // get distinct noise intervals // |E| vs fscore String sql = "SELECT nrOfExamples,%s from eval_overall WHERE heuristic_measure = ? && noise = ? ORDER BY nrOfExamples"; PreparedStatement ps; for (double noise : noiseIntervals) { String s = ""; s += "\t"; s += Joiner.on("\t").join(Ints.asList(nrOfExamplesIntervals)); s += "\n"; for (HeuristicType measure : measures) { ps = conn.prepareStatement(String.format(sql, measure2ColumnName.get(measure))); ps.setString(1, measure.toString()); ps.setDouble(2, noise); ResultSet rs = ps.executeQuery(); s += measure; while (rs.next()) { int nrOfExamples = rs.getInt(1); double avgFscore = rs.getDouble(2); s += "\t" + avgFscore; } s += "\n"; } Files.write(s, new File(dir, "examplesVsScore-" + noise + ".tsv"), Charsets.UTF_8); } // noise vs fscore sql = "SELECT noise,%s from eval_overall WHERE heuristic_measure = ? && nrOfExamples = ?"; NavigableMap<Integer, Map<HeuristicType, double[][]>> input = new TreeMap<>(); for (int nrOfExamples : nrOfExamplesIntervals) { String s = ""; s += "\t"; s += Joiner.on("\t").join(Doubles.asList(noiseIntervals)); s += "\n"; String gnuplot = ""; // F-score ps = conn.prepareStatement( "SELECT noise,avg_fscore_best_returned from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); ResultSet rs = ps.executeQuery(); gnuplot += "\"F_1\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // precision gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_precision_best_returned from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"precision\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // recall gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_recall_best_returned from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"recall\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // MCC gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_mathcorr_best_returned from eval_overall WHERE heuristic_measure = 'MATTHEWS_CORRELATION' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"MCC\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // baseline F-score gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_fscore_baseline from eval_overall WHERE heuristic_measure = 'FMEASURE' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"baseline F_1\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } // baseline MCC gnuplot += "\n\n"; ps = conn.prepareStatement( "SELECT noise,avg_mathcorr_baseline from eval_overall WHERE heuristic_measure = 'MATTHEWS_CORRELATION' && nrOfExamples = ?"); ps.setInt(1, nrOfExamples); rs = ps.executeQuery(); gnuplot += "\"baseline MCC\"\n"; while (rs.next()) { double noise = rs.getDouble(1); double avgFscore = rs.getDouble(2); gnuplot += noise + "," + avgFscore + "\n"; } Files.write(gnuplot.trim(), new File(dir, "noiseVsScore-" + nrOfExamples + ".dat"), Charsets.UTF_8); } if (!input.isEmpty()) { // plotNoiseVsFscore(input); } }
From source file:org.caleydo.view.domino.internal.util.IndexedSort.java
/** * sort the given list and return the sorted list of indices * /*from w w w. java2s .c o m*/ * @param list * @param comparator * @return */ public static <T> int[] sortIndex(final List<T> list, final Comparator<? super T> comparator) { final int size = list.size(); int[] indices = new int[size]; for (int i = 0; i < size; ++i) indices[i] = i; if (size <= 1) return indices; Collections.sort(Ints.asList(indices), new Comparator<Integer>() { @Override public int compare(Integer o1, Integer o2) { return comparator.compare(list.get(o1.intValue()), list.get(o2.intValue())); } }); return indices; }
From source file:com.tapchatapp.android.util.FieldValidator.java
public static boolean validateFields(final Activity activity, int... viewIds) { Iterable<View> views = transform(Ints.asList(viewIds), new Function<Integer, View>() { @Override/*from w ww . j a va 2 s . co m*/ public View apply(Integer viewId) { View view = activity.findViewById(viewId); if (view == null) { throw new IllegalArgumentException("no view with id: " + viewId); } return view; } }); return validateFields(toArray(views, View.class)); }
From source file:de.learnlib.algorithms.rpni.EDSMUtil.java
static <S> long score(UniversalDeterministicAutomaton<S, Integer, ?, Boolean, ?> pta, List<int[]> positiveSamples, List<int[]> negativeSamples) { final StateIDs<S> stateIDs = pta.stateIDs(); final int[] tp = new int[pta.size()]; final int[] tn = new int[pta.size()]; for (final int[] w : positiveSamples) { int index = stateIDs.getStateId(pta.getState(Ints.asList(w))); tp[index]++;// ww w. ja v a 2s . c om } for (final int[] w : negativeSamples) { int index = stateIDs.getStateId(pta.getState(Ints.asList(w))); tn[index]++; } int score = 0; for (final S s : pta.getStates()) { final int indexOfCurrentState = stateIDs.getStateId(s); if (tn[indexOfCurrentState] > 0) { if (tp[indexOfCurrentState] > 0) { return Long.MIN_VALUE; } else { score += tn[indexOfCurrentState] - 1; } } else { if (tp[indexOfCurrentState] > 0) { score += tp[indexOfCurrentState] - 1; } } } return score; }
From source file:com.metamx.druid.kv.VSizeIndexedInts.java
public static VSizeIndexedInts fromArray(int[] array, int maxValue) { return fromList(Ints.asList(array), maxValue); }
From source file:com.tapchatapp.android.util.FieldValidator.java
public static boolean validateFields(final View parentView, int... viewIds) { Iterable<View> views = transform(Ints.asList(viewIds), new Function<Integer, View>() { @Override/*from w ww .j a v a 2 s .c o m*/ public View apply(Integer viewId) { View view = parentView.findViewById(viewId); if (view == null) { throw new IllegalArgumentException("no view with id: " + viewId); } return view; } }); return validateFields(toArray(views, View.class)); }
From source file:kungfu.algdesign.inv.InversionImpl.java
@Override public long countInversions(int[] arr) { List<Integer> ints = Ints.asList(arr); Integer[] integerArray = new Integer[arr.length]; long invCount = sort(ints.toArray(integerArray)); return invCount; }
From source file:org.apache.brooklyn.util.math.BitUtils.java
/** as {@link #reverseBitSignificance(byte...)}, but taking ints for convenience (ignoring high bits) */ public static byte[] reverseBitSignificanceInBytes(int... bytes) { return reverseBitSignificance(Bytes.toArray(Ints.asList(bytes))); }