[Rsiena-commits] r322 - in pkg/RSiena: . src src/model

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Mon Sep 18 14:50:40 CEST 2017


Author: fschoenen
Date: 2017-09-18 14:50:40 +0200 (Mon, 18 Sep 2017)
New Revision: 322

Modified:
   pkg/RSiena/ChangeLog
   pkg/RSiena/DESCRIPTION
   pkg/RSiena/src/model/State.cpp
   pkg/RSiena/src/model/State.h
   pkg/RSiena/src/model/StatisticCalculator.cpp
   pkg/RSiena/src/siena07internals.cpp
Log:
delete network clones not owned by State


Modified: pkg/RSiena/ChangeLog
===================================================================
--- pkg/RSiena/ChangeLog	2017-09-12 14:04:58 UTC (rev 321)
+++ pkg/RSiena/ChangeLog	2017-09-18 12:50:40 UTC (rev 322)
@@ -1,3 +1,7 @@
+2017-09-18 R-Forge Revision 322
+Changes in RSiena:
+   * StatisticCalculator.cpp: delete Network clones not owned by State.
+
 2017-09-10 R-Forge Revision 321
 Changes in RSiena:
    * Merge RSienaTest changes r319-r320.  Renamed init.c to init.cpp.

Modified: pkg/RSiena/DESCRIPTION
===================================================================
--- pkg/RSiena/DESCRIPTION	2017-09-12 14:04:58 UTC (rev 321)
+++ pkg/RSiena/DESCRIPTION	2017-09-18 12:50:40 UTC (rev 322)
@@ -2,7 +2,7 @@
 Type: Package
 Title: Siena - Simulation Investigation for Empirical Network Analysis
 Version: 1.2-4
-Date: 2017-09-10
+Date: 2017-09-18
 Author: Ruth Ripley, Krists Boitmanis, Tom A.B. Snijders, Felix Schoenenberger
 Depends: R (>= 2.15.0), utils
 Imports: Matrix, tcltk, lattice, parallel, MASS, methods

Modified: pkg/RSiena/src/model/State.cpp
===================================================================
--- pkg/RSiena/src/model/State.cpp	2017-09-12 14:04:58 UTC (rev 321)
+++ pkg/RSiena/src/model/State.cpp	2017-09-18 12:50:40 UTC (rev 322)
@@ -17,9 +17,9 @@
 /**
  * Creates a state of variables as of the given observation of the given
  * Data object. The values may be copied or referenced directly as indicated
- * by the parameter <code>copyValues</code>.
+ * by the parameter <code>ownedValues</code>.
  */
-State::State(const Data * pData, int observation, bool copyValues)
+State::State(const Data * pData, int observation, bool ownedValues)
 {
 	const vector<LongitudinalData *> & rVariables =
 		pData->rDependentVariableData();
@@ -35,7 +35,7 @@
 		{
 			const Network * pNetwork = pNetworkData->pNetwork(observation);
 
-			if (copyValues)
+			if (ownedValues)
 			{
 				pNetwork = pNetwork->clone();
 			}
@@ -46,7 +46,7 @@
 		{
 			const int * values = pBehaviorData->values(observation);
 
-			if (copyValues)
+			if (ownedValues)
 			{
 				int * copies = new int[pBehaviorData->n()];
 
@@ -66,7 +66,7 @@
 		}
 	}
 
-	this->lownedValues = copyValues;
+	this->lownedValues = ownedValues;
 }
 
 
@@ -108,7 +108,7 @@
  */
 State::State()
 {
-	this->lownedValues = false;
+	this->lownedValues = false; // depends on the passed pointers
 }
 
 
@@ -130,16 +130,13 @@
  */
 const Network * State::pNetwork(string name) const
 {
-	const Network * pNetwork = 0;
 	map<string, const Network *>::const_iterator iter =
 		this->lnetworks.find(name);
-
 	if (iter != this->lnetworks.end())
 	{
-		pNetwork = iter->second;
+		return iter->second;
 	}
-
-	return pNetwork;
+	return 0;
 }
 
 
@@ -181,7 +178,7 @@
 
 
 /**
- * Deletes the values stored in this state.
+ * Deletes the values stored in this state (only called if lownedValues).
  */
 void State::deleteValues()
 {

Modified: pkg/RSiena/src/model/State.h
===================================================================
--- pkg/RSiena/src/model/State.h	2017-09-12 14:04:58 UTC (rev 321)
+++ pkg/RSiena/src/model/State.h	2017-09-18 12:50:40 UTC (rev 322)
@@ -18,7 +18,7 @@
 class State
 {
 public:
-	State(const Data * pData, int observation, bool copyValues = false);
+	State(const Data * pData, int observation, bool ownedValues = false);
 	State(EpochSimulation * pSimulation);
 	State();
 	virtual ~State();

Modified: pkg/RSiena/src/model/StatisticCalculator.cpp
===================================================================
--- pkg/RSiena/src/model/StatisticCalculator.cpp	2017-09-12 14:04:58 UTC (rev 321)
+++ pkg/RSiena/src/model/StatisticCalculator.cpp	2017-09-18 12:50:40 UTC (rev 322)
@@ -321,7 +321,7 @@
 		}
 		else if (pBehaviorData)
 		{
- 			// create a copy of the start of the period and zero any values
+			// create a copy of the start of the period and zero any values
 			// missing at (either end?) start of period
 
 			const int * values =
@@ -358,6 +358,20 @@
 			throw domain_error("Unexpected class of dependent variable");
 		}
 	}
+
+	// clean up created data not owned by states
+	for (unsigned i = 0; i < rVariables.size(); i++)
+	{
+		NetworkLongitudinalData * pNetworkData =
+			dynamic_cast<NetworkLongitudinalData *>(rVariables[i]);
+		string name = rVariables[i]->name();
+
+		if (pNetworkData)
+		{
+			const Network * pNetwork = this->lpStateLessMissingsEtc->pNetwork(name);
+			delete pNetwork;
+		}
+	}
 }
 
 

Modified: pkg/RSiena/src/siena07internals.cpp
===================================================================
--- pkg/RSiena/src/siena07internals.cpp	2017-09-12 14:04:58 UTC (rev 321)
+++ pkg/RSiena/src/siena07internals.cpp	2017-09-18 12:50:40 UTC (rev 322)
@@ -587,37 +587,37 @@
  */
 void setupBipartiteGroup(SEXP BIPARTITEGROUP, Data * pData)
 {
-    int nBipartite = length(BIPARTITEGROUP);
+	int nBipartite = length(BIPARTITEGROUP);
 
-    for (int bipartite = 0; bipartite < nBipartite; bipartite++)
-    {
-        SEXP as;
-        PROTECT(as = install("nodeSet"));
-        SEXP actorSet = getAttrib(VECTOR_ELT(BIPARTITEGROUP, bipartite), as);
-        SEXP nm;
-        PROTECT(nm = install("name"));
-        SEXP name = getAttrib(VECTOR_ELT(BIPARTITEGROUP, bipartite), nm);
+	for (int bipartite = 0; bipartite < nBipartite; bipartite++)
+	{
+		SEXP as;
+		PROTECT(as = install("nodeSet"));
+		SEXP actorSet = getAttrib(VECTOR_ELT(BIPARTITEGROUP, bipartite), as);
+		SEXP nm;
+		PROTECT(nm = install("name"));
+		SEXP name = getAttrib(VECTOR_ELT(BIPARTITEGROUP, bipartite), nm);
 		SEXP avout;
-        PROTECT(avout = install("averageOutDegree"));
-        SEXP averageOutDegree = getAttrib(VECTOR_ELT(BIPARTITEGROUP,
-				bipartite), avout);
-        const ActorSet * pSenders = pData->pActorSet(CHAR(STRING_ELT(
-					actorSet, 0)));
-        const ActorSet * pReceivers = pData->pActorSet(CHAR(STRING_ELT(
-					actorSet, 1)));
+		PROTECT(avout = install("averageOutDegree"));
+		SEXP averageOutDegree = getAttrib(VECTOR_ELT(BIPARTITEGROUP,
+					bipartite), avout);
+		const ActorSet * pSenders = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 0)));
+		const ActorSet * pReceivers = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 1)));
 		NetworkLongitudinalData *  pNetworkLongitudinalData =
 			pData->createNetworkData(CHAR(STRING_ELT(name, 0)),
-				pSenders, pReceivers);
-        pNetworkLongitudinalData->averageOutDegree(*(REAL(averageOutDegree)));
+					pSenders, pReceivers);
+		pNetworkLongitudinalData->averageOutDegree(*(REAL(averageOutDegree)));
 		setupBipartiteObservations(VECTOR_ELT(BIPARTITEGROUP, bipartite),
-			pNetworkLongitudinalData);
+				pNetworkLongitudinalData);
 
 		// Once all network data has been stored, calculate some
 		// statistical properties of that data.
 
 		pNetworkLongitudinalData->calculateProperties();
-        UNPROTECT(3);
-    }
+		UNPROTECT(3);
+	}
 }
 
 /**
@@ -625,45 +625,44 @@
  *
  */
 void setupBehavior(SEXP BEHAVIOR, BehaviorLongitudinalData * pBehaviorData)
