[英]brain.js reciprocal/reverse the trainning (predict input from output)
I just learned to train a brain.js network and are just playing around with it. 我刚刚学会训练Brain.js网络,并且正在使用它。 Then I'm curious to know if it is possible to go the other way around - predict the input from the output?
然后我很想知道是否有可能采取其他方法-从输出预测输入?
This is my code 这是我的代码
const brain = require('brain.js');
const network = new brain.NeuralNetwork();
/*
network.train([
{ input: { doseA: 0 }, output: { indicatorA: 0 } },
{ input: { doseA: 0.1 }, output: { indicatorA: 0.02 } },
{ input: { doseA: 0.2 }, output: { indicatorA: 0.04 } },
{ input: { doseA: 0.3 }, output: { indicatorA: 0.06 } },
{ input: { doseA: 0.4 }, output: { indicatorA: 0.08 } },
{ input: { doseA: 0.5 }, output: { indicatorA: 0.10 } },
{ input: { doseA: 0.6 }, output: { indicatorA: 0.12 } },
{ input: { doseA: 0.7 }, output: { indicatorA: 0.14 } },
], {
iterations: 1e6,
errorThresh: 0.00001
});
*/
network.fromJSON({"sizes":[1,3,1],"layers":[{"doseA":{}},{"0":{"bias":-0.7720749378204346,"weights":{"doseA":-6.819720268249512}},"1":{"bias":0.2317514568567276,"weights":{"doseA":-1.4340121746063232}},"2":{"bias":-0.34450986981391907,"weights":{"doseA":-2.9449453353881836}}},{"indicatorA":{"bias":-1.0124520063400269,"weights":{"0":-5.02399206161499,"1":-1.69333016872406,"2":-3.1710503101348877}}}],"outputLookup":true,"inputLookup":true,"activation":"sigmoid","trainOpts":{"iterations":1000000,"errorThresh":0.00001,"log":false,"logPeriod":10,"learningRate":0.3,"momentum":0.1,"callbackPeriod":10}})
const result = network.run({ doseA: 0.35 });
console.log(result);
// { indicatorA: 0.06978786736726761 }
but what if I would like to network.run({ indicatorA: 0.07 })
and get { doseA: 0.35 }
? 但是,如果我想进行
network.run({ indicatorA: 0.07 })
并获得{ doseA: 0.35 }
怎么办?
Am I forced to train the network
again but with switched input
and output
? 我是否被迫再次训练
network
,但input
和output
切换? Or is there a way to reverse it? 还是有办法扭转它?
There absolutely is a utility to do this very thing: https://github.com/BrainJS/brain.retro.js 绝对有一个实用程序可以执行此操作: https : //github.com/BrainJS/brain.retro.js
If there is more interest, I can as well get the query utility which allows you to do some pretty interesting mongo style querying: https://github.com/BrainJS/brain.retro.js/blob/master/query.js 如果有更多的兴趣,我也可以获取查询实用程序,该实用程序使您可以执行一些非常有趣的mongo样式查询: https : //github.com/BrainJS/brain.retro.js/blob/master/query.js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.