Exemplo n.º 1
0
        public Household GetNextAgent(ModelDistribution g_x, 
            string dimension, Household prvAgent, SpatialZone currZone)
        {
            StateGenerator currStateGen = new StateGenerator();
            currStateGen.SetParameters(currZone.GetAverageIncome(),
                                            currZone.GetAverageIncome() * 2);
            double q_previous;
            double q_current = 0.00;
            double expIncome = Math.Log(prvAgent.GetIncome());
            KeyValDoublePair currPair = new KeyValDoublePair();
            //start with mean value
            currPair.Category = currStateGen.GetMean();
            currPair.Val = currStateGen.GetTransitionProbablity(currPair.Category);

            for (int i = 0; i < Constants.WARMUP_ITERATIONS; i++)
            {
                q_previous = currStateGen.GetTransitionProbablity(
                               Math.Log((double)prvAgent.GetIncome()));
                q_current = currPair.Val;
                IncomeLevel prevLvl = IncomeConvertor.ConvertValueToLevel(
                                        (uint) Math.Exp(expIncome));
                IncomeLevel currLvl = IncomeConvertor.ConvertValueToLevel(
                                        (uint) Math.Exp(currPair.Category));
                double b_prev = g_x.GetValue(dimension, prevLvl.ToString(),
                    prvAgent.GetNewJointKey(dimension), currZone);
                double b_curr = g_x.GetValue(dimension, currLvl.ToString(),
                    prvAgent.GetNewJointKey(dimension), currZone);
                if (b_prev == 0.00)
                    b_prev = 0.0000001;
                if (b_curr == 0.00)
                    b_curr = 0.0000001;
                if (q_current == 0.00)
                    q_current = 0.0000001;
                double comVal = (b_curr * q_previous) / (b_prev * q_current);
                if (comVal == 0.00)
                    comVal = 0.0000001;
                if (randGen.NextDouble() < comVal)
                {
                    expIncome = currPair.Category;
                }
                currPair = currStateGen.GetNextState();
            }
            return prvAgent.CreateNewCopy((uint)Math.Exp(expIncome));
        }
Exemplo n.º 2
0
        public Household GetNextAgentHousehold(DiscreteMarginalDistribution f_x, 
            ConditionalDistribution g_x, string dimension, 
            Household prvAgent, SpatialZone currZone)
        {
            KeyValPair currDimVal;
            double currProb = 0.00;
            double currRatio = 0.00;
            int cnt = 0;
            do{
                currDimVal = GenerateNextFromG_X(g_x, prvAgent,currZone,0);
                currProb = f_x.GetValue(currDimVal.Category);
                currRatio = currProb / currDimVal.Value;
                if (currRatio > 1.00)
                {
                    currRatio = 1.00;
                }
                if (cnt > 1000)
                {
                    currRatio = 1;
                }
                cnt++;
            } while (myRand.NextDouble() > currRatio);

            // Create the household object based on the currDimVal.category
            return (Household) prvAgent.CreateNewCopy(g_x.GetDimensionName(), Int16.Parse(currDimVal.Category),0);
        }