@@ -10,6 +10,10 @@ export enum AggregationStep {
1010 AGGREGATE
1111}
1212
13+ /**
14+ * Main, abstract, aggregator class whose role is to buffer contributions and to produce
15+ * a result based off their aggregation, whenever some defined condition is met.
16+ */
1317export abstract class Base < T > {
1418 /**
1519 * Contains the ids of all active nodes, i.e. members of the aggregation group at
@@ -32,44 +36,67 @@ export abstract class Base<T> {
3236 protected informant ?: AsyncInformant < T >
3337 /**
3438 * The result promise which, on resolve, will contain the current aggregation result.
39+ * This promise should be fetched by any object making use of an aggregator, in order
40+ * to await upon aggregation.
3541 */
3642 protected result : Promise < T >
3743 /**
38- * The current aggregation round, used for assessing whether a contribution is recent enough
44+ * The current aggregation round, used for assessing whether a node contribution is recent enough
3945 * or not.
4046 */
4147 protected _round = 0
42-
48+ /**
49+ * The current communication round. A single aggregation round is made of possibly multiple
50+ * communication rounds. This makes the aggregator free to perform intermediate aggregation
51+ * steps based off communication with its nodes. Overall, this allows for more complex
52+ * aggregation schemes requiring an exchange of information between nodes before aggregating.
53+ */
4354 protected _communicationRound = 0
4455
4556 constructor (
57+ /**
58+ * The task for which the aggregator should be created.
59+ */
4660 public readonly task : Task ,
61+ /**
62+ * The TF.js model whose weights are updated on aggregation.
63+ */
4764 protected _model ?: tf . LayersModel ,
65+ /**
66+ * The round cut-off for contributions.
67+ */
4868 protected readonly roundCutoff = 0 ,
69+ /**
70+ * The number of communication rounds occuring during any given aggregation round.
71+ */
4972 public readonly communicationRounds = 1
5073 ) {
5174 this . eventEmitter = new EventEmitter ( )
5275 this . contributions = Map ( )
5376 this . _nodes = Set ( )
5477
78+ // Make the initial result promise
5579 this . result = this . makeResult ( )
5680
81+ // On every aggregation, update the object's state to match the current aggregation
82+ // and communication rounds.
5783 this . eventEmitter . on ( 'aggregation' , ( ) => {
5884 this . nextRound ( )
5985 } )
6086 }
6187
6288 /**
63- * Adds a node's contribution to the aggregator for a given round .
64- * The contribution will be aggregated during the round's aggregation step.
89+ * Adds a node's contribution to the aggregator for the given aggregation and communication rounds .
90+ * The contribution will be aggregated during the next aggregation step.
6591 * @param nodeId The node's id
6692 * @param contribution The node's contribution
67- * @param round For which round the contribution was made
93+ * @param round For which aggregation round the contribution was made
94+ * @param communicationRound For which communication round the contribution was made
6895 */
6996 abstract add ( nodeId : client . NodeID , contribution : T , round : number , communicationRound ?: number ) : boolean
7097
7198 /**
72- * Performs the aggregation step over the received node contributions.
99+ * Performs an aggregation step over the received node contributions.
73100 * Must store the aggregation's result in the aggregator's result promise.
74101 */
75102 abstract aggregate ( ) : void
@@ -110,6 +137,10 @@ export abstract class Base<T> {
110137 }
111138 }
112139
140+ /**
141+ * Sets the aggregator's TF.js model.
142+ * @param model The new TF.js model
143+ */
113144 setModel ( model : tf . LayersModel ) : void {
114145 this . _model = model
115146 }
@@ -138,6 +169,10 @@ export abstract class Base<T> {
138169 this . _nodes = nodeIds
139170 }
140171
172+ /**
173+ * Empties the current set of "nodes". Usually called at the end of an aggregation round,
174+ * if the set of nodes is meant to change or to be actualized.
175+ */
141176 resetNodes ( ) : void {
142177 this . _nodes = Set ( )
143178 }
@@ -163,7 +198,9 @@ export abstract class Base<T> {
163198 }
164199
165200 /**
166- * Resets the aggregator's step and prepares it for the next aggregation round.
201+ * Updates the aggregator's state to proceed to the next communication round.
202+ * If all communication rounds were performed, proceeds to the next aggregation round
203+ * and empties the collection of stored contributions.
167204 */
168205 public nextRound ( ) : void {
169206 if ( ++ this . _communicationRound === this . communicationRounds ) {
@@ -184,10 +221,9 @@ export abstract class Base<T> {
184221 }
185222
186223 /**
187- * The aggregation result can be awaited upon in an asynchronous fashion, to allow
188- * for the receipt of contributions while performing other tasks. This function
189- * gives access to the current aggregation result's promise, which will eventually
190- * resolve and contain the result of the very next aggregation step, at the
224+ * Aggregation steps are performed asynchronously, yet can be awaited upon when required.
225+ * This function gives access to the current aggregation result's promise, which will
226+ * eventually resolve and contain the result of the very next aggregation step, at the
191227 * time of the function call.
192228 * @returns The promise containing the aggregation result
193229 */
@@ -196,7 +232,7 @@ export abstract class Base<T> {
196232 }
197233
198234 /**
199- * Constructs the payload sent to other nodes as contribution.
235+ * Constructs the payloads sent to other nodes as contribution.
200236 * @param base Object from which the payload is computed
201237 */
202238 abstract makePayloads ( base : T ) : Map < client . NodeID , T >
@@ -218,8 +254,8 @@ export abstract class Base<T> {
218254 }
219255
220256 /**
221- * The aggregator's current size, defined by its amount of contributions.
222- * The size is bounded by the amount of all active nodes.
257+ * The aggregator's current size, defined by its number of contributions. The size is bounded by
258+ * the amount of all active nodes times the number of communication rounds .
223259 */
224260 get size ( ) : number {
225261 return this . contributions
@@ -235,6 +271,9 @@ export abstract class Base<T> {
235271 return this . _model
236272 }
237273
274+ /**
275+ * The current commnication round.
276+ */
238277 get communicationRound ( ) : number {
239278 return this . _communicationRound
240279 }
0 commit comments