public GibbsSampler() { warmupTime = 0; samplingInterval = 0; agentIDCounter = 0; myImportantSampler = new ImportanceSampler(); myMHSampler = new MetropolisHasting(); Initialze(); }
private List<SimulationObject> GenerateHousholds(SpatialZone currZone, int numHousehold, Household initAgent, bool warmUpStatus, List<ConditionalDistribution> mobelCond, OutputFileWriter currWriter) { int seltdDim = 0; List<ConditionalDistribution> condList = currZone.GetDataHhldCollectionsList(); for(int i = 0; i < mobelCond.Count; i++) { condList.Add(mobelCond[i]); } var generatedAgents = new List<SimulationObject>(); Household prevAgent = initAgent; ImportanceSampler currImpSampler = new ImportanceSampler(); MetropolisHasting currMHSampler = new MetropolisHasting(); int iter = 0; if(warmUpStatus == true) { iter = Constants.WARMUP_ITERATIONS; } else { iter = Constants.SKIP_ITERATIONS * numHousehold; } Household newAgent = new Household(); StringBuilder builder = new StringBuilder(); for(int i = 0; i < iter; i++) { seltdDim = randGen.NextInRange(0, condList.Count - 1); ConditionalDistribution currDist = condList[seltdDim]; // If the selected distribution is dwelling/cars // call important sampling /*if (currDist.GetDimensionName() == "DwellingType") { newAgent = currImpSampler.GetNextAgent(currZone.myDwellMarginal, currDist, currDist.GetDimensionName(), prevAgent, currZone); } else if (currDist.GetDimensionName() == "NumOfCars") { newAgent = currImpSampler.GetNextAgent(currZone.myCarsMarginal, currDist, currDist.GetDimensionName(), prevAgent, currZone); }*/ // If the selected distribution is income // call MH // else if (((ConditionalDistribution)condList[seltdDim]) // .GetDimensionName() == "IncomeLevel") // { // newAgent = myMHSampler.GetNextAgent((ModelDistribution)currDist, // currDist.GetDimensionName(), prevAgent, currZone); // } if(currDist.GetDimensionName() == "HouseholdSize") { newAgent = (Household)currImpSampler.GetNextAgent( currZone.GetHousholdSizeDist(), currDist, currDist.GetDimensionName(), prevAgent, currZone); } else { var currComm = currDist.GetCommulativeValue( prevAgent.GetNewJointKey(currDist.GetDimensionName()) , currZone); newAgent = (Household)GenerateNextAgent(currComm, prevAgent, currDist.GetDimensionName()); } prevAgent = newAgent; if(warmUpStatus == false && (i % Constants.SKIP_ITERATIONS == 0)) { generatedAgents.Add(newAgent); uint currIncome = IncomeConvertor.GetEuroIncome((uint) newAgent.GetIncome()); builder.Append(newAgent.GetZoneID()); builder.Append(','); builder.Append(currZone.GetEPFLName()); builder.Append(','); builder.Append((int)newAgent.GetHhldSize()); builder.Append(','); builder.Append((int)newAgent.GetNumOfWorkers()); builder.Append(','); builder.Append((int)newAgent.GetNumOfKids()); builder.Append(','); builder.Append((int)newAgent.GetNumOfUnivDegree()); builder.Append(','); builder.Append((int)newAgent.GetIncomeLevel()); builder.Append(','); builder.Append((int)newAgent.GetNumOfCars()); builder.Append(','); builder.Append((int)newAgent.GetDwellingType()); currWriter.WriteToFile(builder.ToString()); builder.Clear(); } } return generatedAgents; }