-
Notifications
You must be signed in to change notification settings - Fork 0
/
paramspace.js
50 lines (40 loc) · 1.57 KB
/
paramspace.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
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
function Paramspace() {
this.models = {};
this.domain = [];
this.domainIndices = [];
this.modelsDomains = {};
};
Paramspace.prototype.addModel = function (modelName, modelParameters) {
// Add model to model collection.
this.models[modelName] = modelParameters;
// Expand model parameters.
var modelDomain = [modelParameters];
var newElements = false;
do {
var params = modelDomain.shift();
for (var key in params) {
if (params[key].constructor === Array) {
for (var i = 0; i < params[key].length; i++) {
var p = JSON.parse(JSON.stringify(params));
p[key] = params[key][i];
modelDomain.push(p);
}
newElements = true;
break;
} else {
newElements = false;
}
}
if (newElements == false) {
modelDomain.unshift(params);
}
} while(newElements);
// Add indices of the model's domain section to the modelDomains object.
this.modelsDomains[modelName] = Array.from(new Array(modelDomain.length), (x,i) => i + this.domain.length);
// Extend the domain with new points defined by the model name and parameters.
this.domain = this.domain.concat(Array.from(modelDomain, (p) => {return {'model' : modelName, 'params' : p}}));
// Create a list of domain indices. We can use them instead of object for faster operations.
this.domainIndices = Array.from(this.domain, (x,i) => i);
};
module.exports = Paramspace;