Hindmarsh Rose Model implementation

I worked on implementing the HR model with nengo and created a new neuron class but got a problem with the gian_bias function. someone maybe can help me understand what am I doing wrong on the gain_bias function?
I implement another version with nengo but not defined it as a new neuron class and its working (more or less)

thanks in advance for all the helpers.

here is the function I created

def step(self, dt, J, output):
    X, Y, Z = output
    dXdt = Y - self.a * X**3 + self.b*X**2 - Z + self.I
    dYdt = self.c - self.d*X**2 - Y
    dZdt = self.R * (self.s*(X - self.Vt) - Z)
    output[0] += dt * dXdt
    output[1] += dt * dYdt
    output[2] += dt * dZdt
    
def rates(self, J, gain, bias):
    J = np.expand_dims(J, axis=1)  # Add an extra dimension to J
    rates = np.maximum(0, self.max_rates * (J - self.intercepts))
    return rates.flatten()  # Flatten the rates array 

def gain_bias(self, max_rates, intercepts):
    J_thresholds = np.zeros_like(intercepts)
    J = np.linspace(-1, 1, len(intercepts))[:, None]
    rates = self.rates(J[:-1], max_rates, intercepts)
    for idx, rate in enumerate(rates.T):
        zero_indices = np.where(rate <= 0)[0]
        if zero_indices.size > 0:
            last_zero_idx = zero_indices[-1]
            if last_zero_idx < J.shape[0] -1:
                J_thresholds[idx] = J[zero_indices[last_zero_idx], 0]
            else:
                J_thresholds[idx] = J[-1, 0]
        else:
            J_thresholds[idx] = J[-1, 0]
    gain = np.ones_like(intercepts) / (J_thresholds - intercepts)
    bias = -intercepts * gain
    return gain, bias

If anyone Knows it is also helpful for me also