Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化器赋值失败 #347

Open
xugangxugang opened this issue Jun 19, 2020 · 3 comments
Open

优化器赋值失败 #347

xugangxugang opened this issue Jun 19, 2020 · 3 comments

Comments

@xugangxugang
Copy link

微信截图3
微信截图2
微信截图_1
为什么会赋值失败,神经网络是Architect.Liquid创建的

@xugangxugang
Copy link
Author

源码
var input = 49;
var pool = 84;
var output = 49;
var connections = 34;
var gates = 14;

			 myNetwork = new Architect.Liquid(input, pool, output, connections, gates);
			
			trainer = new Trainer(myNetwork);
			var trainingSet = [{
					input: "",
					output: ""
				},
			
			];
			
			for (var i = 0, 训练数据length = 训练数据.length; i < 训练数据length - 1; i++) {
				trainingSet[i] = {
					input: 训练数据[i + 1],
					output: 训练数据[i]
				}
			}
			
			
			trainer.train(trainingSet, {
				rate: .1,
				iterations: 20000,
				error: .1,
				shuffle: true,
				log: 5,
				cost: Trainer.cost.CROSS_ENTROPY
			});
			
			
			
			console.log( myNetwork.activate(训练数据[0]));

@xugangxugang
Copy link
Author

当我把这些代码放入一个动作块就可以正常预测了,而分开多个动作块就失败了?全局属性也不行

@xugangxugang
Copy link
Author

有问题的全部JS代码,我把创建神经网络的与训练,最后的激活分开后发现了我最前的问题赋值后F[1]变成空,后面我突发奇想我把他们放在一起,神经网络又可以预测了
//创建参数
//var synaptic = require('synaptic');
var Neuron = synaptic.Neuron,
Layer = synaptic.Layer,
Network = synaptic.Network,
Trainer = synaptic.Trainer,
Architect = synaptic.Architect;

		var 训练数据 = "";

		function 获取训练数据() {
			训练数据 = document.getElementById("训练数据").value;

			console.log(训练数据);

			训练数据 = 把训练数据转换成神经网络可识别的数据(训练数据);
		}

		function 把训练数据转换成神经网络可识别的数据(训练数据) {
			训练数据 = 训练数据.split(" ");
			console.log(训练数据);
			for (var i = 0, 训练数据length = 训练数据.length; i < 训练数据length; i++) {
				var 训练数据单条 = 训练数据[i].split(",");
				var 神经网络输入层 = new Array(49);
				for (var ii = 0, 训练数据单条length = 训练数据单条.length; ii < 训练数据单条length; ii++) {


					训练数据单条[ii] = Number(训练数据单条[ii]) - 1;
					if (ii == 6) {
						训练数据单条[ii] = 训练数据单条[ii] + 33;
						for (var iii = 33; iii < 49; iii++) {

							if (神经网络输入层[iii] > 0) {
								continue;
							} else {

								if (训练数据单条[ii] == iii) {
									神经网络输入层[iii] = 1;

								} else {
									神经网络输入层[iii] = 0;
								}

							}

						}

					} else {
						for (var iii = 0; iii < 33; iii++) {

							if (神经网络输入层[iii] > 0) {
								continue;
							} else {

								if (训练数据单条[ii] == iii) {
									神经网络输入层[iii] = 1;

								} else {
									神经网络输入层[iii] = 0;
								}
							}


						}

					}



				}
				console.log(神经网络输入层);
				训练数据[i] = 神经网络输入层;
			}

			return 训练数据;


		}

		function 转换数据为可读的数据(训练数据) {
			var 数据 = "";
			for (var i = 0; i < 训练数据.length; i++) {
				if (i > 32) {
					if (训练数据[i] > 0) {
						数据 = 数据 + (i + 1 - 33) + ",";

					}

				} else {
					if (训练数据[i] > 0) {
						数据 = 数据 + (i + 1) + ",";

					}

				}


			}
			return 数据;



		}


		var myNetwork = "";
		var trainer = "";

		function 创建神经网络() {
			//myNetwork = new Architect.Perceptron(49,300,150,120,90,60,30,15,8,4,2,49);
			var input = 49;
			var pool = 84;
			var output = 49;
			var connections = 34;
			var gates = 14;
			
			 myNetwork = new Architect.Liquid(input, pool, output, connections, gates);
			
			// trainer = new Trainer(myNetwork);
			// var trainingSet = [{
			// 		input: "",
			// 		output: ""
			// 	},
			
			// ];
			
			// for (var i = 0, 训练数据length = 训练数据.length; i < 训练数据length - 1; i++) {
			// 	trainingSet[i] = {
			// 		input: 训练数据[i + 1],
			// 		output: 训练数据[i]
			// 	}
			// }
			
			
			// trainer.train(trainingSet, {
			// 	rate: .1,
			// 	iterations: 20000,
			// 	error: .1,
			// 	shuffle: true,
			// 	log: 5,
			// 	cost: Trainer.cost.CROSS_ENTROPY
			// });
			
			
			
			//console.log( myNetwork.activate(训练数据[0]));
			
		}

		function 训练神经网络() {
		
			trainer = new Trainer(myNetwork);
			var trainingSet = [{
					input: "",
					output: ""
				},

			];

			for (var i = 0, 训练数据length = 训练数据.length; i < 训练数据length - 1; i++) {
				trainingSet[i] = {
					input: 训练数据[i + 1],
					output: 训练数据[i]
				}
			}


			trainer.train(trainingSet, {
				rate: .1,
				iterations: 20000,
				error: .1,
				shuffle: true,
				log: 5,
				cost: Trainer.cost.CROSS_ENTROPY
			});

		}

		function 获取预测数据() {
			var 需要预测数据 = document.getElementById("需要预测数据").value;

			需要预测数据 = 把训练数据转换成神经网络可识别的数据(需要预测数据);
		    
		var 预测结果=	myNetwork.activate(需要预测数据);
		
				预测结果=转换数据为可读的数据(预测结果);
				document.getElementById("预测结果").value=预测结果;
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant