int main(int argc, char ** argv) { #ifdef QUESO_HAS_MPI MPI_Init(&argc, &argv); QUESO::FullEnvironment env(MPI_COMM_WORLD, "", "", NULL); #else QUESO::FullEnvironment env("", "", NULL); #endif QUESO::VectorSpace<> paramSpace(env, "param_", 1, NULL); QUESO::GslVector paramMins(paramSpace.zeroVector()); paramMins.cwSet(0.0); QUESO::GslVector paramMaxs(paramSpace.zeroVector()); paramMaxs.cwSet(1.0); QUESO::BoxSubset<> paramDomain("param_", paramSpace, paramMins, paramMaxs); // We should test the other cases of alpha and beta QUESO::GslVector alpha(paramSpace.zeroVector()); alpha[0] = 2.0; QUESO::GslVector beta(paramSpace.zeroVector()); beta[0] = 3.0; QUESO::BetaJointPdf<> pdf("", paramDomain, alpha, beta); QUESO::GslVector mean(paramSpace.zeroVector()); pdf.distributionMean(mean); const char *msg = "BetaJointPdf mean is incorrect"; double real_mean = alpha[0] / (alpha[0] + beta[0]); queso_require_less_equal_msg(std::abs(mean[0]-real_mean), TOL, msg); QUESO::GslMatrix var(paramSpace.zeroVector()); pdf.distributionVariance(var); const char *msgv = "BetaJointPdf variance is incorrect"; double real_var = alpha[0] * beta[0] / (alpha[0] + beta[0]) / (alpha[0] + beta[0]) / (alpha[0] + beta[0] + 1); queso_require_less_equal_msg(std::abs(var(0,0)-real_var), TOL, msgv); #ifdef QUESO_HAS_MPI MPI_Finalize(); #endif return 0; }
int bicgstab(const LinearOperator& A, HilbertSpaceX& x, const HilbertSpaceB& b, const Preconditioner& M, Iteration& iter) { typedef typename mtl::Collection<HilbertSpaceX>::value_type Scalar; typedef HilbertSpaceX Vector; Scalar rho_1(0), rho_2(0), alpha(0), beta(0), gamma, omega(0); Vector p(size(x)), phat(size(x)), s(size(x)), shat(size(x)), t(size(x)), v(size(x)), r(size(x)), rtilde(size(x)); r = b - A * x; rtilde = r; while (! iter.finished(r)) { rho_1 = dot(rtilde, r); MTL_THROW_IF(rho_1 == 0.0, unexpected_orthogonality()); if (iter.first()) p = r; else { MTL_THROW_IF(omega == 0.0, unexpected_orthogonality()); beta = (rho_1 / rho_2) * (alpha / omega); p = r + beta * (p - omega * v); } phat = solve(M, p); v = A * phat; gamma = dot(rtilde, v); MTL_THROW_IF(gamma == 0.0, unexpected_orthogonality()); alpha = rho_1 / gamma; s = r - alpha * v; if (iter.finished(s)) { x += alpha * phat; break; } shat = solve(M, s); t = A * shat; omega = dot(t, s) / dot(t, t); x += omega * shat + alpha * phat; r = s - omega * t; rho_2 = rho_1; ++iter; } return iter; }
inline std::size_t operator()(RandomGenerator& gen) { std::size_t result = std::numeric_limits<std::size_t>::max(); double theta_max = -1; beta_distribution<double> beta; for(std::size_t i=0, I=this->size(); i < I; ++i){ double theta = beta(gen, std::make_pair(succs[i], fails[i])); if(theta > theta_max){ result = i; theta_max = theta; } } return result; }
T binomial_coefficient(unsigned n, unsigned k, const Policy& pol) { BOOST_STATIC_ASSERT(!pdalboost::is_integral<T>::value); BOOST_MATH_STD_USING static const char* function = "pdalboost::math::binomial_coefficient<%1%>(unsigned, unsigned)"; if(k > n) return policies::raise_domain_error<T>( function, "The binomial coefficient is undefined for k > n, but got k = %1%.", k, pol); T result; if((k == 0) || (k == n)) return 1; if((k == 1) || (k == n-1)) return n; if(n <= max_factorial<T>::value) { // Use fast table lookup: result = unchecked_factorial<T>(n); result /= unchecked_factorial<T>(n-k); result /= unchecked_factorial<T>(k); } else { // Use the beta function: if(k < n - k) result = k * beta(static_cast<T>(k), static_cast<T>(n-k+1), pol); else result = (n - k) * beta(static_cast<T>(k+1), static_cast<T>(n-k), pol); if(result == 0) return policies::raise_overflow_error<T>(function, 0, pol); result = 1 / result; } // convert to nearest integer: return ceil(result - 0.5f); }
// backward Equations NumericMatrix backwardEquations(QTLCross* cross, const IntegerVector& genotypes, const IntegerMatrix& founder_geno, // columns are markers, rows are founder lines const bool is_X_chr, const bool is_female, const IntegerVector& cross_info, const NumericVector& rec_frac, const IntegerVector& marker_index, const double error_prob, const IntegerVector& poss_gen) { int n_pos = marker_index.size(); // possible genotypes for this chromosome and individual int n_gen = poss_gen.size(); // to contain ln Pr(G_i = g | marker data) NumericMatrix beta(n_gen, n_pos); // backward equations for(int pos = n_pos-2; pos >= 0; pos--) { for(int il=0; il<n_gen; il++) { for(int ir=0; ir<n_gen; ir++) { double to_add = beta(ir,pos+1) + cross->step(poss_gen[il], poss_gen[ir], rec_frac[pos], is_X_chr, is_female, cross_info); if(marker_index[pos+1] >=0) to_add += cross->emit(genotypes[marker_index[pos+1]], poss_gen[ir], error_prob, founder_geno(_, marker_index[pos+1]), is_X_chr, is_female, cross_info); if(ir==0) beta(il,pos) = to_add; else beta(il,pos) = addlog(beta(il,pos), to_add); } } } return beta; }
void BinomialLogitSamplerRwm::draw(){ const std::vector<Ptr<BinomialRegressionData> > &data(m_->dat()); SpdMatrix ivar(pri_->siginv()); Vector beta(m_->Beta()); for(int i = 0; i < data.size(); ++i){ Ptr<BinomialRegressionData> dp = data[i]; double eta = beta.dot(dp->x()); double prob = plogis(eta); ivar.add_outer(dp->x(), dp->n() * prob * (1-prob)); } proposal_->set_ivar(ivar); beta = sam_.draw(beta); m_->set_Beta(beta); }
FC_nonp_variance::FC_nonp_variance(MASTER_OBJ * mp, unsigned & enr, GENERAL_OPTIONS * o, DISTR * lp, const ST::string & t,const ST::string & fp, DESIGN * Dp,FC_nonp * FCn,vector<ST::string> & op, vector<ST::string> & vn) : FC(o,t,1,2,fp) { FCnonpp = FCn; likep = lp; designp = Dp; masterp = mp; equationnr = enr, lambdaconst = false; read_options(op,vn); datamatrix betanew(1,2); betanew(0,0) = likep->get_scale()/lambdastart; betanew(0,1) = lambdastart; setbeta(betanew); FCnonpp->tau2 = beta(0,0); FCnonpp->lambda = beta(0,1); }
void LS::impute_latent_data(){ double log_alpha = mod_->log_alpha(); const std::vector<Ptr<BRD> > & dat(mod_->dat()); uint n = dat.size(); suf_->clear(); Vec beta(mod_->beta()); for(uint i=0; i<n; ++i){ Ptr<BRD> dp = dat[i]; const Vec &x(dp->x()); double eta = mod_->predict(x) + log_alpha; double z = draw_z(dp->y(), eta); double lam = draw_lambda(fabs(z- eta)); suf_->add_data(x,z, 1.0/lam); } }
std::string ThreeSstarCoeffs::str() const { std::stringstream ss; for (int i=0; i<nb_stages(); ++i) { ss << std::setw(2) << i << ": " << std::setw(9) << delta(i) << std::setw(9) << beta(i) << std::setw(9) << gamma1(i) << std::setw(9) << gamma2(i) << std::setw(9) << gamma3(i); ss << std::endl; } return ss.str(); }
double do_time_sacado_fad_gemm(unsigned int m, unsigned int n, unsigned int k, unsigned int ndot, unsigned int nloop, bool use_dynamic) { Sacado::Random<double> urand(0.0, 1.0); unsigned int sz = (m*k+k*n+m*n)*(1+ndot); Teuchos::BLAS<int,FadType> blas(false,use_dynamic,sz); Sacado::Fad::Vector<unsigned int, FadType> A(m*k,ndot), B(k*n,ndot), C (m*n,ndot); for (unsigned int j=0; j<k; j++) { for (unsigned int i=0; i<m; i++) { A[i+j*m] = FadType(ndot, urand.number()); for (unsigned int l=0; l<ndot; l++) A[i+j*m].fastAccessDx(l) = urand.number(); } } for (unsigned int j=0; j<n; j++) { for (unsigned int i=0; i<k; i++) { B[i+j*k] = FadType(ndot, urand.number()); for (unsigned int l=0; l<ndot; l++) B[i+j*k].fastAccessDx(l) = urand.number(); } } for (unsigned int j=0; j<n; j++) { for (unsigned int i=0; i<m; i++) { C[i+j*m] = FadType(ndot, urand.number()); for (unsigned int l=0; l<ndot; l++) C[i+j*m].fastAccessDx(l) = urand.number(); } } FadType alpha(ndot, urand.number()); FadType beta(ndot, urand.number()); for (unsigned int l=0; l<ndot; l++) { alpha.fastAccessDx(l) = urand.number(); beta.fastAccessDx(l) = urand.number(); } Teuchos::Time timer("Teuchos Fad GEMM", false); timer.start(true); for (unsigned int j=0; j<nloop; j++) { blas.GEMM(Teuchos::NO_TRANS, Teuchos::NO_TRANS, m, n, k, alpha, &A[0], m, &B[0], k, beta, &C[0], m); } timer.stop(); return timer.totalElapsedTime() / nloop; }
OdeSolution AbstractRushLarsenCardiacCell::Compute(double tStart, double tEnd, double tSamp) { // In this method, we iterate over timesteps, doing the following for each: // - update V using a forward Euler step // - do as in ComputeExceptVoltage(t) to update the remaining state variables // using Rush Larsen method or forward Euler as appropriate // Check length of time interval if (tSamp < mDt) { tSamp = mDt; } const unsigned n_steps = (unsigned) floor((tEnd - tStart)/tSamp + 0.5); assert(fabs(tStart+n_steps*tSamp - tEnd) < 1e-12); const unsigned n_small_steps = (unsigned) floor(tSamp/mDt+0.5); assert(fabs(mDt*n_small_steps - tSamp) < 1e-12); // Initialise solution store OdeSolution solutions; solutions.SetNumberOfTimeSteps(n_steps); solutions.rGetSolutions().push_back(rGetStateVariables()); solutions.rGetTimes().push_back(tStart); solutions.SetOdeSystemInformation(this->mpSystemInfo); std::vector<double> dy(mNumberOfStateVariables, 0); std::vector<double> alpha(mNumberOfStateVariables, 0); std::vector<double> beta(mNumberOfStateVariables, 0); // Loop over time for (unsigned i=0; i<n_steps; i++) { double curr_time = tStart; for (unsigned j=0; j<n_small_steps; j++) { curr_time = tStart + i*tSamp + j*mDt; EvaluateEquations(curr_time, dy, alpha, beta); UpdateTransmembranePotential(dy); ComputeOneStepExceptVoltage(dy, alpha, beta); VerifyStateVariables(); } // Update solutions solutions.rGetSolutions().push_back(rGetStateVariables()); solutions.rGetTimes().push_back(curr_time+mDt); } return solutions; }
Foam::backwardDiffusionFvPatchScalarField::backwardDiffusionFvPatchScalarField ( const fvPatch& p, const DimensionedField<scalar, volMesh>& iF ) : mixedUserDefinedFvPatchScalarField(p, iF) { alfa() = 0.0; beta() = 0.0; eta() = 0.0; omega0() = 0.0; rho0() = 0.0; epsilon() = 0.0; nameInternal_ = dimensionedInternalField().name(); }
// ------------------------------------------------------------- // MatMult_DenseGA // ------------------------------------------------------------- static PetscErrorCode MatMult_DenseGA(Mat mat, Vec x, Vec y) { // FIXME: I'm assuming the Mat and Vec's are compatible and that's // been checked somewhere else. Probably a mistake. PetscErrorCode ierr = 0; struct MatGACtx *ctx; ierr = MatShellGetContext(mat, &ctx); CHKERRQ(ierr); PetscInt Arows, Acols; ierr = MatGetSize(mat, &Arows, &Acols); CHKERRQ(ierr); int g_x, g_y; ierr = Vec2GA(x, ctx->gaGroup, &g_x, false); CHKERRQ(ierr); ierr = Vec2GA(y, ctx->gaGroup, &g_y, false); CHKERRQ(ierr); PetscScalarGA alpha(one), beta(zero); int ndim, itype, lo[2] = {0,0}, ahi[2], xhi[2], yhi[2]; NGA_Inquire(ctx->ga, &itype, &ndim, ahi); ahi[0] -= 1; ahi[1] -= 1; NGA_Inquire(g_x, &itype, &ndim, xhi); xhi[0] -= 1; xhi[1] -= 1; NGA_Inquire(g_y, &itype, &ndim, yhi); yhi[0] -= 1; yhi[1] -= 1; // GA_Print(ctx->ga); // GA_Print(g_x); NGA_Matmul_patch('N', 'N', &alpha, &beta, ctx->ga, lo, ahi, g_x, lo, xhi, g_y, lo, yhi); GA_Pgroup_sync(ctx->gaGroup); // GA_Print(g_y); ierr = GA2Vec(g_y, y); CHKERRQ(ierr); GA_Destroy(g_y); GA_Destroy(g_x); MPI_Comm comm; ierr = PetscObjectGetComm((PetscObject)mat,&comm); CHKERRQ(ierr); ierr = MPI_Barrier(comm); return ierr; }
void ContrastiveLossLayer<Dtype>::Backward_cpu(const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) { Dtype margin = this->layer_param_.contrastive_loss_param().margin(); bool legacy_version = this->layer_param_.contrastive_loss_param().legacy_version(); for (int i = 0; i < 2; ++i) { if (propagate_down[i]) { const Dtype sign = (i == 0) ? 1 : -1; const Dtype alpha = sign * top[0]->cpu_diff()[0] / static_cast<Dtype>(bottom[i]->num()); int num = bottom[i]->num(); int channels = bottom[i]->channels(); for (int j = 0; j < num; ++j) { Dtype* bout = bottom[i]->mutable_cpu_diff(); if (static_cast<int>(bottom[2]->cpu_data()[j])) { // similar pairs caffe_cpu_axpby( channels, alpha, diff_.cpu_data() + (j*channels), Dtype(0.0), bout + (j*channels)); } else { // dissimilar pairs Dtype mdist(0.0); Dtype beta(0.0); if (legacy_version) { mdist = margin - dist_sq_.cpu_data()[j]; beta = -alpha; } else { Dtype dist = sqrt(dist_sq_.cpu_data()[j]); mdist = margin - dist; beta = -alpha * mdist / (dist + Dtype(1e-4)); } if (mdist > Dtype(0.0)) { caffe_cpu_axpby( channels, beta, diff_.cpu_data() + (j*channels), Dtype(0.0), bout + (j*channels)); } else { caffe_set(channels, Dtype(0), bout + (j*channels)); } } } } } }
Foam::tmp<Foam::volScalarField> Foam::dragModels::WenYu::K ( const volScalarField& Ur ) const { volScalarField beta(max(scalar(1) - alpha_, scalar(1.0e-6))); volScalarField bp(pow(beta, -2.65)); volScalarField Re(max(Ur*phase1_.d()/phase2_.nu(), scalar(1.0e-3))); volScalarField Cds ( neg(Re - 1000)*(24.0*(1.0 + 0.15*pow(Re, 0.687))/Re) + pos(Re - 1000)*0.44 ); return 0.75*Cds*phase2_.rho()*Ur*bp/phase1_.d(); }
AMControlInfoList REIXSXESCalibration::computeSpectrometerPosition(int gratingIndex, double eV, double focusOffsetMm, double tiltOffsetDeg) const { qDebug() << "Spectrometer Geometry calculations for: " << gratingNames().at(gratingIndex) << eV << "eV," << focusOffsetMm << "mm defocus," << tiltOffsetDeg << "deg tilt offset:"; AMControlInfoList rv; double hexU = hexapodU(gratingIndex); QVector3D hexXYZ = hexapodXYZ(gratingIndex); QVector3D hexRST = hexapodRST(gratingIndex); QVector3D detPos = detectorPos(eV, gratingIndex); double theta = spectrometerTheta(detPos); double translation = detectorTranslation(detPos, theta, focusOffsetMm); double spectrometerRotation = spectrometerRotationDrive(theta); double tilt = tiltStageDrive(eV, gratingIndex, theta, tiltOffsetDeg); rv.append(AMControlInfo("spectrometerRotationDrive", spectrometerRotation, 0,0, "mm", 0.1, "Linear drive motor for spectrometer angle")); rv.append(AMControlInfo("detectorTranslation", translation, 0,0, "mm", 0.1, "Detector translation")); rv.append(AMControlInfo("detectorTiltDrive", tilt, 0.0, 0.0, "mm", 0.1, "Linear drive motor for detector tilt")); rv.append(AMControlInfo("hexapodX", hexXYZ.x(), 0, 0, "mm", 0.1, "Hexapod X position")); rv.append(AMControlInfo("hexapodY", hexXYZ.y(), 0, 0, "mm", 0.1, "Hexapod Y position")); rv.append(AMControlInfo("hexapodZ", hexXYZ.z(), 0, 0, "mm", 0.1, "Hexapod Z position")); rv.append(AMControlInfo("hexapodU", hexU, 0,0, "deg", 0.1, "Hexapod Tilt around X axis")); rv.append(AMControlInfo("hexapodR", hexRST.x(), 0,0, "mm", 0.1, "Hexapod rotation point R")); rv.append(AMControlInfo("hexapodS", hexRST.y(), 0,0, "mm", 0.1, "Hexapod rotation point S")); rv.append(AMControlInfo("hexapodT", hexRST.z(), 0,0, "mm", 0.1, "Hexapod rotation point T")); qDebug() << " Alpha required for rowland condition (deg):" << r2d(alpha(gratingIndex)); qDebug() << " Beta using that alpha, at " << eV << "eV:" << r2d(beta(eV, gratingIndex)); qDebug() << " Angle of slit-origin ray above y axis (deg)" << r2d(sTheta(gratingIndex)); qDebug() << " Grating tilt to achieve required alpha (deg):" << hexU; qDebug() << " r (mm):" << r(gratingIndex); qDebug() << " r-prime (mm):" << rPrime(eV, gratingIndex); qDebug() << " Spectrometer dTheta: angle up from y axis to center of detector (deg):" << r2d(dTheta(eV, gratingIndex)); qDebug() << " Detector position:" << detPos; qDebug() << " Spectrometer theta: (deg)" << r2d(theta); qDebug() << " Translation: (mm)" << translation; qDebug() << " Spectrometer rotation stage translation: (mm)" << spectrometerRotation; qDebug() << " Detector tilt phi (detector angle down to positive y axis) (deg):" << r2d(detectorPhi(eV, gratingIndex)); qDebug() << " Extra tilt on top of spectrometer angle" << r2d(detectorPhi(eV, gratingIndex) - theta); qDebug() << " Tilt stage translation: (mm)" << tilt; return rv; }
arma::Mat< double > DynamicsTrappenberg::sigma( const arma::Mat< double > x, const arma::Mat< double > u, const mxArray *theta, const mxArray *ptheta) { arma::Mat< double > beta(mxGetPr(mxGetField(theta, 0, "beta")), x.n_rows, 1, 1); arma::Mat< double > baseline(mxGetPr(mxGetField(theta, 0, "theta")), x.n_rows, 1, 1); arma::Mat< double > dx = 1/(1 + exp(-x.col(INDEX_NODES) % beta + baseline)); return dx; }
/* Update alpha and beta values once per RTT */ static void update_params(struct sock *sk) { struct tcp_sock *tp = tcp_sk(sk); struct illinois *ca = inet_csk_ca(sk); if (tp->snd_cwnd < win_thresh) { ca->alpha = ALPHA_BASE; ca->beta = BETA_BASE; } else if (ca->cnt_rtt > 0) { u32 dm = max_delay(ca); u32 da = avg_delay(ca); ca->alpha = alpha(ca, da, dm); ca->beta = beta(da, dm); } rtt_reset(sk); }
Foam::tmp<Foam::volScalarField> Foam::GidaspowSchillerNaumann::K ( const volScalarField& Ur ) const { volScalarField beta(max(scalar(1) - alpha_, scalar(1e-6))); volScalarField bp(pow(beta, -2.65)); volScalarField Re(max(beta*Ur*phasea_.d()/phaseb_.nu(), scalar(1.0e-3))); volScalarField Cds ( neg(Re - 1000)*(24.0*(1.0 + 0.15*pow(Re, 0.687))/Re) + pos(Re - 1000)*0.44 ); return 0.75*Cds*phaseb_.rho()*Ur*bp/phasea_.d(); }
/// /// \brief Vespucci::Math::DimensionReduction::EstimateAdditiveNoise /// \param noise /// \param noise_correlation /// \param sample /// The slow additive noise mat::mator from the HySime paper. I'm looking into /// faster ones. void Vespucci::Math::DimensionReduction::EstimateAdditiveNoise(arma::mat &noise, arma::mat &noise_correlation, const arma::mat &sample) { double small = 1e-6; noise = arma::zeros(sample.n_rows, sample.n_cols); arma::mat RR = sample * sample.t(); arma::mat RRi = arma::inv(RR + small*arma::eye(sample.n_rows, sample.n_rows)); arma::mat XX, RRa, beta; for (arma::uword i = 0; i < sample.n_rows; ++i){ XX = RRi - (RRi.col(i) * RRi.row(i))/RRi(i, i); RRa = RR.col(i); RRa(i) = 0; beta = XX * RRa; beta(i) = 0; noise.row(i) = sample.row(i) - beta.t() * sample; } arma::mat nn = noise * noise.t() / sample.n_rows; noise_correlation = arma::diagmat(nn.diag()); }
void AbstractRushLarsenCardiacCell::SolveAndUpdateState(double tStart, double tEnd) { TimeStepper stepper(tStart, tEnd, mDt); std::vector<double> dy(mNumberOfStateVariables, 0); std::vector<double> alpha(mNumberOfStateVariables, 0); std::vector<double> beta(mNumberOfStateVariables, 0); while (!stepper.IsTimeAtEnd()) { EvaluateEquations(stepper.GetTime(), dy, alpha, beta); UpdateTransmembranePotential(dy); ComputeOneStepExceptVoltage(dy, alpha, beta); VerifyStateVariables(); stepper.AdvanceOneTimeStep(); } }
void Foam::backwardDiffusionFvPatchScalarField::updateCoeffs() { if (updated()) { return; } const label patchi = patch().index(); // Calculating alfa const volVectorField& U = db().lookupObject<volVectorField>("U"); tmp<vectorField> n = patch().nf(); alfa() = -(n & U.boundaryField()[patchi]); // Calculating eta const volScalarField& rho = db().lookupObject<volScalarField>("rho"); eta() = rho0() / rho.boundaryField()[patchi]; nameInternal_ = dimensionedInternalField().name(); bool soretEffect = db().foundObject<volScalarField>("gas::Dsoret_" + nameInternal_); // Calculating epsilon if (soretEffect == true) { const volScalarField& Dsoret = db().lookupObject<volScalarField>("gas::Dsoret_" + nameInternal_); const volScalarField& T = db().lookupObject<volScalarField>("T"); epsilon() = -T.boundaryField()[patchi].snGrad() / T.boundaryField()[patchi] * Dsoret.boundaryField()[patchi]; } else { epsilon() = 0.; } // Calculating beta nameInternal_ = dimensionedInternalField().name(); const volScalarField& Dmix = db().lookupObject<volScalarField>("gas::Dmix_" + nameInternal_); beta() = Dmix.boundaryField()[patchi]*this->patch().deltaCoeffs(); if (debug) { } mixedUserDefinedFvPatchScalarField::updateCoeffs(); }
void diff_dt_nu(double* x, double* nu, double* out) { double t1, t2, t3, t4, t6, t10, t11, t13, t14, t15, t16; t1=((*nu)+1.0)/2.0; t2=digamma(t1); t3=beta((*nu)*0.5,0.5); t4=sqrt(*nu); t6=digamma(0.5*(*nu)); t10=-0.5/t3/t4*(t6-t2+1.0/(*nu)); t11=1.0+((*x)*(*x))/(*nu); t13=pow(t11,-t1); t14=1.0/t3/t4; t15=log(t11); t16=-t1*(*x)*(*x)/(*nu)/(*nu)/t11; out[0]=t10*t13 + t14*(t13*(-0.5*t15-t16)); }
//--------------------------------------------------------------------------- result_readTransportProperties readTransportProperties( const volVectorFieldHolder& U, const surfaceScalarFieldHolder& phi, singlePhaseTransportModelHolder& laminarTransport ) { laminarTransport = singlePhaseTransportModelHolder( U, phi ); // Thermal expansion coefficient [1/K] dimensionedScalar beta(laminarTransport->lookup("beta")); // Reference temperature [K] dimensionedScalar TRef(laminarTransport->lookup("TRef")); // Laminar Prandtl number dimensionedScalar Pr(laminarTransport->lookup("Pr")); // Turbulent Prandtl number dimensionedScalar Prt(laminarTransport->lookup("Prt")); return result_readTransportProperties( beta, TRef, Pr, Prt ); }
void diffX_nu_tCopula(double* x, double* param, double* out) { //double xmin=0, val=0, err=0, val2; double xmax=0; double *inbeder_out; inbeder_out=Calloc(3,double); double t1, t2, t3, t4, t5, t6, t7; double x_help; double nu = param[1]; if(*x>=0) { x_help=*x; } else { x_help=-*x; } xmax=nu/(nu+x_help*x_help); t1=dt(x_help,nu,0); t2=nu/2.0; t3=0.5; inbeder(&xmax,&t2,&t3,inbeder_out); t4=(nu+1.0)/2.0; t5=pow(nu,nu/2.0-1.0)*x_help; t6=pow(1.0/(x_help*x_help+nu),t4); t7=beta(nu/2.0,0.5); out[0]=1.0/(2.0*t1)*( 0.5*inbeder_out[1]+(t5*t6)/t7 ); if(*x<0) { out[0]=-out[0]; } Free(inbeder_out); }
double do_time_sacado_fad_gemv(unsigned int m, unsigned int n, unsigned int ndot, unsigned int nloop, bool use_dynamic) { Sacado::Random<double> urand(0.0, 1.0); unsigned int sz = m*n*(1+ndot) + 2*n*(1+ndot); Teuchos::BLAS<int,FadType> blas(false,use_dynamic,sz); Sacado::Fad::Vector<unsigned int, FadType> A(m*n,ndot), B(n,ndot), C(m,ndot); for (unsigned int j=0; j<n; j++) { for (unsigned int i=0; i<m; i++) { //A[i+j*m] = urand.number(); A[i+j*m] = FadType(ndot, urand.number()); for (unsigned int k=0; k<ndot; k++) A[i+j*m].fastAccessDx(k) = urand.number(); } B[j] = FadType(ndot, urand.number()); for (unsigned int k=0; k<ndot; k++) B[j].fastAccessDx(k) = urand.number(); } for (unsigned int i=0; i<m; i++) { C[i] = FadType(ndot, urand.number()); for (unsigned int k=0; k<ndot; k++) C[i].fastAccessDx(k) = urand.number(); } FadType alpha(ndot, urand.number()); FadType beta(ndot, urand.number()); for (unsigned int k=0; k<ndot; k++) { alpha.fastAccessDx(k) = urand.number(); beta.fastAccessDx(k) = urand.number(); } Teuchos::Time timer("Teuchos Fad GEMV", false); timer.start(true); for (unsigned int j=0; j<nloop; j++) { blas.GEMV(Teuchos::NO_TRANS, m, n, alpha, &A[0], m, &B[0], 1, beta, &C[0], 1); } timer.stop(); return timer.totalElapsedTime() / nloop; }
// Truncation at t = 1. double RNG::right_tgamma_beta(double shape, double rate) { double a = shape; double b = rate; double u = unif(); int k = 1; double cdf = omega_k(1, a, b); while (u > cdf) { cdf += omega_k(++k, a, b); if (k % 100000 == 0) { printf("right_tgamma_beta (itr k=%i): a=%g, b=%g, u=%g, cdf=%g\n", k, a, b, u, cdf); #ifdef USE_R R_CheckUserInterrupt(); #endif } } return beta(a, k); }
void InfAdmixture::samplePs(bool mean) { if(mean){ for(int c1=0;c1<state->getP();c1++) { for(int c2=0;c2<state->getP();c2++) { P[c1][c2]=(state->sumXab(c1,c2)) + state->getBeta(c1,c2); } }}else{ std::vector <double> beta(state->getP(),1.0); for(int c1=0;c1<state->getP();c1++) { for(int c2=0;c2<state->getP();c2++) beta[c2]= state->getBeta(c1,c2); RDirichlet(&beta,&(P[c1])); } } for(int c1=0;c1<state->getP();c1++) { double rs=0; for(int c2=0;c2<state->getP();c2++) rs+=P[c1][c2]; for(int c2=0;c2<state->getP();c2++) P[c1][c2]/=rs; } }
/* funzione per interpolare l'energia */ Double_t en ( Double_t *x, Double_t *par ) { // par[1] = .186; // par[0] = 1.68; /* variabile ausiliaria: par[0] = $\hbar c$ */ Double_t l = TMath::Power( B * par[0] / x[0], 1./3. ); /* * termine tra parentesi (ho sfruttato le funzioni note per non * dover riscrivere un'altra funzione per calcolare $l d\beta/dl$) */ Double_t tmp = l * betad( l, 1. ) - beta( l, 1. ); /* moltiplico per il coefficiente */ tmp = tmp * l * l / ( par[1] * B ); /* primo termine fuori dalle parentesi */ tmp += l * betad( l, 0. ); /* incremento di uno */ tmp += 1.; /* 'par[2]' è la densità d'energia $e_0$ */ return par[2] - tmp / ( 3. * B * x[0] * x[0] ); }
Foam::backwardDiffusionFvPatchScalarField::backwardDiffusionFvPatchScalarField ( const fvPatch& p, const DimensionedField<scalar, volMesh>& iF, const dictionary& dict ) : mixedUserDefinedFvPatchScalarField(p, iF) { // Name of field nameInternal_ = dimensionedInternalField().name(); // Set the nominal value omega0() = scalarField("omega0", dict, p.size()); rho0() = scalarField("rho0", dict, p.size()); // Fixed value condition is forced alfa() = 1000.; eta() = 1.; // Calculating epsilon epsilon() = 0; // Calculating beta const double Dmix = 1e-10; beta() = Dmix*this->patch().deltaCoeffs(); // Read value if available if (dict.found("value")) { fvPatchField<scalar>::operator= ( scalarField("value", dict, p.size()) ); } else { evaluate(); } }