001 /*
002 * Copyright 2011 Christian Kumpe http://kumpe.de/christian/java
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package de.kumpe.hadooptimizer.examples.neurons;
017
018 import de.kumpe.hadooptimizer.EaOptimizerConfiguration;
019 import de.kumpe.hadooptimizer.examples.OptimizerExample;
020 import de.kumpe.hadooptimizer.examples.neurons.NeuronalNetEvaluator.Sample;
021 import de.kumpe.hadooptimizer.impl.GaussianMutator;
022
023 public class XorNet extends OptimizerExample<double[]> {
024 @Override
025 public EaOptimizerConfiguration<double[]> createEaOptimizerConfiguration() {
026 final InputValue[] inputValues = new InputValue[2];
027 final Neuron.Input[] inputs = new Neuron.Input[7];
028 final Neuron output = new Neuron(1, 10);
029 final Sample[] samples = new Sample[4];
030
031 inputValues[0] = new InputValue();
032 inputValues[1] = new InputValue();
033
034 final Neuron hidden1 = new Neuron(1, 10);
035 final Neuron hidden2 = new Neuron(2, 10);
036 final Neuron hidden3 = new Neuron(1, 10);
037
038 inputs[0] = hidden1.addInput(inputValues[0]);
039 inputs[1] = hidden2.addInput(inputValues[0]);
040 inputs[2] = hidden2.addInput(inputValues[1]);
041 inputs[3] = hidden3.addInput(inputValues[1]);
042
043 inputs[4] = output.addInput(hidden1);
044 inputs[5] = output.addInput(hidden2);
045 inputs[6] = output.addInput(hidden3);
046
047 samples[0] = new Sample(new double[] { 0, 0 }, 0);
048 samples[1] = new Sample(new double[] { 1, 0 }, 1);
049 samples[2] = new Sample(new double[] { 0, 1 }, 1);
050 samples[3] = new Sample(new double[] { 1, 1 }, 0);
051
052 final EaOptimizerConfiguration<double[]> conf = new EaOptimizerConfiguration<double[]>();
053 initConfiguration(conf, new double[7]);
054 conf.setMutator(new GaussianMutator());
055 final NeuronalNetEvaluator evaluator = new NeuronalNetEvaluator(
056 inputValues, inputs, output, samples);
057 conf.setEvaluator(evaluator);
058 addReporter(evaluator);
059 return conf;
060 }
061
062 @Override
063 protected String getVersionInfo() {
064 return "$Id: XorNet.java 3890 2011-04-20 14:58:14Z baumbart $";
065 }
066 }