本文整理汇总了Java中it.unimi.dsi.fastutil.doubles.DoubleArrayList.size方法的典型用法代码示例。如果您正苦于以下问题:Java DoubleArrayList.size方法的具体用法?Java DoubleArrayList.size怎么用?Java DoubleArrayList.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.doubles.DoubleArrayList
的用法示例。
在下文中一共展示了DoubleArrayList.size方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reduceCurveNodes
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
* Matrix reducing the nodes, to which portfolio has sensitivities, to new nodes (objNodes), for which sensitivity is accounted for, when relevant curves are already known
* @param curves The relevant curves
* @param objNodes The objective nodes on which sensitivity is to be accounted for
* @return The matrix
*/
public DoubleMatrix2D reduceCurveNodes(final YieldAndDiscountCurve[] curves, final double[] objNodes) {
ArgumentChecker.notNull(curves, "curves");
ArgumentChecker.notNull(objNodes, "objNodes");
int nCurves = curves.length;
DoubleArrayList result = new DoubleArrayList();
for (int i = 0; i < nCurves; ++i) {
Double[] nodes = getNodes(curves[i]);
for (final double element : nodes) {
result.add(element);
}
}
int totalNum = result.size();
int[] tmp = toPositions(objNodes, result.toDoubleArray());
int objNum = tmp.length;
double[][] res = new double[objNum][totalNum];
for (int i = 0; i < objNum; ++i) {
Arrays.fill(res[i], 0.0);
res[i][tmp[i]] = 1.0;
}
return new DoubleMatrix2D(res);
}
示例2: getValueOnQuantile
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
* List will be sorted after passing to this function,
* so a pre-sorting is not needed.
*
* @param list
* @param quantile
* @return
*/
public static double getValueOnQuantile(DoubleArrayList list, double quantile) {
checkArgument(quantile >= 0 && quantile <= 1, "quantile must be in range [0, 1]");
Collections.sort(list, new Comparator<Double>() {
@Override
public int compare(Double o1, Double o2) {
return o1.compareTo(o2);
}
});
int index = (int) (list.size()*quantile);
return list.get(index);
}
示例3: extractFinalResult
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Nonnull
@Override
public Double extractFinalResult(@Nonnull DoubleArrayList intermediateResult) {
int size = intermediateResult.size();
if (size == 0) {
return DEFAULT_FINAL_RESULT;
} else {
Collections.sort(intermediateResult);
return intermediateResult.get((int) ((long) intermediateResult.size() * _percentile / 100));
}
}
示例4: serializeDoubleArrayList
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
/**
* Helper method to serialize a {@link DoubleArrayList}.
*/
private static byte[] serializeDoubleArrayList(DoubleArrayList doubleArray) {
int size = doubleArray.size();
int byteBufferSize = V1Constants.Numbers.INTEGER_SIZE + (size * V1Constants.Numbers.DOUBLE_SIZE);
ByteBuffer byteBuffer = ByteBuffer.allocate(byteBufferSize);
byteBuffer.putInt(size);
double[] elements = doubleArray.elements();
for (int i = 0; i < size; i++) {
byteBuffer.putDouble(elements[i]);
}
return byteBuffer.array();
}
示例5: execute
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
public Set<ComputedValue> execute(final FunctionExecutionContext executionContext, final FunctionInputs inputs, final ComputationTarget target,
final Set<ValueRequirement> desiredValues) {
final ValueProperties properties = desiredValues.iterator().next().getConstraints().copy().get();
final VolatilityCubeData<Tenor, Tenor, Double> volatilityCubeData = (VolatilityCubeData<Tenor, Tenor, Double>) inputs.getValue(STANDARD_VOLATILITY_CUBE_DATA);
final SurfaceData<Tenor, Tenor> forwardSwapSurface = (SurfaceData<Tenor, Tenor>) inputs.getValue(SURFACE_DATA);
final DoubleArrayList swapMaturitiesList = new DoubleArrayList();
final DoubleArrayList swaptionExpiriesList = new DoubleArrayList();
final DoubleArrayList alphaList = new DoubleArrayList();
final DoubleArrayList betaList = new DoubleArrayList();
final DoubleArrayList nuList = new DoubleArrayList();
final DoubleArrayList rhoList = new DoubleArrayList();
final DoubleArrayList chiSqList = new DoubleArrayList();
final Map<DoublesPair, DoubleMatrix2D> inverseJacobians = new HashMap<>();
final Map<Pair<Tenor, Tenor>, Double[]> fittedRelativeStrikes = new HashMap<>();
for (final Tenor expiry : volatilityCubeData.getUniqueXValues()) {
final double swaptionExpiry = getTime(expiry);
for (final Tenor maturity : volatilityCubeData.getUniqueYValues()) {
final double swapMaturity = getTime(maturity);
final double forward = forwardSwapSurface.getValue(expiry, maturity);
if (volatilityCubeData.asMap().containsKey(Triple.of(expiry, maturity, forward))) {
final List<ObjectsPair<Double, Double>> strikeVol = volatilityCubeData.getZValuesForXandY(expiry, maturity);
final int nVols = strikeVol.size();
if (nVols < 4) {
s_logger.info("Smile had less than 4 points for expiry = {} and maturity = {}", expiry, maturity);
continue;
}
final double[] strikes = new double[nVols];
final Double[] strikeCopy = new Double[nVols]; //TODO
final double[] blackVols = new double[nVols];
final double[] errors = new double[nVols];
int i = 0;
for (final ObjectsPair<Double, Double> sv : strikeVol) {
strikes[i] = sv.getFirst();
strikeCopy[i] = sv.getFirst();
blackVols[i] = sv.getSecond();
errors[i++] = ERROR;
}
final LeastSquareResultsWithTransform fittedResult = new SABRModelFitter(forward, strikes, swaptionExpiry, blackVols, errors, SABR_FUNCTION).solve(SABR_INITIAL_VALUES, FIXED);
final DoubleMatrix1D parameters = fittedResult.getModelParameters();
swapMaturitiesList.add(swapMaturity);
swaptionExpiriesList.add(swaptionExpiry);
alphaList.add(parameters.getEntry(0));
betaList.add(parameters.getEntry(1));
rhoList.add(parameters.getEntry(2));
nuList.add(parameters.getEntry(3));
final DoublesPair expiryMaturityPair = DoublesPair.of(swaptionExpiry, swapMaturity);
inverseJacobians.put(expiryMaturityPair, fittedResult.getModelParameterSensitivityToData());
chiSqList.add(fittedResult.getChiSq());
fittedRelativeStrikes.put(Pairs.of(expiry, maturity), strikeCopy);
}
}
}
if (swapMaturitiesList.size() < 5) { //don't have sufficient fits to construct a surface
throw new OpenGammaRuntimeException("Could not construct SABR parameter surfaces; have under 5 surface points");
}
final double[] swapMaturities = swapMaturitiesList.toDoubleArray();
final double[] swaptionExpiries = swaptionExpiriesList.toDoubleArray();
final double[] alpha = alphaList.toDoubleArray();
final double[] beta = betaList.toDoubleArray();
final double[] nu = nuList.toDoubleArray();
final double[] rho = rhoList.toDoubleArray();
final InterpolatedDoublesSurface alphaSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, alpha, INTERPOLATOR, "SABR alpha surface");
final InterpolatedDoublesSurface betaSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, beta, INTERPOLATOR, "SABR beta surface");
final InterpolatedDoublesSurface nuSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, nu, INTERPOLATOR, "SABR nu surface");
final InterpolatedDoublesSurface rhoSurface = InterpolatedDoublesSurface.from(swaptionExpiries, swapMaturities, rho, INTERPOLATOR, "SABR rho surface");
final SABRFittedSurfaces fittedSurfaces = new SABRFittedSurfaces(alphaSurface, betaSurface, nuSurface, rhoSurface, inverseJacobians);
final ValueSpecification sabrSurfacesSpecification = new ValueSpecification(SABR_SURFACES, target.toSpecification(), properties);
final ValueSpecification smileIdsSpecification = new ValueSpecification(VOLATILITY_CUBE_FITTED_POINTS, target.toSpecification(), properties);
return Sets.newHashSet(new ComputedValue(sabrSurfacesSpecification, fittedSurfaces), new ComputedValue(smileIdsSpecification, new FittedSmileDataPoints(fittedRelativeStrikes)));
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:72,代码来源:SABRNonLinearLeastSquaresSwaptionCubeFittingFunction.java
示例6: convertForDisplay
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
@Override
/**
* Put together a map of results such that VolatilitySurfaceDetail.js can render it
* Required outputs:
* <p>'xs' and 'ys' - String arrays for axes labels.
* <p>'surface' - 2D double array with size matching xs and ys
*/
public Object convertForDisplay(ResultConverterCache context, ValueSpecification valueSpec, VolatilitySurface value, ConversionMode mode) {
Map<String, Object> result = new HashMap<String, Object>();
Surface<Double, Double, Double> inputSurface = value.getSurface();
if (inputSurface instanceof DoublesSurface) {
// Compute unique X data
Double[] xData = inputSurface.getXData();
DoubleArrayList uniqueXs = new DoubleArrayList();
for (int i = 0; i < xData.length; i++) {
if (!uniqueXs.contains(xData[i])) {
uniqueXs.add(xData[i]);
}
}
final int xCount = uniqueXs.size();
result.put("xCount", xCount);
// Compute unique Y data
Double[] yData = inputSurface.getYData();
DoubleArrayList uniqueYs = new DoubleArrayList();
for (int j = 0; j < yData.length; j++) {
if (!uniqueYs.contains(yData[j])) {
uniqueYs.add(yData[j]);
}
}
Collections.sort(uniqueYs);
final int yCount = uniqueYs.size();
result.put("yCount", yCount);
// Convert for display
if (mode == ConversionMode.FULL) {
String[] xStrings = new String[xCount];
for (int i = 0; i < xCount; i++) {
xStrings[i] = uniqueXs.get(i).toString();
}
result.put("xs", xStrings);
String[] ysStrings = new String[yCount];
for (int i = 0; i < yCount; i++) {
ysStrings[i] = uniqueYs.get(i).toString();
}
result.put("ys", ysStrings);
double[][] outputSurface = new double[yCount][xCount];
boolean[][] missingValues = new boolean[yCount][xCount];
// Summary view includes only the actual points of the surface
for (int y = 0; y < yCount; y++) {
for (int x = 0; x < xCount; x++) {
Double volatility = inputSurface.getZValue(uniqueXs.get(x), uniqueYs.get(y));
if (volatility == null) {
missingValues[y][x] = true;
//Some 'obviously wrong' value in case client displays it. Can't use NaN
outputSurface[y][x] = Double.MAX_VALUE;
} else {
outputSurface[y][x] = volatility;
}
}
}
result.put("surface", outputSurface);
result.put("missingValues", missingValues);
}
} else {
result.put("summary", "Converter only displays VolatilitySurface(DoublesSurface) as we require axes data");
}
return result;
}
示例7: calculateCorrelations
import it.unimi.dsi.fastutil.doubles.DoubleArrayList; //导入方法依赖的package包/类
private double[][] calculateCorrelations(double[][] results, String datasetNames[]) {
DatasetMetaDataMapping mapping = DatasetMetaDataMapping.getInstance();
DatasetMetaData metadata[] = new DatasetMetaData[datasetNames.length];
for (int i = 0; i < datasetNames.length; ++i) {
metadata[i] = mapping.getMetaData(datasetNames[i]);
}
double correlations[][] = new double[results.length][CORRELATION_TABLE_COLUMN_HEADINGS.length];
DoubleArrayList annotatorResults = new DoubleArrayList(datasetNames.length);
DoubleArrayList numberOfDocuments = new DoubleArrayList(datasetNames.length);
DoubleArrayList avgDocumentLength = new DoubleArrayList(datasetNames.length);
DoubleArrayList numberOfEntities = new DoubleArrayList(datasetNames.length);
DoubleArrayList entitiesPerDoc = new DoubleArrayList(datasetNames.length);
DoubleArrayList entitiesPerToken = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfPersons = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfOrganizations = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfLocations = new DoubleArrayList(datasetNames.length);
DoubleArrayList amountOfOthers = new DoubleArrayList(datasetNames.length);
double annotatorResultsAsArray[];
int elementCount;
for (int i = 0; i < correlations.length; ++i) {
Arrays.fill(correlations[i], NOT_AVAILABLE_SENTINAL);
// load the values for this annotator
annotatorResults.clear();
numberOfDocuments.clear();
avgDocumentLength.clear();
numberOfEntities.clear();
entitiesPerDoc.clear();
entitiesPerToken.clear();
amountOfPersons.clear();
amountOfOrganizations.clear();
amountOfLocations.clear();
amountOfOthers.clear();
for (int j = 0; j < results[i].length; ++j) {
if ((metadata[j] != null) && (results[i][j] >= 0)) {
annotatorResults.add(results[i][j]);
numberOfDocuments.add(metadata[j].numberOfDocuments);
avgDocumentLength.add(metadata[j].avgDocumentLength);
numberOfEntities.add(metadata[j].numberOfEntities);
entitiesPerDoc.add(metadata[j].entitiesPerDoc);
entitiesPerToken.add(metadata[j].entitiesPerToken);
amountOfPersons.add(metadata[j].amountOfPersons);
amountOfOrganizations.add(metadata[j].amountOfOrganizations);
amountOfLocations.add(metadata[j].amountOfLocations);
amountOfOthers.add(metadata[j].amountOfOthers);
}
}
// If we have enough datasets with metadata and results of the
// current annotator for these datasets
elementCount = annotatorResults.size();
if (elementCount > MIN_NUMBER_OF_VALUES_FOR_CORR_CALC) {
annotatorResultsAsArray = annotatorResults.toArray(new double[elementCount]);
correlations[i][0] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, numberOfDocuments.toArray(new double[elementCount]));
correlations[i][1] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, avgDocumentLength.toArray(new double[elementCount]));
correlations[i][2] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, numberOfEntities.toArray(new double[elementCount]));
correlations[i][3] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, entitiesPerDoc.toArray(new double[elementCount]));
correlations[i][4] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, entitiesPerToken.toArray(new double[elementCount]));
correlations[i][5] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfPersons.toArray(new double[elementCount]));
correlations[i][6] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfOrganizations.toArray(new double[elementCount]));
correlations[i][7] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfLocations.toArray(new double[elementCount]));
correlations[i][8] = PearsonsSampleCorrelationCoefficient.calculateRankCorrelation(
annotatorResultsAsArray, amountOfOthers.toArray(new double[elementCount]));
// correlations[i][9] = annotatorResultsAsArray.length;
}
}
return correlations;
}