当你继承一个类时,你如何应用基类的信息?

时间:2018-03-02 16:39:01

标签: vb.net

如何将基类应用于子继承类?

var brain = require('brain.js');
var net = new brain.NeuralNetwork();
const readline = require('readline');

const r1 = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

var ca = 0,
    wa = 0;

net.train([
    {input: [0,0,0,0,0], output: [0]}
]);

function genRan(){
    var a,b,c,d,e;
    var array = [];
    a = Math.round(Math.random());
    b = Math.round(Math.random());
    c = Math.round(Math.random());
    d = Math.round(Math.random());
    e = Math.round(Math.random());

    array.push(a,b,c,d,e);
    //console.log(array);
    var guess = net.run(array);
    ask(array,guess);
}

function ask(a,b){
    var array = a,
        guess = b;
    r1.question((wa+ca) + ") input: " + array + " We think: " + guess[0] + ". Am I correct? (Y/N)", (answer) => {

        if(answer == "Y" || answer == "y"){
            ca++;
            net.train([
                {input : array, output : Math.round(guess[0])}
            ]);
        }else if(answer == "N" || answer == "n"){
            wa++;
            var roundGuess = Math.round(guess[0]);
            var opposite;
            switch (roundGuess){
                case 1:
                    opposite = 0;
                    break;
                case 0:
                    opposite = 1;
                    break;
                default:
                    opposite = null
            }
            net.train([
                {input : array, output : [opposite]}
            ]);     
        }
        console.log("Success percent: " + (100 *ca/(ca+wa)) + "% " + (ca+wa) +" attempts\n\r");
        genRan();
    })

}
genRan();

0 个答案:

没有答案