void noekeon_dec(void *buffer, const void *key){ uint8_t rc; int8_t i; uint8_t nullv[16]; uint8_t dkey[16]; changendian(buffer); memset(nullv, 0, 16); memcpy(dkey, key, 16); changendian(dkey); theta((uint32_t*)nullv, (uint32_t*)dkey); // cli_putstr_P(PSTR("\r\nTheta: ")); // cli_hexdump(dkey, 16); for(i=ROUND_NR-1; i>=0; --i){ #ifdef __AVR__ rc = pgm_read_byte(rc_tab+i); #else rc = rc_tab[i]; #endif noekeon_round((uint32_t*)dkey, (uint32_t*)buffer, 0, rc); } theta((uint32_t*)dkey, (uint32_t*)buffer); ((uint8_t*)buffer)[RC_POS] ^= 0x80; changendian(buffer); }
void Spacetime::makeInitialGuess_analytic(void) { /// compute G, C, M, and MInv state matrices matrix<double> G, C, M, MInv; G = computeG_analytic(); M = computeM_analytic(); C = computeC_analytic(); MInv = !M; // compute torque with PD controller double Kp = 1.5, Kv = 1.5; matrix<double> state = getState(); matrix<double> theta(2,1); double theta1 = state(0,0); double theta2 = state(1,0); theta(0,0) = theta1; theta(1,0) = theta2; matrix<double> thetad(state_d); thetad.SetSize(DOF*joints.size(), 1); matrix<double> thetaDot(2,1); thetaDot(0,0) = state(2,0); thetaDot(1,0) = state(3,0); matrix<double> u = C + G + M*(Kp*(thetad - theta) - Kv*thetaDot); uSequence.push_back(u); // apply torque and advance system stepPhysics_analytic(u); }
/* * Noekeon Encryption */ void Noekeon::encrypt_n(const byte in[], byte out[], size_t blocks) const { for(size_t i = 0; i != blocks; ++i) { u32bit A0 = load_be<u32bit>(in, 0); u32bit A1 = load_be<u32bit>(in, 1); u32bit A2 = load_be<u32bit>(in, 2); u32bit A3 = load_be<u32bit>(in, 3); for(size_t j = 0; j != 16; ++j) { A0 ^= RC[j]; theta(A0, A1, A2, A3, EK.data()); A1 = rotate_left(A1, 1); A2 = rotate_left(A2, 5); A3 = rotate_left(A3, 2); gamma(A0, A1, A2, A3); A1 = rotate_right(A1, 1); A2 = rotate_right(A2, 5); A3 = rotate_right(A3, 2); } A0 ^= RC[16]; theta(A0, A1, A2, A3, EK.data()); store_be(out, A0, A1, A2, A3); in += BLOCK_SIZE; out += BLOCK_SIZE; } }
static void group_velocity (int ik, int ith, FttVector * u, guint ntheta, gdouble g) { double cg = g/(4.*M_PI*frequency (ik)); u->x = cg*cos (theta (ith, ntheta)); u->y = cg*sin (theta (ith, ntheta)); u->z = 0.; }
TrifBank::TrifBank(float alpha, SizeType filterCount, SizeType fftSize, float sampleFreq, float minFreq, float maxFreq) { float startFreq, endFreq; int i; float f, d, z; endFreq = maxFreq; if (filterCount == 0 || fftSize == 0 || sampleFreq <= 0 || minFreq < 0 || maxFreq < 0 ) { throw StrangerException("Arguments have not valid size values"); } mSize = filterCount; mFftSize = fftSize; mFilterBank.resize(mSize+2, 0); if (endFreq <= 0) { endFreq = 0.5; } mFilterBank[0] = (SizeType)Round(2 * minFreq * ((float)(fftSize / 2 - 1))); mFilterBank[filterCount+1] = (SizeType)Round(2 * endFreq * (float)(fftSize / 2 - 1)); startFreq = (minFreq) ? theta(2.0 * M_PI * minFreq, alpha) : 0.0; /* pulses in transform domain */ endFreq = (endFreq < 0.5) ? theta(2.0 * M_PI * endFreq, alpha) : M_PI; d = (endFreq - startFreq) / (float)(filterCount + 1); z = (float)(fftSize / 2 - 1) / M_PI; f = startFreq; for(i = 1; i <= filterCount; i++) { f += d; mFilterBank[i] = (SizeType)Round(thetaInv(f, alpha) * z); /* index in the original domain */ } }
void VerdictVector::rtheta_to_xy() { //careful about overwriting double x_ = r() * cos( theta() ); double y_ = r() * sin( theta() ); x( x_ ); y( y_ ); }
vector ConstructTheta(double cr, vector& c) { vector theta(c.GetLength(),.0); for(int i = 0; i < c.GetLength(); i++) if(c(i) >= cr) theta(i) = 1.0; return theta; }
int main() { const int sz=7; CArray A(sz); A(0) = complex<float>(1,2); A(1) = complex<float>(3,4); Array<float,1> Ar = real(A); BZTEST(int(Ar(0)) == 1 && int(Ar(1)) == 3); Array<float,1> Ai = imag(A); BZTEST(int(Ai(0)) == 2 && int(Ai(1)) == 4); CArray Ac(sz); Ac = conj(A); BZTEST(Ac(0) == complex<float>(1,-2)); BZTEST(Ac(1) == complex<float>(3,-4)); Array<float,1> Ab(sz); Ab = abs(A); BZTEST(fabs(Ab(0) - 2.236068) < eps); BZTEST(fabs(Ab(1) - 5.0) < eps); Ab = arg(A); BZTEST(fabs(Ab(0) - atan(2.0)) < eps); BZTEST(fabs(Ab(1) - atan(4.0/3.0)) < eps); Array<float,1> r(sz), theta(sz); r(0) = 4.0f; r(1) = 15.0f; theta(0) = float(3.141592/3.0); theta(1) = float(3.0*3.141592/2.0); Ac = blitz::polar(r,theta); BZTEST(fabs(real(Ac(0)) - 2) < eps); BZTEST(fabs(imag(Ac(0)) - 3.4641012) < eps); BZTEST(fabs(real(Ac(1)) - 0.0) < eps); BZTEST(fabs(imag(Ac(1)) + 15.0) < eps); Array<complex<long double>,1> A11(5),B11(5),C11(5); A11=1,2,3,4,5; B11=1,2,3,4,5; C11=A11+B11; BZTEST(fabs(real(C11(0)) - 2.) < eps); C11=A11/B11; BZTEST(fabs(real(C11(1)) - 1.) < eps); C11=1.0l/A11; BZTEST(fabs(real(C11(2)) - 1/3.) < eps); C11=A11/1.0l; BZTEST(fabs(real(C11(3)) - 4.) < eps); C11=complex<long double>(0,1)/A11; BZTEST(fabs(imag(C11(4)) - 1/5.) < eps); C11=A11/complex<long double>(0,1); BZTEST(fabs(imag(C11(0)) - -1.) < eps); return 0; }
double SPF::update_theta(int user) { double change = accu(abs(theta(user) - (a_theta(user) / b_theta(user)))); double total = accu(theta(user)); theta(user) = a_theta(user) / b_theta(user); for (int k = 0; k < settings->k; k++) logtheta(k, user) = gsl_sf_psi(a_theta(k, user)); logtheta(user) = logtheta(user) - log(b_theta(user)); return change / total; }
void SPF::initialize_parameters() { int user, neighbor, n, item, i, k; if (!settings->factor_only) { for (user = 0; user < data->user_count(); user++) { // user influence for (n = 0; n < data->neighbor_count(user); n++) { neighbor = data->get_neighbor(user, n); tau(neighbor, user) = 1.0; logtau(neighbor, user) = log(1.0 + 1e-5); double all = settings->b_tau; for (i = 0; i < data->item_count(neighbor); i++) { item = data->get_item(neighbor, i); all += data->ratings(neighbor, item); } //TODO: this doeesn't need to be done as much... only one time per user (U), not UxU times b_tau(neighbor, user) = all; } } } if (!settings->social_only) { // user preferences for (user = 0; user < data->user_count(); user++) { for (k = 0; k < settings->k; k++) { theta(k, user) = (settings->a_theta + gsl_rng_uniform_pos(rand_gen)) / (settings->b_theta); logtheta(k, user) = log(theta(k, user)); } theta.col(user) /= accu(theta.col(user)); } // item attributes for (item = 0; item < data->item_count(); item++) { for (k = 0; k < settings->k; k++) { beta(k, item) = (settings->a_beta + gsl_rng_uniform_pos(rand_gen)) / (settings->b_beta); logbeta(k, item) = log(beta(k, item)); } beta.col(item) /= accu(beta.col(item)); } } if (settings->item_bias) { for (item = 0; item < data->item_count(); item++) { delta(item) = data->popularity(item); } } }
/* * Noekeon Encryption */ void Noekeon::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const { verify_key_set(m_DK.empty() == false); #if defined(BOTAN_HAS_NOEKEON_SIMD) if(CPUID::has_simd_32()) { while(blocks >= 4) { simd_decrypt_4(in, out); in += 4 * BLOCK_SIZE; out += 4 * BLOCK_SIZE; blocks -= 4; } } #endif for(size_t i = 0; i != blocks; ++i) { uint32_t A0 = load_be<uint32_t>(in, 0); uint32_t A1 = load_be<uint32_t>(in, 1); uint32_t A2 = load_be<uint32_t>(in, 2); uint32_t A3 = load_be<uint32_t>(in, 3); for(size_t j = 16; j != 0; --j) { theta(A0, A1, A2, A3, m_DK.data()); A0 ^= RC[j]; A1 = rotl<1>(A1); A2 = rotl<5>(A2); A3 = rotl<2>(A3); gamma(A0, A1, A2, A3); A1 = rotr<1>(A1); A2 = rotr<5>(A2); A3 = rotr<2>(A3); } theta(A0, A1, A2, A3, m_DK.data()); A0 ^= RC[0]; store_be(out, A0, A1, A2, A3); in += BLOCK_SIZE; out += BLOCK_SIZE; } }
int main(int argc, char ** argv) { if (argc < 3) { std::cout << "Usage: " << argv[0] << " <no. of cones> <input filename> [<direction-x> <direction-y>]" << std::endl; return 1; } unsigned int k = atoi(argv[1]); if (k<2) { std::cout << "The number of cones should be larger than 1!" << std::endl; return 1; } // open the file containing the vertex list std::ifstream inf(argv[2]); if (!inf) { std::cout << "Cannot open file " << argv[2] << "!" << std::endl; return 1; } Direction_2 initial_direction; if (argc == 3) initial_direction = Direction_2(1, 0); // default initial_direction else if (argc == 5) initial_direction = Direction_2(atof(argv[3]), atof(argv[4])); else { std::cout << "Usage: " << argv[0] << " <no. of cones> <input filename> [<direction-x> <direction-y>]" << std::endl; return 1; } // iterators for reading the vertex list file std::istream_iterator<Point_2> input_begin( inf ); std::istream_iterator<Point_2> input_end; // initialize the functor CGAL::Construct_theta_graph_2<Kernel, Graph> theta(k, initial_direction); // create an adjacency_list object Graph g; // construct the theta graph on the vertex list theta(input_begin, input_end, g); // obtain the number of vertices in the constructed graph boost::graph_traits<Graph>::vertices_size_type n = boost::num_vertices(g); // generate gnuplot files for plotting this graph std::string file_prefix = "t" + boost::lexical_cast<std::string>(k) + "n" + boost::lexical_cast<std::string>(n); CGAL::gnuplot_output_2(g, file_prefix); return 0; }
MatrixXd LDA::getTheta(void) { if(SAMPLE_LAG>0) { return thetasum*(1.0/numstats); } else { MatrixXd theta(documentsSize(),K); for(int m=0; m<documentsSize(); m++) { // theta.row(m)=((nd.row(m).cast<double>().array()+alpha)/(ndsum.cast<double>().array()+K*alpha)).matrix(); for(int k=0; k<K; k++) { theta(m,k)=(nd(m,k)+alpha)/(ndsum(m)+K*alpha); } } return theta; } }
double BasisAngle( const Epetra_MultiVector& S, const Epetra_MultiVector& T ) { // // Computes the largest acute angle between the two orthogonal basis // if (S.NumVectors() != T.NumVectors()) { return acos( 0.0 ); } else { int lwork, info = 0; int m = S.NumVectors(), n = T.NumVectors(); int num_vecs = ( m < n ? m : n ); double U[ 1 ], Vt[ 1 ]; lwork = 3*m*n; std::vector<double> work( lwork ); std::vector<double> theta( num_vecs ); Epetra_LAPACK lapack; Epetra_LocalMap localMap( S.NumVectors(), 0, S.Map().Comm() ); Epetra_MultiVector Pvec( localMap, T.NumVectors() ); info = Pvec.Multiply( 'T', 'N', 1.0, S, T, 0.0 ); // // Perform SVD on S^T*T // lapack.GESVD( 'N', 'N', num_vecs, num_vecs, Pvec.Values(), Pvec.Stride(), &theta[0], U, 1, Vt, 1, &work[0], &lwork, &info ); assert( info == 0 ); return (acos( theta[num_vecs-1] ) ); } // // Default return statement, should never be executed. // return acos( 0.0 ); }
void KeccakPermutationOnWords(UINT64 *state) { unsigned int i; //displayStateAsWords(3, "Same, as words", state); for(i=0; i<nrRounds; i++) { //displayRoundNumber(3, i); theta(state); //displayStateAsWords(3, "After theta", state); rho(state); //displayStateAsWords(3, "After rho", state); pi(state); //displayStateAsWords(3, "After pi", state); chi(state); //displayStateAsWords(3, "After chi", state); iota(state, i); //displayStateAsWords(3, "After iota", state); } }
/*! Given an array of desired joint values, this computed an infinitesimal motion of each link as motion *from the current values* towards the desired values is started. Used mainly to see if any contacts prevent this motion. */ void KinematicChain::infinitesimalMotion(const double *jointVals, std::vector<transf> &newLinkTranVec) const { //start with the link jacobian in local link coordinates //but keep just the actuated part Matrix J(actuatedJacobian(linkJacobian(false))); //joint values matrix Matrix theta(numJoints, 1); //a very small motion //either 0.1 radians or 0.1 mm, should be small enough double inf = 0.1; //a very small threshold double eps = 1.0e-6; for(int j=0; j<numJoints; j++) { int sign; if ( jointVals[firstJointNum + j] + eps < jointVec[j]->getVal() ) { sign = -1; } else if ( jointVals[firstJointNum + j] > jointVec[j]->getVal() + eps ) { sign = 1; } else { sign = 0; } theta.elem(j,0) = sign * inf; } //compute infinitesimal motion Matrix dm(6*numLinks, 1); matrixMultiply(J, theta, dm); //and convert it to transforms for (int l=0; l<numLinks; l++) { transf tr = rotXYZ( dm.elem(6*l+3, 0), dm.elem(6*l+4, 0), dm.elem(6*l+5, 0) ) * translate_transf( vec3( dm.elem(6*l+0, 0), dm.elem(6*l+1, 0), dm.elem(6*l+2, 0) ) ); newLinkTranVec[l] = tr; } }
std::string Pose::toString() const { stringstream ss; ss << "[" << x() << ", " << y() << ", " << theta()*180.0/M_PI << "deg]"; return ss.str(); }
/** * Update the detector information from a raw file * @param filename :: The input filename */ void UpdateInstrumentFromFile::updateFromRaw(const std::string & filename) { ISISRAW2 iraw; if (iraw.readFromFile(filename.c_str(),false) != 0) { g_log.error("Unable to open file " + filename); throw Exception::FileError("Unable to open File:" , filename); } const int32_t numDetector = iraw.i_det; std::vector<int32_t> detID(iraw.udet, iraw.udet + numDetector); std::vector<float> l2(iraw.len2, iraw.len2 + numDetector); std::vector<float> theta(iraw.tthe, iraw.tthe + numDetector); // Is ut01 (=phi) present? Sometimes an array is present but has wrong values e.g.all 1.0 or all 2.0 bool phiPresent = iraw.i_use>0 && iraw.ut[0]!= 1.0 && iraw.ut[0] !=2.0; std::vector<float> phi(0); if( phiPresent ) { phi = std::vector<float>(iraw.ut, iraw.ut + numDetector); } else { phi = std::vector<float>(numDetector, 0.0); } g_log.information() << "Setting detector postions from RAW file.\n"; setDetectorPositions(detID, l2, theta, phi); }
// [[Rcpp::export]] Rcpp::List europeanOptionArraysEngine(std::string type, Rcpp::NumericMatrix par) { QuantLib::Option::Type optionType = getOptionType(type); int n = par.nrow(); Rcpp::NumericVector value(n), delta(n), gamma(n), vega(n), theta(n), rho(n), divrho(n); QuantLib::Date today = QuantLib::Date::todaysDate(); QuantLib::Settings::instance().evaluationDate() = today; QuantLib::DayCounter dc = QuantLib::Actual360(); for (int i=0; i<n; i++) { double underlying = par(i, 0); // first column double strike = par(i, 1); // second column QuantLib::Spread dividendYield = par(i, 2); // third column QuantLib::Rate riskFreeRate = par(i, 3); // fourth column QuantLib::Time maturity = par(i, 4); // fifth column #ifdef QL_HIGH_RESOLUTION_DATE // in minutes boost::posix_time::time_duration length = boost::posix_time::minutes(boost::uint64_t(maturity * 360 * 24 * 60)); #else int length = int(maturity*360 + 0.5); // FIXME: this could be better #endif double volatility = par(i, 5); // sixth column boost::shared_ptr<QuantLib::SimpleQuote> spot(new QuantLib::SimpleQuote( underlying )); boost::shared_ptr<QuantLib::SimpleQuote> vol(new QuantLib::SimpleQuote( volatility )); boost::shared_ptr<QuantLib::BlackVolTermStructure> volTS = flatVol(today, vol, dc); boost::shared_ptr<QuantLib::SimpleQuote> qRate(new QuantLib::SimpleQuote( dividendYield )); boost::shared_ptr<QuantLib::YieldTermStructure> qTS = flatRate(today, qRate, dc); boost::shared_ptr<QuantLib::SimpleQuote> rRate(new QuantLib::SimpleQuote( riskFreeRate )); boost::shared_ptr<QuantLib::YieldTermStructure> rTS = flatRate(today, rRate, dc); #ifdef QL_HIGH_RESOLUTION_DATE QuantLib::Date exDate(today.dateTime() + length); #else QuantLib::Date exDate = today + length; #endif boost::shared_ptr<QuantLib::Exercise> exercise(new QuantLib::EuropeanExercise(exDate)); boost::shared_ptr<QuantLib::StrikedTypePayoff> payoff(new QuantLib::PlainVanillaPayoff(optionType, strike)); boost::shared_ptr<QuantLib::VanillaOption> option = makeOption(payoff, exercise, spot, qTS, rTS, volTS); value[i] = option->NPV(); delta[i] = option->delta(); gamma[i] = option->gamma(); vega[i] = option->vega(); theta[i] = option->theta(); rho[i] = option->rho(); divrho[i] = option->dividendRho(); } return Rcpp::List::create(Rcpp::Named("value") = value, Rcpp::Named("delta") = delta, Rcpp::Named("gamma") = gamma, Rcpp::Named("vega") = vega, Rcpp::Named("theta") = theta, Rcpp::Named("rho") = rho, Rcpp::Named("divRho") = divrho); }
void check_theta(void) { double S = 430, X = 405, T = 1.0/12, r = 0.07, v = 0.20, b = 0.02; /* Interest rate - dividend yield (0.05) */ assert_equal(theta(0, S, X, T, r, b, v), -31.1924); assert_equal(theta_put(S, X, T, r, b, v), -31.1924); }
void BatesModel::generateArguments() { process_.reset(new BatesProcess( process_->riskFreeRate(), process_->dividendYield(), process_->s0(), v0(), kappa(), theta(), sigma(), rho(), lambda(), nu(), delta())); }
static void wave_read (GtsObject ** o, GtsFile * fp) { (* GTS_OBJECT_CLASS (gfs_wave_class ())->parent_class->read) (o, fp); if (fp->type == GTS_ERROR) return; GfsWave * wave = GFS_WAVE (*o); if (fp->type == '{') { GtsFileVariable var[] = { {GTS_UINT, "nk", TRUE, &wave->nk}, {GTS_UINT, "ntheta", TRUE, &wave->ntheta}, {GTS_DOUBLE, "alpha_s", TRUE, &wave->alpha_s}, {GTS_NONE} }; gts_file_assign_variables (fp, var); if (fp->type == GTS_ERROR) return; } GfsDomain * domain = GFS_DOMAIN (wave); guint ik, ith; wave->F = gfs_matrix_new (wave->nk, wave->ntheta, sizeof (GfsVariable *)); for (ik = 0; ik < wave->nk; ik++) for (ith = 0; ith < wave->ntheta; ith++) { gchar * name = g_strdup_printf ("F%d_%d", ik, ith); gchar * description = g_strdup_printf ("Action density for f = %g Hz and theta = %g degrees", frequency (ik), theta (ith, wave->ntheta)*180./M_PI); wave->F[ik][ith] = gfs_domain_get_or_add_variable (domain, name, description); g_assert (wave->F[ik][ith]); g_free (name); g_free (description); } }
TEST(generateExpression, integrate_ode) { static const bool user_facing = true; std::stringstream msgs; stan::lang::integrate_ode so; // null ctor should work and not raise error std::string integration_function_name = "bar"; std::string system_function_name = "foo"; stan::lang::variable y0("y0_var_name"); y0.set_type(stan::lang::bare_array_type(stan::lang::double_type())); stan::lang::variable t0("t0_var_name"); t0.set_type(stan::lang::double_type()); stan::lang::variable ts("ts_var_name"); ts.set_type(stan::lang::bare_array_type(stan::lang::double_type())); stan::lang::variable theta("theta_var_name"); theta.set_type(stan::lang::bare_array_type(stan::lang::double_type())); stan::lang::variable x("x_var_name"); x.set_type(stan::lang::bare_array_type(stan::lang::double_type())); stan::lang::variable x_int("x_int_var_name"); x.set_type(stan::lang::bare_array_type(stan::lang::int_type())); stan::lang::integrate_ode so2(integration_function_name, system_function_name, y0, t0, ts, theta, x, x_int); stan::lang::expression e1(so2); generate_expression(e1, user_facing, msgs); EXPECT_EQ(msgs.str(), "bar(foo_functor__(), y0_var_name, t0_var_name, ts_var_name, " "theta_var_name, x_var_name, x_int_var_name, pstream__)"); }
/* A vertex is connected to beams. The question is how many bars are rotuled We define 2 dofs per node */ void frameSolver2d::createDofs() { // printf("coucou %d fixations\n",_fixations.size()); for(std::size_t i = 0; i < _fixations.size(); ++i) { const gmshFixation &f = _fixations[i]; // printf("f._vertex(%d) = %p %d // %g\n",i,f._vertex,f._direction,f._value); MVertex *v = f._vertex->mesh_vertices[0]; Dof DOF(v->getNum(), f._direction); pAssembler->fixDof(DOF, f._value); } // printf("coucou2\n"); computeRotationTags(); // printf("coucou3\n"); for(std::size_t i = 0; i < _beams.size(); i++) { // printf("beam[%d] rot %d // %d\n",i,_beams[i]._rotationTags[0],_beams[i]._rotationTags[1]); for(std::size_t j = 0; j < 2; j++) { MVertex *v = _beams[i]._element->getVertex(j); Dof theta(v->getNum(), Dof::createTypeWithTwoInts(2, _beams[i]._rotationTags[j])); pAssembler->numberDof(theta); Dof U(v->getNum(), 0); pAssembler->numberDof(U); Dof V(v->getNum(), 1); pAssembler->numberDof(V); } } // printf("%d dofs\n",pAssembler->sizeOfR()); }
void UNIFAQ::UNIFAQMixture::activity_coefficients(double tau, const std::vector<double> &z, std::vector<double> &gamma){ std::size_t N = z.size(); std::vector<double> r(N), q(N), l(N), phi(N), theta(N), ln_Gamma_C(N); double summerzr = 0, summerzq = 0, summerzl = 0; for (std::size_t i = 0; i < N; ++i) { double summerr = 0, summerq = 0; const UNIFAQLibrary::Component &c = components[i]; for (std::size_t j = 0; j < c.groups.size(); ++j) { const UNIFAQLibrary::ComponentGroup &cg = c.groups[j]; summerr += cg.count*cg.group.R_k; summerq += cg.count*cg.group.Q_k; } r[i] = summerr; q[i] = summerq; summerzr += z[i] * r[i]; summerzq += z[i] * q[i]; } for (std::size_t i = 0; i < N; ++i) { phi[i] = z[i] * r[i] / summerzr; theta[i] = z[i] * q[i] / summerzq; l[i] = 10.0 / 2.0*(r[i] - q[i]) - (r[i] - 1); summerzl += z[i] * l[i]; } for (std::size_t i = 0; i < N; ++i) { ln_Gamma_C[i] = log(phi[i] / z[i]) + 10.0 / 2.0*q[i] * log(theta[i] / phi[i]) + l[i] - phi[i] / z[i] * summerzl; gamma[i] = exp(ln_gamma_R(tau, i, 0) + ln_Gamma_C[i]); } }
arma::rowvec Btm::calc_theta() { // B - number of biterms arma::rowvec theta(K, arma::fill::zeros); for (int k = 0; k < K; k++) { theta[k] = (topic_count_bt[k] + alpha) / (B + K * alpha); } return theta; }
void rocks_in_space::constrain_vel(vel& v) { auto polar = car_to_pol(v); if (polar.r() > max_ship_speed) { v = pol_to_car({ max_ship_speed, polar.theta() }); } }
void VerdictVector::scale_angle(double gamma, double ) { const double r_factor = 0.3; const double theta_factor = 0.6; xy_to_rtheta(); // if neary 2pi, treat as zero // some near zero stuff strays due to roundoff if (theta() > TWO_VERDICT_PI - 0.02) theta() = 0; // the above screws up on big sheets - need to overhaul at the sheet level if ( gamma < 1 ) { //squeeze together points of short radius so that //long chords won't cross them theta() += (VERDICT_PI-theta())*(1-gamma)*theta_factor*(1-r()); //push away from center of circle, again so long chords won't cross r( (r_factor + r()) / (1 + r_factor) ); //scale angle by gamma theta() *= gamma; } else { //scale angle by gamma, making sure points nearly 2pi are treated as zero double new_theta = theta() * gamma; if ( new_theta < 2.5 * VERDICT_PI || r() < 0.2) theta( new_theta ); } rtheta_to_xy(); }
static void noekeon_round(uint32_t *key, uint32_t *state, uint8_t const1, uint8_t const2){ ((uint8_t*)state)[RC_POS] ^= const1; theta(key, state); ((uint8_t*)state)[RC_POS] ^= const2; pi1(state); gamma_1(state); pi2(state); }
//--------------------------------------------------------------------------- void TEstimation::preparePosteriorDensityPoints(){ //prepare vector for points at which the density (also prior!!!) is estimated theta=ColumnVector(posteriorDensityPoints); //float step=1.2/(posteriorDensityPoints-1); //for(int j=1; j<=posteriorDensityPoints; ++j) theta(j)=-0.1+(j-1)*step; //since the parameters are standardized between 0 and 1, we can easy calculate the posterior between 0 and 1 step=1.0/(posteriorDensityPoints-1.0); for(int j=0; j<posteriorDensityPoints; ++j) theta(j+1)=(j)*step; }