@Override public Plan selectPlan(HasPlansAndId<Plan, Person> person) { List<cadyts.demand.Plan<T>> plans = new ArrayList<cadyts.demand.Plan<T>>() ; Vector choiceProbs = new Vector( person.getPlans().size() ) ; int pos = 0 ; for ( Plan plan : person.getPlans() ) { plans.add( cContext.getPlansTranslator().getCadytsPlan(plan) ) ; choiceProbs.add(pos, ExpBetaPlanSelector.getSelectionProbability(new ExpBetaPlanSelector(beta), plan.getPerson(), plan) ); // I guess these are supposed to be the prior probabilities. If so, than the above shoudl be correct (albeit a bit expensive). // I would have expected that these are internally ignored when brute force is switched on, but they are not. // I think that what it does is to use them when plans are equal according to cadyts. kai, dec'13 pos++ ; } int idx = cContext.getCalibrator().selectPlan(plans, choiceProbs) ; // cContext.getCalibrator().addToDemand(cadytsPlan) ; // I _think_ that's done inside calibrator.selectPlan. kai, dec'13 return person.getPlans().get(idx) ; }
public void testGetSelectionProbability() { /* * the expected results were computed with R. The standard output of double precision numbers in R has 7 digits. */ final double EPSILON_R = 1e-7; this.config.planCalcScore().setBrainExpBeta(2.0); Person person = PopulationUtils.getFactory().createPerson(Id.create(1, Person.class)); Plan plan1 = PersonUtils.createAndAddPlan(person, false); plan1.setScore(180.0); Plan plan2 = PersonUtils.createAndAddPlan(person, false); plan2.setScore(180.1); Plan plan3 = PersonUtils.createAndAddPlan(person, false); plan3.setScore(180.5); Plan plan4 = PersonUtils.createAndAddPlan(person, false); plan4.setScore(169.9); ExpBetaPlanSelector testee = new ExpBetaPlanSelector(this.config.planCalcScore()); assertEquals(0.2024421, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan1), EPSILON_R); assertEquals(0.2472634, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan2), EPSILON_R); assertEquals(0.5502947, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan3), EPSILON_R); assertEquals(6.208075e-10, ExpBetaPlanSelector.getSelectionProbability(testee, person, plan4), EPSILON_R); }