Author: tommaso
Date: Thu Dec 5 20:41:59 2013
New Revision: 1548289
URL: http://svn.apache.org/r1548289
Log:
fixed typos in bpls test, improved perceptron to not updateweights when sample
and evaluated outputs are the same
Modified:
labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BackPropagationLearningStrategyTest.java
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java
Modified:
labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java
URL:
http://svn.apache.org/viewvc/labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java?rev=1548289&r1=1548288&r2=1548289&view=diff
==============================================================================
--- labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java
(original)
+++ labs/yay/trunk/core/src/main/java/org/apache/yay/core/BasicPerceptron.java
Thu Dec 5 20:41:59 2013
@@ -68,12 +68,14 @@ public class BasicPerceptron implements
for (int i = 0; i < currentWeights.length; i++) {
currentWeights[i] += inputs[i];
}
+ perceptronNeuron.updateWeights(currentWeights);
} else if (diff < 0) {
for (int i = 0; i < currentWeights.length; i++) {
currentWeights[i] -= inputs[i];
}
+ perceptronNeuron.updateWeights(currentWeights);
}
- perceptronNeuron.updateWeights(currentWeights);
+
}
@Override
Modified:
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BackPropagationLearningStrategyTest.java
URL:
http://svn.apache.org/viewvc/labs/yay/trunk/core/src/test/java/org/apache/yay/core/BackPropagationLearningStrategyTest.java?rev=1548289&r1=1548288&r2=1548289&view=diff
==============================================================================
---
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BackPropagationLearningStrategyTest.java
(original)
+++
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BackPropagationLearningStrategyTest.java
Thu Dec 5 20:41:59 2013
@@ -39,7 +39,7 @@ import static junit.framework.Assert.ass
public class BackPropagationLearningStrategyTest {
@Test
- public void testLearningWitgRandomNetwork() throws Exception {
+ public void testLearningWithRandomNetwork() throws Exception {
BackPropagationLearningStrategy backPropagationLearningStrategy = new
BackPropagationLearningStrategy();
RealMatrix[] initialWeights = createRandomWeights();
@@ -55,7 +55,7 @@ public class BackPropagationLearningStra
}
@Test
- public void testLearningWitgRandomNetworkAndRandomSettings() throws
Exception {
+ public void testLearningWithRandomNetworkAndRandomSettings() throws
Exception {
BackPropagationLearningStrategy backPropagationLearningStrategy = new
BackPropagationLearningStrategy(Math.random(),
Math.random(), new FeedForwardStrategy(Math.random() >= 0.5d ? new
TanhFunction() : new SigmoidFunction()),
new LogisticRegressionCostFunction(Math.random()));
Modified:
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java
URL:
http://svn.apache.org/viewvc/labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java?rev=1548289&r1=1548288&r2=1548289&view=diff
==============================================================================
---
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java
(original)
+++
labs/yay/trunk/core/src/test/java/org/apache/yay/core/BasicPerceptronTest.java
Thu Dec 5 20:41:59 2013
@@ -87,16 +87,44 @@ public class BasicPerceptronTest {
r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
r.nextDouble(), r.nextDouble());
basicPerceptron.learn(bigDataset);
- Double output = basicPerceptron.predict(createTrainingExample(null, 1d,
+ Double output = basicPerceptron.predict(createInput(r));
+ assertTrue(output == 0d || output == 1d);
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testLearnPredictAndUpdateWithBigDataset() throws Exception {
+ Random r = new Random();
+ BasicPerceptron basicPerceptron = new BasicPerceptron(1d, r.nextDouble(),
r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
- r.nextDouble(), r.nextDouble()));
+ r.nextDouble(), r.nextDouble());
+ basicPerceptron.learn(bigDataset);
+ TrainingExample<Double, Double> input = createInput(r);
+ Double output = basicPerceptron.predict(input);
assertTrue(output == 0d || output == 1d);
+ basicPerceptron.learn(createTrainingExample(1d, r.nextDouble(),
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble()));
+ Double secondOutput = basicPerceptron.predict(input);
+ assertTrue(secondOutput == 0d || secondOutput == 1d);
}
- @Test
+ private TrainingExample<Double, Double> createInput(Random r) {
+ return createTrainingExample(null, 1d,
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble(), r.nextDouble(), r.nextDouble(),
+ r.nextDouble(), r.nextDouble());
+ }
+
+ @Test
@SuppressWarnings("unchecked")
public void testLearnPhaseWithSmallDataset() throws Exception {
BasicPerceptron basicPerceptron = new BasicPerceptron(1d, 2d, 3d, 4d);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]