LecuyerUniformRng::sample_type LecuyerUniformRng::next() const { long k = temp1/q1; // Compute temp1=(a1*temp1) % m1 // without overflows (Schrage's method) temp1 = a1*(temp1-k*q1)-k*r1; if (temp1 < 0) temp1 += m1; k = temp2/q2; // Compute temp2=(a2*temp2) % m2 // without overflows (Schrage's method) temp2 = a2*(temp2-k*q2)-k*r2; if (temp2 < 0) temp2 += m2; // Will be in the range 0..bufferSize-1 int j = y/bufferNormalizer; // Here temp1 is shuffled, temp1 and temp2 are // combined to generate output y = buffer[j]-temp2; buffer[j] = temp1; if (y < 1) y += m1-1; double result = y/double(m1); // users don't expect endpoint values if (result > maxRandom) result = (double) maxRandom; return sample_type(result,1.0); }
inline typename PolarStudentTRng<URNG>::sample_type PolarStudentTRng<URNG>::next() const { Real u, v, rSqr; do{ //samples remapped to [-1,1]: v = 2.* uniformGenerator_.next().value - 1.; u = 2.* uniformGenerator_.next().value - 1.; rSqr = v*v + u*u; }while(rSqr >= 1.); return sample_type(u * std::sqrt(degFreedom_ * (std::pow(rSqr, -2./degFreedom_)-1.) / rSqr), 1.); }
PathGenerator<GSG>::PathGenerator( const boost::shared_ptr<StochasticProcess>& process, const TimeGrid& timeGrid, const GSG& generator, bool brownianBridge) : brownianBridge_(brownianBridge), generator_(generator), dimension_(generator_.dimension()), timeGrid_(timeGrid), process_(boost::dynamic_pointer_cast<StochasticProcess1D>(process)), next_(std::vector<sample_type>(GSG::maxNumberOfThreads, sample_type(Path(timeGrid_),1.0))), temp_(GSG::maxNumberOfThreads,std::vector<Real>(dimension_)), bb_(timeGrid_) { QL_REQUIRE(dimension_==timeGrid_.size()-1, "sequence generator dimensionality (" << dimension_ << ") != timeSteps (" << timeGrid_.size()-1 << ")"); }
ImagePtr upsample(ImagePtr image, const ImageSize& sampling) { sample_type(UpSamplingAdapter, unsigned char); sample_type(UpSamplingAdapter, unsigned short); sample_type(UpSamplingAdapter, unsigned int); sample_type(UpSamplingAdapter, unsigned long); sample_type(UpSamplingAdapter, float); sample_type(UpSamplingAdapter, double); sample_type(UpSamplingAdapter, RGB<unsigned char>); sample_type(UpSamplingAdapter, RGB<unsigned short>); sample_type(UpSamplingAdapter, RGB<unsigned int>); sample_type(UpSamplingAdapter, RGB<unsigned long>); sample_type(UpSamplingAdapter, RGB<float>); sample_type(UpSamplingAdapter, RGB<double>); throw std::runtime_error("cannot upsample this image type"); }
inline typename InverseCumulativeRng<RNG, IC>::sample_type InverseCumulativeRng<RNG, IC>::next() const { typename RNG::sample_type sample = uniformGenerator_.next(); return sample_type(ICND_(sample.value),sample.weight); }