本文整理汇总了Java中org.apache.commons.math3.util.Pair.getFirst方法的典型用法代码示例。如果您正苦于以下问题:Java Pair.getFirst方法的具体用法?Java Pair.getFirst怎么用?Java Pair.getFirst使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.util.Pair
的用法示例。
在下文中一共展示了Pair.getFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendTupleToActuator
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
protected void sendTupleToActuator(Tuple tuple){
/*for(Pair<Integer, Double> actuatorAssociation : getAssociatedActuatorIds()){
int actuatorId = actuatorAssociation.getFirst();
double delay = actuatorAssociation.getSecond();
if(actuatorId == tuple.getActuatorId()){
send(actuatorId, delay, FogEvents.TUPLE_ARRIVAL, tuple);
return;
}
}
int childId = getChildIdForTuple(tuple);
if(childId != -1)
sendDown(tuple, childId);*/
for(Pair<Integer, Double> actuatorAssociation : getAssociatedActuatorIds()){
int actuatorId = actuatorAssociation.getFirst();
double delay = actuatorAssociation.getSecond();
String actuatorType = ((Actuator)CloudSim.getEntity(actuatorId)).getActuatorType();
if(tuple.getDestModuleName().equals(actuatorType)){
send(actuatorId, delay, FogEvents.TUPLE_ARRIVAL, tuple);
return;
}
}
for(int childId : getChildrenIds()){
sendDown(tuple, childId);
}
}
示例2: handleEventChange
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
/**
* Adds the keys we can display in the camera window to the dropdown list.
*
* @param itemKeyPair the current data item we want to display
*/
@Override
@Subscribe
public void handleEventChange(Pair<Data, String> itemKeyPair) {
this.dataItem = itemKeyPair.getFirst();
String selectedKey = (String) keyComboBox.getSelectedItem();
keyComboBox.removeAllItems();
for (String key : dataItem.keySet()) {
double[] data = Utils.toDoubleArray(dataItem.get(key));
if (data != null && data.length > 0 && data.length % Constants.N_PIXELS == 0) {
keyComboBox.addItem(key);
if (key.equals(selectedKey)) {
keyComboBox.setSelectedItem(key);
}
}
}
}
示例3: handleEventChange
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
@Subscribe
public void handleEventChange(Pair<Data, String> itemKeyPair) {
log.debug("hexmap got a new item");
String key;
if (defaultKey != null) {
key = defaultKey;
} else {
key = itemKeyPair.getSecond();
}
this.dataItem = itemKeyPair.getFirst();
minValueInData = 0;
maxValueInData = 0;
overlays = updateOverlays(overlayKeys, dataItem);
if (dataItem.containsKey(key)) {
updateMapDisplay(dataItem, key);
} else {
log.error("The key: " + key
+ " was not found in the data item. Nothing to display.");
}
}
示例4: handleEventChange
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
@Override
@Subscribe
public void handleEventChange(Pair<Data, String> itemKeyPair) {
Data item = itemKeyPair.getFirst();
Integer roi = (Integer) item.get("ROI");
if (roi != null) {
slider.setMaximum(roi - 1);
}
Serializable eventNum = item.get("EventNum");
if (eventNum != null) {
eventNumber.setText(eventNum.toString());
}
Serializable trigger = item.get("TriggerType");
if (trigger != null) {
triggerTypeField.setText(trigger.toString());
}
Serializable file = item.get("@source");
if (file != null) {
fileField.setText(file.toString());
}
}
示例5: evaluate
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
/** {@inheritDoc} */
public Evaluation evaluate(final RealVector point) {
// Copy so optimizer can change point without changing our instance.
final RealVector p = paramValidator == null ?
point.copy() :
paramValidator.validate(point.copy());
if (lazyEvaluation) {
return new LazyUnweightedEvaluation((ValueAndJacobianFunction) model,
target,
p);
} else {
// Evaluate value and jacobian in one function call.
final Pair<RealVector, RealMatrix> value = model.value(p);
return new UnweightedEvaluation(value.getFirst(),
value.getSecond(),
target,
p);
}
}
示例6: 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);
}
示例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: getBySlug
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
private <T> T getBySlug(MaprDbDao<T> dbDao, String slug) {
Pair<String, Long> slugPostfixPair = getSlugPostfixPair(slug);
String slugWithoutPostfix = slugPostfixPair.getFirst();
Long postfix = slugPostfixPair.getSecond();
if (postfix == null) {
throw new IllegalArgumentException("Slug name must contain numeric postfix");
}
return dbDao.processStore((connection, store) -> {
QueryCondition condition = connection.newCondition()
.and()
.is("slug_name", QueryCondition.Op.EQUAL, slugWithoutPostfix)
.is("slug_postfix", QueryCondition.Op.EQUAL, postfix)
.close();
Query query = connection.newQuery()
.select("*")
.where(condition.build())
.build();
Iterator<Document> iterator = store.findQuery(query).iterator();
if (!iterator.hasNext()) {
return null;
}
return dbDao.mapOjaiDocument(iterator.next());
});
}
示例9: assertStateCompleted
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
/**
* Given the result of {@link WaitUntilCompleteListener#waitForCompletion}, this method fails if the completed state
* is not as expected, or if an exception is thrown. The completed state could be COMPLETED or CANCELED. This state
* is set when {@link WaitUntilCompleteListener#queryCompleted} is called.
*/
private static void assertStateCompleted(final Pair<QueryState, Exception> result, final QueryState expectedState) {
final QueryState actualState = result.getFirst();
final Exception exception = result.getSecond();
if (actualState != expectedState || exception != null) {
fail(String.format("Query state is incorrect (expected: %s, actual: %s) AND/OR \nException thrown: %s",
expectedState, actualState, exception == null ? "none." : exception));
}
}
示例10: assertFailsWithException
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
/**
* Given a set of controls, this method ensures TEST_QUERY fails with the given class and desc.
*/
private static void assertFailsWithException(final String controls, final Class<? extends Throwable> exceptionClass,
final String exceptionDesc, final String query) {
setControls(controls);
final WaitUntilCompleteListener listener = new WaitUntilCompleteListener();
QueryTestUtil.testWithListener(drillClient, QueryType.SQL, query, listener);
final Pair<QueryState, Exception> result = listener.waitForCompletion();
final QueryState state = result.getFirst();
assertTrue(String.format("Query state should be FAILED (and not %s).", state), state == QueryState.FAILED);
assertExceptionMessage(result.getSecond(), exceptionClass, exceptionDesc);
}
示例11: gini
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
private static <T> double gini(final T[] preds, final Object[] expected, final boolean doPerfect) {
final List<Pair<Object, T>> sortedByPdesc = new LinkedList<>();
for (int i = 0; i < preds.length; ++i) {
sortedByPdesc.add(new Pair<>(expected[i], preds[i]));
}
final boolean isBinary = sortedByPdesc.get(0).getSecond() instanceof Boolean;
Collections.sort(sortedByPdesc, (o1, o2) -> {
if (doPerfect) {
if (isBinary) {
return ((Boolean) o1.getFirst()).booleanValue() ? -1 : 1;
}
return ((Number) o1.getFirst()).doubleValue() >= ((Number) o2.getFirst()).doubleValue() ? -1 : 1;
}
return ((Number) o1.getSecond()).doubleValue() >= ((Number) o2.getSecond()).doubleValue() ? -1 : 1;
});
double sum = 0;
double giniSum = 0;
for (final Pair<Object, T> prediction : sortedByPdesc) {
if (isBinary) {
sum += (Boolean) prediction.getFirst() ? 1 : 0;
} else {
sum += (Double) prediction.getFirst();
}
giniSum += sum;
}
giniSum = giniSum / sum - (sortedByPdesc.size() + 1.0) / 2;
return giniSum / sortedByPdesc.size();
}
示例12: run
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
@Override
public ModelPipeline<S, O> run(final Iterable<S> data, final Iterable<S> unlabled,
final FeaturesConfig<? extends S, O> config, final int labelIndex) {
final Pair<Iterable<S>, PreprocessingPipeline<S>> modelAndPipe = modelAndPipe(data,
config,
learner.getOriginalArguments());
final Iterable<S> samples = modelAndPipe.getFirst();
final PreprocessingPipeline<S> pipe = modelAndPipe.getSecond();
final File cacheFile = new File("cache/samples_" + samples.hashCode() + "_" + pipe.hashCode());
final IModel<S, O> model = (IModel<S, O>) learner
.run(createSamples(samples, pipe, cacheFile), null, config, labelIndex);
return new ModelPipeline<>(model, pipe, config == null ? null : config.getPostProcessor(), labelIndex);
}
示例13: modelAndPipe
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
public Pair<Iterable<S>, PreprocessingPipeline<S>> modelAndPipe(final Iterable<S> data,
final FeaturesConfig<? extends S, O> origConfig, final @Nonnull IArguments arguments) {
final Pair<Iterable<S>, List<S>> split = SplitSimulation.split(data, trainRatio, null);
final Iterable<S> train = split.getFirst();
List<S> valid = split.getSecond();
if (trainRatio < 1) {
logger.info("Learning on " + ((List<?>) train).size() + " samples, " + valid.size() + " ignored.");
}
FeaturesConfig<? extends S, O> config = null;
PreprocessingPipeline<S> pipe = null;
if (preprocess) {
if (selection != null) {
final DoublePair<Set<String>> result = selection.run(train, origConfig, learner);
if (result != null) {
config = new SimpleFeatureConfig<>(origConfig.newFeatureProvider(),
new ManualSelectionFilter(result.getKey(), true), null);
}
}
if (config == null) {
config = origConfig;
}
pipe = new PreprocessingPipelineSupplier<>(train, (FeaturesConfig<S, O>) config, serializer, arguments)
.get();
} else {
config = origConfig;
}
valid = null;
return new Pair<>(train, pipe);
}
示例14: handleEventChange
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
@Override
@Subscribe
public void handleEventChange(Pair<Data, String> itemKeyPair) {
this.item = itemKeyPair.getFirst();
if (item.containsKey("NROI")) {
this.roi = (Integer) item.get("NROI");
}
drawPlot();
}
示例15: solve
import org.apache.commons.math3.util.Pair; //导入方法依赖的package包/类
@Override
protected RealVector solve(final RealMatrix jacobian,
final RealVector residuals) {
try {
final Pair<RealMatrix, RealVector> normalEquation =
computeNormalMatrix(jacobian, residuals);
final RealMatrix normal = normalEquation.getFirst();
final RealVector jTr = normalEquation.getSecond();
return new CholeskyDecomposition(
normal, SINGULARITY_THRESHOLD, SINGULARITY_THRESHOLD)
.getSolver()
.solve(jTr);
} catch (NonPositiveDefiniteMatrixException e) {
throw new ConvergenceException(LocalizedFormats.UNABLE_TO_SOLVE_SINGULAR_PROBLEM, e);
}
}