Skip to content

Commit 026c964

Browse files
committed
Add options to propagate()
{ decay: 40, memoryPerf: 100} by default
1 parent 8af5541 commit 026c964

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

lib/concept-network-state.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,13 @@ ConceptNetworkState.prototype = {
171171
* ### propagate
172172
*
173173
* Propagate the activation values along the links.
174+
*
175+
* @param {Object} options {decay,memoryPerf}
174176
**/
175-
propagate : function () {
177+
propagate : function (options) {
178+
if (options && typeof options !== 'object') {
179+
throw new Error("propagate() parameter should be an object");
180+
}
176181
var influenceNb = []; // nodeId -> nb of influence number
177182
var influenceValue = []; // nodeId -> influence value
178183
for (var nodeId in this.nodeState) {
@@ -211,8 +216,14 @@ ConceptNetworkState.prototype = {
211216
if (typeof nodeState === 'undefined') {
212217
nodeState = { activationValue: 0, oldActivationValue: 0, age: 0 };
213218
}
214-
var decay = 40;
215-
var memoryPerf = 100;
219+
if (!options) {
220+
options = {
221+
decay : 40,
222+
memoryPerf : 100
223+
};
224+
}
225+
var decay = options.decay || 40;
226+
var memoryPerf = options.memoryPerf || 100;
216227
var minusAge = 200 / (1 + Math.exp(-nodeState.age / memoryPerf)) - 100;
217228
var newActivationValue;
218229
// If this node is not influenced at all

test/concept-network-state_test.js

+20
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,26 @@ describe('ConceptNetworkState', function () {
235235
assert.equal(cns.getActivationValue(node2.id) > 0, true);
236236
});
237237

238+
it('should accept options', function () {
239+
assert.doesNotThrow(function () {
240+
cns.propagate({anything: 1});
241+
},
242+
null,
243+
"unexpected error");
244+
});
245+
246+
it('should take decay into account', function () {
247+
cns.propagate({decay: 200});
248+
assert.deepEqual(cns.nodeState, {}, 'all nodes should be deactivated');
249+
});
250+
251+
it('should take memoryPerf into account', function () {
252+
cns.activate(node1.id);
253+
cns.propagate({memoryPerf: Infinity});
254+
assert.equal(cns.getActivationValue(node1.id), 60,
255+
'with an infinite memory perf, activation should not decay too much');
256+
});
257+
238258
});
239259

240260
});

0 commit comments

Comments
 (0)