List of usage examples for java.lang Math exp
@HotSpotIntrinsicCandidate public static double exp(double a)
From source file:edu.duke.cs.osprey.voxq.QuadraticQFunction.java
double evalQ(double x) { return Math.exp(c + x * (b + a * x)); }
From source file:de.uni_erlangen.lstm.models.adm1.DAEModel.java
@Override public void computeDerivatives(double t, double[] x, double[] dx) throws MaxCountExceededException, DimensionMismatchException { for (int i = 0; i < x.length; i++) { if (x[i] < 0) { xtemp[i] = 0.0;/*from www .j av a2s. c o m*/ } else { xtemp[i] = x[i]; } } // Adjustments for acid-base equations factor = (1.0 / (param[0]) - 1.0 / (273.15 + xtemp[36])) / (100.0 * R); K_w = Math.pow(10, -param[2]) * Math.exp(55900.0 * factor); // T adjustment for K_w K_a_co2 = Math.pow(10, -param[7]) * Math.exp(7646.0 * factor); // T adjustment for K_a_co2 K_a_IN = Math.pow(10, -param[8]) * Math.exp(51965.0 * factor); // T adjustment for K_a_IN K_H_h2 = param[9] * Math.exp(-4180.0 * factor); // T adjustment for K_H_h2 K_H_ch4 = param[10] * Math.exp(-14240.0 * factor); // T adjustment for K_H_ch4 K_H_co2 = param[11] * Math.exp(-19410.0 * factor); // T adjustment for K_H_co2 p_gas_h2o = param[12] * Math.exp(5290.0 * (1.0 / (param[0]) - 1.0 / (273.15 + xtemp[36]))); // T adjustment for water vapour saturation pressure K_a_va = Math.pow(10, -param[3]); K_a_bu = Math.pow(10, -param[4]); K_a_pro = Math.pow(10, -param[5]); K_a_ac = Math.pow(10, -param[6]); if (fix_pH >= 0) { // S_H_ion based on set pH shDAE = false; S_H_ion = Math.pow(10, -fix_pH); // Run the DAE functions runDAE(); } else { // Run the DAE functions runDAE(); // SH+ Equation (pH and ion states) if (!shDAE) { // Scat+(S_IN-Snh3)-hco3-(Sac/64)-(Spro/112)-(Sbu/160)-(Sva/208)-San phi = xtemp[24] + (xtemp[10] - xtemp[31]) - xtemp[30] - (xtemp[29] / 64.0) - (xtemp[28] / 112.0) - (xtemp[27] / 160.0) - (xtemp[26] / 208.0) - xtemp[25]; S_H_ion = (-phi * 0.5) + 0.5 * Math.sqrt(phi * phi + (4.0 * K_w)); // SH+ } } // Adjustments for gas pressure p_gas_h2 = xtemp[32] * R * (273.15 + xtemp[36]) / 16.0; p_gas_ch4 = xtemp[33] * R * (273.15 + xtemp[36]) / 64.0; p_gas_co2 = xtemp[34] * R * (273.15 + xtemp[36]); P_gas = p_gas_h2 + p_gas_ch4 + p_gas_co2 + p_gas_h2o; // pH Inhibition I_pH_aa = Math.pow(pHLim_aa, n_aa) / (Math.pow(S_H_ion, n_aa) + Math.pow(pHLim_aa, n_aa)); I_pH_ac = Math.pow(pHLim_ac, n_ac) / (Math.pow(S_H_ion, n_ac) + Math.pow(pHLim_ac, n_ac)); I_pH_h2 = Math.pow(pHLim_h2, n_h2) / (Math.pow(S_H_ion, n_h2) + Math.pow(pHLim_h2, n_h2)); I_IN_lim = 1.0 / (1.0 + param[19] / xtemp[10]); // 1.0/(1.0+K_S_IN/S_IN) I_h2_fa = 1.0 / (1.0 + xtemp[7] / param[20]); // 1.0/(1.0+S_h2/K_Ih2_fa) I_h2_c4 = 1.0 / (1.0 + xtemp[7] / param[21]); // 1.0/(1.0+S_h2/K_Ih2_c4) I_h2_pro = 1.0 / (1.0 + xtemp[7] / param[22]); // 1.0/(1.0+S_h2/K_Ih2_pro) I_nh3 = 1.0 / (1.0 + xtemp[31] / param[23]); // 1.0/(1.0+S_nh3/K_I_nh3) // Inhibitors inhib[0] = I_pH_aa * I_IN_lim; // Inhibition Equation 5 & 6 inhib[1] = inhib[0] * I_h2_fa; // Inhibition Equation 7 inhib[2] = inhib[0] * I_h2_c4; // Inhibition Equation 8 & 9 inhib[3] = inhib[0] * I_h2_pro; // Inhibition Equation 10 inhib[4] = I_pH_ac * I_IN_lim * I_nh3; // Inhibition Equation 11 inhib[5] = I_pH_h2 * I_IN_lim; // Inhibition Equation 12 // Biochemical process rates proc1 = param[24] * xtemp[12]; // k_dis*X_xc, Disintegration proc2 = param[25] * xtemp[13]; // k_hyd_ch*X_ch, Hydrolysis of carbohydrates proc3 = param[26] * xtemp[14]; // k_hyd_pr*X_pr, Hydrolysis of proteins proc4 = param[27] * xtemp[15]; // k_hyd_li*X_li, Hydrolysis of lipids proc5 = param[28] * xtemp[0] / (param[29] + xtemp[0]) * xtemp[16] * inhib[0]; // k_m_su*(S_su/(K_S_su+S_su))*X_su*inhib_5, Uptake of sugars proc6 = param[30] * xtemp[1] / (param[31] + xtemp[1]) * xtemp[17] * inhib[0]; // k_m_aa*(S_aa/(K_S_aa+S_aa))*X_aa*inhib_6, Uptake of amino acids proc7 = param[32] * xtemp[2] / (param[33] + xtemp[2]) * xtemp[18] * inhib[1]; // k_m_fa*(S_fa/(K_S_fa+S_fa))*X_aa*inhib_7, Uptake of LCFA proc8 = param[34] * xtemp[3] / (param[35] + xtemp[3]) * xtemp[19] * xtemp[3] / (xtemp[3] + xtemp[4] + eps) * inhib[2]; // k_m_c4*(S_va/(K_S_c4+S_va))*X_c4*(S_va/(S_bu+S_va+eps))*inhib_8, Uptake of valerate proc9 = param[34] * xtemp[4] / (param[35] + xtemp[4]) * xtemp[19] * xtemp[4] / (xtemp[3] + xtemp[4] + eps) * inhib[2]; // k_m_c4*(S_bu/(K_S_c4+S_bu))*X_c4*(S_bu/(S_va+S_bu+eps))*inhib_9, Uptake of butyrate proc10 = param[36] * xtemp[5] / (param[37] + xtemp[5]) * xtemp[20] * inhib[3]; // k_m_pro*(S_pro/(K_S_pro+S_pro))*X_pro*inhib_10, Uptake of propionate proc11 = param[38] * xtemp[6] / (param[39] + xtemp[6]) * xtemp[21] * inhib[4]; // k_m_ac*(S_ac/(K_S_ac+S_ac))*X_ac*inhib_11, Uptake of acetate proc12 = param[40] * xtemp[7] / (param[41] + xtemp[7]) * xtemp[22] * inhib[5]; // k_m_h2*(S_h2/(K_S_h2+S_h2))*X_h2*inhib_12, Uptake of hydrogen proc13 = param[42] * xtemp[16]; // k_dec_Xsu*X_su, Decay of X_su proc14 = param[43] * xtemp[17]; // k_dec_Xaa*X_aa, Decay of X_aa proc15 = param[44] * xtemp[18]; // k_dec_Xfa*X_fa, Decay of X_fa proc16 = param[45] * xtemp[19]; // k_dec_Xc4*X_c4, Decay of X_c4 proc17 = param[46] * xtemp[20]; // k_dec_Xpro*X_pro, Decay of X_pro proc18 = param[47] * xtemp[21]; // k_dec_Xac*X_ac, Decay of X_ac proc19 = param[48] * xtemp[22]; // k_dec_Xh2*X_h2, Decay of X_h2 // Gas transfer rates procT8 = param[55] * (xtemp[7] - 16.0 * K_H_h2 * p_gas_h2); // kLa*(S_h2-16.0*K_H_h2*p_gas_h2) procT9 = param[55] * (xtemp[8] - 64.0 * K_H_ch4 * p_gas_ch4); // kLa*(S_ch4-64.0*K_H_ch4*p_gas_ch4) procT10 = param[55] * ((xtemp[9] - xtemp[30]) - K_H_co2 * p_gas_co2); // kLa*((S_IC-S_hco3)-K_H_co2*p_gas_co2) // Reactions // reac1 = proc2+(1.0-f_fa_li)*proc4-proc5; reac1 = proc2 + (1.0 - param[69]) * proc4 - proc5; reac2 = proc3 - proc6; // reac3 = f_fa_li*proc4-proc7; reac3 = param[69] * proc4 - proc7; // reac4 = (1.0-Y_aa)*f_va_aa*proc6-proc8; reac4 = (1.0 - param[79]) * param[80] * proc6 - proc8; //reac5 = (1.0-Y_su)*f_bu_su*proc5+(1.0-Y_aa)*f_bu_aa*proc6-proc9; reac5 = (1.0 - param[71]) * param[72] * proc5 + (1.0 - param[79]) * param[82] * proc6 - proc9; // reac6 = (1.0-Y_su)*f_pro_su*proc5+(1.0-Y_aa)*f_pro_aa*proc6+(1.0-Y_c4)*0.54*proc8-proc10; reac6 = (1.0 - param[71]) * param[74] * proc5 + (1.0 - param[79]) * param[83] * proc6 + (1.0 - param[86]) * 0.54 * proc8 - proc10; // reac7 = (1.0-Y_su)*f_ac_su*proc5+(1.0-Y_aa)*f_ac_aa*proc6+(1.0-Y_fa)*0.7*proc7+(1.0-Y_c4)*0.31*proc8+(1.0-Y_c4)*0.8*proc9+(1.0-Y_pro)*0.57*proc10-proc11; reac7 = (1.0 - param[71]) * param[76] * proc5 + (1.0 - param[79]) * param[84] * proc6 + (1.0 - param[85]) * 0.7 * proc7 + (1.0 - param[86]) * 0.31 * proc8 + (1.0 - param[86]) * 0.8 * proc9 + (1.0 - param[87]) * 0.57 * proc10 - proc11; // reac8 = (1.0-Y_su)*f_h2_su*proc5+(1.0-Y_aa)*f_h2_aa*proc6+(1.0-Y_fa)*0.3*proc7+(1.0-Y_c4)*0.15*proc8+(1.0-Y_c4)*0.2*proc9+(1.0-Y_pro)*0.43*proc10-proc12-procT8; reac8 = (1.0 - param[71]) * param[91] * proc5 + (1.0 - param[79]) * param[92] * proc6 + (1.0 - param[85]) * 0.3 * proc7 + (1.0 - param[86]) * 0.15 * proc8 + (1.0 - param[86]) * 0.2 * proc9 + (1.0 - param[87]) * 0.43 * proc10 - proc12 - procT8; // reac9 = (1.0-Y_ac)*proc11+(1.0-Y_h2)*proc12-procT9; reac9 = (1.0 - param[88]) * proc11 + (1.0 - param[90]) * proc12 - procT9; reac10 = -stoich1 * proc1 - stoich2 * proc2 - stoich3 * proc3 - stoich4 * proc4 - stoich5 * proc5 - stoich6 * proc6 - stoich7 * proc7 - stoich8 * proc8 - stoich9 * proc9 - stoich10 * proc10 - stoich11 * proc11 - stoich12 * proc12 - stoich13 * proc13 - stoich13 * proc14 - stoich13 * proc15 - stoich13 * proc16 - stoich13 * proc17 - stoich13 * proc18 - stoich13 * proc19 - procT10; // reac11 = (N_xc-f_xI_xc*N_I-f_sI_xc*N_I-f_pr_xc*N_aa)*proc1-Y_su*N_bac*proc5+(N_aa-Y_aa*N_bac)*proc6-Y_fa*N_bac*proc7-Y_c4*N_bac*proc8-Y_c4*N_bac*proc9-Y_pro*N_bac*proc10-Y_ac*N_bac*proc11-Y_h2*N_bac*proc12+(N_bac-N_xc)*(proc13+proc14+proc15+proc16+proc17+proc18+proc19); reac11 = -(param[93] - param[65] * param[94] - param[57] * param[94] - param[61] * param[95]) * proc1 - param[71] * param[96] * proc5 + (param[95] - param[79] * param[96]) * proc6 - param[85] * param[96] * proc7 - param[86] * param[96] * proc8 - param[86] * param[96] * proc9 - param[87] * param[96] * proc10 - param[88] * param[96] * proc11 - param[90] * param[96] * proc12 + (param[96] - param[93]) * (proc13 + proc14 + proc15 + proc16 + proc17 + proc18 + proc19); // reac12 = f_sI_xc*proc1; reac12 = param[57] * proc1; reac13 = -proc1 + proc13 + proc14 + proc15 + proc16 + proc17 + proc18 + proc19; // reac14 = f_ch_xc*proc1-proc2; reac14 = param[59] * proc1 - proc2; // reac15 = f_pr_xc*proc1-proc3; reac15 = param[61] * proc1 - proc3; // reac16 = f_li_xc*proc1-proc4; reac16 = param[63] * proc1 - proc4; // reac17 = Y_su*proc5-proc13; reac17 = param[71] * proc5 - proc13; // reac18 = Y_aa*proc6-proc14; reac18 = param[79] * proc6 - proc14; // reac19 = Y_fa*proc7-proc15; reac19 = param[85] * proc7 - proc15; // reac20 = Y_c4*proc8+Y_c4*proc9-proc16; reac20 = param[86] * proc8 + param[86] * proc9 - proc16; // reac21 = Y_pro*proc10-proc17; reac21 = param[87] * proc10 - proc17; // reac22 = Y_ac*proc11-proc18; reac22 = param[88] * proc11 - proc18; // reac23 = Y_h2*proc12-proc19; reac23 = param[90] * proc12 - proc19; // reac24 = f_xI_xc*proc1; reac24 = param[65] * proc1; q_gas = param[97] * (P_gas - P_atm); if (q_gas < 0) q_gas = 0.0; // DE's -> Soluble matter // dSsu/dt = Qad/Vad,liq(Ssu,i-Ssu)+reac1 dx[0] = (xtemp[35] / param[98]) * (u[0] - xtemp[0]) + reac1; // Ssu dx[1] = (xtemp[35] / param[98]) * (u[1] - xtemp[1]) + reac2; // Saa dx[2] = (xtemp[35] / param[98]) * (u[2] - xtemp[2]) + reac3; // Sfa dx[3] = (xtemp[35] / param[98]) * (u[3] - xtemp[3]) + reac4; // Sva dx[4] = (xtemp[35] / param[98]) * (u[4] - xtemp[4]) + reac5; // Sbu dx[5] = (xtemp[35] / param[98]) * (u[5] - xtemp[5]) + reac6; // Spro dx[6] = (xtemp[35] / param[98]) * (u[6] - xtemp[6]) + reac7; // Sac if (!sh2DAE) { dx[7] = (xtemp[35] / param[98]) * (u[7] - xtemp[7]) + reac8; // Sh2 } dx[8] = (xtemp[35] / param[98]) * (u[8] - xtemp[8]) + reac9; // Sch4 dx[9] = (xtemp[35] / param[98]) * (u[9] - xtemp[9]) + reac10; // SIC dx[10] = (xtemp[35] / param[98]) * (u[10] - xtemp[10]) + reac11; // SIN dx[11] = (xtemp[35] / param[98]) * (u[11] - xtemp[11]) + reac12; // SI // DE's -> Particulate matter dx[12] = (xtemp[35] / param[98]) * (u[12] - xtemp[12]) + reac13; // Xc dx[13] = (xtemp[35] / param[98]) * (u[13] - xtemp[13]) + reac14; // Xch dx[14] = (xtemp[35] / param[98]) * (u[14] - xtemp[14]) + reac15; // Xpr dx[15] = (xtemp[35] / param[98]) * (u[15] - xtemp[15]) + reac16; // Xli dx[16] = (xtemp[35] / param[98]) * (u[16] - xtemp[16]) + reac17; // Xsu dx[17] = (xtemp[35] / param[98]) * (u[17] - xtemp[17]) + reac18; // Xaa dx[18] = (xtemp[35] / param[98]) * (u[18] - xtemp[18]) + reac19; // Xfa dx[19] = (xtemp[35] / param[98]) * (u[19] - xtemp[19]) + reac20; // Xc4 dx[20] = (xtemp[35] / param[98]) * (u[20] - xtemp[20]) + reac21; // Xpro dx[21] = (xtemp[35] / param[98]) * (u[21] - xtemp[21]) + reac22; // Xac dx[22] = (xtemp[35] / param[98]) * (u[22] - xtemp[22]) + reac23; // Xh2 dx[23] = (xtemp[35] / param[98]) * (u[23] - xtemp[23]) + reac24; // XI dx[24] = (xtemp[35] / param[98]) * (u[24] - xtemp[24]); // Scat+ dx[25] = (xtemp[35] / param[98]) * (u[25] - xtemp[25]); // San- // Acid-base process rates for ODE //k_A_Bva*(S_hva*(K_A_va+S_H_ion)-K_a_va*S_va) if (!shDAE && fix_pH < 0) { dx[26] = -(param[49] * (xtemp[26] * (K_a_va + S_H_ion) - K_a_va * xtemp[3])); // Sva- dx[27] = -(param[50] * (xtemp[27] * (K_a_bu + S_H_ion) - K_a_bu * xtemp[4])); // Sbu- dx[28] = -(param[51] * (xtemp[28] * (K_a_pro + S_H_ion) - K_a_pro * xtemp[5])); // Spro- dx[29] = -(param[52] * (xtemp[29] * (K_a_ac + S_H_ion) - K_a_ac * xtemp[6])); // Sac- dx[30] = -(param[53] * (xtemp[30] * (K_a_co2 + S_H_ion) - K_a_co2 * xtemp[9])); // SHCO3- dx[31] = -(param[54] * (xtemp[31] * (K_a_IN + S_H_ion) - K_a_IN * xtemp[10])); // SNH3 } dx[32] = -xtemp[32] * q_gas / param[99] + procT8 * param[98] / param[99]; // Sgas,h2 dx[33] = -xtemp[33] * q_gas / param[99] + procT9 * param[98] / param[99]; // Sgas,ch4 dx[34] = -xtemp[34] * q_gas / param[99] + procT10 * param[98] / param[99]; // Sgas,co2 dx[35] = 0; // Flow dx[36] = 0; // Temp // Correction by factor of 64.0 due to COD basis of Sgas,ch4 // Methane gas (m3/d) //xtemp[37] = (q_gas*xtemp[33])*R*(273.15+xtemp[36])/64.0; // Calculate methane production from concentration in gas phase xtemp[37] = q_gas * (p_gas_ch4 / P_gas); // Calculate methane production from partial pressures xtemp[38] = q_gas;// Gas production (m3/d) xtemp[39] = -Math.log10(S_H_ion); // pH // SCO2 = SIC - SHCO3 xtemp[40] = xtemp[9] - xtemp[30]; // SCO2 // SNH4+ = SIN - SNH3 xtemp[41] = xtemp[10] - xtemp[31]; // SNH4+ }
From source file:edu.byu.nlp.al.ActiveMeasurementSelector.java
public Collection<FlatInstance<SparseFeatureVector, Integer>> selectNext(int batchSize) { State currentModel = modelTrainedOn(dataset, trainingOperations, null); // ClassificationMeasurementModelExpectations expectations = ClassificationMeasurementModelExpectations.from(currentModel); ArgMinMaxTracker<Double, FlatInstance<SparseFeatureVector, Integer>> candidateTracker = new ArgMinMaxTracker<>( rnd, batchSize);//from www . j a v a 2 s . c o m int candidatesConsidered = 0; while (candidatesConsidered < minCandidates) { for (FlatInstance<SparseFeatureVector, Integer> candidate : candidates) { // don't repeat an answer we already have if (candidateTracker.argmax().contains(candidate)) { continue; } // skip a random subset of the available candidates (ensuring we evaluate SOMEONE) if (rnd.nextDouble() > thinningRate) { continue; } candidatesConsidered += 1; int annotatorIndex = candidate.getMeasurement().getAnnotator(); String rawAnnotator = dataset.getInfo().getAnnotatorIdIndexer().get(annotatorIndex); MeasurementExpectation<Integer> candExpectation = ClassificationMeasurementExpectations .fromMeasurement(candidate.getMeasurement(), dataset, currentModel.getInstanceIndices(), currentModel.getLogNuY()); // calculate parameters to p(tau|x,y,w) double mean_jk = candExpectation.sumOfExpectedValuesOfSigma(); double alpha = currentModel.getNuSigma2()[annotatorIndex][0], beta = currentModel.getNuSigma2()[annotatorIndex][1]; double var_jk = beta / (alpha - 1); // point estimate (ignoring uncertainty in w) double mean_utility_jk = 0; for (int t = 0; t < numSamples; t++) { // double var_jk = 1.0/new GammaDistribution(alpha, beta).sample(); // sample variance (integrating over w). note: probably incorrect double tau_jkt = new NormalDistribution(mean_jk, Math.sqrt(var_jk)).sample(); MeasurementPojo speculativeMeasurementPojo = candidate.getMeasurement().getPojo().copy(); speculativeMeasurementPojo.value = tau_jkt; Measurement speculativeMeasurement = ClassificationMeasurementParser.pojoToMeasurement( speculativeMeasurementPojo, rawAnnotator, candidate.getSource(), candidate.getStartTimestamp(), candidate.getEndTimestamp(), dataset.getInfo().getIndexers()); FlatInstance<SparseFeatureVector, Integer> speculativeMeasurementInst = new BasicFlatInstance<SparseFeatureVector, Integer>( candidate.getInstanceId(), candidate.getSource(), annotatorIndex, candidate.getAnnotation(), speculativeMeasurement, candidate.getStartTimestamp(), candidate.getEndTimestamp()); // add the speculative measurement and train Datasets.addAnnotationToDataset(dataset, speculativeMeasurementInst); State model = modelTrainedOn(dataset, CANDIDATE_TRAINING_OPS, currentModel); // remove the speculative measurement Datasets.removeAnnotationFromDataset(dataset, speculativeMeasurementInst); // calculate utility U=R-C of this model (where reward = accuracy or equivalently, negative hamming loss) // and cost is constant double[][] logNuY = model.getLogNuY(); for (int i = 0; i < logNuY.length; i++) { mean_utility_jk += Math.exp(DoubleArrays.max(logNuY[i])); } } mean_utility_jk /= numSamples; candidateTracker.offer(mean_utility_jk, candidate); } } // return top k (and remove from future candidates) logger.info("\n**********************************************************\n" + "******* Selected batch of size " + candidateTracker.argmax().size() + " *******\n" + "**********************************************************\n"); candidates.removeAll(candidateTracker.argmax()); return candidateTracker.argmax(); }
From source file:beast.evomodel.speciation.BirthDeathModel.java
double logConditioningTerm(double height) { final double r = getR(); final double a = getA(); final double rho = getRho(); final double ca = 1 - a; final double erh = Math.exp(r * height); if (erh != 1.0) { return Math.log(r * ca * (rho + ca / (erh - 1))); } else { // use exp(x)-1 = x for x near 0 return Math.log(ca * (r * rho + ca / height)); }/*ww w . j a v a 2s . c om*/ }
From source file:com.opengamma.analytics.financial.interestrate.inflation.method.InflationMarketModelConvexityAdjustmentForCapFloor.java
/** * Computes the convexity adjustment for zero coupon inflation swap with a monthly index. * @param coupon The zero-coupon payment. * @param inflationConvexity The inflation provider. * @return The convexity adjustment.// w w w . j av a2 s . co m */ public double getZeroCouponConvexityAdjustment(final CapFloorInflationZeroCouponMonthly coupon, final BlackSmileCapInflationZeroCouponWithConvexityProviderInterface inflationConvexity) { Validate.notNull(coupon, "Coupon"); Validate.notNull(inflationConvexity, "Inflation"); final double fixingTime = coupon.getReferenceEndTime(); final double naturalPaymentTime = coupon.getNaturalPaymentTime(); final double paymentTime = coupon.getPaymentTime(); final double volatility = inflationConvexity.getInflationConvexityAdjustmentParameters() .getPriceIndexAtmVolatility()[0]; final double correlationInflationRate = inflationConvexity.getInflationConvexityAdjustmentParameters() .getPriceIndexRateCorrelation().getYValue(fixingTime); final double volBondForward = getVolBondForward(naturalPaymentTime, paymentTime, inflationConvexity); final double adjustment = volatility * volBondForward * correlationInflationRate * naturalPaymentTime; return Math.exp(adjustment); }
From source file:com.opengamma.analytics.financial.model.volatility.surface.SurfaceConverter.java
Surface<Double, Double, Double> moneynessToLogMoneyness(final Surface<Double, Double, Double> moneynessSurf) { final Function<Double, Double> surFunc = new Function<Double, Double>() { @Override/*from www.j av a 2s. c o m*/ public Double evaluate(final Double... tx) { final double t = tx[0]; final double lm = tx[1]; Validate.isTrue(t >= 0, "Must have t >= 0.0"); final double m = Math.exp(lm); return moneynessSurf.getZValue(t, m); } }; return FunctionalDoublesSurface.from(surFunc); }
From source file:dr.inference.model.IndianBuffetProcessPrior.java
@Override public double getSizeLogLikelihood() { PoissonDistribution poisson = new PoissonDistribution(alpha.getParameterValue(0) * H()); calculateLogLikelihood();/*from ww w. j av a 2 s . c om*/ return poisson.logPdf(KPlus) - Math.log(1 - Math.exp(-poisson.mean())); }
From source file:es.udc.gii.common.eaf.benchmark.real_param.cec2005.CEC2005ObjectiveFunction.java
public double ackley(double[] x) { double s1 = 0.0d; double s2 = 0.0d; for (int i = 0; i < x.length; i++) { s1 += x[i] * x[i];/*from w w w .j a v a 2s . c o m*/ s2 += Math.cos(2 * Math.PI * x[i]); } return -20 * Math.exp(-0.2 * Math.sqrt(1.0 / x.length * s1)) - Math.exp(1.0 / x.length * s2) + 20 + Math.E; }
From source file:mt.Tracking.java
public static XYSeries drawexpFunction(final interpolation.Polynomial polynomial, final double from, final double to, final double step, final String name) { XYSeries series = new XYSeries(name); for (double x = from; x <= to; x = x + step) series.add(x, Math.exp(polynomial.predict(x))); return series; }
From source file:com.opengamma.analytics.financial.interestrate.future.provider.BondFutureHullWhiteMethod.java
/** * Computes the future price from the curves used to price the underlying bonds and a Hull-White one factor model. * @param future The future security.//from www. j av a2s. c o m * @param data The curve and Hull-White parameters. * @param nbPoint The number of point in the numerical cross estimation. * @return The future price. */ public double price(final BondFuture future, final HullWhiteIssuerProviderInterface data, final int nbPoint) { ArgumentChecker.notNull(future, "Future"); ArgumentChecker.notNull(data, "Hull-White data bundle"); final Pair<String, Currency> issuerCcy = future.getDeliveryBasket()[0].getIssuerCcy(); ArgumentChecker.isTrue(data.getHullWhiteIssuerCurrency().equals(issuerCcy), "Incompatible data and futures"); final int nbBond = future.getDeliveryBasket().length; final String issuerName = future.getDeliveryBasket()[0].getIssuer(); final HullWhiteOneFactorPiecewiseConstantParameters parameters = data.getHullWhiteParameters(); final IssuerProviderInterface issuer = data.getIssuerProvider(); final MulticurveProviderInterface multicurvesDecorated = new MulticurveProviderDiscountingDecoratedIssuer( issuer, future.getCurrency(), issuerName); final double expiry = future.getNoticeLastTime(); final double delivery = future.getDeliveryLastTime(); final double dfdelivery = data.getIssuerProvider().getDiscountFactor(issuerCcy, delivery); // Constructing non-homogeneous point series for the numerical estimations. final int nbPtWing = ((int) Math.floor(nbPoint / 20.)); // Number of point on each wing. final int nbPtCenter = nbPoint - 2 * nbPtWing; final double prob = 1.0 / (2.0 * nbPtCenter); final double xStart = NORMAL.getInverseCDF(prob); final double[] x = new double[nbPoint]; for (int loopwing = 0; loopwing < nbPtWing; loopwing++) { x[loopwing] = xStart * (1.0 + (nbPtWing - loopwing) / 2.0); x[nbPoint - 1 - loopwing] = -xStart * (1.0 + (nbPtWing - loopwing) / 2.0); } for (int loopcent = 0; loopcent < nbPtCenter; loopcent++) { x[nbPtWing + loopcent] = xStart + loopcent * (-2.0 * xStart) / (nbPtCenter - 1); } // Figures for each bond final double[][] cfTime = new double[nbBond][]; final double[][] df = new double[nbBond][]; final double[][] alpha = new double[nbBond][]; final double[][] beta = new double[nbBond][]; final double[][] cfaAdjusted = new double[nbBond][]; final double[] e = new double[nbBond]; final double[][] pv = new double[nbPoint][nbBond]; final AnnuityPaymentFixed[] cf = new AnnuityPaymentFixed[nbBond]; for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) { cf[loopbnd] = future.getDeliveryBasket()[loopbnd].accept(CFEC, multicurvesDecorated); final int nbCf = cf[loopbnd].getNumberOfPayments(); cfTime[loopbnd] = new double[nbCf]; df[loopbnd] = new double[nbCf]; alpha[loopbnd] = new double[nbCf]; beta[loopbnd] = new double[nbCf]; cfaAdjusted[loopbnd] = new double[nbCf]; for (int loopcf = 0; loopcf < nbCf; loopcf++) { cfTime[loopbnd][loopcf] = cf[loopbnd].getNthPayment(loopcf).getPaymentTime(); df[loopbnd][loopcf] = issuer.getDiscountFactor(issuerCcy, cfTime[loopbnd][loopcf]); alpha[loopbnd][loopcf] = MODEL.alpha(parameters, 0.0, expiry, delivery, cfTime[loopbnd][loopcf]); beta[loopbnd][loopcf] = MODEL.futuresConvexityFactor(parameters, expiry, cfTime[loopbnd][loopcf], delivery); cfaAdjusted[loopbnd][loopcf] = df[loopbnd][loopcf] / dfdelivery * beta[loopbnd][loopcf] * cf[loopbnd].getNthPayment(loopcf).getAmount() / future.getConversionFactor()[loopbnd]; for (int looppt = 0; looppt < nbPoint; looppt++) { pv[looppt][loopbnd] += cfaAdjusted[loopbnd][loopcf] * Math.exp(-alpha[loopbnd][loopcf] * alpha[loopbnd][loopcf] / 2.0 - alpha[loopbnd][loopcf] * x[looppt]); } } e[loopbnd] = future.getDeliveryBasket()[loopbnd].getAccruedInterest() / future.getConversionFactor()[loopbnd]; for (int looppt = 0; looppt < nbPoint; looppt++) { pv[looppt][loopbnd] -= e[loopbnd]; } } // Minimum: create a list of index of the CTD in each interval and a first estimate of the crossing point (x[]). final double[] pvMin = new double[nbPoint]; final int[] indMin = new int[nbPoint]; for (int looppt = 0; looppt < nbPoint; looppt++) { pvMin[looppt] = Double.POSITIVE_INFINITY; for (int loopbnd = 0; loopbnd < nbBond; loopbnd++) { if (pv[looppt][loopbnd] < pvMin[looppt]) { pvMin[looppt] = pv[looppt][loopbnd]; indMin[looppt] = loopbnd; } } } final ArrayList<Double> refx = new ArrayList<>(); final ArrayList<Integer> ctd = new ArrayList<>(); int lastInd = indMin[0]; ctd.add(indMin[0]); for (int looppt = 1; looppt < nbPoint; looppt++) { if (indMin[looppt] != lastInd) { ctd.add(indMin[looppt]); lastInd = indMin[looppt]; refx.add(x[looppt]); } } // Sum on each interval final int nbInt = ctd.size(); final double[] kappa = new double[nbInt - 1]; double price = 0.0; if (nbInt == 1) { for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) { price += cfaAdjusted[ctd.get(0)][loopcf]; } price -= e[ctd.get(0)]; } else { // The intersections final BracketRoot bracketer = new BracketRoot(); final double accuracy = 1.0E-8; final RidderSingleRootFinder rootFinder = new RidderSingleRootFinder(accuracy); for (int loopint = 1; loopint < nbInt; loopint++) { final BondDifference cross = new BondDifference(cfaAdjusted[ctd.get(loopint - 1)], alpha[ctd.get(loopint - 1)], e[ctd.get(loopint - 1)], cfaAdjusted[ctd.get(loopint)], alpha[ctd.get(loopint)], e[ctd.get(loopint)]); final double[] range = bracketer.getBracketedPoints(cross, refx.get(loopint - 1) - 0.01, refx.get(loopint - 1) + 0.01); kappa[loopint - 1] = rootFinder.getRoot(cross, range[0], range[1]); } // From -infinity to first cross. for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(0)].length; loopcf++) { price += cfaAdjusted[ctd.get(0)][loopcf] * NORMAL.getCDF(kappa[0] + alpha[ctd.get(0)][loopcf]); } price -= e[ctd.get(0)] * NORMAL.getCDF(kappa[0]); // Between cross for (int loopint = 1; loopint < nbInt - 1; loopint++) { for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(loopint)].length; loopcf++) { price += cfaAdjusted[ctd.get(loopint)][loopcf] * (NORMAL.getCDF(kappa[loopint] + alpha[ctd.get(loopint)][loopcf]) - NORMAL.getCDF(kappa[loopint - 1] + alpha[ctd.get(loopint)][loopcf])); } price -= e[ctd.get(loopint)] * (NORMAL.getCDF(kappa[loopint]) - NORMAL.getCDF(kappa[loopint - 1])); } // From last cross to +infinity for (int loopcf = 0; loopcf < cfaAdjusted[ctd.get(nbInt - 1)].length; loopcf++) { price += cfaAdjusted[ctd.get(nbInt - 1)][loopcf] * (1.0 - NORMAL.getCDF(kappa[nbInt - 2] + alpha[ctd.get(nbInt - 1)][loopcf])); } price -= e[ctd.get(nbInt - 1)] * (1 - NORMAL.getCDF(kappa[nbInt - 2])); } return price; }