本文整理匯總了Java中com.google.common.primitives.Doubles類的典型用法代碼示例。如果您正苦於以下問題:Java Doubles類的具體用法?Java Doubles怎麽用?Java Doubles使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Doubles類屬於com.google.common.primitives包,在下文中一共展示了Doubles類的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: parseToken
import com.google.common.primitives.Doubles; //導入依賴的package包/類
void parseToken(int i, String token) {
if (dataTypes[i - 2] == null) {
// test double parsing, in case of error we consider it a string time series
if (Doubles.tryParse(token) != null) {
dataTypes[i - 2] = TimeSeriesDataType.DOUBLE;
TDoubleArrayList doubleValues = createDoubleValues();
doubleValues.add(parseDouble(token));
values[i - 2] = doubleValues;
} else {
dataTypes[i - 2] = TimeSeriesDataType.STRING;
List<String> stringValues = createStringValues();
stringValues.add(checkString(token));
values[i - 2] = stringValues;
}
} else {
if (dataTypes[i - 2] == TimeSeriesDataType.DOUBLE) {
((TDoubleArrayList) values[i - 2]).add(parseDouble(token));
} else if (dataTypes[i - 2] == TimeSeriesDataType.STRING) {
((List<String>) values[i - 2]).add(checkString(token));
} else {
throw assertDataType(dataTypes[i - 2]);
}
}
}
示例4: applyDefaultSort
import com.google.common.primitives.Doubles; //導入依賴的package包/類
public void applyDefaultSort(){
sortKeys.sort((a, b) -> {
int res =0;
if(hints != null){
res = -1*Ints.compare(getRowHintCount(a), getRowHintCount(b));
}
if(res==0)
res = -1*Ints.compare(getRowDimCount(a), getRowDimCount(b));
if(res==0)
res = Doubles.compare(getRowCost(a), getRowCost(b));
if(res==0){
if(getRootSelectionCount(a)==0)
res = 1;
if(getRootSelectionCount(b)==0 && res==0)
res = -1;
}
return res;
});
}
示例5: 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);
}
示例6: parseDouble
import com.google.common.primitives.Doubles; //導入依賴的package包/類
public static double parseDouble(String input) throws NumberInvalidException
{
try
{
double d0 = Double.parseDouble(input);
if (!Doubles.isFinite(d0))
{
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
}
else
{
return d0;
}
}
catch (NumberFormatException var3)
{
throw new NumberInvalidException("commands.generic.num.invalid", new Object[] {input});
}
}
示例7: toArray
import com.google.common.primitives.Doubles; //導入依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
if (componentType == boolean.class) {
return Booleans.toArray((Collection) values);
} else if (componentType == byte.class) {
return Bytes.toArray((Collection) values);
} else if (componentType == short.class) {
return Shorts.toArray((Collection) values);
} else if (componentType == int.class) {
return Ints.toArray((Collection) values);
} else if (componentType == long.class) {
return Longs.toArray((Collection) values);
} else if (componentType == float.class) {
return Floats.toArray((Collection) values);
} else if (componentType == double.class) {
return Doubles.toArray((Collection) values);
} else if (componentType == char.class) {
return Chars.toArray((Collection) values);
}
return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
示例8: getValues
import com.google.common.primitives.Doubles; //導入依賴的package包/類
static
public List<?> getValues(Tensor tensor){
DataType dataType = tensor.dataType();
switch(dataType){
case FLOAT:
return Floats.asList(TensorUtil.toFloatArray(tensor));
case DOUBLE:
return Doubles.asList(TensorUtil.toDoubleArray(tensor));
case INT32:
return Ints.asList(TensorUtil.toIntArray(tensor));
case INT64:
return Longs.asList(TensorUtil.toLongArray(tensor));
case STRING:
return Arrays.asList(TensorUtil.toStringArray(tensor));
case BOOL:
return Booleans.asList(TensorUtil.toBooleanArray(tensor));
default:
throw new IllegalArgumentException();
}
}
示例9: multiDimTest
import com.google.common.primitives.Doubles; //導入依賴的package包/類
@Test
public void multiDimTest() throws JsonProcessingException, IOException
{
String json = "{\"request\":{\"values\":[[1.0]]}}";
System.out.println(json);
ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = mapper.getFactory();
JsonParser parser = factory.createParser(json);
JsonNode j = mapper.readTree(parser);
JsonNode values = j.get("request").get("values");
double[][] v = mapper.readValue(values.toString(),double[][].class);
double[] vs = Doubles.concat(v);
int[] shape = {v.length,v[0].length };
((ObjectNode) j.get("request")).replace("values",mapper.valueToTree(vs));
((ObjectNode) j.get("request")).set("shape",mapper.valueToTree(shape));
System.out.println(j.toString());
}
示例10: encodeModel
import com.google.common.primitives.Doubles; //導入依賴的package包/類
@Override
public MiningModel encodeModel(Schema schema){
GBTClassificationModel model = getTransformer();
String lossType = model.getLossType();
switch(lossType){
case "logistic":
break;
default:
throw new IllegalArgumentException("Loss function " + lossType + " is not supported");
}
Schema segmentSchema = new Schema(new ContinuousLabel(null, DataType.DOUBLE), schema.getFeatures());
List<TreeModel> treeModels = TreeModelUtil.encodeDecisionTreeEnsemble(model, segmentSchema);
MiningModel miningModel = new MiningModel(MiningFunction.REGRESSION, ModelUtil.createMiningSchema(segmentSchema.getLabel()))
.setSegmentation(MiningModelUtil.createSegmentation(Segmentation.MultipleModelMethod.WEIGHTED_SUM, treeModels, Doubles.asList(model.treeWeights())))
.setOutput(ModelUtil.createPredictedOutput(FieldName.create("gbtValue"), OpType.CONTINUOUS, DataType.DOUBLE));
return MiningModelUtil.createBinaryLogisticClassification(miningModel, 2d, 0d, RegressionModel.NormalizationMethod.LOGIT, false, schema);
}
示例11: visit
import com.google.common.primitives.Doubles; //導入依賴的package包/類
@Nullable
@Override
public Boolean visit(ComparisonCondition condition, @Nullable Object json) {
Comparison comparison = condition.getComparison();
Object value = condition.getValue();
// Null comparisons are always false.
if (json == null || value == null) {
return false;
}
if (json instanceof Number && value instanceof Number) {
Number nLeft = (Number) json;
Number nRight = (Number) value;
if (promoteToDouble(nLeft) || promoteToDouble(nRight)) {
return matchesComparison(comparison, Doubles.compare(nLeft.doubleValue(), nRight.doubleValue()));
} else {
return matchesComparison(comparison, Longs.compare(nLeft.longValue(), nRight.longValue()));
}
}
if (json instanceof String && value instanceof String) {
return matchesComparison(comparison, ((String) json).compareTo((String) value));
}
// Everything else is unsupported and therefore does not match.
return false;
}
示例12: plot
import com.google.common.primitives.Doubles; //導入依賴的package包/類
/**
* Plot a time series, connecting the observation times to the measurements.
*
* @param timeSeries the series to plot.
* @param title the title of the plot.
* @param seriesName the name of the series to display.
*/
public static void plot(final TimeSeries timeSeries, final String title, final String seriesName) {
Thread plotThread = new Thread(() -> {
final List<Date> xAxis = new ArrayList<>(timeSeries.observationTimes().size());
for (OffsetDateTime dateTime : timeSeries.observationTimes()) {
xAxis.add(Date.from(dateTime.toInstant()));
}
List<Double> seriesList = Doubles.asList(round(timeSeries.asArray(), 2));
final XYChart chart = new XYChartBuilder().theme(Styler.ChartTheme.GGPlot2)
.height(600)
.width(800)
.title(title)
.build();
XYSeries residualSeries = chart.addSeries(seriesName, xAxis, seriesList);
residualSeries.setXYSeriesRenderStyle(XYSeries.XYSeriesRenderStyle.Scatter);
residualSeries.setMarker(new Circle()).setMarkerColor(Color.RED);
JPanel panel = new XChartPanel<>(chart);
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setVisible(true);
});
plotThread.start();
}
示例13: 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);
}
示例14: getBankRiskWeightedAssetsOverTime
import com.google.common.primitives.Doubles; //導入依賴的package包/類
@RecorderSource(
value = "bankRiskWeightedAssets",
collectionLengthMember="getNumberOfCommercialBanksForRecorderSampling()"
)
public List<Double> getBankRiskWeightedAssetsOverTime() {
final List<Double>
ret = Doubles.asList(
new double[getNumberOfCommercialBanksForRecorderSampling()]);
int index = 0;
for(final Bank bank : population.getAgentsOfType(CommercialBank.class)) {
double RWA = bank.accept(new ComputeRiskWeightedAssetsOperation());
ret.set(index++, RWA);
}
return ret;
}
示例15: DividendFunctionProvider
import com.google.common.primitives.Doubles; //導入依賴的package包/類
/**
* Constructor. Dividend data must be sorted in chronological order
* @param dividendTimes The dividend times
* @param dividends The dividend payment amount/ratio
*/
public DividendFunctionProvider(final double[] dividendTimes, final double[] dividends) {
ArgumentChecker.notNull(dividendTimes, "dividendTimes");
ArgumentChecker.notNull(dividends, "dividends");
final int nDiv = dividendTimes.length;
ArgumentChecker.isTrue(nDiv == dividends.length, "Wrong data length");
for (int i = 0; i < nDiv; ++i) {
ArgumentChecker.isTrue(dividendTimes[i] > 0., "dividendTimes should be positive");
ArgumentChecker.isTrue(Doubles.isFinite(dividendTimes[i]), "dividendTimes should be finite");
ArgumentChecker.isTrue(dividends[i] > 0., "dividends should be positive");
ArgumentChecker.isTrue(Doubles.isFinite(dividends[i]), "dividends should be finite");
}
for (int i = 1; i < nDiv; ++i) {
ArgumentChecker.isTrue(dividendTimes[i] - dividendTimes[i - 1] > 0., "dividendTimes should be in ascending order");
}
_dividendTimes = Arrays.copyOf(dividendTimes, nDiv);
_dividends = Arrays.copyOf(dividends, nDiv);
_nDividends = nDiv;
}