1.0.15 • Published 5 years ago

naturalness v1.0.15

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
5 years ago

naturalness

Library implementing "On the Naturalness of Software"

npm install
npm test
const naturalness = require('./index.js');
const Event = naturalness.Event;
const Sequence = naturalness.Sequence;
const NaturalnessModel = naturalness.NaturalnessModel;

let a = new Event('a');
let b = new Event('b');
let c = new Event('c');
let d = new Event('d');
let e = new Event('e');
let f = new Event('f');

let one = new Sequence([a, b, c, d, e]);
let two = new Sequence([a, b, c, d, c]);
let three = new Sequence([f, f, f, f, f, f, f, f, f, f]);

let model = new NaturalnessModel();

model.learn(one);
model.learn(two);
let crossEntropy = model.crossEntropy(three);

console.log(`crossEntropy is : ${crossEntropy}`);
const naturalness = require('./index.js');
const Event = naturalness.Event;
const NaturalnessDynamicModel = naturalness.NaturalnessDynamicModel;

let a = new Event('a');
let b = new Event('b');
let c = new Event('c');
let d = new Event('d');
let e = new Event('e');
let f = new Event('f');

let model = new NaturalnessDynamicModel(6);

model.learnAllSuffix([a, b, c, d, e]);
//The following sequences have been learnt
// a, b, c, d, e
// b, c, d, e
// c, d, e
// d, e
// e

model.learn([c, d, a]);
//One sequence have been learnt
//c, d, a

model.learnAllSuffix([f, f, f, f, f, f, f, f, f, f]);
//Many sequences have been learnt (max size is 6)
//f, f, f, f, f, f
//f, f, f, f, f
//f, f, f, f
//...

let map = model.getProbabilityMap([a, b, c, d]);
console.log(`p(e | [a, b, c, d]) : ${map.get(e)[0]}`);
console.log(`p(e | [b, c, d]) : ${map.get(e)[1]}`);
console.log(`p(e | [c, d]) : ${map.get(e)[2]}`);
console.log(`p(e | [d]) : ${map.get(e)[3]}`);
1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago