-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsom.js
45 lines (38 loc) · 920 Bytes
/
som.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
import { writeFileSync } from 'filendir';
import fs from 'fs';
import _ from 'lodash/fp';
import Kohonen, { hexagonHelper } from 'kohonen';
const stars = _.flow(
fs.readFileSync,
JSON.parse,
_.filter(_.has('data')),
_.filter(_.flow(
_.get('data'),
_.reduce((seed, current) => seed && _.negate(_.isNull), true),
)),
_.filter(_.flow(
_.get('data'),
_.size,
_.isEqual(2799)
)),
)('data/data.json');
const neurons = hexagonHelper.generateGrid(13, 13);
const k = new Kohonen({
data: _.map(_.get('data'), stars),
neurons,
maxStep: 10000,
maxLearningCoef: 1,
minLearningCoef: .001,
maxNeighborhood: 5,
minNeighborhood: 1,
});
k.training((neurons, step) => console.log(step));
const positions = k.mapping();
const results = _.unzip([
positions,
_.map(
_.pick(['name', 'spectralType']),
stars,
),
]);
writeFileSync(`data/result.json`, JSON.stringify(results));