-
 {
-    int observations = ncols(VECTOR_ELT(BEHAVIOR, 0));
+	int observations = ncols(VECTOR_ELT(BEHAVIOR, 0));
 
-    if (observations != pBehaviorData->observationCount())
-    {
+	if (observations != pBehaviorData->observationCount())
+	{
 		error ("wrong number of observations in Behavior");
-    }
-    int nActors = nrows(VECTOR_ELT(BEHAVIOR, 0));
+	}
+	int nActors = nrows(VECTOR_ELT(BEHAVIOR, 0));
 
-    if (nActors != pBehaviorData->n())
-    {
-        error ("wrong number of actors");
-    }
-    int * start = INTEGER(VECTOR_ELT(BEHAVIOR, 0));
+	if (nActors != pBehaviorData->n())
+	{
+		error ("wrong number of actors");
+	}
+	int * start = INTEGER(VECTOR_ELT(BEHAVIOR, 0));
 	int * missing = LOGICAL(VECTOR_ELT(BEHAVIOR, 1));
 
-    for (int period = 0; period < observations; period++)
-    {
-        for (int actor = 0; actor < nActors; actor++)
-        {
-            pBehaviorData->value(period, actor, *start++);
+	for (int period = 0; period < observations; period++)
+	{
+		for (int actor = 0; actor < nActors; actor++)
+		{
+			pBehaviorData->value(period, actor, *start++);
 			pBehaviorData->missing(period, actor, *missing++);
-       }
-    }
-    SEXP uo;
-    PROTECT(uo = install("uponly"));
-    SEXP uponly = getAttrib(VECTOR_ELT(BEHAVIOR, 0), uo);
-    SEXP dow;
-    PROTECT(dow = install("downonly"));
-    SEXP downonly = getAttrib(VECTOR_ELT(BEHAVIOR,0), dow);
-    for (int period = 0; period < (observations - 1); period++)
-    {
-        pBehaviorData->upOnly(period, LOGICAL(uponly)[period]);
-        pBehaviorData->downOnly(period, LOGICAL(downonly)[period]);
-    }
-    SEXP sim;
-    PROTECT(sim = install("simMean"));
-    SEXP simMean = getAttrib(VECTOR_ELT(BEHAVIOR,0), sim);
+		}
+	}
+	SEXP uo;
+	PROTECT(uo = install("uponly"));
+	SEXP uponly = getAttrib(VECTOR_ELT(BEHAVIOR, 0), uo);
+	SEXP dow;
+	PROTECT(dow = install("downonly"));
+	SEXP downonly = getAttrib(VECTOR_ELT(BEHAVIOR,0), dow);
+	for (int period = 0; period < (observations - 1); period++)
+	{
+		pBehaviorData->upOnly(period, LOGICAL(uponly)[period]);
+		pBehaviorData->downOnly(period, LOGICAL(downonly)[period]);
+	}
+	SEXP sim;
+	PROTECT(sim = install("simMean"));
+	SEXP simMean = getAttrib(VECTOR_ELT(BEHAVIOR,0), sim);
 	pBehaviorData->similarityMean(REAL(simMean)[0]);
 	SEXP sims;
 	PROTECT(sims = install("simMeans"));
@@ -674,48 +673,50 @@
 	for (int net = 0; net < numberNetworks; net++)
 	{
 		pBehaviorData->similarityMeans(REAL(simMeans)[net],
-			CHAR(STRING_ELT(simNames, net)));
+				CHAR(STRING_ELT(simNames, net)));
 	}
 
-    // Now that the values are set, calculate some important statistics
+	// Now that the values are set, calculate some important statistics
 	pBehaviorData->calculateProperties();
 	UNPROTECT(5);
 }
+
 /**
  * Create one group of Behavior Networks
  *
  */
 void setupBehaviorGroup(SEXP BEHGROUP, Data *pData)
 {
-    int nBehavior = length(BEHGROUP);
+	int nBehavior = length(BEHGROUP);
 
-    for (int behavior= 0; behavior < nBehavior; behavior++)
-    {
+	for (int behavior= 0; behavior < nBehavior; behavior++)
+	{
 		SEXP as;
 		PROTECT(as = install("nodeSet"));
-        SEXP actorSet = getAttrib(VECTOR_ELT(VECTOR_ELT(BEHGROUP, behavior), 0),
-								  as);
+		SEXP actorSet = getAttrib(VECTOR_ELT(VECTOR_ELT(BEHGROUP, behavior), 0),
+				as);
 
-        SEXP nm;
-        PROTECT(nm = install("name"));
-        SEXP name = getAttrib(VECTOR_ELT(VECTOR_ELT(BEHGROUP, behavior), 0),
-							  nm);
+		SEXP nm;
+		PROTECT(nm = install("name"));
+		SEXP name = getAttrib(VECTOR_ELT(VECTOR_ELT(BEHGROUP, behavior), 0),
+				nm);
 
-        const ActorSet * myActorSet = pData->pActorSet(CHAR(STRING_ELT(
-                                                                actorSet, 0)));
-	BehaviorLongitudinalData * pBehaviorData =
-	    pData->createBehaviorData(CHAR(STRING_ELT(name, 0)), myActorSet);
-//	Rprintf("%x\n", pBehaviorData);
-	setupBehavior(VECTOR_ELT(BEHGROUP, behavior), pBehaviorData);
-        UNPROTECT(2);
-    }
+		const ActorSet * myActorSet = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 0)));
+		BehaviorLongitudinalData * pBehaviorData =
+			pData->createBehaviorData(CHAR(STRING_ELT(name, 0)), myActorSet);
+		//	Rprintf("%x\n", pBehaviorData);
+		setupBehavior(VECTOR_ELT(BEHGROUP, behavior), pBehaviorData);
+		UNPROTECT(2);
+	}
 }
+
 /**
  * Create a constant covariate
  *
  */
