📄 nnlearner.java
字号:
/* * YALE - Yet Another Learning Environment * Copyright (C) 2002, 2003 * Simon Fischer, Ralf Klinkenberg, Ingo Mierswa, * Katharina Morik, Oliver Ritthoff * Artificial Intelligence Unit * Computer Science Department * University of Dortmund * 44221 Dortmund, Germany * email: yale@ls8.cs.uni-dortmund.de * web: http://yale.cs.uni-dortmund.de/ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA. */package edu.udo.cs.yale.operator.learner.nn;import edu.udo.cs.yale.operator.parameter.*;import edu.udo.cs.yale.operator.OperatorException;import edu.udo.cs.yale.operator.learner.Learner;import edu.udo.cs.yale.operator.learner.Model;import edu.udo.cs.yale.example.ExampleSet;import edu.udo.cs.yale.example.ExampleReader;import edu.udo.cs.yale.example.Example;import java.util.List;/** Learns a neural net. * <h4>Parameters:</h4> * <ul> * <li><tt>hidden_layer</tt> number of neurons in the hidden layer * <li><tt>lambda</tt> approximation increment * </ul> * <b>Classname for config-file:</b>NeuralNetLearner * @author simon * @version 22.06.2001 */public class NNLearner extends Learner { private int hiddenLayer; private double lambda; public void initApply() throws OperatorException { super.initApply(); hiddenLayer = getParameterAsInt("hidden_layer"); lambda = getParameterAsDouble("lambda"); } public Model learn(ExampleSet exampleSet) { NeuralNet nn = new NeuralNet(hiddenLayer, exampleSet.getNumberOfAttributes(), 1, lambda); ExampleReader i = exampleSet.getExampleReader(); while (i.hasNext()) { Example e = i.next(); double[] s = new double[e.getNumberOfAttributes()]; for (int j = 0; j < s.length; j++) s[j] = e.getValue(j); nn.learn(s, new double[] { e.getLabel() }); } return nn; } public List getParameterTypes() { List types = super.getParameterTypes(); types.add(new ParameterTypeInt("hidden_layer", "Number of neurons in the hidden layer.", 0, Integer.MAX_VALUE, 10)); types.add(new ParameterTypeDouble("lambda", "Parameter lambda.", 0, 1, 0.05)); return types; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -