List of usage examples for java.lang Math log10
@HotSpotIntrinsicCandidate public static double log10(double a)
From source file:be.ac.ua.comp.scarletnebula.core.Server.java
private void refreshUntilServerHasState(final VmState state, final int attempt) { if (getStatus() == state || attempt > 20) { return;//ww w . j a v a 2 s .c om } try { refresh(); } catch (final ServerDisappearedException e) { getCloud().unlink(this); return; } catch (final Exception e) { log.error("Something happened while refreshing server " + this, e); } if (getStatus() == state) { return; } // If the server's state still isn't the one we want it to be, try // again, but only after waiting // a logarithmic amount of time. final double wait = 15.0 * (Math.log10(attempt) + 1.0); final java.util.Timer timer = new java.util.Timer(); timer.schedule(new java.util.TimerTask() { @Override public void run() { refreshUntilServerHasState(state, attempt + 1); log.debug("Refreshing state for server " + getFriendlyName() + " because timer fired, waiting for state " + state.toString()); cancel(); } }, (long) (wait * 1000)); }
From source file:eu.crisis_economics.abm.fund.FundTest.java
/** * This test is in two parts./*from w w w . ja v a 2s. c o m*/ * Part 1: a new fund is created with an initial deposit. This deposit is * reserved as private equity. A collection of household stubs are * created with ample starting deposits. For a number of business * cycles, the households all withdraw or contribute random sums to * the fund. The size of these sums is drawn from a Gaussian * distribution with custom mean and variance. After a fixed number * of business cycles have elapsed, the total amount of cash owned * by each household (be this in fund investments or bank deposits) * is counted. Since the fund has no investment sources and cannot * make a profit, it is expected that no household ever loses or * gains assets (cash plus fund account value). At every step, it is * further asserted that the equity of the fund is not significantly * different to the private (constant) equity. * Part 2: the fund and all households are destroyed and respawned. Households * begin with ample deposits. The test now continues as in Part 1, except * that the fund deposit account is directly injected with exogenous * profits during each business cycle. The size of these profits is * drawn from a Gaussian distribution with custom mean and variance. * At the conclusion of Part 2, the amount of cash in the system * is tallied. It is then asserted that the sum of all household deposits * and fund account values is equal to the initial cash in the system * plus total exogenous profits. * Part 3: as Part 2, except the fund now makes exogenous losses as well as * profits. In this test, the fund is deliberately taken to the edge of * its private equity due to market losses. */ public void testPrivateEquityConstancyAndConservationOfCash() { /* * Test parameters */ final int numberOfBusinessCycles = 1000; final double meanFundProfit = 1.e6, fundProfitVariance = 2.e5, meanHouseholdInvestment = 0., householdInvestmentVariances = 1000., householdInitialDeposits = 1.e7, fundInitialDeposits = 0.; Random dice = new Random(12345); myFund = new MutualFund(myBank, new HomogeneousPortfolioWeighting(), new FundamentalistStockReturnExpectationFunction(), clearingHouse, new NoSmoothingAlgorithm()); // Fresh fund myFund.debit(fundInitialDeposits); final Contract exogenousReturns = myFund.mDepositor.depositAccount; Assert.assertEquals(myFund.getEquity(), fundInitialDeposits); for (int i = 0; i < myHouseholds.length; ++i) { myHouseholds[i] = // Ample household liquidity new HouseholdStub(myFund, myBank, householdInitialDeposits); Assert.assertEquals(myHouseholds[i].getTotalAssets(), householdInitialDeposits, 1.e-5); } /* * Part 1 */ for (int i = 0; i < numberOfBusinessCycles; ++i) { // Random household investments and withdrawals for (int j = 0; j < N_HOUSEHOLDS; ++j) { final double investment = dice.nextGaussian() * householdInvestmentVariances + meanHouseholdInvestment; try { if (investment > 0.) myFund.invest(myHouseholds[j], investment); else if (investment < 0.) { final double maximumWithdrawal = myFund.getBalance(myHouseholds[j]); if (maximumWithdrawal == 0.) continue; myFund.requestWithdrawal(myHouseholds[j], Math.min(-investment, maximumWithdrawal)); } } catch (final InsufficientFundsException noFunds) { Assert.fail(); } } myFund.preClearingProcessing(); // No profits from fund investments. try { myFund.postClearingProcessing(); } catch (final InsufficientFundsException unexpectedException) { Assert.fail(); } System.out.printf("MutualFund assets: %16.10g\n", myFund.getTotalAssets()); System.out.printf("MutualFund liabilities: %16.10g\n", myFund.getTotalLiabilities()); System.out.printf("MutualFund equity: %16.10g\n", myFund.getEquity()); // Assertions final double postClearingEquity = myFund.getEquity(); Assert.assertEquals(postClearingEquity, fundInitialDeposits, 1.e-5); continue; } // Assert no cash has been created System.out.printf("household deposits [open] fund investments [open]" + " deposits [close] fund investments [close] sum [close]\n"); for (int i = 0; i < N_HOUSEHOLDS; ++i) { // Assert no money creation final double closingHouseholdDeposits = myHouseholds[i].bankAccount.getBalance(), closingFundAccountValue = myFund.getBalance(myHouseholds[i]); System.out.printf("%5d %16.10g %16.10g %16.10g %16.10g %16.10g\n", i, householdInitialDeposits, 0., closingHouseholdDeposits, closingFundAccountValue, closingHouseholdDeposits + closingFundAccountValue); Assert.assertEquals(closingHouseholdDeposits + closingFundAccountValue, householdInitialDeposits, 1.e-6); } /* * Part 2 */ // Rerun with exogenous fund profits double totalFundProfits = 0.; for (int i = 0; i < numberOfBusinessCycles; ++i) { // Random household investments and withdrawals for (int j = 0; j < N_HOUSEHOLDS; ++j) { final double investment = dice.nextGaussian() * householdInvestmentVariances + meanHouseholdInvestment; try { if (investment > 0.) myFund.invest(myHouseholds[j], investment); else if (investment < 0.) { final double maximumWithdrawal = myFund.getBalance(myHouseholds[j]); if (maximumWithdrawal == 0.) continue; myFund.requestWithdrawal(myHouseholds[j], Math.min(-investment, maximumWithdrawal)); } } catch (final InsufficientFundsException noFunds) { Assert.fail(); } } myFund.preClearingProcessing(); final double fundProfits = dice.nextGaussian() * fundProfitVariance + meanFundProfit; exogenousReturns.setValue(exogenousReturns.getValue() + fundProfits); totalFundProfits += fundProfits; try { myFund.postClearingProcessing(); } catch (final InsufficientFundsException unexpectedException) { Assert.fail(); } System.out.printf("MutualFund profits: %16.10g\n", fundProfits); System.out.printf("MutualFund assets: %16.10g\n", myFund.getTotalAssets()); System.out.printf("MutualFund liabilities: %16.10g\n", myFund.getTotalLiabilities()); System.out.printf("MutualFund equity: %16.10g\n", myFund.getEquity()); System.out.println("Number of shares: " + myFund.mInvestmentAccount.getNumberOfEmittedShares()); // Assertions final double postClearingEquity = myFund.getEquity(); Assert.assertEquals(postClearingEquity, fundInitialDeposits, 1.e-1); continue; } // Tally the total amount of cash in the system. double totalHouseholdProfits = 0.; System.out.printf("household deposits [open] fund investments [open]" + " deposits [close] fund investments [close] sum [close]\n"); for (int i = 0; i < N_HOUSEHOLDS; ++i) { // Assert no money creation final double closingHouseholdDeposits = myHouseholds[i].bankAccount.getBalance(), closingFundAccountValue = myFund.getBalance(myHouseholds[i]); System.out.printf("%5d %16.10g %16.10g %16.10g %16.10g %16.10g\n", i, householdInitialDeposits, 0., closingHouseholdDeposits, closingFundAccountValue, closingHouseholdDeposits + closingFundAccountValue); totalHouseholdProfits += (closingHouseholdDeposits + closingFundAccountValue) - householdInitialDeposits; } System.out.printf("Aggregate household profits: %16.10g. MutualFund profits: %16.10g\n", totalHouseholdProfits, totalFundProfits); Assert.assertEquals(totalHouseholdProfits / Math.pow(10., (int) Math.log10(totalHouseholdProfits)), totalFundProfits / Math.pow(10., (int) Math.log10(totalFundProfits)), 1.e-12); /* * Part 3 */ // Rerun with predetermined fund losses. UnivariateFunction forcedFundAssetPosition = new UnivariateFunction() { @Override public double value(double time) { return fundInitialDeposits + 1.e-5 + householdInvestmentVariances * (1. + Math.sin(2. * Math.PI * time / 50.)); } }; for (int i = 0; i < numberOfBusinessCycles; ++i) { // Random household investments and withdrawals for (int j = 0; j < N_HOUSEHOLDS; ++j) { final double investment = dice.nextGaussian() * householdInvestmentVariances + meanHouseholdInvestment; try { if (investment > 0.) { myFund.invest(myHouseholds[j], investment); } else if (investment < 0.) { final double maximumWithdrawal = myFund.getBalance(myHouseholds[j]); if (maximumWithdrawal == 0.) continue; double withdrawal = Math.min(-investment, maximumWithdrawal); myFund.requestWithdrawal(myHouseholds[j], withdrawal); } } catch (final InsufficientFundsException noFunds) { Assert.fail(); } } myFund.preClearingProcessing(); final double profitsNow = forcedFundAssetPosition.value(i) - exogenousReturns.getValue(); totalFundProfits += profitsNow; exogenousReturns.setValue(forcedFundAssetPosition.value(i)); try { myFund.postClearingProcessing(); } catch (final InsufficientFundsException unexpectedException) { Assert.fail(); } System.out.printf("MutualFund profits: %16.10g\n", profitsNow); System.out.printf("MutualFund assets: %16.10g\n", myFund.getTotalAssets()); System.out.printf("MutualFund liabilities: %16.10g\n", myFund.getTotalLiabilities()); System.out.printf("MutualFund equity: %16.10g\n", myFund.getEquity()); System.out.println("Number of shares: " + myFund.mInvestmentAccount.getNumberOfEmittedShares()); // Assertions final double postClearingEquity = myFund.getEquity(); Assert.assertEquals(postClearingEquity, fundInitialDeposits, 1.e-1); continue; } // Tally the total amount of cash in the system. totalHouseholdProfits = 0.; System.out.printf("household deposits [open] fund investments [open]" + " deposits [close] fund investments [close] sum [close]\n"); for (int i = 0; i < N_HOUSEHOLDS; ++i) { // Assert no money creation final double closingHouseholdDeposits = myHouseholds[i].bankAccount.getBalance(), closingFundAccountValue = myFund.getBalance(myHouseholds[i]); System.out.printf("%5d %16.10g %16.10g %16.10g %16.10g %16.10g\n", i, householdInitialDeposits, 0., closingHouseholdDeposits, closingFundAccountValue, closingHouseholdDeposits + closingFundAccountValue); totalHouseholdProfits += (closingHouseholdDeposits + closingFundAccountValue) - householdInitialDeposits; } System.out.printf("Aggregate household profits: %16.10g. MutualFund profits: %16.10g\n", totalHouseholdProfits, totalFundProfits); Assert.assertEquals( totalHouseholdProfits / Math.pow(10., (int) Math.log10(Math.abs(totalHouseholdProfits))), totalFundProfits / Math.pow(10., (int) Math.log10(Math.abs(totalFundProfits))), 1.e-12); return; }
From source file:edu.ucuenca.authorsdisambiguation.Distance.java
private double NGD(String a, String b) throws IOException, SQLException { a = a.trim();/* ww w .j a v a2s . co m*/ b = b.trim(); if (a.compareToIgnoreCase(b) == 0) { return 0; } //double n0 = getResultsCount(""+a+""); //double n1 = getResultsCount(""+b+""); //String c = ""+a+" "+b+""; double n0 = getResultsCount("\"" + a + "\"~10"); double n1 = getResultsCount("\"" + b + "\"~10"); String c = "\"" + a + " " + b + "\"~50"; double n2 = getResultsCount(c); //double m = 5026040.0 * 590; double m = 5029469; double distance = 0; int Measure = 0; double l1 = Math.max(Math.log10(n0), Math.log10(n1)) - Math.log10(n2); double l2 = Math.log10(m) - Math.min(Math.log10(n0), Math.log10(n1)); if (Measure == 0) { distance = l1 / l2; } if (Measure == 1) { distance = 1 - (Math.log10(n2) / Math.log10(n0 + n1 - n2)); } if (n0 == 0 || n1 == 0 || n2 == 0) { distance = 1; } //System.out.println("n0="+n0); //System.out.println("n1="+n1); //System.out.println("n2="+n2); //System.out.println(a + "," + b + "=" + distance2); return distance; }
From source file:com.bloatit.model.Member.java
protected int calculateInfluence() { final int karma = getDao().getKarma(); if (karma >= 0) { return (int) (Math.log10((INFLUENCE_GELIFICATOR + karma) / INFLUENCE_GELIFICATOR) * INFLUENCE_MULTIPLICATOR + INFLUENCE_BASE); }//from w w w. j ava2 s . c o m return 0; }
From source file:com.alvermont.terraj.planet.project.AbstractProjector.java
/** * Calculate a log in base 2//from w ww . j a v a2s.com * * @param val The value to calculate the logarithm in base 2 for * @return The logarithm to base 2 of the input value */ protected double log2(double val) { return Math.log10(val) / Math.log10(2); }
From source file:edu.byu.nlp.util.Matrices.java
private static int strWidthOf(double number, int numDigits) { if (number == 0) { return 1; } else {//from www . ja va2 s. c o m int asInt = (int) Math.round(number * (Math.pow(10, numDigits))); return (int) Math.ceil(Math.log10(asInt + 1)); } }
From source file:org.apache.flink.compiler.plandump.PlanJSONDumpGenerator.java
public static final String formatNumber(double number, String suffix) { if (number <= 0.0) { return String.valueOf(number); }/*from ww w .j a v a2 s . c o m*/ int power = (int) Math.ceil(Math.log10(number)); int group = (power - 1) / 3; if (group >= SIZE_SUFFIXES.length) { group = SIZE_SUFFIXES.length - 1; } else if (group < 0) { group = 0; } // truncate fractional part int beforeDecimal = power - group * 3; if (power > beforeDecimal) { for (int i = power - beforeDecimal; i > 0; i--) { number /= 10; } } return group > 0 ? String.format(Locale.US, "%.2f %s", number, SIZE_SUFFIXES[group]) : String.format(Locale.US, "%.2f", number); }
From source file:net.sf.extjwnl.princeton.file.PrincetonRandomAccessDictionaryFile.java
private int getDigitCount(long number) { return (number == 0) ? 1 : (int) Math.log10(number) + 1; }
From source file:org.apache.flink.optimizer.plandump.PlanJSONDumpGenerator.java
public static String formatNumber(double number, String suffix) { if (number <= 0.0) { return String.valueOf(number); }// w ww .j av a 2 s. c om int power = (int) Math.ceil(Math.log10(number)); int group = (power - 1) / 3; if (group >= SIZE_SUFFIXES.length) { group = SIZE_SUFFIXES.length - 1; } else if (group < 0) { group = 0; } // truncate fractional part int beforeDecimal = power - group * 3; if (power > beforeDecimal) { for (int i = power - beforeDecimal; i > 0; i--) { number /= 10; } } return group > 0 ? String.format(Locale.US, "%.2f %s", number, SIZE_SUFFIXES[group]) : String.format(Locale.US, "%.2f", number); }
From source file:msi.gaml.operators.Maths.java
@operator(value = "log", can_be_const = true, category = { IOperatorCategory.ARITHMETIC }) @doc(value = "Returns the logarithm (base 10) of the operand.", masterDoc = true, usages = @usage("an exception is raised if the operand is equals or less than zero."), examples = @example(value = "log(10)", equals = "1.0"), see = "ln") public static Double log(final Double x) { if (x <= 0) { throw GamaRuntimeException.warning("The ln operator cannot accept negative or null inputs"); // return Double.MAX_VALUE; // A compromise... }/*from w w w. java2s. c om*/ return Math.log10(x); }