Esempio n. 1
0
void BasicCircular::from_prior(RNG& rng)
{
	xc = x_min + (x_max - x_min)*rng.rand();
	yc = y_min + (y_max - y_min)*rng.rand();
	width = exp(log(1E-2*size) + log(1E3)*rng.rand());

	mu = exp(log(mu_min) + log(mu_max/mu_min)*rng.rand());
}
Esempio n. 2
0
void MyConditionalPrior::from_prior(RNG& rng)
{
    location_log_period = cauchy.generate(rng);
    scale_log_period = 5*rng.rand();

    location_log_amplitude = cauchy.generate(rng);
    scale_log_amplitude = 5*rng.rand();
}
Esempio n. 3
0
void Sinusoid::generate(RNG& rng)
{
    A = -log(1.0 - rng.rand());
    log10_period = log10(1E-3 * t_range) + 3.0 * rng.rand();
    phi = 2.0 * M_PI * rng.rand();

    for(double& nn : n)
        nn = rng.randn();

    assemble();
}
Esempio n. 4
0
void Sinusoid::generate(RNG& rng)
{
    A = exp(0.1*rng.randn());
    log10_period = -rng.rand();
    phi = 2.0 * M_PI * rng.rand();

    calculate_mu();

    for(size_t i=0; i<N; ++i)
        y[i] = mu[i] + sigma*rng.randn();

    calculate_logl();
}
Esempio n. 5
0
double Sinusoid::perturb(RNG& rng)
{
    double logH = 0.0;

    if(rng.rand() < 0.5)
    {
        // Perturb one of the three parameters
        int which = rng.rand_int(3);
        if(which == 0)
        {
            A = 1.0 - exp(-A);
            A += rng.randh();
            wrap(A, 0.0, 1.0);
            A = -log(1.0 - A);
        }
        else if(which == 1)
        {
            log10_period += 3.0 * rng.randh();
            wrap(log10_period, log10(1E-3 * t_range), log10(t_range));
        }
        else
        {
            phi += 2 * M_PI * rng.randh();
            wrap(phi, 0.0, 2 * M_PI);
        }
    }
    else
    {
        // Perturb some of the ns.
        if(rng.rand() <= 0.5)
        {
            // Just change one
            int which = rng.rand_int(N);
            logH -= -0.5*pow(n[which], 2);
            n[which] += rng.randh();
            logH += -0.5*pow(n[which], 2);
        }
        else
        {
            // Potentially regenerate many
            int reps = pow(N, rng.rand());
            for(int i=0; i<reps; ++i)
                n[rng.rand_int(N)] = rng.randn();
        }

    }

    assemble();

    return logH;
}
Esempio n. 6
0
void MyModel::from_prior(RNG& rng)
{
	objects.from_prior(rng);
	objects.consolidate_diff();
	sigma = exp(log(1E-3) + log(1E6)*rng.rand());
	calculate_mu();
}
Esempio n. 7
0
        unsigned long long operator() ( const double & lam, RNG & rng ) const {
          using std::log;
          using std::sqrt;
          using ::lgamma;

          double loglam = log(lam);
          double b = 0.931 + 2.53 * sqrt(lam);
          double a = -0.059 + 0.02483 * b;
          double ln_invalpha = log( 1.1239 + 1.1328/(b-3.4) );
          double vr = 0.9277 - 3.6224/(b-2);

          while (true) {
            double U = rng.rand() - 0.5;
            double V = rng.rand();
            double us = 0.5 - std::abs(U);
            unsigned long long retval
              = static_cast<unsigned long long>( (2*a/us + b)*U + lam + 0.43 );

            if ((us >= 0.07) && (V <= vr))
              return retval;

            if ((retval < 0) || ((us < 0.013) && (V > us)))
              continue;

            if ((log(V) + ln_invalpha - log(a/(us*us)+b)) <=
                (-lam + retval*loglam - lgamma(retval+1)))
              return retval;
          }
        }
