-
Notifications
You must be signed in to change notification settings - Fork 1
/
nand.js
37 lines (33 loc) · 986 Bytes
/
nand.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const handleStar = require('../handle-star').handleStar
/**
* Representation of an Aggregator, that can calculate a generalization of the
* logical 'nand' operation on floating point numbers in [0.0, 1.0], where the
* edge cases of 1.0 and 0.0 will reproduce the behaviour of logical and with
* true and false respectively.
*/
class Nand {
/**
* Construct a Nand Aggregator using an array of aggregators.
* @param aggregators - an array of aggregators
*/
constructor (aggregators) {
this.aggregators = aggregators
}
/**
* Returns the score of this Nand Aggregator.
*/
eval (scores) {
const agList = handleStar(this.aggregators, scores)
return 1.0 - agList.reduce(
(and, element) => and * element.eval(scores),
1.0)
}
}
/**
* Return an Nand Aggregator from an aggregator array. The parameters
* will be forwarded to Nand.constructor().
*/
function create (...args) {
return new Nand(...args)
}
module.exports = { create }