[quote name='CryoGenesis' timestamp='1332101788' post='4923102']
Whats the point of Bias?
Is it needed for the neural network to function?
The point of Bias is to shift the activation function along x axis (and it can be considered as a constant input for the implementation as I suggested)
It's needed for practical purpose : if you don't use a bias, the function you are approximating (ie the problem you are solving) must pass threw (0,f(0)) where f is the activation function you chose. Otherwise, the net won't converge. With a bias you don't have this limitation anymore.
Oh and does the bias have to be used for every node or just the input nodes?
[/quote]
The bias has to be used with any node that does signal integration, so typically all the nodes except input ones (since these are just 'slots' to provide input to the net).
[/quote]
Thanks for the info but now it always returns between 0.6 - 0.7...
Here is the source code just in case I've done something wrong
package AI;
public class Node {
public float[] weight;
public float value;
public float activation;
public final float e = 2.7183f;
public final float p = 1;
public boolean in = false;
public Node(float[] weight){
this.weight = weight;
}
public static void main(String[] args){
NeuralNetwork net = new NeuralNetwork(1,1,2,2);
net.createNetwork();
float[] f = {100f};
net.input(f);
System.out.println(net.getOutput(0));
}
public float activationSigmoidMethod(float activation){
double a = -activation/p;
double b = e;
double c = Math.pow(e, a);
double e = 1 + c;
double f = 1/e;
return (float) f;
}
public void input(Node[] node, int num){
if(in = true){
activation += 1;
}
for(int i = 0; i < node.length; i++){
activation += (node.value * node.weight[num]);
}
value = activationSigmoidMethod(activation);
activation = 0;
}
public float getOutput(){
return value;
}
}
package AI;
import java.util.Random;
public class NeuralNetwork {
public Node[] in;
public Node[] out;
public Node[][] node;
public NeuralNetwork(int ins, int outs, int layers, int num){
in = new Node[ins];
out = new Node[outs];
node = new Node[layers][num];
}
public float[][] returnInWeights(){
float[][] ini = new float[in.length][node[0].length];
for(int i = 0; i < in.length; i ++){
for(int b = 0; b < node[0].length; b++){
ini = in.weight;
}
}
return ini;
}
public float[][][] returnNodeNormWeights(){
float[][][] weight = new float[node.length][node[0].length][node[0][0].weight.length];
for(int i = 0; i < node.length - 1; i ++){
for(int b = 0; b < node.length; b ++){
for(int a = 0; a < node.weight.length; a++){
weight[a] =node.weight[a];
}
}
}
return weight;
}
public float[][] returnOutNodeWeights(){
int length = node.length - 1;
float[][] nodes = new float[node[length].length][node[length][node[length].length].weight.length];
for(int i = 0; i < node[length].length; i ++){
for(int b = 0; b < node[length][node[length].length].weight.length; b++){
nodes = node[length].weight;
}
}
return nodes;
}
public float[] returnRanWeights(int amount){
Random a = new Random();
float[] weight = new float[amount];
for(int i = 0; i < amount; i ++){
weight = a.nextFloat() + a.nextFloat() - 1;
}
return weight;
}
public void createNetwork(){
for(int i = 0; i < in.length; i ++){
in = new Node(returnRanWeights(node[0].length));
in.in = true;
}
for(int i = 0; i < node.length; i ++){
for(int b = 0; b < node.length; b ++){
if(i < node.length - 1){
node = new Node(returnRanWeights(node[i + 1].length));
}else{
node = new Node(returnRanWeights(out.length));
}
}
}
for(int i = 0; i < out.length; i ++){
out = new Node(null);
}
}
public void input(float[] inp){
for(int i = 0; i < in.length; i++){
in.value = inp;
}
for(int i = 0; i < node.length; i ++){
for(int b = 0; b < node.length; b ++){
if(i == 0){
node.input(in, b);
}else{
node.input(node[i-1],b);
}
}
}
for(int i = 0; i < out.length; i++){
out.input(node[node.length - 1], i);
}
}
public float getOutput(int num){
return out[num].getOutput();
}
public float[] getOutput(){
float[] a = new float[out.length];
for(int i = 0; i < a.length; i++){
a = getOutput(i);
}
return a;
}
}