You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by to...@apache.org on 2012/10/10 09:20:11 UTC

svn commit: r1396494 - in /labs/yay/trunk/core/src/main/java/org/apache/yay/neuron: BinaryThresholdNeuron.java RectifiedLinearNeuron.java SigmoidNeuron.java

Author: tommaso
Date: Wed Oct 10 07:20:11 2012
New Revision: 1396494

URL: http://svn.apache.org/viewvc?rev=1396494&view=rev
Log:
adding a few more neuron implementations

Added:
    labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java   (with props)
    labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/RectifiedLinearNeuron.java   (with props)
    labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/SigmoidNeuron.java   (with props)

Added: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java?rev=1396494&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java Wed Oct 10 07:20:11 2012
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.yay.neuron;
+
+import org.apache.yay.BasicElaborationUnit;
+import org.apache.yay.StepActivationFunction;
+
+/**
+ * A neuron which: <ul>
+ * <li>first computes a weighted sum of the inputs</li>
+ * <li>then send out a fixed size of activity if the weighted sum exceeds a
+ * threshold</li>
+ * </ul>
+ */
+public class BinaryThresholdNeuron extends BasicElaborationUnit<Double> {
+
+    private double[] weights;
+
+    public BinaryThresholdNeuron(double threshold, double... weights) {
+        this.activationFunction = new StepActivationFunction(threshold);
+        this.weights = weights;
+    }
+
+    @Override
+    protected Double combine(Double... inputs) {
+        Double res = 0d;
+        for (int i = 0; i < inputs.length; i++) {
+            res += inputs[i] * weights[i];
+        }
+        return res;
+    }
+}

Propchange: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/BinaryThresholdNeuron.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/RectifiedLinearNeuron.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/RectifiedLinearNeuron.java?rev=1396494&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/RectifiedLinearNeuron.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/RectifiedLinearNeuron.java Wed Oct 10 07:20:11 2012
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.yay.neuron;
+
+import org.apache.yay.ActivationFunction;
+
+/**
+ * A rectified linear neuron which is similar to {@link LinearNeuron} but cuts
+ * all the negative outputs to 0
+ */
+public class RectifiedLinearNeuron extends LinearNeuron {
+
+    public RectifiedLinearNeuron(Double bias, double... weights) {
+        super(bias, weights);
+        this.activationFunction = new ActivationFunction<Double>() {
+            @Override
+            public Double apply(Double signal) {
+                return signal > 0 ? signal : 0;
+            }
+        };
+    }
+}

Propchange: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/RectifiedLinearNeuron.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/SigmoidNeuron.java
URL: http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/SigmoidNeuron.java?rev=1396494&view=auto
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/SigmoidNeuron.java (added)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/SigmoidNeuron.java Wed Oct 10 07:20:11 2012
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.yay.neuron;
+
+import org.apache.yay.SigmoidFunction;
+
+/**
+ * A linear neuron whose output is smoothed via a {@link SigmoidFunction}
+ */
+public class SigmoidNeuron extends LinearNeuron {
+
+    public SigmoidNeuron(Double bias, double... weights) {
+        super(bias, weights);
+        this.activationFunction = new SigmoidFunction();
+    }
+}

Propchange: labs/yay/trunk/core/src/main/java/org/apache/yay/neuron/SigmoidNeuron.java
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org