コード例 #1
0
/**
 * Constructs the MetropolisHastingsSimulation object.
 *
 * @param pModel Pointer to the Model.
 * @param pData Pointer to the Data.
 */
MetropolisHastingsSimulation::MetropolisHastingsSimulation(Model* pModel,
		Data* pData) :
		Simulation(pModel, pData), //
		lScores(1, VectorXd(nStatistics())), //
		lScoreTargets(VectorXd::Zero(nStatistics())), //
		lNeedsDerivative(false), //
		lDerivative(1, MatrixXd(nParameters(), nParameters())), //
		lMeanScoresMinusTargets(), //
		lNRunMH(nPeriods()), //
		lResult(&lTheta, &lScoreTargets, 0/*ptr*/, &lScores, 0/*ptr*/,
				&lMeanScoresMinusTargets, 0/*ptr*/, 0/*ptr*/, &lDerivative, 0/*ptr*/)
	{
	// Conditional is not possible with maximum likelihood
	// R: sienaModelCreate.r sienaModelCreate() (line ~56)
	assert(!pModel->conditional());
	// Calculate the number of simulation steps per period.
	// R: initializeFran.r initializeFRAN() (line ~504)
	const MatrixXd targets = calculateTargetStatistics();
	const ArrayXb basicRates = rStatisticEffects().array()
			== &Simulation::RATE_EFFECT;
	const VectorXd zero = VectorXd::Zero(nStatistics());
	for (int m = 0; m < nPeriods(); ++m) {
		lNRunMH[m] = N_RUN_MH_MULTIPLICATOR_DEFAULT
				* basicRates.select(targets.row(m).transpose(), zero).sum();
		if (lNRunMH[m] > 100) {
			lNRunMH[m] = round((double) lNRunMH[m] / 100.0) * 100;
		}
	}
}
コード例 #2
0
/**
 * Constructs the StatisticsSimulation object.
 *
 * @param pModel Pointer to the Model.
 * @param pData Pointer to the Data.
 * @param nThreads Number of threads used to perform parallel simulations.
 */
StatisticsSimulation::StatisticsSimulation(Model* pModel, Data* pData,
		const unsigned int nThreads) :
		Simulation(pModel, pData), //
		lNThreads(nThreads), //
		lEpochSimulations(), //
		lSeeds(pData->observationCount() - 1, vector<int>()), //
		lTargets(calculateTargetStatistics().colwise().sum()), //
		lPeriodWiseTargets(calculateTargetStatistics()), //
		lStatistic(), //
		lStatisticsData(), //
		lStatistics(), //
		lScoresData(), //
		lScores(), //
		lTimesData(), //
		lTimes(), //
		lMeanStatisticsMinusTargets(nStatistics()), //
		lResult(&lTheta, &lTargets, &lPeriodWiseTargets, &lStatistic, &lStatistics,
				&lMeanStatisticsMinusTargets, &lSeeds, &lScores, 0/*ptr*/, &lTimes) {
	assert(lNThreads > 0);
	resizeEpochSimulations(lNThreads);
	// Setup the mapped matrices for statistics and time. Statistics is always
	// needed.
	LOG(Priority::DEBUG, "setup mapped statistics vector");
	setupMaps(lStatistics, lStatisticsData, lNThreads, nPeriods(),
			nStatistics());
	// Conditional is not changed during phases, so no later change required.
	if (lpModel->conditional()) {
		LOG(Priority::DEBUG, "setup mapped times vector");
		setupMaps(lTimes, lTimesData, lNThreads, nPeriods(), 1);
	}
	// Score might not be needed if they are needsChanged, creates the stores.
	int n = lpModel->needScores() ? lNThreads : 0;
	setupMaps(lScores, lScoresData, n, nPeriods(), nParameters());

	static MeanStatisticsCalculator s;
	addResultModificator(&s);
}