Esempio n. 1
0
/**
 * For each j and the given i, this method calculates the sum
 * sum_h w_{ih} x_{hj}.
 */
void WXXClosureEffect::calculateSums(int i,
	const Network * pNetwork,
	double * sums) const
{
	int n = pNetwork->n();

	// Initialize

	for (int j = 0; j < n; j++)
	{
		sums[j] = 0;
	}

	// Iterate over all h with non-zero non-missing w_{ih}

	for (DyadicCovariateValueIterator iterH = this->rowValues(i);
		iterH.valid();
		iterH.next())
	{
		int h = iterH.actor();

		// Iterate over all j with a tie from h

		for (IncidentTieIterator iterJ = pNetwork->outTies(h);
			iterJ.valid();
			iterJ.next())
		{
			int j = iterJ.actor();

			// Add the term w_{ih} x_{hj} (= w_{ih})
			sums[j] += iterH.value();
		}
	}
}
Esempio n. 2
0
/**
 * For each j and the given i, this method calculates the sum
 * sum_h w_{ih} w_{hj}, or other directionalities depending on out1 and out2.
 */
void WWXClosureEffect::calculateSums(int i,
	const Network * pNetwork,
	double * sums) const
{
	int n = pNetwork->n();

	// Initialize

	for (int j = 0; j < n; j++)
	{
		sums[j] = 0;
	}


	if (this->lout1)
	// Iterate over all h with non-zero non-missing w_{ih}
	{
		for (DyadicCovariateValueIterator iterH = this->rowValues(i);
			iterH.valid();
			iterH.next())
		{
			int h = iterH.actor();
	
			if (this->lout2)
			{

		// Iterate over all j with non-zero non-missing w_{hj}
				for (DyadicCovariateValueIterator iterJ = this->rowValues(h);
					iterJ.valid();
					iterJ.next())
				{
					int j = iterJ.actor();
	
					// Add the term w_{ih} w_{hj}
					sums[j] += iterH.value() * iterJ.value();
				}
			}
			else
			{
		// Iterate over all j with non-zero non-missing w_{jh}
				for (DyadicCovariateValueIterator iterJ = this->columnValues(h);
					iterJ.valid();
					iterJ.next())
				{
					int j = iterJ.actor();
	
					// Add the term w_{ih} w_{jh}
					sums[j] += iterH.value() * iterJ.value();
				}
			}
		}
	}
	else
	// Iterate over all h with non-zero non-missing w_{hi}
	{
		for (DyadicCovariateValueIterator iterH = this->columnValues(i);
			iterH.valid();
			iterH.next())
		{
			int h = iterH.actor();
			if (this->lout2)
			{
		// Iterate over all j with non-zero non-missing w_{hj}
				for (DyadicCovariateValueIterator iterJ = this->rowValues(h);
					iterJ.valid();
					iterJ.next())
				{
					int j = iterJ.actor();
	
					// Add the term w_{hi} w_{hj}
					sums[j] += iterH.value() * iterJ.value();
				}
			}
			else
			{
		// Iterate over all j with non-zero non-missing w_{jh}
				for (DyadicCovariateValueIterator iterJ = this->columnValues(h);
					iterJ.valid();
					iterJ.next())
				{
					int j = iterJ.actor();
	
					// Add the term w_{hi} w_{jh}
					sums[j] += iterH.value() * iterJ.value();
				}
			}
		}
	}
}