本文整理匯總了Java中org.apache.commons.math3.util.Pair.getSecond方法的典型用法代碼示例。如果您正苦於以下問題:Java Pair.getSecond方法的具體用法?Java Pair.getSecond怎麽用?Java Pair.getSecond使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.math3.util.Pair
的用法示例。
在下文中一共展示了Pair.getSecond方法的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: 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);
}
}
示例3: 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);
}
}
示例4: 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.");
}
}
示例5: wrap
import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
/**
* Create a JsonObject wrapping a raw {@code Pair<Long msec,T reading>>} sample.
* @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;
}
示例6: 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);
}
}
示例7: 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);
}
示例8: 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);
}
示例9: 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());
});
}
示例10: 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));
}
}
示例11: create
import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
@Nonnull
public static <S extends Sample> PreprocessingPipeline<S> create(final Iterable<S> trainingSamples,
final IFeatureProvider<S> provider, final IFeatureFilter filter, final Normalization normalization,
final IArguments arguments) {
final Pair<String[], Map<String, Stats>> featureSelection = provider
.featureNames(new Samples<>(trainingSamples), arguments);
return new PreprocessingPipeline<>(provider, filter.allowedFeatures(featureSelection.getFirst()),
featureSelection.getSecond(), normalization, arguments);
}
示例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: test
import org.apache.commons.math3.util.Pair; //導入方法依賴的package包/類
private static void test(final Pair<? extends ILearner, Double> tuple, final IDataset<SimpleSample, ?> instances,
final ObjectiveFunction<? super SimpleSample, ? super Serializable> objective) {
if (tuple != null) {
final double expected = tuple.getSecond();
Assert.assertTrue(expected + " > -0.82", expected > -0.82);
Tests.testLearner(tuple.getFirst(), instances, objective, expected);
}
}
示例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);
}
}