Skip to content

Commit

Permalink
altered network to learn XOR problem and fixed numerous bugs generati…
Browse files Browse the repository at this point in the history
…ng NaN values
  • Loading branch information
Jim Bracewell authored and Jim Bracewell committed Feb 12, 2014
1 parent 1f003cf commit 203a66c
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 208 deletions.
15 changes: 7 additions & 8 deletions hiddenPotential.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
end
total = 0;

for j = 1:size(thisFireTimes,2)
if thisFireTimes(j) ~= 0
total = total + nu(threshold, t - thisFireTimes(j));
end

end
% for j = 1:size(thisFireTimes,2)
% if thisFireTimes(j) ~= 0
% total = total + nu(threshold, t - thisFireTimes(j));
% end
%
% end

for j = 1:size(weights(:,i),1)
if fireTimes(j) ~= 0
Expand All @@ -40,9 +40,8 @@

function rtn = spikeResponse(s)
t_m = 0.05;
t_s = 0.02;
t_s = 0.0002;

s = s-0.1;
rtn = (exp(-s/t_m) - exp(-s/t_s)) * H(s);


Expand Down
68 changes: 0 additions & 68 deletions hiddenPotential.m~

This file was deleted.

29 changes: 15 additions & 14 deletions runSpikeSimulation.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
%TODO - change architecure so that there are 8 input nodes, which are fully
%connected to the first hidden input layer

node_count = 8;
input_fire_times = zeros(node_count,1);
input_hidden_weights = convertTo2d(weights(1,:,:));
node_count = 2;
input_fire_times = zeros(2,1);
input_hidden_weights = convertTo2d(weights(1,1:2,:));
hidden1_fire_times = zeros(node_count,1);

hidden1_hidden2_weights = convertTo2d(weights(2,:,:)); %need a way to extract the values into an 8x8 matrix, as they are coming out as 1x8x8 with this command
hidden2_fire_times = zeros(node_count,1);

hidden2_output_weights = convertTo2d(weights(1,:,:));
output_fire_times = zeros(node_count,1);
hidden2_output_weights = weights(3,:,1);
output_fire_times = zeros(1,1);
threshold = 0.1;

%run the network
Expand All @@ -21,7 +21,7 @@
%check if input neuron has fired
if i >= peakLocs(1,pointer)
input_fire_times(pointer) = peakLocs(1,pointer);
if (pointer < node_count)
if (pointer < 2)
pointer = pointer + 1;
end

Expand All @@ -32,7 +32,7 @@
potential = hiddenPotential(j, i, input_hidden_weights, input_fire_times, hidden1_fire_times(:), threshold);

%if passes the threshold, add a firing time to that neuron
if potential >= threshold && hidden1_fire_times(j) == 0
if potential >= threshold %&& hidden1_fire_times(j) == 0
hidden1_fire_times(j) = i;
end

Expand All @@ -43,16 +43,16 @@
potential = hiddenPotential(j, i, hidden1_hidden2_weights, hidden1_fire_times(:), hidden2_fire_times(:), threshold);

%if passes the threshold, set the fire time
if potential >= threshold && hidden2_fire_times(j) == 0
if potential >= threshold % && hidden2_fire_times(j) == 0
hidden2_fire_times(j) = i;
end

end


for j = 1:node_count
for j = 1
potential = hiddenPotential(j, i, hidden2_output_weights', hidden2_fire_times(:), output_fire_times(:), threshold);
if potential >= threshold && output_fire_times(j) == 0
if potential >= threshold %&& output_fire_times(j) == 0
output_fire_times(j) = i;

end
Expand All @@ -66,13 +66,14 @@
end

%create fireTimes matrix
fireTimes = [peakLocs;hidden1_fire_times';hidden2_fire_times';output_fire_times'];
output_fire_times = [output_fire_times, 0];
fireTimes = [peakLocs;hidden1_fire_times';hidden2_fire_times';output_fire_times];

weights = zeros(3,8,8);
weights = zeros(3,2,2);

weights(1,:,:) = input_hidden_weights;
weights(1,1:2,:) = input_hidden_weights;
weights(2,:,:) = hidden1_hidden2_weights;
weights(3,:,:) = hidden2_output_weights;
weights(3,:,1) = hidden2_output_weights;



Expand Down
85 changes: 0 additions & 85 deletions runSpikeSimulation.m~

This file was deleted.

47 changes: 40 additions & 7 deletions spikePropAlgorithm.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@



deltas = zeros(no_of_layers,no_of_output_nodes);
deltas = zeros(no_of_layers,2);
for i = 1:no_of_output_nodes
deltas(no_of_layers,i) = deltaOutput(fire_times(no_of_layers,i), desired_fire_times(i), weights(no_of_layers -1,:,i), fire_times(no_of_layers -1, :));
deltas(no_of_layers,:) = deltaOutput(fire_times(no_of_layers,i), desired_fire_times(i), weights(no_of_layers -1,:,i), fire_times(no_of_layers -1, :));

end

Expand Down Expand Up @@ -71,15 +71,28 @@
end

%step 4: adapt weights for other layers
for k = no_of_layers -1:-1:2
for j = 1:8
for i = 1:8
for k = 3
for j = 1:2
for i = 1:2
weights(k-1, i,j) = weights(k-1,i,j) - step_size*(spikeResponse(fire_times(k,j) - fire_times(k-1,i))) * deltas(k, j);
end
end

end

for k = 2
for j = 1:2
for i = 1:2
weights(k-1, i,j) = weights(k-1,i,j) - step_size*(spikeResponse(fire_times(k,j) - fire_times(k-1,i))) * deltas(k, j)
hello = - step_size*(spikeResponse(fire_times(k,j) - fire_times(k-1,i))) * deltas(k, j)
if isnan(hello)
poo = 3;
end

end
end
end



end
Expand All @@ -96,6 +109,7 @@
%prev_weights and prev_layer_fire_times have a one-to-one mapping to one
%node in the previous layer
%deltas, weights and next_layer_fire_times have a one-to-one mapping to one

%node in the next layer
function rtn = deltaHidden(output, weights, prev_weights, deltas, next_layer_fire_times, prev_layer_fire_times, current_layer_fire_time)
numerator = 0;
Expand All @@ -109,7 +123,11 @@
hello = 4;

end

rtn = numerator/denominator;
if isnan(rtn)
po = 34;
end

end

Expand All @@ -128,16 +146,31 @@
denominator = 0.1;

end

rtn = ( desired - output) / denominator;
if isnan(rtn)
po = 34;
end
end


function rtn = spikeResponseDerivative(s)
t_m = 0.05;
t_s = 0.02;
t_s = 0.0002;

if s <= 0
rtn = 0;
else

rtn = (exp(-s/t_s)/t_s - exp(-s/t_m)/t_m) ;

end

rtn = (exp(-s/t_s)/t_s - exp(-s/t_m)/t_m);

if isnan(rtn)
hello = 3;

end
end

function rtn = h(s)
Expand Down
12 changes: 8 additions & 4 deletions spikeResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
%multiplied by 1, the peak of this function is of magnitude 0.3.
function rtn = spikeResponse(s)
t_m = 0.05;
t_s = 0.02;
t_s = 0.0002;

s = s -0.001;
if s <= 0
rtn = 0;
else

%added 0.1 delay
rtn = (exp(-s/t_m) - exp(-s/t_s) ) * H(s);
if rtn == 0
rtn = (exp(-s/t_m) - exp(-s/t_s));
end

if isnan(rtn)
hello = 4;

end
Expand Down
Loading

0 comments on commit 203a66c

Please sign in to comment.