You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, this the error.
Inconsistent units in subexpression alpha_m:
%Expression '(0.1/mV) * (-v + 25mV) / (exp((-v + 25mV)/(10*mV)) - 1)' does not have the expected unit hertz (unit is 1).
And here is my code, i am tryinga simple regression
from brian2 import *
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error
Define the Hodgkin-Huxley equations
eqs_hh = '''
dv/dt = (1/C) * (I - gNa * m3 * h * (v - ENa) - gK * n4 * (v - EK) - gL * (v - EL)) : volt
dm/dt = (alpha_m * (1 - m) - beta_m * m) : 1
dh/dt = (alpha_h * (1 - h) - beta_h * h) : 1
dn/dt = (alpha_n * (1 - n) - beta_n * n) : 1
I : amp
C : farad
gNa : siemens
gK : siemens
gL : siemens
ENa : volt
EK : volt
EL : volt
alpha_m = (0.1/mV) * (-v + 25mV) / (exp((-v + 25mV)/(10mV)) - 1) : Hz
beta_m = 4 * exp(-v/(18mV)) : Hz
alpha_h = 0.07 * exp(-v/(20mV)) : Hz
beta_h = 1/(exp((-v + 30mV)/(10mV)) + 1) : Hz
alpha_n = (0.01/mV) * (-v + 10mV) / (exp((-v + 10mV)/(10mV)) - 1) : Hz
beta_n = 0.125 * exp(-v/(80*mV)) : Hz
'''
Set the parameters for the Hodgkin-Huxley equations
C = 1uF
gNa = 120mS
gK = 36mS
gL = 0.3mS
ENa = 50mV
EK = -77mV
EL = -54.4*mV
Hi, this the error.
Inconsistent units in subexpression alpha_m:
%Expression '(0.1/mV) * (-v + 25mV) / (exp((-v + 25mV)/(10*mV)) - 1)' does not have the expected unit hertz (unit is 1).
And here is my code, i am tryinga simple regression
from brian2 import *
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_absolute_error
Define the Hodgkin-Huxley equations
eqs_hh = '''
dv/dt = (1/C) * (I - gNa * m3 * h * (v - ENa) - gK * n4 * (v - EK) - gL * (v - EL)) : volt
dm/dt = (alpha_m * (1 - m) - beta_m * m) : 1
dh/dt = (alpha_h * (1 - h) - beta_h * h) : 1
dn/dt = (alpha_n * (1 - n) - beta_n * n) : 1
I : amp
C : farad
gNa : siemens
gK : siemens
gL : siemens
ENa : volt
EK : volt
EL : volt
alpha_m = (0.1/mV) * (-v + 25mV) / (exp((-v + 25mV)/(10mV)) - 1) : Hz
beta_m = 4 * exp(-v/(18mV)) : Hz
alpha_h = 0.07 * exp(-v/(20mV)) : Hz
beta_h = 1/(exp((-v + 30mV)/(10mV)) + 1) : Hz
alpha_n = (0.01/mV) * (-v + 10mV) / (exp((-v + 10mV)/(10mV)) - 1) : Hz
beta_n = 0.125 * exp(-v/(80*mV)) : Hz
'''
Set the parameters for the Hodgkin-Huxley equations
C = 1uF
gNa = 120mS
gK = 36mS
gL = 0.3mS
ENa = 50mV
EK = -77mV
EL = -54.4*mV
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=42
)
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 Hodgkin-Huxley neuron group
neurons = NeuronGroup(num_inputs, eqs_hh, method='exponential_euler',
namespace={'C': C, 'gNa': gNa, 'gK': gK, 'gL': gL, 'ENa': ENa, 'EK': EK, 'EL': EL},
threshold='v > -40mV', refractory='v > -40mV')
Define the network architecture
hidden_layer1 = NeuronGroup(num_hidden1, eqs_hh, method='exponential_euler',
namespace={'C': C, 'gNa': gNa, 'gK': gK, 'gL': gL, 'ENa': ENa, 'EK': EK, 'EL': EL},
threshold='v > -40mV', refractory='v > -40mV')
hidden_layer2 = NeuronGroup(num_hidden2, eqs_hh, method='exponential_euler',
namespace={'C': C, 'gNa': gNa, 'gK': gK, 'gL': gL, 'ENa': ENa, 'EK': EK, 'EL': EL},
threshold='v > -40mV', refractory='v > -40mV')
hidden_layer3 = NeuronGroup(num_hidden3, eqs_hh, method='exponential_euler',
namespace={'C': C, 'gNa': gNa, 'gK': gK, 'gL': gL, 'ENa': ENa, 'EK': EK, 'EL': EL},
threshold='v > -40mV', refractory='v > -40mV')
output_layer = NeuronGroup(num_output, eqs_hh, method='exponential_euler',
namespace={'C': C, 'gNa': gNa, 'gK': gK, 'gL': gL, 'ENa': ENa, 'EK': EK, 'EL': EL},
threshold='v > -40mV', refractory='v > -40mV')
Define the connections between the layers
synapse_input_hidden1 = Synapses(neurons, hidden_layer1, 'w : 1', on_pre='v_post += wmV')
synapse_hidden1_hidden2 = Synapses(hidden_layer1, hidden_layer2, 'w : 1', on_pre='v_post += wmV')
synapse_hidden2_hidden3 = Synapses(hidden_layer2, hidden_layer3, 'w : 1', on_pre='v_post += wmV')
synapse_hidden3_output = Synapses(hidden_layer3, output_layer, 'w : 1', on_pre='v_post += wmV')
Set the initial weights
synapse_input_hidden1.connect()
synapse_hidden1_hidden2.connect()
synapse_hidden2_hidden3.connect()
synapse_hidden3_output.connect()
Set the Hodgkin-Huxley equations for the synapses
synapse_input_hidden1.w = 'j'
synapse_hidden1_hidden2.w = 'j'
synapse_hidden2_hidden3.w = 'j'
synapse_hidden3_output.w = 'j'
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}")
The text was updated successfully, but these errors were encountered: