public static int[] sort(float[] list, boolean asc) { return sort(list, 0, list.length-1, asc); } public static int[] sort(float[] list, int begin, int end, boolean asc)
public static int[] sort(final float[] list, final boolean asc) { return sort(list, 0, list.length - 1, asc); }
public static int[] sort(double[] list, boolean asc) { return sort(list, 0, list.length-1, asc); } public static int[] sort(double[] list, int begin, int end, boolean asc)
public static int[] sort(final double[] list, final boolean asc) { return sort(list, 0, list.length - 1, asc); }
protected int[] sortSamplesByFeature(final DataPoint[] samples, final int fid) { final double[] score = new double[samples.length]; for (int i = 0; i < samples.length; i++) { score[i] = samples[i].getFeatureValue(fid); } final int[] idx = MergeSorter.sort(score, true); return idx; }
protected int[] sortSamplesByFeature(DataPoint[] samples, int fid) { double[] score = new double[samples.length]; for(int i=0;i<samples.length;i++) score[i] = samples[i].getFeatureValue(fid); int[] idx = MergeSorter.sort(score, true); return idx; } /**
public static void main(final String[] args) { final float[][] f = new float[1000][]; for (int r = 0; r < f.length; r++) { f[r] = new float[500]; final Random rd = new Random(); for (int i = 0; i < f[r].length; i++) { final float x = rd.nextInt(10); f[r][i] = x; } } final double start = System.nanoTime(); for (final float[] element : f) { sort(element, false); } final double end = System.nanoTime(); logger.info(() -> "# " + (end - start) / 1e9 + " "); }
public static void main(String[] args) { float[][] f = new float[1000][]; for(int r=0;r<f.length;r++) { f[r] = new float[500]; Random rd = new Random(); for(int i=0;i<f[r].length;i++) { //float x = rd.nextFloat(); float x = rd.nextInt(10); //System.out.print(x + " "); f[r][i] = x; } //System.out.println(""); } double start = System.nanoTime(); for(int r=0;r<f.length;r++) sort(f[r], false); double end = System.nanoTime(); System.out.println("# " + (double)(end-start)/1e9 + " "); }
protected float computeModelScoreOnValidation(int start, int end) { float score = 0; for(int i=start;i<=end;i++) { int[] idx = MergeSorter.sort(modelScoresOnValidation[i], false); score += scorer.score(new RankList(validationSamples.get(i), idx)); } return score; }
protected float computeModelScoreOnValidation(final int start, final int end) { float score = 0; for (int i = start; i <= end; i++) { final int[] idx = MergeSorter.sort(modelScoresOnValidation[i], false); score += scorer.score(new RankList(validationSamples.get(i), idx)); } return score; }
/** * This function is equivalent to the inherited function rank(...), but it uses the cached model's outputs instead of computing them from scratch. * @param rankListIndex * @param current * @return */ protected RankList rank(final int rankListIndex, final int current) { final RankList orig = samples.get(rankListIndex); final double[] scores = new double[orig.size()]; for (int i = 0; i < scores.length; i++) { scores[i] = modelScores[current + i]; } final int[] idx = MergeSorter.sort(scores, false); return new RankList(orig, idx); }
/** * This function is equivalent to the inherited function rank(...), but it uses the cached model's outputs instead of computing them from scratch. * @param rankListIndex * @param current * @return */ protected RankList rank(int rankListIndex, int current) { RankList orig = samples.get(rankListIndex); double[] scores = new double[orig.size()]; for(int i=0;i<scores.length;i++) scores[i] = modelScores[current+i]; int[] idx = MergeSorter.sort(scores, false); return new RankList(orig, idx); } protected float computeModelScoreOnTraining()
s[j] = scores.get(k++); rl = new RankList(rl, MergeSorter.sort(s, false)); test.set(i, rl);
private int[] reorder(RankList rl, int fid) { double[] score = new double[rl.size()]; for(int i=0;i<rl.size();i++) score[i] = rl.get(i).getFeatureValue(fid); return MergeSorter.sort(score, false); }
private int[] reorder(final RankList rl, final int fid) { final double[] score = new double[rl.size()]; for (int i = 0; i < rl.size(); i++) { score[i] = rl.get(i).getFeatureValue(fid); } return MergeSorter.sort(score, false); }
final int[] idx = MergeSorter.sort(scores, false);
public RankList rank(final RankList rl) { final double[] scores = new double[rl.size()]; for (int i = 0; i < rl.size(); i++) { scores[i] = eval(rl.get(i)); } final int[] idx = MergeSorter.sort(scores, false); return new RankList(rl, idx); }
public RankList rank(RankList rl) { double[] scores = new double[rl.size()]; for(int i=0;i<rl.size();i++) scores[i] = eval(rl.get(i)); int[] idx = MergeSorter.sort(scores, false); return new RankList(rl, idx); }
@Override public RankList rank(final RankList rl) { final double[] score = new double[rl.size()]; if (current_feature == -1) { for (int i = 0; i < rl.size(); i++) { for (int j = 0; j < features.length; j++) { score[i] += weight[j] * rl.get(i).getFeatureValue(features[j]); } rl.get(i).setCached(score[i]);//use cache of a data point to store its score given the model at this state } } else//This branch is only active during the training process. Here we trade the "clean" codes for efficiency { for (int i = 0; i < rl.size(); i++) { //cached score = a_1*x_1 + a_2*x_2 + ... + a_n*x_n //a_2 ==> a'_2 //new score = cached score + (a'_2 - a_2)*x_2 ====> NO NEED TO RE-COMPUTE THE WHOLE THING score[i] = rl.get(i).getCached() + weight_change * rl.get(i).getFeatureValue(features[current_feature]); rl.get(i).setCached(score[i]); } } final int[] idx = MergeSorter.sort(score, false); return new RankList(rl, idx); }
public RankList rank(RankList rl) { double[] score = new double[rl.size()]; if(current_feature == -1) { for(int i=0;i<rl.size();i++) { for(int j=0;j<features.length;j++) score[i] += weight[j] * rl.get(i).getFeatureValue(features[j]); rl.get(i).setCached(score[i]);//use cache of a data point to store its score given the model at this state } } else//This branch is only active during the training process. Here we trade the "clean" codes for efficiency { for(int i=0;i<rl.size();i++) { //cached score = a_1*x_1 + a_2*x_2 + ... + a_n*x_n //a_2 ==> a'_2 //new score = cached score + (a'_2 - a_2)*x_2 ====> NO NEED TO RE-COMPUTE THE WHOLE THING score[i] = rl.get(i).getCached() + weight_change * rl.get(i).getFeatureValue(features[current_feature]); rl.get(i).setCached(score[i]); } } int[] idx = MergeSorter.sort(score, false); return new RankList(rl, idx); } public double eval(DataPoint p)