-void setupConstantCovariate(SEXP COCOVAR, ConstantCovariate *
-		pConstantCovariate)
+void setupConstantCovariate(SEXP COCOVAR,
+		ConstantCovariate * pConstantCovariate)
 {
 	int nActors = length(COCOVAR);
 	// Rprintf("%x\n", pConstantCovariate);
@@ -739,29 +740,29 @@
 	{
 		impute = TRUE;
 		imputationValues = REAL(ans);
-//		Rprintf("We have something to impute\n");
+		//		Rprintf("We have something to impute\n");
 	}
 
-    for (int actor = 0; actor < nActors; actor++)
-    {
+	for (int actor = 0; actor < nActors; actor++)
+	{
 		double value = *start++;
 		if (ISNAN(value))
 		{
 			if (impute) // imputationValues already were centered, if necessary
 			{
 				pConstantCovariate->value(actor, imputationValues[actor]);
-//				Rprintf("We impute value %f for actor %d\n",
-//					imputationValues[actor], actor + 1);
+				//				Rprintf("We impute value %f for actor %d\n",
+				//					imputationValues[actor], actor + 1);
 			}
 			else if (centered) // no user input provided
 			{
-			pConstantCovariate->value(actor, 0);
-//				Rprintf("We use 0 for actor %d\n", actor + 1);
+				pConstantCovariate->value(actor, 0);
+				//				Rprintf("We use 0 for actor %d\n", actor + 1);
 			}
 			else // no user input provided, not centered
 			{
 				pConstantCovariate->value(actor, mean);
-//				Rprintf("We use the mean %f for actor %d\n", mean, actor + 1);
+				//				Rprintf("We use the mean %f for actor %d\n", mean, actor + 1);
 			}
 			pConstantCovariate->missing(actor, 1);
 		}
@@ -771,7 +772,7 @@
 			pConstantCovariate->missing(actor, 0);
 
 		}
-    }
+	}
 	UNPROTECT(3);
 }
 /**
@@ -780,32 +781,32 @@
  */
 void setupConstantCovariateGroup(SEXP COCOVARGROUP, Data *pData)
 {
-    int nConstantCovariate = length(COCOVARGROUP);
-//    Rprintf("nConstantCovariate %d\n", nConstantCovariate);
-    for (int constantCovariate = 0; constantCovariate < nConstantCovariate;
-	 constantCovariate++)
-    {
-        SEXP as;
-        PROTECT(as = install("nodeSet"));
-        SEXP actorSet = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate),
-                                  as);
-        SEXP nm;
-        PROTECT(nm = install("name"));
-        SEXP name = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate), nm);
-        const ActorSet * myActorSet = pData->pActorSet(CHAR(STRING_ELT(
-                                                                actorSet, 0)));
-        int nActors = length(VECTOR_ELT(COCOVARGROUP, constantCovariate));
-//    Rprintf("nactors %d\n", nActors);
+	int nConstantCovariate = length(COCOVARGROUP);
+	//    Rprintf("nConstantCovariate %d\n", nConstantCovariate);
+	for (int constantCovariate = 0; constantCovariate < nConstantCovariate;
+			constantCovariate++)
+	{
+		SEXP as;
+		PROTECT(as = install("nodeSet"));
+		SEXP actorSet = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate),
+				as);
+		SEXP nm;
+		PROTECT(nm = install("name"));
+		SEXP name = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate), nm);
+		const ActorSet * myActorSet = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 0)));
+		int nActors = length(VECTOR_ELT(COCOVARGROUP, constantCovariate));
+		//    Rprintf("nactors %d\n", nActors);
 
-        if (nActors != myActorSet->n())
-        {
-            error ("wrong number of actors");
-        }
+		if (nActors != myActorSet->n())
+		{
+			error ("wrong number of actors");
+		}
 		ConstantCovariate * pConstantCovariate =
 			pData->createConstantCovariate(CHAR(STRING_ELT(name, 0)),
-				myActorSet);
-        setupConstantCovariate(VECTOR_ELT(COCOVARGROUP,	constantCovariate),
-			pConstantCovariate);
+					myActorSet);
+		setupConstantCovariate(VECTOR_ELT(COCOVARGROUP,	constantCovariate),
+				pConstantCovariate);
 		SEXP mn;
 		PROTECT(mn = install("mean"));
 		SEXP obsmean = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate), mn);
@@ -824,28 +825,29 @@
 		SEXP sim;
 		PROTECT(sim = install("simMean"));
 		SEXP simMean = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate),
-			sim);
+				sim);
 		pConstantCovariate->similarityMean(REAL(simMean)[0]);
 		SEXP sims;
 		PROTECT(sims = install("simMeans"));
 		SEXP simMeans = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate),
-			sims);
+				sims);
 		SEXP simNames;
 		PROTECT(simNames = getAttrib(simMeans, R_NamesSymbol));
 		int numberNetworks = length(simMeans);
 		for (int net = 0; net < numberNetworks; net++)
 		{
 			pConstantCovariate->similarityMeans(REAL(simMean)[net],
-				CHAR(STRING_ELT(simNames, net)));
+					CHAR(STRING_ELT(simNames, net)));
 		}
 		SEXP range;
 		PROTECT(range = install("range"));
 		SEXP Range = getAttrib(VECTOR_ELT(COCOVARGROUP, constantCovariate),
-			range);
+				range);
 		pConstantCovariate->range(REAL(Range)[0]);
-        UNPROTECT(8);
-    }
+		UNPROTECT(8);
+	}
 }
