var test=new network([2,3,1]);
test.reset();
console.log(test.layers);
function network(args){
this.layers=[];
this.numberoflayers=args.length;
this.reset=
function(){
for(i=0;i<this.numberoflayers;i++){
this.layers.push(new layer(args[i],args[i+1]));
this.layers[i].reset();
}
}
}
function layer(num,numlayer){
this.nodes=[];
this.reset=
function(){
for(i=0;i<num;i++){
this.nodes.push(new node(numlayer));
this.nodes[i].reset();
}
}
}
function node(num){
this.weights=[];
this.reset=
function(){
for(i=0;i<num;i++){
this.weights.push(0);
}
}
}
このコードは、ニューラルネットワークを作成するための私の試みです。問題は、コードを実行するときに作成する必要があるすべてのオブジェクトをループするのではなく、各配列の最初のオブジェクトを作成することだけです。たとえば、test.layer配列には3つのレイヤーオブジェクトが含まれている必要がありますが、最初のレイヤーの後で停止します。 layer.nodesおよびnodes.weightsと同じです。 ご協力いただきありがとうございます。forループがない場合のオブジェクトコンストラクタ