Java Code Examples for com.google.common.primitives.Doubles#min()
The following examples show how to use
com.google.common.primitives.Doubles#min() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Jaccard.java From termsuite-core with Apache License 2.0 | 6 votes |
@Override protected double getValue(ContextVector source, ContextVector target, Explanation expl) { double infSum = 0; double supSum = 0; Set<Term> terms = Sets.newHashSet(); terms.addAll(source.terms()); terms.addAll(target.terms()); double sourceValue; double targetValue; double partialInf; double partialSup; for (Term term : terms) { sourceValue = source.getAssocRate(term); targetValue = target.getAssocRate(term); partialInf = Doubles.min(sourceValue, targetValue); partialSup = Doubles.max(sourceValue, targetValue); infSum += partialInf; supSum += partialSup; if(partialInf > 0) expl.addExplanation(term, partialInf); } return supSum == 0 ? 0 : infSum / supSum; }
Example 2
Source File: DiscountingBondFutureProductPricer.java From Strata with Apache License 2.0 | 6 votes |
/** * Calculates the price of the bond future product with z-spread. * <p> * The price of the product is the price on the valuation date. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates * of the issuer discounting curve. * <p> * Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of {@link FixedCouponBond}. * For example, a price of 99.32% is represented in Strata by 0.9932. * * @param future the future * @param discountingProvider the discounting provider * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodPerYear the number of periods per year * @return the price of the product, in decimal form */ public double priceWithZSpread( ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear) { ImmutableList<ResolvedFixedCouponBond> basket = future.getDeliveryBasket(); int size = basket.size(); double[] priceBonds = new double[size]; for (int i = 0; i < size; ++i) { ResolvedFixedCouponBond bond = basket.get(i); double dirtyPrice = bondPricer.dirtyPriceFromCurvesWithZSpread( bond, discountingProvider, zSpread, compoundedRateType, periodPerYear, future.getLastDeliveryDate()); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice( bond, future.getLastDeliveryDate(), dirtyPrice) / future.getConversionFactors().get(i); } return Doubles.min(priceBonds); }
Example 3
Source File: DiscountingBondFutureProductPricer.java From Strata with Apache License 2.0 | 5 votes |
/** * Calculates the price of the bond future product. * <p> * The price of the product is the price on the valuation date. * <p> * Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of {@link FixedCouponBond}. * For example, a price of 99.32% is represented in Strata by 0.9932. * * @param future the future * @param discountingProvider the discounting provider * @return the price of the product, in decimal form */ public double price(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider) { ImmutableList<ResolvedFixedCouponBond> basket = future.getDeliveryBasket(); int size = basket.size(); double[] priceBonds = new double[size]; for (int i = 0; i < size; ++i) { ResolvedFixedCouponBond bond = basket.get(i); double dirtyPrice = bondPricer.dirtyPriceFromCurves(bond, discountingProvider, future.getLastDeliveryDate()); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice( bond, future.getLastDeliveryDate(), dirtyPrice) / future.getConversionFactors().get(i); } return Doubles.min(priceBonds); }
Example 4
Source File: JoinPruleBase.java From dremio-oss with Apache License 2.0 | 4 votes |
protected boolean checkBroadcastConditions(RelOptPlanner planner, JoinRel join, RelNode left, RelNode right) { final RelMetadataQuery mq = join.getCluster().getMetadataQuery(); // Right node is the one that is being considered to be broadcasted.. double targetRowCount = mq.getRowCount(right); int targetColumnCount = right.getRowType().getFieldCount(); double targetCellCount = targetRowCount * targetColumnCount; double otherRowCount = mq.getRowCount(left); if (targetRowCount < PrelUtil.getSettings(join.getCluster()).getBroadcastThreshold() && ! left.getTraitSet().getTrait(DistributionTraitDef.INSTANCE).equals(DistributionTrait.SINGLETON) && (join.getJoinType() == JoinRelType.INNER || join.getJoinType() == JoinRelType.LEFT)) { // DX-3862: For broadcast joins, the cost should not just consider the traits and join type. If the broadcast table is small enough, // we shouldn't need to worry too much and allow broadcast join and see what the planner picks. final PlannerSettings plannerSettings = PrelUtil.getSettings(join.getCluster()); double cellCountThreshold = plannerSettings.getOptions().getOption(PlannerSettings.BROADCAST_CELL_COUNT_THRESHOLD); if (targetCellCount > cellCountThreshold) { // DX-17913 : For cases when the table is too big due to large number of columns, we should not do the broadcast join. logger.debug("Won't do broadcast join if the size of the table is too big based of total number of cells (rows x columns)"); return false; } if (targetRowCount <= plannerSettings.getOptions().getOption(PlannerSettings.BROADCAST_MIN_THRESHOLD)) { logger.debug("Enable broadcast plan? true (rightRowCount {} smaller than minimum broadcast threshold)", targetRowCount); return true; } final long maxWidthPerNode = plannerSettings.getMaxWidthPerNode(); if (maxWidthPerNode <= 0) { logger.debug("No executors are available. Won't do broadcast join"); return false; } // In this case, the broadcast table is big-ish. So, we should check to see if it is reasonable to do broadcast. // The broadcasted table will be sent at most (numEndPoints * maxWidthPerNode) times, (rightRowCount) rows. We add a // penalty to broadcast (broadcastFactor). final double broadcastFactor = plannerSettings.getBroadcastFactor(); final int numEndPoints = plannerSettings.numEndPoints(); final long maxWidthPerQuery = plannerSettings.getOptions().getOption(ExecConstants.MAX_WIDTH_GLOBAL); final long sliceTarget = plannerSettings.getSliceTarget(); final double minFactor = Doubles.min(otherRowCount * 1.0 / sliceTarget, numEndPoints * maxWidthPerNode, maxWidthPerQuery); final boolean enableBroadCast = (minFactor * broadcastFactor < otherRowCount); logger.debug("Enable broadcast plan? {} minFactor {} (numEndPoints {}, maxWidthPerNode {}, rightRowCount {}, broadcastFactor {}, leftRowCount {}, sliceTarget {}, maxWidthPerQuery {})", enableBroadCast, minFactor, numEndPoints, maxWidthPerNode, targetRowCount, broadcastFactor, otherRowCount, sliceTarget, maxWidthPerQuery); return enableBroadCast; } return false; }