source: src/main/java/negotiator/boaframework/opponentmodel/PerfectIAMhagglerBayesianModel.java@ 316

Last change on this file since 316 was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 24.8 KB
Line 
1package negotiator.boaframework.opponentmodel;
2
3import java.util.ArrayList;
4import java.util.Map;
5
6import javax.swing.JOptionPane;
7
8import agents.bayesianopponentmodel.EvaluatorHypothesis;
9import agents.bayesianopponentmodel.Hypothesis;
10import genius.core.Bid;
11import genius.core.Domain;
12import genius.core.boaframework.NegotiationSession;
13import genius.core.boaframework.OpponentModel;
14import genius.core.issue.Issue;
15import genius.core.issue.IssueDiscrete;
16import genius.core.issue.IssueInteger;
17import genius.core.issue.IssueReal;
18import genius.core.issue.ValueDiscrete;
19import genius.core.protocol.BilateralAtomicNegotiationSession;
20import genius.core.tournament.TournamentConfiguration;
21import genius.core.utility.AdditiveUtilitySpace;
22import genius.core.utility.EVALFUNCTYPE;
23import genius.core.utility.Evaluator;
24import genius.core.utility.EvaluatorDiscrete;
25import genius.core.utility.EvaluatorInteger;
26import genius.core.utility.EvaluatorReal;
27import negotiator.boaframework.opponentmodel.iamhaggler.WeightHypothesis;
28import negotiator.boaframework.opponentmodel.tools.UtilitySpaceAdapter;
29
30/**
31 * IAMhagglerModel by Colin Williams, adapted for the BOA framework. Modified
32 * such that it has perfect knowledge about the opponent's strategy.
33 *
34 * Tim Baarslag, Koen Hindriks, Mark Hendrikx, Alex Dirkzwager and Catholijn M.
35 * Jonker. Decoupling Negotiating Agents to Explore the Space of Negotiation
36 * Strategies
37 *
38 * @author Colin Williams, Mark Hendrikx
39 */
40public class PerfectIAMhagglerBayesianModel extends OpponentModel {
41 private ArrayList<Bid> biddingHistory;
42 private ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses;
43 private ArrayList<ArrayList<WeightHypothesis>> weightHypotheses;
44 private double previousBidUtility;
45 private Double maxUtility;
46 private Double minUtility;
47 private double[] expectedWeights;
48 private double SIGMA = 0.25;
49 private final int totalTriangularFunctions = 4;
50 private Domain domain;
51 private AdditiveUtilitySpace utilitySpace;
52 private boolean useAll = false;
53 private int startingBidIssue = 0;
54
55 @Override
56 public void setOpponentUtilitySpace(BilateralAtomicNegotiationSession session) {
57
58 if (TournamentConfiguration.getBooleanOption("accessPartnerPreferences", false)) {
59 opponentUtilitySpace = (AdditiveUtilitySpace) session.getAgentAUtilitySpace();
60 if (negotiationSession.getUtilitySpace().getFileName().equals(opponentUtilitySpace.getFileName())) {
61 opponentUtilitySpace = (AdditiveUtilitySpace) session.getAgentBUtilitySpace();
62 }
63 } else {
64 JOptionPane.showMessageDialog(null,
65 "This opponent model needs access to the opponent's\npreferences. See tournament options.",
66 "Model error", 0);
67 System.err.println("Global.experimentalSetup should be enabled!");
68 }
69 }
70
71 @Override
72 public void init(NegotiationSession negotiationSession, Map<String, Double> parameters) {
73 this.negotiationSession = negotiationSession;
74 previousBidUtility = 1;
75 weightHypotheses = new ArrayList<ArrayList<WeightHypothesis>>();
76 evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
77 this.domain = negotiationSession.getUtilitySpace().getDomain();
78 this.utilitySpace = (AdditiveUtilitySpace) negotiationSession.getUtilitySpace();
79 expectedWeights = new double[domain.getIssues().size()];
80 biddingHistory = new ArrayList<Bid>();
81
82 while (!testIndexOfFirstIssue(negotiationSession.getUtilitySpace().getDomain().getRandomBid(null),
83 startingBidIssue)) {
84 startingBidIssue++;
85 }
86
87 initWeightHypotheses();
88 initEvaluatorHypotheses();
89 }
90
91 /**
92 * Just an auxiliary function to calculate the index where issues start on a
93 * bid because we found out that it depends on the domain.
94 *
95 * @return true when the received index is the proper index
96 */
97 private boolean testIndexOfFirstIssue(Bid bid, int i) {
98 try {
99 @SuppressWarnings("unused")
100 ValueDiscrete valueOfIssue = (ValueDiscrete) bid.getValue(i);
101 } catch (Exception e) {
102 return false;
103 }
104 return true;
105 }
106
107 /**
108 * Initialise the weight hypotheses.
109 */
110 private void initWeightHypotheses() {
111 int weightHypothesesNumber = 11;
112 for (int i = 0; i < domain.getIssues().size(); ++i) {
113 ArrayList<WeightHypothesis> weightHypothesis = new ArrayList<WeightHypothesis>();
114 for (int j = 0; j < weightHypothesesNumber; ++j) {
115 WeightHypothesis weight = new WeightHypothesis();
116 weight.setProbability((1.0 - (((double) j + 1.0) / weightHypothesesNumber))
117 * (1.0 - (((double) j + 1.0) / weightHypothesesNumber))
118 * (1.0 - (((double) j + 1.0D) / weightHypothesesNumber)));
119 weight.setWeight((double) j / (weightHypothesesNumber - 1));
120 weightHypothesis.add(weight);
121 }
122
123 // Normalization
124 double n = 0.0D;
125 for (int j = 0; j < weightHypothesesNumber; ++j) {
126 n += weightHypothesis.get(j).getProbability();
127 }
128 for (int j = 0; j < weightHypothesesNumber; ++j) {
129 weightHypothesis.get(j).setProbability(weightHypothesis.get(j).getProbability() / n);
130 }
131
132 weightHypotheses.add(weightHypothesis);
133 }
134 }
135
136 /**
137 * Initialise the evaluator hypotheses.
138 */
139 private void initEvaluatorHypotheses() {
140 evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
141 for (int i = 0; i < utilitySpace.getNrOfEvaluators(); ++i) {
142 ArrayList<EvaluatorHypothesis> lEvalHyps;
143 EvaluatorReal lHypEvalReal;
144 EvaluatorInteger lHypEvalInteger;
145 EvaluatorHypothesis lEvaluatorHypothesis;
146 switch (utilitySpace.getEvaluator(utilitySpace.getIssue(i).getNumber()).getType()) {
147
148 case REAL: {
149 lEvalHyps = new ArrayList<EvaluatorHypothesis>();
150 evaluatorHypotheses.add(lEvalHyps);
151
152 IssueReal lIssue = (IssueReal) utilitySpace.getIssue(i);
153
154 /* Uphill */
155 lHypEvalReal = new EvaluatorReal();
156 lHypEvalReal.setUpperBound(lIssue.getUpperBound());
157 lHypEvalReal.setLowerBound(lIssue.getLowerBound());
158 lHypEvalReal.setType(EVALFUNCTYPE.LINEAR);
159 lHypEvalReal.addParam(1, 1.0 / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
160 lHypEvalReal.addParam(0,
161 -lHypEvalReal.getLowerBound() / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
162 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
163 lEvaluatorHypothesis.setDesc("uphill");
164 lEvalHyps.add(lEvaluatorHypothesis);
165
166 /* Triangular */
167 for (int k = 1; k <= totalTriangularFunctions; ++k) {
168 lHypEvalReal = new EvaluatorReal();
169 lHypEvalReal.setUpperBound(lIssue.getUpperBound());
170 lHypEvalReal.setLowerBound(lIssue.getLowerBound());
171 lHypEvalReal.setType(EVALFUNCTYPE.TRIANGULAR);
172 lHypEvalReal.addParam(0, lHypEvalReal.getLowerBound());
173 lHypEvalReal.addParam(1, lHypEvalReal.getUpperBound());
174 double lMaxPoint = lHypEvalReal.getLowerBound()
175 + (double) k * (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound())
176 / (totalTriangularFunctions + 1);
177 lHypEvalReal.addParam(2, lMaxPoint);
178 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
179 lEvalHyps.add(lEvaluatorHypothesis);
180 lEvaluatorHypothesis.setDesc("triangular " + String.format("%1.2f", lMaxPoint));
181 }
182
183 /* Downhill */
184 lHypEvalReal = new EvaluatorReal();
185 lHypEvalReal.setUpperBound(lIssue.getUpperBound());
186 lHypEvalReal.setLowerBound(lIssue.getLowerBound());
187 lHypEvalReal.setType(EVALFUNCTYPE.LINEAR);
188 lHypEvalReal.addParam(1, -1.0 / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
189 lHypEvalReal.addParam(0, 1.0
190 + lHypEvalReal.getLowerBound() / (lHypEvalReal.getUpperBound() - lHypEvalReal.getLowerBound()));
191 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalReal);
192 lEvaluatorHypothesis.setDesc("downhill");
193 lEvalHyps.add(lEvaluatorHypothesis);
194
195 for (int k = 0; k < lEvalHyps.size(); ++k) {
196 lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
197 }
198
199 break;
200 }
201 case INTEGER: {
202 lEvalHyps = new ArrayList<EvaluatorHypothesis>();
203 evaluatorHypotheses.add(lEvalHyps);
204
205 IssueInteger lIssue = (IssueInteger) utilitySpace.getIssue(i);
206
207 /* Uphill */
208 lHypEvalInteger = new EvaluatorInteger();
209 lHypEvalInteger.setUpperBound(lIssue.getUpperBound());
210 lHypEvalInteger.setLowerBound(lIssue.getLowerBound());
211 lHypEvalInteger.setOffset(-lHypEvalInteger.getLowerBound()
212 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
213 lHypEvalInteger.setSlope(1.0 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
214 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalInteger);
215 lEvaluatorHypothesis.setDesc("uphill");
216 lEvalHyps.add(lEvaluatorHypothesis);
217
218 /* Downhill */
219 lHypEvalInteger = new EvaluatorInteger();
220 lHypEvalInteger.setUpperBound(lIssue.getUpperBound());
221 lHypEvalInteger.setLowerBound(lIssue.getLowerBound());
222 lHypEvalInteger.setOffset(1.0 + lHypEvalInteger.getLowerBound()
223 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
224 lHypEvalInteger.setSlope(-1.0 / (lHypEvalInteger.getUpperBound() - lHypEvalInteger.getLowerBound()));
225 lEvaluatorHypothesis = new EvaluatorHypothesis(lHypEvalInteger);
226 lEvaluatorHypothesis.setDesc("downhill");
227 lEvalHyps.add(lEvaluatorHypothesis);
228
229 for (int k = 0; k < lEvalHyps.size(); ++k) {
230 lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
231 }
232
233 break;
234 }
235 case DISCRETE: {
236 lEvalHyps = new ArrayList<EvaluatorHypothesis>();
237 evaluatorHypotheses.add(lEvalHyps);
238
239 IssueDiscrete lDiscIssue = (IssueDiscrete) utilitySpace.getIssue(i);
240
241 /* Uphill */
242 EvaluatorDiscrete lDiscreteEval = new EvaluatorDiscrete();
243 for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j)
244 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), Integer.valueOf(1000 * j + 1));
245 lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
246 lEvaluatorHypothesis.setDesc("uphill");
247 lEvalHyps.add(lEvaluatorHypothesis);
248
249 /* Triangular */
250 if (lDiscIssue.getNumberOfValues() > 2) {
251 for (int k = 1; k < lDiscIssue.getNumberOfValues() - 1; ++k) {
252 lDiscreteEval = new EvaluatorDiscrete();
253 for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j) {
254 if (j < k) {
255 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j), 1000 * j / k);
256 } else
257 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j),
258 1000 * (lDiscIssue.getNumberOfValues() - j
259 - 1 / (lDiscIssue.getNumberOfValues() - k - 1) + 1));
260 }
261 lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
262 lEvalHyps.add(lEvaluatorHypothesis);
263 lEvaluatorHypothesis.setDesc("triangular " + String.valueOf(k));
264 }
265 }
266
267 /* Downhill */
268 lDiscreteEval = new EvaluatorDiscrete();
269 for (int j = 0; j < lDiscIssue.getNumberOfValues(); ++j)
270 lDiscreteEval.addEvaluation(lDiscIssue.getValue(j),
271 Integer.valueOf(1000 * (lDiscIssue.getNumberOfValues() - j - 1) + 1));
272 lEvaluatorHypothesis = new EvaluatorHypothesis(lDiscreteEval);
273 lEvaluatorHypothesis.setDesc("downhill");
274 lEvalHyps.add(lEvaluatorHypothesis);
275
276 for (int k = 0; k < lEvalHyps.size(); ++k) {
277 lEvalHyps.get(k).setProbability(1.0 / lEvalHyps.size());
278 }
279
280 break;
281 }
282 }
283 }
284
285 for (int i = 0; i < expectedWeights.length; ++i)
286 expectedWeights[i] = getExpectedWeight(i);
287
288 normalize(expectedWeights);
289 }
290
291 @Override
292 public double getBidEvaluation(Bid bid) {
293 try {
294 return getNormalizedUtility(bid);
295 } catch (Exception e) {
296 e.printStackTrace();
297 }
298 return 0;
299 }
300
301 /**
302 * Get the normalised utility of a bid.
303 *
304 * @param bid
305 * The bid to get the normalised utility of.
306 * @return the normalised utility of a bid.
307 * @throws Exception
308 */
309 public double getNormalizedUtility(Bid bid) throws Exception {
310 return getNormalizedUtility(bid, false);
311 }
312
313 /**
314 * Get the normalised utility of a bid.
315 *
316 * @param bid
317 * The bid to get the normalised utility of.
318 * @param debug
319 * Whether or not to output debugging information
320 * @return the normalised utility of a bid.
321 * @throws Exception
322 */
323 public double getNormalizedUtility(Bid bid, boolean debug) throws Exception {
324 double u = getExpectedUtility(bid);
325 if (minUtility == null || maxUtility == null)
326 findMinMaxUtility();
327 if (Double.isNaN(u)) {
328 return 0.0;
329 }
330 return (u - minUtility) / (maxUtility - minUtility);
331 }
332
333 /**
334 * Get the expected utility of a bid.
335 *
336 * @param bid
337 * The bid to get the expected utility of.
338 * @return the expected utility of the bid.
339 * @throws Exception
340 */
341 public double getExpectedUtility(Bid bid) throws Exception {
342 double u = 0;
343 for (int i = 0; i < domain.getIssues().size(); i++) {
344 u += expectedWeights[i] * getExpectedEvaluationValue(bid, i);
345 }
346 return u;
347 }
348
349 /**
350 * Update the beliefs about the opponent, based on an observation.
351 *
352 * @param opponentBid
353 * The opponent's bid that was observed.
354 * @throws Exception
355 */
356 public void updateModel(Bid opponentBid, double time) {
357 if (!useAll) {
358 if (biddingHistory.contains(opponentBid))
359 return;
360 }
361 biddingHistory.add(opponentBid);
362
363 if (biddingHistory.size() > 1) {
364 try {
365 updateWeights();
366 } catch (Exception e) {
367 e.printStackTrace();
368 }
369 }
370 try {
371 updateEvaluationFunctions();
372 } catch (Exception e) {
373 e.printStackTrace();
374 }
375 try {
376 previousBidUtility = opponentUtilitySpace.getUtility(opponentBid);
377 } catch (Exception e) {
378 e.printStackTrace();
379 }
380
381 for (int i = 0; i < expectedWeights.length; ++i)
382 expectedWeights[i] = getExpectedWeight(i);
383
384 normalize(expectedWeights);
385
386 try {
387 findMinMaxUtility();
388 } catch (Exception e) {
389 e.printStackTrace();
390 }
391
392 }
393
394 /**
395 * Normalise the values in an array so that they sum to 1.
396 *
397 * @param array
398 * The array to normalise;
399 */
400 private void normalize(double[] array) {
401 double n = 0;
402 for (int i = 0; i < array.length; ++i) {
403 n += array[i];
404 }
405 if (n == 0) {
406 for (int i = 0; i < array.length; ++i) {
407 array[i] = 1.0 / array.length;
408 }
409 return;
410 }
411
412 for (int i = 0; i < array.length; ++i) {
413 array[i] = array[i] / n;
414 }
415 }
416
417 /**
418 * Find the minimum and maximum utilities of the bids in the utility space.
419 *
420 * @throws Exception
421 */
422 protected void findMinMaxUtility() throws Exception {
423 maxUtility = getExtremeUtility(Extreme.MAX);
424 minUtility = getExtremeUtility(Extreme.MIN);
425 }
426
427 public double getWeight(Issue issue) {
428 return getExpectedWeight(issue.getNumber() - startingBidIssue);
429 }
430
431 public enum Extreme {
432 MIN, MAX
433 }
434
435 private double getExtremeUtility(Extreme extreme) {
436 double u = 0;
437 for (int i = 0; i < domain.getIssues().size(); i++) {
438 u += expectedWeights[i] * getExtremeEvaluationValue(i, extreme);
439 }
440 return u;
441 }
442
443 private double getExtremeEvaluationValue(int number, Extreme extreme) {
444 double expectedEval = 0;
445 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
446 expectedEval += evaluatorHypothesis.getProbability()
447 * getExtremeEvaluation(evaluatorHypothesis.getEvaluator(), extreme);
448 }
449 return expectedEval;
450 }
451
452 public double getExtremeEvaluation(Evaluator evaluator, Extreme extreme) {
453 double extremeEval = initExtreme(extreme);
454 switch (evaluator.getType()) {
455 case DISCRETE:
456 EvaluatorDiscrete discreteEvaluator = (EvaluatorDiscrete) evaluator;
457 for (ValueDiscrete value : discreteEvaluator.getValues()) {
458 try {
459 switch (extreme) {
460 case MAX:
461 extremeEval = Math.max(extremeEval, discreteEvaluator.getEvaluation(value));
462 break;
463 case MIN:
464 extremeEval = Math.min(extremeEval, discreteEvaluator.getEvaluation(value));
465 break;
466 }
467 } catch (Exception e) {
468 e.printStackTrace();
469 }
470 }
471 break;
472 case INTEGER:
473 EvaluatorInteger integerEvaluator = (EvaluatorInteger) evaluator;
474 switch (extreme) {
475 case MAX:
476 extremeEval = Math.max(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()),
477 integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
478 // if(integerEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
479 // {
480 // extremeEval = Math.max(extremeEval,
481 // integerEvaluator.getEvaluation(integerEvaluator.getTopParam()));
482 // }
483 break;
484 case MIN:
485 extremeEval = Math.min(integerEvaluator.getEvaluation(integerEvaluator.getUpperBound()),
486 integerEvaluator.getEvaluation(integerEvaluator.getLowerBound()));
487 // if(integerEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR)
488 // {
489 // extremeEval = Math.min(extremeEval,
490 // integerEvaluator.getEvaluation(integerEvaluator.getTopParam()));
491 // }
492 break;
493 }
494 break;
495 case REAL:
496 EvaluatorReal realEvaluator = (EvaluatorReal) evaluator;
497 switch (extreme) {
498 case MAX:
499 extremeEval = Math.max(realEvaluator.getEvaluation(realEvaluator.getUpperBound()),
500 realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
501 if (realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR) {
502 extremeEval = Math.max(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
503 }
504 break;
505 case MIN:
506 extremeEval = Math.min(realEvaluator.getEvaluation(realEvaluator.getUpperBound()),
507 realEvaluator.getEvaluation(realEvaluator.getLowerBound()));
508 if (realEvaluator.getFuncType() == EVALFUNCTYPE.TRIANGULAR) {
509 extremeEval = Math.min(extremeEval, realEvaluator.getEvaluation(realEvaluator.getTopParam()));
510 }
511 break;
512 }
513 break;
514 }
515 return extremeEval;
516 }
517
518 private double initExtreme(Extreme extreme) {
519 switch (extreme) {
520 case MAX:
521 return Double.MIN_VALUE;
522 case MIN:
523 return Double.MAX_VALUE;
524 }
525 return 0;
526 }
527
528 /**
529 * Update the evaluation functions.
530 *
531 * @throws Exception
532 */
533 private void updateEvaluationFunctions() throws Exception {
534 maxUtility = null;
535 minUtility = null;
536
537 Bid bid = biddingHistory.get(biddingHistory.size() - 1);
538 ArrayList<ArrayList<EvaluatorHypothesis>> evaluatorHypotheses = new ArrayList<ArrayList<EvaluatorHypothesis>>();
539
540 for (int i = 0; i < this.evaluatorHypotheses.size(); ++i) {
541 ArrayList<EvaluatorHypothesis> tmp = new ArrayList<EvaluatorHypothesis>();
542 for (int j = 0; j < this.evaluatorHypotheses.get(i).size(); ++j) {
543 EvaluatorHypothesis evaluatorHypothesis = new EvaluatorHypothesis(
544 this.evaluatorHypotheses.get(i).get(j).getEvaluator());
545 evaluatorHypothesis.setDesc(this.evaluatorHypotheses.get(i).get(j).getDesc());
546 evaluatorHypothesis.setProbability(this.evaluatorHypotheses.get(i).get(j).getProbability());
547 tmp.add(evaluatorHypothesis);
548 }
549 evaluatorHypotheses.add(tmp);
550 }
551
552 for (int i = 0; i < this.domain.getIssues().size(); i++) {
553 double n = 0.0D;
554 double utility = 0.0D;
555 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
556 utility = getPartialUtility(bid, i) + getExpectedWeight(i) * evaluatorHypothesis.getEvaluator()
557 .getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
558 n += evaluatorHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
559 }
560
561 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(i)) {
562 utility = getPartialUtility(bid, i) + getExpectedWeight(i) * evaluatorHypothesis.getEvaluator()
563 .getEvaluation(utilitySpace, bid, utilitySpace.getIssue(i).getNumber());
564 evaluatorHypothesis.setProbability(evaluatorHypothesis.getProbability()
565 * conditionalDistribution(utility, previousBidUtility) / n);
566 }
567 }
568
569 this.evaluatorHypotheses = evaluatorHypotheses;
570 }
571
572 /**
573 * Update the weights.
574 *
575 * @throws Exception
576 */
577 private void updateWeights() throws Exception {
578 maxUtility = null;
579 minUtility = null;
580
581 Bid bid = biddingHistory.get(biddingHistory.size() - 1);
582 ArrayList<ArrayList<WeightHypothesis>> weightHypotheses = new ArrayList<ArrayList<WeightHypothesis>>();
583
584 for (int i = 0; i < this.weightHypotheses.size(); ++i) {
585 ArrayList<WeightHypothesis> tmp = new ArrayList<WeightHypothesis>();
586 for (int j = 0; j < this.weightHypotheses.get(i).size(); ++j) {
587 WeightHypothesis weightHypothesis = new WeightHypothesis();
588 weightHypothesis.setWeight(this.weightHypotheses.get(i).get(j).getWeight());
589 weightHypothesis.setProbability(this.weightHypotheses.get(i).get(j).getProbability());
590 tmp.add(weightHypothesis);
591 }
592 weightHypotheses.add(tmp);
593 }
594
595 for (int i = 0; i < domain.getIssues().size(); i++) {
596 double n = 0.0D;
597 double utility = 0.0D;
598 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
599 utility = getPartialUtility(bid, i) + weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
600 n += weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility);
601 }
602
603 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i)) {
604 utility = getPartialUtility(bid, i) + weightHypothesis.getWeight() * getExpectedEvaluationValue(bid, i);
605 weightHypothesis.setProbability(
606 weightHypothesis.getProbability() * conditionalDistribution(utility, previousBidUtility) / n);
607 }
608 }
609
610 this.weightHypotheses = weightHypotheses;
611
612 }
613
614 /**
615 * The conditional distribution function.
616 *
617 * @param utility
618 * The utility.
619 * @param previousBidUtility
620 * The utility of the previous bid.
621 * @return
622 */
623 private double conditionalDistribution(double utility, double previousBidUtility) {
624 double x = (previousBidUtility - utility) / previousBidUtility;
625 return (1.0 / (SIGMA * Math.sqrt(2 * Math.PI))) * Math.exp(-(x * x) / (2 * SIGMA * SIGMA));
626 }
627
628 /**
629 * Get the expected evaluation value of a bid for a particular issue.
630 *
631 * @param bid
632 * The bid to get the expected evaluation value of.
633 * @param number
634 * The number of the issue to get the expected evaluation value
635 * of.
636 * @return the expected evaluation value of a bid for a particular issue.
637 * @throws Exception
638 */
639 private double getExpectedEvaluationValue(Bid bid, int number) throws Exception {
640 double expectedEval = 0;
641 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(number)) {
642 expectedEval += evaluatorHypothesis.getProbability() * evaluatorHypothesis.getEvaluator()
643 .getEvaluation(utilitySpace, bid, utilitySpace.getIssue(number).getNumber());
644 }
645 return expectedEval;
646 }
647
648 /**
649 * Get the partial utility of a bid, excluding a specific issue.
650 *
651 * @param bid
652 * The bid to get the partial utility of.
653 * @param number
654 * The number of the issue to exclude.
655 * @return the partial utility of a bid, excluding a specific issue.
656 * @throws Exception
657 */
658 private double getPartialUtility(Bid bid, int number) throws Exception {
659 double u = 0;
660 for (int i = 0; i < domain.getIssues().size(); i++) {
661 if (number == i) {
662 continue;
663 }
664 double w = 0;
665 for (WeightHypothesis weightHypothesis : weightHypotheses.get(i))
666 w += weightHypothesis.getProbability() * weightHypothesis.getWeight();
667 u += w * getExpectedEvaluationValue(bid, i);
668 }
669 return u;
670 }
671
672 /**
673 * Get the expected weight of a particular issue.
674 *
675 * @param number
676 * The issue number.
677 * @return the expected weight of a particular issue.
678 */
679 public double getExpectedWeight(int number) {
680 double expectedWeight = 0;
681 for (WeightHypothesis weightHypothesis : weightHypotheses.get(number)) {
682 expectedWeight += weightHypothesis.getProbability() * weightHypothesis.getWeight();
683 }
684 return expectedWeight;
685 }
686
687 public EvaluatorHypothesis getBestHypothesis(int issue) {
688 double maxEvaluatorProbability = -1;
689 EvaluatorHypothesis bestEvaluatorHypothesis = null;
690 for (EvaluatorHypothesis evaluatorHypothesis : evaluatorHypotheses.get(issue)) {
691 if (evaluatorHypothesis.getProbability() > maxEvaluatorProbability) {
692 maxEvaluatorProbability = evaluatorHypothesis.getProbability();
693 bestEvaluatorHypothesis = evaluatorHypothesis;
694 }
695 }
696 return bestEvaluatorHypothesis;
697 }
698
699 public Hypothesis getHypothesis(int index) {
700 return this.evaluatorHypotheses.get(index).get(index);
701 }
702
703 @Override
704 public AdditiveUtilitySpace getOpponentUtilitySpace() {
705 return new UtilitySpaceAdapter(this, domain);
706 }
707
708 public String getName() {
709 return "IAMhaggler Bayesian Model";
710 }
711
712 public void cleanUp() {
713 super.cleanUp();
714 biddingHistory = null;
715 evaluatorHypotheses = null;
716 weightHypotheses = null;
717 expectedWeights = null;
718 opponentUtilitySpace = null;
719 domain = null;
720 utilitySpace = null;
721 }
722
723 @Override
724 public void setOpponentUtilitySpace(AdditiveUtilitySpace opponentUtilitySpace) {
725 this.opponentUtilitySpace = opponentUtilitySpace;
726 }
727}
Note: See TracBrowser for help on using the repository browser.