Esempio n. 8
0
void Gravity::from_prior(RNG& rng)
{
	for(size_t i=0; i<x.size(); i++)
	{
		do
		{
			x[i] = -10. + 20.*rng.rand();
			y[i] = -10. + 20.*rng.rand();
			z[i] = -10. + 20.*rng.rand();
		}while(x[i]*x[i] + y[i]*y[i] + z[i]*z[i] > 100.);

		do
		{
			vx[i] = -10. + 20.*rng.rand();
			vy[i] = -10. + 20.*rng.rand();
			vz[i] = -10. + 20.*rng.rand();
		}while(vx[i]*vx[i] + vy[i]*vy[i] + vz[i]*vz[i] > 100.);
	}

	refresh();
	compute_scalars();
}
Esempio n. 9
0
        unsigned long long operator() ( const double & lam, RNG & rng ) const {
          double enlam = exp(-lam);
          unsigned long long X = 0u;
          double prod = 1.0;

          while (true) {
            prod *= rng.rand();

            if (prod > enlam)
              X += 1u;
            else
              return X;
          }
        }
Esempio n. 10
0
double MyModel::perturb(RNG& rng)
{
	double logH = 0.;

	if(rng.rand() <= 0.75)
	{
		logH += objects.perturb(rng);
		calculate_image();
	}
	else
	{
		sigma = log(sigma);
		sigma += log(1E6)*rng.randh();
		sigma = mod(sigma - log(1.), log(1E6)) + log(1.);
		sigma = exp(sigma);
	}

	return logH;
}
Esempio n. 11
0
double MyModel::perturb(RNG& rng)
{
	double logH = 0.;

	if(rng.rand() <= 0.75)
	{
		logH += objects.perturb(rng);
		objects.consolidate_diff();
		calculate_mu();
	}
	else
	{
		sigma = log(sigma);
		sigma += log(1E6)*rng.randh();
		sigma = mod(sigma - log(1E-3), log(1E6)) + log(1E-3);
		sigma = exp(sigma);
	}

	return logH;
}
Esempio n. 12
0
void MyModel::from_prior(RNG& rng)
{
	objects.from_prior(rng);
	calculate_image();
	sigma = exp(log(1.) + log(1E6)*rng.rand());
}
Esempio n. 13
0
void MyConditionalPrior::from_prior(RNG& rng)
{
    Cauchy c;
    A_min = exp(c.generate(rng));
    mu = 3.0*rng.rand();
}
Esempio n. 14
0
void Pareto::from_prior(RNG& rng)
{
	f0 = exp(log(f0_min) + log(f0_max/f0_min)*rng.rand());
	alpha = 1. + 4.*rng.rand();
}
Esempio n. 15
0
double Sinusoid::perturb(RNG& rng)
{
    double logH = 0.0;

    int proposal_type = 1;//rng.rand_int(4);

    if(proposal_type == 0)
    {
        // Perturb parameters, changing data along with it
        std::vector<double> mu_old = mu;

        logH += perturb_parameters(rng);
        calculate_mu();

        double n;
        for(size_t i=0; i<N; ++i)
        {
            n = (y[i] - mu_old[i]) / sigma;
            y[i] = mu[i] + sigma * n;
        }

        calculate_logl();
    }
    else if(proposal_type == 1)
    {
        // Perturb parameters, keeping data constant
        // (aka Metropolis step of the posterior!)
        logH -= logl;

        logH += perturb_parameters(rng);

        calculate_mu();
        calculate_logl();

        logH += logl;        
    }
    else if(proposal_type == 2)
    {
        // Just change one datum
        int which = rng.rand_int(N);

        logH -= -0.5*pow((y[which] - mu[which])/sigma, 2);
        y[which] += sigma * rng.randh();
        logH += -0.5*pow((y[which] - mu[which])/sigma, 2);

        calculate_logl();
    }
    else
    {
        // Potentially regenerate many of the data points
        int reps = pow(N, rng.rand());
        int which;
        for(int i=0; i<reps; ++i)
        {
            which = rng.rand_int(N);
            y[which] = mu[which] + sigma * rng.randn();
        }

        calculate_logl();
    }

    return logH;
}