📄 nnlearner.java
字号:
/*
* YALE - Yet Another Learning Environment
* Copyright (C) 2001-2004
* Simon Fischer, Ralf Klinkenberg, Ingo Mierswa,
* Katharina Morik, Oliver Ritthoff
* Artificial Intelligence Unit
* Computer Science Department
* University of Dortmund
* 44221 Dortmund, Germany
* email: yale-team@lists.sourceforge.net
* 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.AbstractLearner;
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.
*
* @author simon, ingo
* @version $Id: NNLearner.java,v 2.7 2004/09/14 08:39:06 ingomierswa Exp $
*/
public class NNLearner extends AbstractLearner {
public Model learn(ExampleSet exampleSet) {
int hiddenLayer = getParameterAsInt("hidden_layer");
double lambda = getParameterAsDouble("lambda");
NeuralNet nn = new NeuralNet(exampleSet.getLabel(), 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 + -