source: src/main/java/genius/core/logging/AgentStatistics.java

Last change on this file was 1, checked in by Wouter Pasman, 7 years ago

Initial import : Genius 9.0.0

File size: 3.9 KB
Line 
1package genius.core.logging;
2
3import javax.xml.bind.annotation.XmlElement;
4import javax.xml.bind.annotation.XmlRootElement;
5
6/**
7 * Statistic results from one agent. immutable.
8 *
9 */
10@XmlRootElement
11public class AgentStatistics {
12 @XmlElement
13 private String agentname = null;
14
15 @XmlElement
16 private double totalUndiscountedUtility = 0;
17 @XmlElement
18 private double totalDiscountedUtility = 0;
19 @XmlElement
20 private long numberOfSessions = 0;
21 @XmlElement
22 private double totalNashDist;
23 @XmlElement
24 private double totalWelfare;
25 @XmlElement
26 private double totalParetoDistance;
27
28 /**
29 * For de-serialization
30 */
31 private AgentStatistics() {
32 }
33
34 /**
35 * @param name
36 * the agent's name
37 * @param undiscounted
38 * the total undiscounted utility accumulated over nSessions
39 * @param discounted
40 * the total discounted utility accumulated over nSessions
41 * @param nash
42 * the total distance to nash accumulated over nSessions
43 * @param welfare
44 * the total social welfare accumulated over nSessions
45 * @param paretodist
46 * the total accumulated distance to paretofrontier over
47 * nSessions
48 * @param nSessions
49 * the total number of sessions that was accumulated data over.
50 */
51 public AgentStatistics(String name, double undiscounted, double discounted, double nash, double welfare,
52 double paretodist, long nSessions) {
53 agentname = name;
54 totalUndiscountedUtility = undiscounted;
55 totalDiscountedUtility = discounted;
56 totalNashDist = nash;
57 totalWelfare = welfare;
58 totalParetoDistance = paretodist;
59 numberOfSessions = nSessions;
60 }
61
62 /**
63 * Adds a new utility and returns a new statistic object with that.
64 *
65 * @param undiscounted
66 * the un-discounted utility to be added
67 * @param discounted
68 * the discounted utility to be added
69 * @param nashdist
70 * the nash distance to be added
71 * @param welfare
72 * the social welfare to be added
73 * @param paretodist
74 * the distance to pareto to be added
75 */
76 public AgentStatistics withUtility(double undiscounted, double discounted, double nashdist, double welfare,
77 double paretodist) {
78 return new AgentStatistics(agentname, totalUndiscountedUtility + undiscounted,
79 totalDiscountedUtility + discounted, totalNashDist + nashdist, totalWelfare + welfare,
80 totalParetoDistance + paretodist, numberOfSessions + 1);
81 }
82
83 public String toString() {
84 return "statistic of " + agentname + ":" + getMeanUndiscounted() + " " + getMeanDiscounted();
85 }
86
87 /**
88 *
89 * @return the mean discounted utility of the agent
90 */
91 @XmlElement // this puts the mean get into the serialized objects
92 public double getMeanDiscounted() {
93 return numberOfSessions == 0 ? 0 : totalDiscountedUtility / numberOfSessions;
94 }
95
96 /**
97 *
98 * @return the mean undiscounted utility of the agent
99 */
100 @XmlElement // this puts the mean get into the serialized objects
101 public double getMeanUndiscounted() {
102 return numberOfSessions == 0 ? 0 : totalUndiscountedUtility / numberOfSessions;
103 }
104
105 /**
106 *
107 * @return name of agent for which the statistics are stored.
108 */
109 public String getName() {
110 return agentname;
111 }
112
113 /**
114 *
115 * @return the mean nash distance of the agent
116 */
117 @XmlElement // this puts the mean get into the serialized objects
118 public double getMeanNashDistance() {
119 return numberOfSessions == 0 ? 0 : totalNashDist / numberOfSessions;
120 }
121
122 /**
123 *
124 * @return the mean social welfare of the agent
125 */
126 @XmlElement // this puts the mean get into the serialized objects
127 public double getMeanWelfare() {
128 return numberOfSessions == 0 ? 0 : totalWelfare / numberOfSessions;
129 }
130
131 /**
132 *
133 * @return the mean distance to pareto of the agent
134 */
135 @XmlElement // this puts the mean get into the serialized objects
136 public double getMeanParetoDistance() {
137 return numberOfSessions == 0 ? 0 : totalParetoDistance / numberOfSessions;
138 }
139}
Note: See TracBrowser for help on using the repository browser.