本文整理汇总了Java中com.google.common.primitives.Doubles.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java Doubles.toArray方法的具体用法?Java Doubles.toArray怎么用?Java Doubles.toArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.primitives.Doubles
的用法示例。
在下文中一共展示了Doubles.toArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MutableDistribution
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/** Constructs an empty Distribution with the specified {@link DistributionFitter}. */
public MutableDistribution(DistributionFitter distributionFitter) {
this.distributionFitter = checkNotNull(distributionFitter);
ImmutableSortedSet<Double> boundaries = distributionFitter.boundaries();
checkArgument(boundaries.size() > 0);
checkArgument(Ordering.natural().isOrdered(boundaries));
this.intervalCounts = TreeRangeMap.create();
double[] boundariesArray = Doubles.toArray(distributionFitter.boundaries());
// Add underflow and overflow intervals
this.intervalCounts.put(Range.lessThan(boundariesArray[0]), 0L);
this.intervalCounts.put(Range.atLeast(boundariesArray[boundariesArray.length - 1]), 0L);
// Add finite intervals
for (int i = 1; i < boundariesArray.length; i++) {
this.intervalCounts.put(Range.closedOpen(boundariesArray[i - 1], boundariesArray[i]), 0L);
}
}
示例2: generateLibLinearProblem
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public Problem generateLibLinearProblem(int[] features, FeatureNormalizer fn) {
Problem problem = new Problem();
Vector<Double> targets = new Vector<Double>();
Vector<Feature[]> ftrVectors = new Vector<Feature[]>();
List<Pair<FeaturePack<T>, Double>> plainVectors = getPlain();
for (Pair<FeaturePack<T>, Double> vectAndGold : plainVectors) {
ftrVectors.add(LibLinearModel.featureMapToFeatures(
fn.ftrToNormalizedFtrArray(vectAndGold.first), features));
targets.add(vectAndGold.second);
}
problem.l = ftrVectors.size();
problem.n = features.length;
problem.x = ftrVectors.toArray(new Feature[][]{});
problem.y = Doubles.toArray(targets);
return problem;
}
示例3: testPercentiles_indexes_varargsAll_computeInPlace
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@AndroidIncompatible // slow
public void testPercentiles_indexes_varargsAll_computeInPlace() {
double[] dataset = Doubles.toArray(PSEUDORANDOM_DATASET);
List<Integer> indexes = new ArrayList<Integer>();
ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder();
for (int index = 0; index <= 100; index++) {
indexes.add(index);
expectedBuilder.put(index, expectedLargeDatasetPercentile(index));
}
Random random = new Random(770683168895677741L);
Collections.shuffle(indexes, random);
assertThat(percentiles().indexes(Ints.toArray(indexes)).computeInPlace(dataset))
.comparingValuesUsing(QUANTILE_CORRESPONDENCE)
.containsExactlyEntriesIn(expectedBuilder.build());
assertThat(dataset).usingExactEquality().containsExactlyElementsIn(PSEUDORANDOM_DATASET);
}
示例4: buildObject
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
@Override
public StringLabelledMatrix1D buildObject(final FudgeDeserializer deserializer, final FudgeMsg message) {
final FudgeMsg msg = message.getMessage(MATRIX_FIELD_NAME);
final List<String> keys = new LinkedList<>();
final List<Double> values = new LinkedList<>();
for (final FudgeField field : msg) {
switch (field.getOrdinal()) {
case KEY_ORDINAL:
keys.add((String) field.getValue());
break;
case VALUE_ORDINAL:
values.add((Double) field.getValue());
break;
}
}
final String labelsTitle = message.getString(LABELS_TITLE_FIELD_NAME);
final String valuesTitle = message.getString(VALUES_TITLE_FIELD_NAME);
final String[] keysArray = keys.toArray(ArrayUtils.EMPTY_STRING_ARRAY);
final double[] valuesArray = Doubles.toArray(values);
return new StringLabelledMatrix1D(keysArray, keysArray, labelsTitle, valuesArray, valuesTitle);
}
示例5: createVolatilitySurface
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/**
* Create instance of {@link VolatilitySurface}
* @param data the {@link SurfaceRawData} to create the surface from
* @return a VolatilitySurface
*/
public static VolatilitySurface createVolatilitySurface(SurfaceRawData data) {
Interpolator1D linearFlat =
CombinedInterpolatorExtrapolatorFactory.getInterpolator(Interpolator1DFactory.LINEAR,
Interpolator1DFactory.FLAT_EXTRAPOLATOR,
Interpolator1DFactory.FLAT_EXTRAPOLATOR);
GridInterpolator2D interpolator2D = new GridInterpolator2D(linearFlat, linearFlat);
double[] strikes = Doubles.toArray(data.getStrikes());
int points = strikes.length;
double[] times = new double[points];
double[] vols = new double[points];
List<Tenor> tenorList = data.getTimes();
List<Double> volList = data.getzData();
for (int i = 0; i < points; i++) {
Tenor tenor = tenorList.get(i);
times[i] = tenor.getPeriod().getDays() / 365d;
vols[i] = volList.get(i) / 100d;
}
InterpolatedDoublesSurface surface = InterpolatedDoublesSurface.from(times, strikes, vols, interpolator2D);
return new VolatilitySurface(surface);
}
示例6: createPriceSurface
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/**
* Create instance of {@link NodalDoublesSurface}
* @param data the {@link SurfaceRawData} to create the surface from
* @return a VolatilitySurface
*/
public static NodalDoublesSurface createPriceSurface(SurfaceRawData data) {
double[] strikes = Doubles.toArray(data.getStrikes());
int points = strikes.length;
double[] times = new double[points];
double[] prices = new double[points];
List<Tenor> tenorList = data.getTimes();
List<Double> priceList = data.getzData();
for (int i = 0; i < points; i++) {
Tenor tenor = tenorList.get(i);
times[i] = tenor.getPeriod().getDays() / 365d;
prices[i] = priceList.get(i);
}
return new NodalDoublesSurface(times, strikes, prices);
}
示例7: ATM
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/**
* Creates a new atm instance with the {@link de.Linus122.TimeIsMoney.Main} class.
*
* @param plugin The {@link de.Linus122.TimeIsMoney.Main} class that implements {@link org.bukkit.plugin.java.JavaPlugin}.
*/
public ATM(Main plugin) {
this.plugin = plugin;
plugin.getServer().getPluginManager().registerEvents(this, plugin);
plugin.getCommand("atm").setExecutor(this);
if (!bankAccountsFile.exists()) {
try {
bankAccountsFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
bankAccountsConfig = YamlConfiguration.loadConfiguration(bankAccountsFile);
worths = Doubles.toArray(Main.finalconfig.getDoubleList("atm_worth_gradation"));
}
示例8: testSliceSamplingOfMonotonicBetaDistribution
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
/**
* Test slice sampling of a monotonic beta distribution as an example of sampling of a bounded random variable.
* Checks that input mean and variance are recovered by 10000 samples to a relative error of 0.5% and 2%,
* respectively.
*/
@Test
public void testSliceSamplingOfMonotonicBetaDistribution() {
rng.setSeed(RANDOM_SEED);
final double alpha = 10.;
final double beta = 1.;
final BetaDistribution betaDistribution = new BetaDistribution(alpha, beta);
final Function<Double, Double> betaLogPDF = betaDistribution::logDensity;
final double xInitial = 0.5;
final double xMin = 0.;
final double xMax = 1.;
final double width = 0.1;
final int numSamples = 10000;
final SliceSampler betaSampler = new SliceSampler(rng, betaLogPDF, xMin, xMax, width);
final double[] samples = Doubles.toArray(betaSampler.sample(xInitial, numSamples));
final double mean = betaDistribution.getNumericalMean();
final double variance = betaDistribution.getNumericalVariance();
final double sampleMean = new Mean().evaluate(samples);
final double sampleVariance = new Variance().evaluate(samples);
Assert.assertEquals(relativeError(sampleMean, mean), 0., 0.005);
Assert.assertEquals(relativeError(sampleVariance, variance), 0., 0.02);
}
示例9: testPercentiles_indexes_varargsAll_computeInPlace
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public void testPercentiles_indexes_varargsAll_computeInPlace() {
double[] dataset = Doubles.toArray(PSEUDORANDOM_DATASET);
List<Integer> indexes = new ArrayList<Integer>();
ImmutableMap.Builder<Integer, Double> expectedBuilder = ImmutableMap.builder();
for (int index = 0; index <= 100; index++) {
indexes.add(index);
expectedBuilder.put(index, expectedLargeDatasetPercentile(index));
}
Random random = new Random(770683168895677741L);
Collections.shuffle(indexes, random);
assertQuantilesMap(expectedBuilder.build(),
percentiles().indexes(Ints.toArray(indexes)).computeInPlace(dataset));
assertDatasetAnyOrder(PSEUDORANDOM_DATASET, dataset);
}
示例10: testScale_indexes_collection_computeInPlace
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public void testScale_indexes_collection_computeInPlace() {
double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES);
ImmutableMap<Integer, Double> expected = ImmutableMap.of(
0, SIXTEEN_SQUARES_MIN,
10, SIXTEEN_SQUARES_MAX,
5, SIXTEEN_SQUARES_MEDIAN,
1, SIXTEEN_SQUARES_DECILE_1,
8, SIXTEEN_SQUARES_DECILE_8
);
assertQuantilesMap(expected,
Quantiles.scale(10).indexes(ImmutableList.of(0, 10, 5, 1, 8, 1)).computeInPlace(dataset));
assertDatasetAnyOrder(SIXTEEN_SQUARES_DOUBLES, dataset);
}
示例11: testQuartiles_indexes_varargs_computeInPlace
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public void testQuartiles_indexes_varargs_computeInPlace() {
double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES);
assertThat(quartiles().indexes(1, 3).computeInPlace(dataset))
.comparingValuesUsing(QUANTILE_CORRESPONDENCE)
.containsExactly(
1, SIXTEEN_SQUARES_QUARTILE_1,
3, SIXTEEN_SQUARES_QUARTILE_3);
assertThat(dataset).usingExactEquality().containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES);
}
示例12: testScale_index_compute_doubleVarargs
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public void testScale_index_compute_doubleVarargs() {
double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES);
assertThat(Quantiles.scale(10).index(1).compute(dataset))
.isWithin(ALLOWED_ERROR)
.of(SIXTEEN_SQUARES_DECILE_1);
assertThat(dataset)
.usingExactEquality()
.containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES)
.inOrder();
}
示例13: testScale_index_computeInPlace
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public void testScale_index_computeInPlace() {
double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES);
assertThat(Quantiles.scale(10).index(1).computeInPlace(dataset))
.isWithin(ALLOWED_ERROR)
.of(SIXTEEN_SQUARES_DECILE_1);
assertThat(dataset).usingExactEquality().containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES);
}
示例14: testScale_indexes_varargs_computeInPlace
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public void testScale_indexes_varargs_computeInPlace() {
double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES);
assertThat(Quantiles.scale(10).indexes(0, 10, 5, 1, 8, 1).computeInPlace(dataset))
.comparingValuesUsing(QUANTILE_CORRESPONDENCE)
.containsExactly(
0, SIXTEEN_SQUARES_MIN,
10, SIXTEEN_SQUARES_MAX,
5, SIXTEEN_SQUARES_MEDIAN,
1, SIXTEEN_SQUARES_DECILE_1,
8, SIXTEEN_SQUARES_DECILE_8);
assertThat(dataset).usingExactEquality().containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES);
}
示例15: testScale_indexes_collection_computeInPlace
import com.google.common.primitives.Doubles; //导入方法依赖的package包/类
public void testScale_indexes_collection_computeInPlace() {
double[] dataset = Doubles.toArray(SIXTEEN_SQUARES_DOUBLES);
assertThat(
Quantiles.scale(10)
.indexes(ImmutableList.of(0, 10, 5, 1, 8, 1))
.computeInPlace(dataset))
.comparingValuesUsing(QUANTILE_CORRESPONDENCE)
.containsExactly(
0, SIXTEEN_SQUARES_MIN,
10, SIXTEEN_SQUARES_MAX,
5, SIXTEEN_SQUARES_MEDIAN,
1, SIXTEEN_SQUARES_DECILE_1,
8, SIXTEEN_SQUARES_DECILE_8);
assertThat(dataset).usingExactEquality().containsExactlyElementsIn(SIXTEEN_SQUARES_DOUBLES);
}