it runs but i get an error float division zero. Can anyone help please?
from brian2 import *
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error
# Define the LIF equations
eqs_lif = '''
dv/dt = (1/C) * (I - gL * (v - EL + eps)) : volt
I : amp
C : farad
gL : siemens
EL : volt
eps : volt # Small constant value to prevent division by zero
'''
# Set the parameters for the LIF equations
C = 1*uF
gL = 0.3*mS
EL = -54.4*mV
eps = 1e-9 * volt # Small constant value to prevent division by zero
# Generate random input data
input_data = np.random.random((1000, 44))
output_data = np.random.random((1000, 1))
# Split the data into training and validation sets
input_train, input_val, output_train, output_val = train_test_split(
input_data, output_data, test_size=0.2, random_state=1
)
# Define the Brian model for the neural network
num_inputs = 44
num_hidden1 = 100
num_hidden2 = 50
num_hidden3 = 25
num_output = 1
start_scope()
# Create input and output variables
input_var = TimedArray(input_train * nA, dt=1*ms)
output_var = output_train.squeeze() * volt
# Create the LIF neuron group
neurons = NeuronGroup(num_inputs, eqs_lif, threshold='v > -40*mV', reset='v = EL',
namespace={'C': C, 'gL': gL, 'EL': EL})
# Define the network architecture
hidden_layer1 = NeuronGroup(num_hidden1, eqs_lif, threshold='v > -40*mV', reset='v = EL',
namespace={'C': C, 'gL': gL, 'EL': EL, 'eps': eps})
hidden_layer2 = NeuronGroup(num_hidden2, eqs_lif, threshold='v > -40*mV', reset='v = EL',
namespace={'C': C, 'gL': gL, 'EL': EL, 'eps': eps})
hidden_layer3 = NeuronGroup(num_hidden3, eqs_lif, threshold='v > -40*mV', reset='v = EL',
namespace={'C': C, 'gL': gL, 'EL': EL, 'eps': eps})
output_layer = NeuronGroup(num_output, eqs_lif, threshold='v > -40*mV', reset='v = EL',
namespace={'C': C, 'gL': gL, 'EL': EL, 'eps': eps})
# Define the connections between the layers
synapse_input_hidden1 = Synapses(neurons, hidden_layer1, 'w : volt', on_pre='v_post += w')
synapse_hidden1_hidden2 = Synapses(hidden_layer1, hidden_layer2, 'w : volt', on_pre='v_post += w')
synapse_hidden2_hidden3 = Synapses(hidden_layer2, hidden_layer3, 'w : volt', on_pre='v_post += w')
synapse_hidden3_output = Synapses(hidden_layer3, output_layer, 'w : volt', on_pre='v_post += w')
# Set the initial weights
synapse_input_hidden1.connect()
synapse_hidden1_hidden2.connect()
synapse_hidden2_hidden3.connect()
synapse_hidden3_output.connect()
# Set the LIF equations for the synapses
synapse_input_hidden1.w = 'j*mV'
synapse_hidden1_hidden2.w = 'j*mV'
synapse_hidden2_hidden3.w = 'j*mV'
synapse_hidden3_output.w = 'j*mV'
# Define the monitors to record variables
mon_neurons = SpikeMonitor(neurons)
mon_output = StateMonitor(output_layer, 'v', record=True)
# Run the simulation
runtime = 1000 * ms
run(runtime)
# Extract the output values
output_values = mon_output.v.squeeze()
# Calculate mean absolute error
mae = mean_absolute_error(output_train, output_values)
# Print the mean absolute error
print(f"Epoch 1: MAE = {mae:.4f}")
# Evaluate the model on the validation set
input_var_val = TimedArray(input_val * nA, dt=1*ms)
neurons.I = input_var_val
run(runtime)
output_values_val = mon_output.v.squeeze()
val_mae = mean_absolute_error(output_val, output_values_val)
# Print the validation mean absolute error
print(f"Epoch 1: Val MAE = {val_mae:.4f}")