Bugfix: Fix Brain.js training issues

This commit is contained in:
Starbeamrainbowlabs 2019-07-30 15:28:31 +01:00
parent 7d709c0fa5
commit 25bb302033
2 changed files with 17 additions and 7 deletions

View file

@ -82,10 +82,13 @@ class AITrainer {
learningRate: this.settings.ai.learning_rate, learningRate: this.settings.ai.learning_rate,
momentum: this.settings.ai.momentum, momentum: this.settings.ai.momentum,
log: true,
logPeriod: 50,
timeout: Infinity timeout: Infinity
}); });
await fs.promises.writeFile(destination_filename, net.toJSON()); await fs.promises.writeFile(destination_filename, JSON.stringify(net.toJSON()));
// console.log(result); // console.log(result);
return true; return true;

View file

@ -42,10 +42,12 @@ class DatasetFetcher {
// console.log(`Distance from gateway: ${haversine(gateway_location, rssi)}m`); // console.log(`Distance from gateway: ${haversine(gateway_location, rssi)}m`);
let next_output = clamp(normalise(rssi.rssi, let next_output = [
{ min: this.settings.ai.rssi_min, max: this.settings.ai.rssi_max }, clamp(normalise(rssi.rssi,
{ min: 0, max: 1 } { min: this.settings.ai.rssi_min, max: this.settings.ai.rssi_max },
), 0, 1); { min: 0, max: 1 }
), 0, 1)
];
result.push({ result.push({
input: next_input, input: next_input,
@ -58,11 +60,16 @@ class DatasetFetcher {
reading.latitude, reading.latitude,
reading.longitude reading.longitude
); );
next_input.distance = haversine(gateway_location, reading); next_input.distance = clamp(
normalise(haversine(gateway_location, reading),
{ min: 0, max: 20000 },
{ min: 0, max: 1 }
),
0, 1);
result.push({ result.push({
input: next_input, input: next_input,
output: 0 output: [ 0 ]
}); });
} }