+
 /**
  * Create all observations for a changing covariate
  *
@@ -893,20 +895,20 @@
 				if (impute) // imputationValues have been centered, if necessary
 				{
 					pChangingCovariate->value(actor, period, imputationValue);
-//					Rprintf("We impute value %f for actor %d in period %d\n",
-//										imputationValue, actor + 1, period + 1);
+					//					Rprintf("We impute value %f for actor %d in period %d\n",
+					//										imputationValue, actor + 1, period + 1);
 				}
 				else if (centered) // no user input provided
 				{
 					pChangingCovariate->value(actor, period, 0);
-//					Rprintf("We use 0 for actor %d in period %d\n",
-//								actor + 1, period + 1);
+					//					Rprintf("We use 0 for actor %d in period %d\n",
+					//								actor + 1, period + 1);
 				}
 				else // no user input provided, not centered
 				{
 					pChangingCovariate->value(actor, period, mean);
-//					Rprintf("We use the mean %f for actor %d in period %d\n",
-//								mean, actor + 1, period + 1);
+					//					Rprintf("We use the mean %f for actor %d in period %d\n",
+					//								mean, actor + 1, period + 1);
 				}
 				pChangingCovariate->missing(actor, period, 1);
 			}
@@ -916,37 +918,38 @@
 				pChangingCovariate->missing(actor, period, 0);
 			}
 		}
-    }
+	}
 	UNPROTECT(3);
 }
+
 /**
  * Create one group of changing covariates
  *
  */
 void setupChangingCovariateGroup(SEXP VARCOVARGROUP, Data *pData)
 {
-    if (length(VARCOVARGROUP) == 0)
-        return;
-    int observations = ncols(VECTOR_ELT(VARCOVARGROUP,0));
-    if (observations != pData->observationCount() - 1)
-    {
+	if (length(VARCOVARGROUP) == 0)
+		return;
+	int observations = ncols(VECTOR_ELT(VARCOVARGROUP,0));
+	if (observations != pData->observationCount() - 1)
+	{
 		error ("wrong number of observations in Changing Covariate");
-    }
-    int nChangingCovariate = length(VARCOVARGROUP);
+	}
+	int nChangingCovariate = length(VARCOVARGROUP);
 	for (int changingCovariate = 0;
-		 changingCovariate < nChangingCovariate;
-		 changingCovariate++)
+			changingCovariate < nChangingCovariate;
+			changingCovariate++)
 	{
 		SEXP as;
 		PROTECT(as = install("nodeSet"));
 		SEXP actorSet = getAttrib(VECTOR_ELT(VARCOVARGROUP, changingCovariate),
-			as);
+				as);
 		SEXP nm;
 		PROTECT(nm = install("name"));
 		SEXP name = getAttrib(VECTOR_ELT(VARCOVARGROUP, changingCovariate),
-			nm);
+				nm);
 		const ActorSet * myActorSet = pData->pActorSet(CHAR(STRING_ELT(
-					actorSet, 0)));
+						actorSet, 0)));
 		int nActors = nrows(VECTOR_ELT(VARCOVARGROUP,changingCovariate));
 
 		if (nActors != myActorSet->n())
@@ -955,9 +958,9 @@
 		}
 		ChangingCovariate * pChangingCovariate =
 			pData->createChangingCovariate(CHAR(STRING_ELT(name, 0)),
-				myActorSet);
+					myActorSet);
 		setupChangingCovariate(VECTOR_ELT(VARCOVARGROUP, changingCovariate),
-			pChangingCovariate);
+				pChangingCovariate);
 		SEXP mn;
 		PROTECT(mn = install("mean"));
 		SEXP obsmean = getAttrib(VECTOR_ELT(VARCOVARGROUP, changingCovariate), mn);
@@ -976,42 +979,43 @@
 		SEXP sim;
 		PROTECT(sim = install("simMean"));
 		SEXP simMean = getAttrib(VECTOR_ELT(VARCOVARGROUP, changingCovariate),
-			sim);
+				sim);
 		pChangingCovariate->similarityMean(REAL(simMean)[0]);
 		SEXP sims;
 		PROTECT(sims = install("simMeans"));
 		SEXP simMeans = getAttrib(VECTOR_ELT(VARCOVARGROUP, changingCovariate),
-			sims);
+				sims);
 		SEXP simNames;
 		PROTECT(simNames = getAttrib(simMeans, R_NamesSymbol));
 		int numberNetworks = length(simMeans);
 		for (int net = 0; net < numberNetworks; net++)
 		{
 			pChangingCovariate->similarityMeans(REAL(simMean)[net],
-				CHAR(STRING_ELT(simNames, net)));
+					CHAR(STRING_ELT(simNames, net)));
 		}
 		SEXP range;
 		PROTECT(range = install("range"));
 		SEXP Range = getAttrib(VECTOR_ELT(VARCOVARGROUP, changingCovariate),
-			range);
+				range);
 		pChangingCovariate->range(REAL(Range)[0]);
 		UNPROTECT(8);
 	}
 }
