当前位置: 首页>>代码示例>>Java>>正文


Java Doubles.toArray方法代码示例

本文整理汇总了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);
  }
}
 
开发者ID:google,项目名称:java-monitoring-client-library,代码行数:22,代码来源:MutableDistribution.java

示例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;
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:18,代码来源:ExampleGatherer.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:17,代码来源:QuantilesTest.java

示例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);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:LabelledMatrix1DBuilder.java

示例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);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:29,代码来源:VolUtils.java

示例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);
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:22,代码来源:VolUtils.java

示例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"));
}
 
开发者ID:mastercake10,项目名称:TimeIsMoney,代码行数:22,代码来源:ATM.java

示例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);
}
 
开发者ID:broadinstitute,项目名称:gatk-protected,代码行数:30,代码来源:SliceSamplerUnitTest.java

示例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);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:15,代码来源:QuantilesTest.java

示例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);
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:14,代码来源:QuantilesTest.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:10,代码来源:QuantilesTest.java

示例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();
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:QuantilesTest.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:8,代码来源:QuantilesTest.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:13,代码来源:QuantilesTest.java

示例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);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:QuantilesTest.java


注:本文中的com.google.common.primitives.Doubles.toArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。