Brain JS视觉训练进度

时间:2018-12-01 05:06:29

标签: javascript jquery brain.js

我正在使用Brain JS学习ML / DL,到目前为止,它的运行状况很好。但是,我的最终目标是让其他人分析数据以预测销售量,但负责执行此报告的人员不是技术人员,也不知道要访问控制台来查看进度(他们将一遍又一遍地单击刷新)。到目前为止,我写的内容似乎只能登录控制台,而不能登录HTML。代码在下面,并且trainingData数组已缩短。为了进一步说明,console.log(percentage)可以很好地工作,但是$("#status").text(percentage)直到学习结束后才能发挥作用。无论如何随时更新状态?

<script type="text/javascript">
    $(document).ready(function(){
        const network = new brain.NeuralNetworkGPU();

        const trainingData = [
          { input: [2, 1], output: [0] },
          { input: [2, 1], output: [0] },
          { input: [2, 1], output: [0] },
        ];  
        var numIterations = 30000;
        network.train(trainingData, {
            iterations: numIterations,
            errorThresh: .005,
            callback: function(data) {
                var percentage = (data.iterations / numIterations) * 100 + "%";
                $("#status").html("<strong>Training: </strong>" + percentage);  
                console.log(percentage);
            },
            callbackPeriod: 500
        });

        var outcome1 = "<strong>2 vs. 1: </strong>" + ((1 - network.run([2,1])) * 100).toFixed(1);
        var outcome2 = "<strong>2 vs. 10: </strong>" + ((1 - network.run([2,10])) * 100).toFixed(1);
        var outcome3 = "<strong>2 vs. 5: </strong>" + ((1 - network.run([2,5])) * 100).toFixed(1);
        var outcome4 = "<strong>2 vs. 8: </strong>" + ((1 - network.run([2,8])) * 100).toFixed(1)

        $("#outcome1").html(outcome1);
        $("#outcome2").html(outcome2);
        $("#outcome3").html(outcome3);
        $("#outcome4").html(outcome4);

        $("#status").text("DONE");
    });

</script>

0 个答案:

没有答案