Add unified training mode, but apparently we're now crashing the client 🤔

This commit is contained in:
Starbeamrainbowlabs 2019-08-05 17:06:31 +01:00
parent 80606f93d8
commit 3ebc54ef74
4 changed files with 64 additions and 4 deletions

View File

@ -18,6 +18,7 @@ export default async function(c) {
// 2: CLI Argument Parsing
let args = process.argv.slice(2); // Slice out the node binary name and the filename
let extras = [];
for(let i = 0; i < args.length; i++) {
if(!args[i].startsWith("-")) {
extras.push(args[i]);
@ -35,6 +36,13 @@ export default async function(c) {
case "-v":
console.log(program.version);
break;
case "--ai-unified":
settings.ai.mode = "unified";
break;
case "--ai-split":
settings.ai.mode = "split";
break;
// Add more arguments here
}
@ -99,7 +107,14 @@ export default async function(c) {
l.log(`${a.fgreen}${a.hicol}Training AIs${a.reset}`);
let ai_trainer = c.cradle.AITrainer;
await ai_trainer.train_all();
switch(settings.ai.mode) {
case "split":
await ai_trainer.train_all();
break;
case "unified":
await ai_trainer.train_unified();
break;
}
break;
case "geojson-debug":

View File

@ -17,8 +17,11 @@ ${a.fblue}${a.hicol}Subcommands:${a.reset}
${a.fyellow}train-ai${a.reset} Trains the AI on the consolidated data
${a.fblue}${a.hicol}Options:${a.reset}
${a.fyellow}-h --help ${a.reset}Show this message
${a.fyellow}-v --version ${a.reset}Show the version of this program
${a.fyellow}-h --help ${a.reset} Show this message
${a.fyellow}-v --version ${a.reset} Show the version of this program
${a.fyellow} --ai-unified${a.reset} Switch to the unified AI training mode. This trains 1 AI for everything, instead of 1 AI per gateway.
${a.fyellow} --ai-split${a.reset} Switch to the split AI training mode (the default). This trains 1 AI per gateway.
${a.fblue}${a.hicol}Environment Variables:${a.reset}
(none yet)

View File

@ -84,6 +84,12 @@ learning_rate = 0.1
# The momentum term to use when learning
momentum = 0.1
# Either "split" or "unified".
# Describes the mode of training for the AIs.
# In split mode (the default), 1 AI is trained for each of the gateways detected.
# In unified mode, we train 1 AI that predict everything.
mode = "split"
# The directory to output trained AIs to, relative to the repository root.
output_directory = "app/ais/"

View File

@ -15,7 +15,43 @@ class AITrainer {
this.repo_gateway = GatewayRepo;
}
async train_unified() {
this.l.log(`${this.a.fgreen}${this.a.hicol}Unified training mode activated.${this.a.reset}`);
let filepath = path.join(
this.root_dir,
"..",
this.settings.ai.output_directory,
"ai.json"
);
if(!fs.existsSync(path.dirname(filepath)))
await fs.promises.mkdir(path.dirname(filepath), { recursive: true });
let training_result = await this.train_gateway(null, filepath);
await fs.promises.writeFile(
path.join(
path.dirname(this.root_dir),
this.settings.ai.output_directory,
"index.json"
),
JSON.stringify({
properties: {
rssi_min: -150,
rssi_max: 0
},
index: [{
id: "Unified AI (not a real gateway)",
filename: "ai.json",
latitude: 0, longitude: 0,
net_settings: training_result.net_settings
}]
}, null, "\t")
);
}
async train_all() {
this.l.log(`${this.a.fgreen}${this.a.hicol}Split (default) training mode activated.${this.a.reset}`);
let index = [];
for(let gateway of this.repo_gateway.iterate()) {
let filepath = path.join(this.root_dir, "..", this.settings.ai.output_directory, `${gateway.id}.json`);
@ -87,7 +123,7 @@ class AITrainer {
timeout: Infinity
});
await fs.promises.writeFile(destination_filename, JSON.stringify(net.toJSON()));
await fs.promises.writeFile(destination_filename, JSON.stringify(net.toJSON()), null, "\t");
// console.log(result);
return {