+
 /**
  * Create a constant dyadic covariate
  *
  */
 void setupDyadicCovariate(SEXP DYADVAR,
-                          ConstantDyadicCovariate * pConstantDyadicCovariate)
+		ConstantDyadicCovariate * pConstantDyadicCovariate)
 {
-    double *start = REAL(VECTOR_ELT(DYADVAR, 0));
-    double *missingstart = REAL(VECTOR_ELT(DYADVAR, 1));
-    int listlen = ncols(VECTOR_ELT(DYADVAR, 0));
-//	Rprintf("listlen =  %d\n", listlen);
-    int pos = 0;
-    for (int row = 0; row < listlen; row++)
-    {
+	double *start = REAL(VECTOR_ELT(DYADVAR, 0));
+	double *missingstart = REAL(VECTOR_ELT(DYADVAR, 1));
+	int listlen = ncols(VECTOR_ELT(DYADVAR, 0));
+	//	Rprintf("listlen =  %d\n", listlen);
+	int pos = 0;
+	for (int row = 0; row < listlen; row++)
+	{
 		int i;
 		int j;
 		double val;
@@ -1020,10 +1024,10 @@
 		val = start[pos++];
 		pConstantDyadicCovariate->value(i-1, j-1, val);
 	}
-    listlen = ncols(VECTOR_ELT(DYADVAR, 1));
-    pos = 0;
-    for (int row = 0; row < listlen; row++)
-    {
+	listlen = ncols(VECTOR_ELT(DYADVAR, 1));
+	pos = 0;
+	for (int row = 0; row < listlen; row++)
+	{
 		int i;
 		int j;
 		double val;
@@ -1040,35 +1044,35 @@
  */
 void setupDyadicCovariateGroup(SEXP DYADVARGROUP, Data *pData)
 {
-    int nDyadicCovariate = length(DYADVARGROUP);
-//    Rprintf("nDyadicCovariate %d\n", nDyadicCovariate);
-    for (int dyadicCovariate = 0; dyadicCovariate < nDyadicCovariate;
-	 dyadicCovariate++)
-    {
-        SEXP as;
-        PROTECT(as = install("nodeSet"));
-        SEXP actorSet = getAttrib(VECTOR_ELT(DYADVARGROUP, dyadicCovariate),
-                                  as);
-        SEXP nm;
-        PROTECT(nm = install("name"));
-        SEXP name = getAttrib(VECTOR_ELT(DYADVARGROUP, dyadicCovariate),
-                              nm);
-        const ActorSet * myActorSet1 = pData->pActorSet(CHAR(STRING_ELT(
-                                                                actorSet, 0)));
-        const ActorSet * myActorSet2 = pData->pActorSet(CHAR(STRING_ELT(
-                                                                 actorSet, 1)));
+	int nDyadicCovariate = length(DYADVARGROUP);
+	//    Rprintf("nDyadicCovariate %d\n", nDyadicCovariate);
+	for (int dyadicCovariate = 0; dyadicCovariate < nDyadicCovariate;
+			dyadicCovariate++)
+	{
+		SEXP as;
+		PROTECT(as = install("nodeSet"));
+		SEXP actorSet = getAttrib(VECTOR_ELT(DYADVARGROUP, dyadicCovariate),
+				as);
+		SEXP nm;
+		PROTECT(nm = install("name"));
+		SEXP name = getAttrib(VECTOR_ELT(DYADVARGROUP, dyadicCovariate),
+				nm);
+		const ActorSet * myActorSet1 = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 0)));
+		const ActorSet * myActorSet2 = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 1)));
 		ConstantDyadicCovariate * pConstantDyadicCovariate =
 			pData->createConstantDyadicCovariate(CHAR(STRING_ELT(name, 0)),
-				myActorSet1, myActorSet2);
+					myActorSet1, myActorSet2);
 		setupDyadicCovariate(VECTOR_ELT(DYADVARGROUP, dyadicCovariate),
-			pConstantDyadicCovariate);
+				pConstantDyadicCovariate);
 		SEXP mean;
 		PROTECT(mean = install("mean"));
 		SEXP Mean = getAttrib(VECTOR_ELT(DYADVARGROUP, dyadicCovariate),
-			mean);
+				mean);
 		pConstantDyadicCovariate->mean(REAL(Mean)[0]);
-        UNPROTECT(3);
-    }
+		UNPROTECT(3);
+	}
 }
 
 /**
@@ -1076,14 +1080,14 @@
  *
  */
 void unpackChangingDyadicPeriod(SEXP VARDYADVALS, ChangingDyadicCovariate *
-                                pChangingDyadicCovariate, int period)
+		pChangingDyadicCovariate, int period)
 {
-    double *start = REAL(VECTOR_ELT(VARDYADVALS, 0));
+	double *start = REAL(VECTOR_ELT(VARDYADVALS, 0));
 	int listlen = ncols(VECTOR_ELT(VARDYADVALS, 0));
-//	Rprintf("listlen =  %d\n", listlen);
-    int pos = 0;
-    for (int row = 0; row < listlen; row++)
-    {
+	//	Rprintf("listlen =  %d\n", listlen);
+	int pos = 0;
+	for (int row = 0; row < listlen; row++)
+	{
 		int i;
 		int j;
 		double val;
@@ -1091,13 +1095,13 @@
 		j = start[pos++];
 		val = start[pos++];
 		pChangingDyadicCovariate->value(i - 1, j - 1, period, val);
-    }
-    double *missingstart = REAL(VECTOR_ELT(VARDYADVALS, 1));
-    listlen = ncols(VECTOR_ELT(VARDYADVALS, 1));
-//	Rprintf("listlen =  %d\n", listlen);
+	}
+	double *missingstart = REAL(VECTOR_ELT(VARDYADVALS, 1));
+	listlen = ncols(VECTOR_ELT(VARDYADVALS, 1));
+	//	Rprintf("listlen =  %d\n", listlen);
 	pos = 0;
-    for (int row = 0; row < listlen; row++)
-    {
+	for (int row = 0; row < listlen; row++)
+	{
 		int i;
 		int j;
 		double val;
@@ -1105,73 +1109,73 @@
 		j = missingstart[pos++];
 		val = missingstart[pos++];
 		pChangingDyadicCovariate->missing(i - 1, j - 1, period, val);
-    }
+	}
 }
 /**
  * Create all observations for a changing dyadic covariate
  *
  */
 void setupChangingDyadicObservations(SEXP VARDYAD,
-			      ChangingDyadicCovariate *
-                              pChangingDyadicCovariate)
-
+		ChangingDyadicCovariate * pChangingDyadicCovariate)
 {
-    int observations = length(VARDYAD);
-    //   if (observations != pworkLongitudinalData->observationCount())
-    // {
-    //	error ("wrong number of observations in OneMode");
-    //  }
-    for (int period = 0; period < (observations - 1); period++)
-    {
+	int observations = length(VARDYAD);
+	//   if (observations != pworkLongitudinalData->observationCount())
+	// {
+	//	error ("wrong number of observations in OneMode");
+	//  }
+	for (int period = 0; period < (observations - 1); period++)
+	{
 		unpackChangingDyadicPeriod(VECTOR_ELT(VARDYAD, period),
-			pChangingDyadicCovariate, period);
-    }
+				pChangingDyadicCovariate, period);
+	}
 }
+
 /**
  * Create one group of changing dyadic covariates
  *
  */
 void setupChangingDyadicCovariateGroup(SEXP VARDYADGROUP, Data * pData)
 {
-    int nChangingDyadic = length(VARDYADGROUP);
+	int nChangingDyadic = length(VARDYADGROUP);
 
-    for (int changingDyadic = 0; changingDyadic < nChangingDyadic;
-         changingDyadic++)
-    {
-        SEXP as;
-        PROTECT(as = install("nodeSet"));
-        SEXP actorSet = getAttrib(VECTOR_ELT(VARDYADGROUP, changingDyadic), as);
-        SEXP nm;
-        PROTECT(nm = install("name"));
-        SEXP name = getAttrib(VECTOR_ELT(VARDYADGROUP, changingDyadic), nm);
-        const ActorSet * myActorSet1 = pData->pActorSet(CHAR(STRING_ELT(
-                                                                actorSet, 0)));
-        const ActorSet * myActorSet2 = pData->pActorSet(CHAR(STRING_ELT(
-                                                                actorSet, 1)));
+	for (int changingDyadic = 0; changingDyadic < nChangingDyadic;
+			changingDyadic++)
+	{
+		SEXP as;
+		PROTECT(as = install("nodeSet"));
+		SEXP actorSet = getAttrib(VECTOR_ELT(VARDYADGROUP, changingDyadic), as);
+		SEXP nm;
+		PROTECT(nm = install("name"));
+		SEXP name = getAttrib(VECTOR_ELT(VARDYADGROUP, changingDyadic), nm);
+		const ActorSet * myActorSet1 = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 0)));
+		const ActorSet * myActorSet2 = pData->pActorSet(CHAR(STRING_ELT(
+						actorSet, 1)));
 		ChangingDyadicCovariate *  pChangingDyadicCovariate =
 			pData->createChangingDyadicCovariate(CHAR(STRING_ELT(name, 0)),
-				myActorSet1, myActorSet2);
+					myActorSet1, myActorSet2);
 		setupChangingDyadicObservations(VECTOR_ELT(VARDYADGROUP,
-				changingDyadic),
-			pChangingDyadicCovariate);
- 		SEXP mean;
+					changingDyadic),
+				pChangingDyadicCovariate);
+		SEXP mean;
 		PROTECT(mean = install("mean"));
 		SEXP Mean = getAttrib(VECTOR_ELT(VARDYADGROUP, changingDyadic),
-			mean);
+				mean);
 		pChangingDyadicCovariate->mean(REAL(Mean)[0]);
 		UNPROTECT(3);
-    }
+	}
 }
+
 /**
  * Create the exogenous composition change events for one actor set within
  * one group.
  */
 void setupExogenousEventSet(SEXP EXOGEVENTSET, Data *pData)
 {
-    /* pass in the data for one actor set as two items: first
-	   a list of columns: event type, period, actor, time.
-	   Secondly a matrix of booleans, indicating whether active at start
-	   of period.*/
+	/* pass in the data for one actor set as two items: first
+		 a list of columns: event type, period, actor, time.
+		 Secondly a matrix of booleans, indicating whether active at start
+		 of period.*/
 
 	/* first find the actor set */
 	SEXP as;
@@ -1180,39 +1184,39 @@
 
 	/* now process the events */
 	SEXP EVENTS = VECTOR_ELT(EXOGEVENTSET, 0);
-    int nEvents = length(VECTOR_ELT(EVENTS, 0));
-    //Rprintf("number of rows of data frame %d\n",nEvents);
+	int nEvents = length(VECTOR_ELT(EVENTS, 0));
+	//Rprintf("number of rows of data frame %d\n",nEvents);
 	//Rprintf("%d\n", length(EVENTS));
-    int * type = INTEGER(VECTOR_ELT(EVENTS, 0));
+	int * type = INTEGER(VECTOR_ELT(EVENTS, 0));
 	//Rprintf("type %d\n",*type);
 	int * period = INTEGER(VECTOR_ELT(EVENTS, 1));
 	//Rprintf("period %d\n",*period);
 	int * actor = INTEGER(VECTOR_ELT(EVENTS, 2));
 	//Rprintf("actor %d\n",*actor);
-    double * time = REAL(VECTOR_ELT(EVENTS, 3));
+	double * time = REAL(VECTOR_ELT(EVENTS, 3));
 	//Rprintf("time %5.4f\n",*time);
 	const ActorSet * myActorSet = pData->pActorSet(CHAR(STRING_ELT(actorSet,
-															   0)));
-    for (int event = 0; event < nEvents; event++)
-    {
+					0)));
+	for (int event = 0; event < nEvents; event++)
+	{
 		if (*type == 1)
 		{
-				pData->addJoiningEvent(*period-1, myActorSet, *actor-1, *time);
+			pData->addJoiningEvent(*period-1, myActorSet, *actor-1, *time);
 		}
 		else
 		{
 			pData->addLeavingEvent(*period-1, myActorSet, *actor-1, *time);
 		}
 		type++;
- 		period++;
- 		actor++;
- 		time++;
-  }
-/* retrieve some to check*/
-//     const EventSet * myeventset= pData->pEventSet(0);
-// 	EventSet::iterator myit = myeventset->begin();
-// 	Rprintf("period 1 first event? %d %3.2f\n",(*myit)->actor(),
-// 			(*myit)->time());
+		period++;
+		actor++;
+		time++;
+	}
+	/* retrieve some to check*/
+	//     const EventSet * myeventset= pData->pEventSet(0);
+	// 	EventSet::iterator myit = myeventset->begin();
+	// 	Rprintf("period 1 first event? %d %3.2f\n",(*myit)->actor(),
+	// 			(*myit)->time());
 
 	/* initialise the active flags */
 	SEXP ACTIVES= VECTOR_ELT(EXOGEVENTSET, 1);
