本文整理汇总了Java中org.apache.commons.math3.util.Pair类的典型用法代码示例。如果您正苦于以下问题:Java Pair类的具体用法?Java Pair怎么用?Java Pair使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Pair类属于org.apache.commons.math3.util包,在下文中一共展示了Pair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: wrap
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
/**
* Create a JsonObject wrapping a raw {@code Pair<Long msec,T reading>>} sample.
* @param <T> Tuple type
* @param sample the raw sample
* @param id the sensor's Id
* @return the wrapped sample
*/
public static <T> JsonObject wrap(Pair<Long,T> sample, String id) {
JsonObject jo = new JsonObject();
jo.addProperty(KEY_ID, id);
jo.addProperty(KEY_TS, sample.getFirst());
T value = sample.getSecond();
if (value instanceof Number)
jo.addProperty(KEY_READING, (Number)sample.getSecond());
else if (value instanceof String)
jo.addProperty(KEY_READING, (String)sample.getSecond());
else if (value instanceof Boolean)
jo.addProperty(KEY_READING, (Boolean)sample.getSecond());
// else if (value instanceof array) {
// // TODO cvt to JsonArray
// }
// else if (value instanceof Object) {
// // TODO cvt to JsonObject
// }
else {
Class<?> clazz = value != null ? value.getClass() : Object.class;
throw new IllegalArgumentException("Unhandled value type: "+ clazz);
}
return jo;
}
示例2: getSlugPostfixPair
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
private Pair<String, Long> getSlugPostfixPair(String slug) {
if (!slug.contains(SLUG_POSTFIX_DELIMITER)) {
return new Pair<>(slug, null);
}
int indexOfPossiblePostfix = slug.lastIndexOf(SLUG_POSTFIX_DELIMITER);
String possiblePostfixAsString = slug.substring(indexOfPossiblePostfix + 1, slug.length());
if (!StringUtils.isNumeric(possiblePostfixAsString)) {
return new Pair<>(slug, null);
}
// slug name has numeric postfix
String slugNameWithoutNumericPostfix = slug.substring(0, indexOfPossiblePostfix);
Long postfix = Long.parseLong(possiblePostfixAsString);
return new Pair<>(slugNameWithoutNumericPostfix, postfix);
}
示例3: getGreedyRegressors
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
public static Pair<List<AnnotationRegressor>, List<FeatureNormalizer>> getGreedyRegressors(Websearch ws,
boolean includeS1, boolean includeS2, boolean includeS3) {
List<AnnotationRegressor> regressors = new Vector<>();
List<FeatureNormalizer> fns = new Vector<>();
int i = 0;
while (true) {
URL modelI = getDefaultModel(SmaphVersion.GREEDY, ws, includeS1, includeS2, includeS3, i);
if (modelI == null)
break;
URL zscoreI = getDefaultZscoreNormalizer(SmaphVersion.GREEDY, ws, includeS1, includeS2, includeS3, i);
AnnotationRegressor arI = getCachedAnnotationRegressor(modelI);
FeatureNormalizer fnI = getCachedFeatureNormalizer(zscoreI, new GreedyFeaturePack());
regressors.add(arI);
fns.add(fnI);
i++;
}
return new Pair<>(regressors, fns);
}
示例4: settingNoOpInjectionsAndQuery
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
@Test
public void settingNoOpInjectionsAndQuery() {
final long before = countAllocatedMemory();
final String controls = Controls.newBuilder()
.addExceptionOnBit(getClass(), "noop", RuntimeException.class, getEndpoint(DRILLBIT_BETA))
.build();
setControls(controls);
final WaitUntilCompleteListener listener = new WaitUntilCompleteListener();
QueryTestUtil.testWithListener(drillClient, QueryType.SQL, TEST_QUERY, listener);
final Pair<QueryState, Exception> pair = listener.waitForCompletion();
assertStateCompleted(pair, QueryState.COMPLETED);
final long after = countAllocatedMemory();
assertEquals(String.format("We are leaking %d bytes", after - before), before, after);
}
示例5: passThrough
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
@Test // To test pause and resume. Test hangs and times out if resume did not happen.
public void passThrough() {
final long before = countAllocatedMemory();
final WaitUntilCompleteListener listener = new WaitUntilCompleteListener() {
@Override
public void queryIdArrived(final QueryId queryId) {
super.queryIdArrived(queryId);
final ExtendedLatch trigger = new ExtendedLatch(1);
(new ResumingThread(queryId, ex, trigger)).start();
trigger.countDown();
}
};
final String controls = Controls.newBuilder()
.addPause(PojoRecordReader.class, "read-next")
.build();
setControls(controls);
QueryTestUtil.testWithListener(drillClient, QueryType.SQL, TEST_QUERY, listener);
final Pair<QueryState, Exception> result = listener.waitForCompletion();
assertStateCompleted(result, QueryState.COMPLETED);
final long after = countAllocatedMemory();
assertEquals(String.format("We are leaking %d bytes", after - before), before, after);
}
示例6: splitTagAndBasename
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
public Pair<String,Path> splitTagAndBasename(Path path){
String name = path.getName();
Path parent = path.getParent();
if(name.startsWith(LR_PREFIX) == false){
return null;
}
name = name.substring(LR_PREFIX.length());
int underscore = name.indexOf(LR_TAG_DELIM);
if(underscore == -1){
return null;
}
String tag = name.substring(0, underscore);
String basename = name.substring(underscore + 1);
if(LR_ALL_TAGS.contains(tag) == false){
return null;
}
return new Pair<>(tag, new Path(parent, basename));
}
示例7: convertToDouble
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
/**
* Converts the from the actual {@code Number} type to {@code double}
*
* @param <T> Type of the number used to represent the points and
* weights of the quadrature rules.
* @param rule Points and weights.
* @return points and weights as {@code double}s.
*/
private static <T extends Number> Pair<double[], double[]> convertToDouble(Pair<T[], T[]> rule) {
final T[] pT = rule.getFirst();
final T[] wT = rule.getSecond();
final int len = pT.length;
final double[] pD = new double[len];
final double[] wD = new double[len];
for (int i = 0; i < len; i++) {
pD[i] = pT[i].doubleValue();
wD[i] = wT[i].doubleValue();
}
return new Pair<double[], double[]>(pD, wD);
}
示例8: run
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
@Override
public Predictions<E, P>[] run() {
final Pair<List<I>, List<I>> sets = partition();
final Predictions<E, P>[] preds = new Predictions[learner.length];
for (int i = 0; i < preds.length; ++i) {
final long start = System.currentTimeMillis();
final ModelPipeline<I, P> model = learner[i].run(sets.getFirst(), sets.getSecond(), config, label);
preds[i] = Predictions
.create(actualFold, model, sets.getSecond(), (int) (System.currentTimeMillis() - start));
logger.info("Completed {} on {} train and {} test samples",
getTitle(),
sets.getFirst().size(),
sets.getSecond().size());
}
return preds;
}
示例9: sortDescending2
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
public static <T, N extends Number> LinkedList<Pair<T, N>> sortDescending2(final List<Pair<T, N>> list) {
final LinkedList<Pair<T, N>> newList = new LinkedList<>(list);
java.util.Collections.sort(newList, (o1, o2) -> {
int comp = Double.valueOf(o1.getSecond().doubleValue()).compareTo(o2.getSecond().doubleValue());
if (comp == 0) {
if (o1.getFirst() instanceof Comparable) {
comp = ((Comparable<T>) o1.getFirst()).compareTo(o2.getFirst());
Check.state(comp != 0);
} else {
return 0;
}
}
return comp > 0 ? -1 : 1;
});
return newList;
}
示例10: transform
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
/**
* Performs a change of variable so that the integration can be performed
* on an arbitrary interval {@code [a, b]}.
* It is assumed that the natural interval is {@code [-1, 1]}.
*
* @param rule Original points and weights.
* @param a Lower bound of the integration interval.
* @param b Lower bound of the integration interval.
* @return the points and weights adapted to the new interval.
*/
private static Pair<double[], double[]> transform(Pair<double[], double[]> rule,
double a,
double b) {
final double[] points = rule.getFirst();
final double[] weights = rule.getSecond();
// Scaling
final double scale = (b - a) / 2;
final double shift = a + scale;
for (int i = 0; i < points.length; i++) {
points[i] = points[i] * scale + shift;
weights[i] *= scale;
}
return new Pair<double[], double[]>(points, weights);
}
示例11: run
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
@SuppressWarnings("null")
public final List<Pair<I, O>> run(final Iterable<? extends I> queue, final int directThreshold, final int limit) {
final List<Callable<Pair<I, O>>> tasks = new LinkedList<>();
int i = -1;
for (final I it : queue) {
final int j = ++i;
tasks.add(() -> {
try {
return new Pair<>(it, exec(j, it));
} catch (final Exception e) {
e.printStackTrace();
throw new IllegalStateException(e);
}
});
if (i + 1 >= limit) {
break;
}
}
return new LinkedList<>(JobPool.invokeAll(tasks, directThreshold));
}
示例12: addFile
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
@SuppressWarnings("resource")
private static void addFile(final File file, final String dirBase, final List<Pair<InputStream, String>> streams,
final File target) {
if (file.isDirectory()) {
for (final File fil : file.listFiles()) {
addFile(fil, dirBase + file.getName() + "/", streams, target);
}
} else {
try {
if (!file.getName().equals(target.getName())) {
streams.add(new Pair<InputStream, String>(new FileInputStream(file), dirBase + file.getName()));
}
} catch (final FileNotFoundException e) {
throw new IllegalArgumentException(e);
}
}
}
示例13: zip2
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
public static void zip2(final List<Pair<InputStream, String>> files, final File target) {
final byte[] buffer = new byte[1024];
try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(target))) {
for (final Pair<InputStream, String> file : files) {
final ZipEntry ze = new ZipEntry(file.getSecond());
zos.putNextEntry(ze);
int len;
while ((len = file.getFirst().read(buffer)) > 0) {
zos.write(buffer, 0, len);
}
file.getFirst().close();
zos.closeEntry();
}
} catch (final IOException e) {
throw new IllegalStateException(e);
}
}
示例14: updateWordObject
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
/** Updates the current word object from the current caret offset. */
@Override
protected void updateWordObject() {
Pair<Integer, Integer> wi = getWordIndexAndRelativePosition(text.getCaretOffset());
TrpWordType newWord = getWordObject(wi.getLeft());
if (newWord==null)
return;
logger.debug("updating word object, caret offset: "+text.getCaretOffset()+", word index and relative positon: "+wi+" newWord="+newWord.getId()+" changed="+(newWord != currentWordObject));
if (newWord != currentWordObject) {
currentWordObject = newWord;
if (getType() == TranscriptionLevel.WORD_BASED) { // only send signal if in in word based editor -> should be true here always
sendSelectionChangedSignal();
text.redraw();
}
}
}
示例15: computeTopographicError
import org.apache.commons.math3.util.Pair; //导入依赖的package包/类
/**
* Computes the topographic error.
* The topographic error is the proportion of data for which first and
* second best matching units are not adjacent in the map.
*
* @param data Feature vectors.
* @param net Network.
* @param distance Distance function.
* @return the error.
* @throws NoDataException if {@code data} is empty.
*/
public static double computeTopographicError(Iterable<double[]> data,
Network net,
DistanceMeasure distance) {
int notAdjacentCount = 0;
int count = 0;
for (double[] f : data) {
++count;
final Pair<Neuron, Neuron> p = findBestAndSecondBest(f, net, distance);
if (!net.getNeighbours(p.getFirst()).contains(p.getSecond())) {
// Increment count if first and second best matching units
// are not neighbours.
++notAdjacentCount;
}
}
if (count == 0) {
throw new NoDataException();
}
return ((double) notAdjacentCount) / count;
}