Пример #1
0
/**
 * Indicates if all ties are reciprocated with the same value.
 */
bool OneModeNetwork::symmetric() const {
	// The current implementation is linear in the total number of ties.
	// The time complexity can be reduced to a constant by maintaining
	// the number of non-symmetric ties.

	// Assume the network is symmetric until we can disprove it.
	bool rc = true;

	// Test the incoming and outgoing ties of each actor in turn.

	for (int i = 0; i < this->n() && rc; i++) {
		if (this->outDegree(i) == this->inDegree(i)) {
			IncidentTieIterator outIter = this->outTies(i);
			IncidentTieIterator inIter = this->inTies(i);

			// No need to test both iterators for validity, as the numbers
			// of incoming and outgoing ties are the same.

			while (outIter.valid() && rc) {
				if (outIter.actor() != inIter.actor()
						|| outIter.value() != inIter.value()) {
					// Found a mismatch.
					rc = false;
				}

				outIter.next();
				inIter.next();
			}
		} else {
			// The numbers of incoming and outgoing ties differ, which
			// destroys the symmetry immediately.

			rc = false;
		}
	}

	return rc;
}
Пример #2
0
/**
 * Returns the statistic corresponding to the given ego as part of
 * the endowment function with respect to the initial values of a
 * behavior variable and the current values.
 */
double SimilarityEffect::egoEndowmentStatistic(int ego, const int * difference,
	double * currentValues)
{
	if (this->lalterPopularity)
	{
		throw runtime_error(string("endowmentStatistic not implemented for") +
			"average similarity x popularity alter effect and " +
			"total similarity x popularity alter effect.");
	}

	double statistic = 0;
	const Network * pNetwork = this->pNetwork();

	double similarityMean =  this->similarityMean();

	if (!this->missing(this->period(), ego) &&
		!this->missing(this->period() + 1, ego))
	{
		if (difference[ego] > 0)
		{
			if (pNetwork->outDegree(ego))
			{
				double thisStatistic = 0;

				for (IncidentTieIterator iter = pNetwork->outTies(ego);
					 iter.valid();
					 iter.next())
				{
					if (!this->missing(this->period(), iter.actor()) &&
						!this->missing(this->period() + 1, iter.actor()))
					{
						double alterValue = currentValues[iter.actor()];
						double range = this->range();
						thisStatistic += iter.value() *
							(1.0 - fabs(alterValue - currentValues[ego]) /
								range);
						thisStatistic -= similarityMean;
					}
				}

				if (this->laverage)
				{
					thisStatistic /= pNetwork->outDegree(ego);
				}

				if (this->legoPopularity)
				{
					thisStatistic *= pNetwork->inDegree(ego);
				}
				statistic = thisStatistic;

				// do the same using the current state plus difference
				// in i's value rather than current state and subtract it.
				// not sure whether this is correct.

				thisStatistic = 0;

				for (IncidentTieIterator iter = pNetwork->outTies(ego);
					 iter.valid();
					 iter.next())
				{
					if (!this->missing(this->period(), iter.actor()) &&
						!this->missing(this->period() + 1, iter.actor()))
					{
						double alterValue = currentValues[iter.actor()] +
							difference[iter.actor()];
						double range = this->range();
						thisStatistic += iter.value() *
							(1.0 - fabs(alterValue - (difference[ego] +
									currentValues[ego]))
								/ range);
						thisStatistic -= similarityMean;
					}
				}

				if (this->laverage)
				{
					thisStatistic /= pNetwork->outDegree(ego);
				}
				if (this->legoPopularity)
				{
					thisStatistic *= pNetwork->inDegree(ego);
				}

				statistic -= thisStatistic;
			}
		}
	}

	return statistic;
}