@@ -1223,11 +1227,11 @@
 	int *active = LOGICAL(ACTIVES);
 	for (int period = 0; period < pData->observationCount(); period++)
 	{
-			for (int actor = 0; actor < nActors; actor++)
-			{
-				pData->active(myActorSet, actor, period, *active);
-				active++;
-			}
+		for (int actor = 0; actor < nActors; actor++)
+		{
+			pData->active(myActorSet, actor, period, *active);
+			active++;
+		}
 
 	}
 	UNPROTECT(1);
@@ -1239,13 +1243,13 @@
  */
 void setupExogenousEventGroup(SEXP EXOGEVENTGROUP, Data *pData)
 {
-    /* pass in the data for each actor set as two items: first
-	   a list of columns: event type, period, actor, time.
-	   Secondly a matrix of booleans, indicating whether active at start
-	   of period.*/
+	/* pass in the data for each actor set as two items: first
+		 a list of columns: event type, period, actor, time.
+		 Secondly a matrix of booleans, indicating whether active at start
+		 of period.*/
 
-    int nActorSets = length(EXOGEVENTGROUP);
-//	Rprintf("number of actor sets %d\n", nActorSets);
+	int nActorSets = length(EXOGEVENTGROUP);
+	//	Rprintf("number of actor sets %d\n", nActorSets);
 
 	for (int actorSet = 0; actorSet < nActorSets; actorSet++)
 	{
@@ -1257,87 +1261,87 @@
  *  Creates all the basic effects for one network
  */
 SEXP createEffects(SEXP EFFECTS, Model *pModel, vector<Data *> * pGroupData,
-	const char *networkName, int effectCol, int parmCol, int int1Col,
-	int int2Col, int initValCol, int typeCol, int groupCol, int periodCol,
-	int rateTypeCol, int netTypeCol, int settingCol)
-    {
-        // find out how many effects there are
-        int nEffects = length(VECTOR_ELT(EFFECTS, 0));
+		const char *networkName, int effectCol, int parmCol, int int1Col,
+		int int2Col, int initValCol, int typeCol, int groupCol, int periodCol,
+		int rateTypeCol, int netTypeCol, int settingCol)
+{
+	// find out how many effects there are
+	int nEffects = length(VECTOR_ELT(EFFECTS, 0));
 
-        // create the effects
+	// create the effects
 
-		/* set up a vector to return the pointers in */
-		SEXP effectPtrs;
-		PROTECT(effectPtrs = allocVector(VECSXP, nEffects));
+	/* set up a vector to return the pointers in */
+	SEXP effectPtrs;
+	PROTECT(effectPtrs = allocVector(VECSXP, nEffects));
 
-		for (int i = 0; i < nEffects; i++)
-		{
-			EffectInfo * pEffectInfo = 0;
+	for (int i = 0; i < nEffects; i++)
+	{
+		EffectInfo * pEffectInfo = 0;
 
-			const char * effectName =
-				CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, effectCol), i));
-			int parm1 = INTEGER(VECTOR_ELT(EFFECTS, parmCol))[i];
-			double parm = parm1;
-			const char * interaction1 =
-				CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, int1Col), i));
-			const char * interaction2 =
-				CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, int2Col), i));
-            double initialValue = REAL(VECTOR_ELT(EFFECTS, initValCol))[i];
-			const char * effectType =
-				CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, typeCol), i));
-			const char * rateType =
-				CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, rateTypeCol), i));
-			const char * netType =
-				CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, netTypeCol), i));
-			const char * setting =
-				CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, settingCol), i));
+		const char * effectName =
+			CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, effectCol), i));
+		int parm1 = INTEGER(VECTOR_ELT(EFFECTS, parmCol))[i];
+		double parm = parm1;
+		const char * interaction1 =
+			CHAR(STRING_ELT(VECTOR_ELT(EFFECTS, int1Col), i));
[TRUNCATED]

To get the complete diff run:
    svnlook diff /svnroot/rsiena -r 322


More information about the Rsiena-commits mailing list