-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simplified example (Main class) * Neural network can now take arrays as inputs instead of Matrices * modified readme * outsource sigmoid to own class with static methods
- Loading branch information
Kim Feichtinger
authored and
Kim Feichtinger
committed
Mar 5, 2018
1 parent
c4c2347
commit a0b79ad
Showing
4 changed files
with
101 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
# Basic Neural Network | ||
# Basic Neural Network | ||
|
||
This is a very basic Java Neural Network library using EJML (Efficient Java Matrix Library) based on an example by Daniel Shiffman. | ||
|
||
## Features | ||
|
||
- Neural Network with variable amounts of Inputs, hidden nodes and outputs | ||
- Only one hidden layer supported (yet) | ||
- Maven Dependency manager | ||
- ... | ||
|
||
## TODO | ||
|
||
- add support for multy-layered Neural Networks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package utilities; | ||
|
||
import org.ejml.simple.SimpleMatrix; | ||
|
||
/** | ||
* Created by KimFeichtinger on 05.03.18. | ||
*/ | ||
public class Sigmoid { | ||
|
||
public static SimpleMatrix applySigmoid(SimpleMatrix input, boolean derivative){ | ||
SimpleMatrix output = new SimpleMatrix(input.numRows(), input.numCols()); | ||
for (int i = 0; i < input.numRows(); i++) { | ||
for (int j = 0; j < input.numCols(); j++) { | ||
double value = input.get(i, j); | ||
// apply dsigmoid if derivative = true, otherwise usual Sigmoid | ||
if(derivative){ | ||
output.set(i, j, dsigmoid(value)); | ||
}else { | ||
output.set(i, j, sigmoid(value)); | ||
} | ||
} | ||
} | ||
|
||
return output; | ||
} | ||
|
||
private static double sigmoid(double input){ | ||
return 1 / (1 + Math.exp(-input)); | ||
} | ||
|
||
// derivative of Sigmoid (not real derivative because Sigmoid function has already been applied to the input) | ||
private static double dsigmoid(double input){ | ||
return input * (1 - input); | ||
} | ||
|
||
} |