Пример #1
0
def convert_hhgate(gate):
    """Convert a MOOSE gate into GateHHRates in NeuroML"""
    hh_rates = neuroml.GateHHRates(id=gate.id_.value, name=gate.name)
    alpha = gate.tableA.copy()
    beta = gate.tableB - alpha
    vrange = np.linspace(gate.min, gate.max, len(alpha))
    afn, ap = hhfit.find_ratefn(vrange, alpha)
    bfn, bp = hhfit.find_ratefn(vrange, beta)
    if afn is None:
        raise Exception('could not find a fitting function for `alpha`')
    if bfn is  None:
        raise Exception('could not find a fitting function for `alpha`')
    afn_type = fn_rate_map[afn]
    afn_component_type = None
    if afn_type is None:
        afn_type, afn_component_type = define_component_type(afn)
    hh_rates.forward_rate = neuroml.HHRate(type=afn_type,
                                           midpoint='%gmV' % (ap[2]),
                                           scale='%gmV' % (ap[1]),
                                           rate='%gper_ms' % (ap[0]))
    bfn_type = fn_rate_map[bfn]
    bfn_component_type = None
    if bfn_type is None:
        bfn_type, bfn_component_type = define_component_type(bfn)
    hh_rates.reverse_rate = neuroml.HHRate(type=bfn_type,
                                           midpoint='%gmV' % (bp[2]),
                                           scale='%gmV' % (bp[1]),
                                           rate='%gper_ms' % (bp[0]))
    return hh_rates, afn_component_type, bfn_component_type
Пример #2
0
def convert_hhgate(gate):
    """Convert a MOOSE gate into GateHHRates in NeuroML"""
    hh_rates = neuroml.GateHHRates(id=gate.id_.value, name=gate.name)
    alpha = gate.tableA.copy()
    beta = gate.tableB - alpha
    vrange = np.linspace(gate.min, gate.max, len(alpha))
    afn, ap = hhfit.find_ratefn(vrange, alpha)
    bfn, bp = hhfit.find_ratefn(vrange, beta)
    if afn is None:
        raise Exception('could not find a fitting function for `alpha`')
    if bfn is None:
        raise Exception('could not find a fitting function for `alpha`')
    afn_type = fn_rate_map[afn]
    afn_component_type = None
    if afn_type is None:
        afn_type, afn_component_type = define_component_type(afn)
    hh_rates.forward_rate = neuroml.HHRate(type=afn_type,
                                           midpoint='%gmV' % (ap[2]),
                                           scale='%gmV' % (ap[1]),
                                           rate='%gper_ms' % (ap[0]))
    bfn_type = fn_rate_map[bfn]
    bfn_component_type = None
    if bfn_type is None:
        bfn_type, bfn_component_type = define_component_type(bfn)
    hh_rates.reverse_rate = neuroml.HHRate(type=bfn_type,
                                           midpoint='%gmV' % (bp[2]),
                                           scale='%gmV' % (bp[1]),
                                           rate='%gper_ms' % (bp[0]))
    return hh_rates, afn_component_type, bfn_component_type
Пример #3
0
 def test_sigmoid(self):
     print('Testing sigmoid')
     fn, params = hhfit.find_ratefn(self.v_array, self.sigmoid)
     print('Sigmoid params original:', self.p_sigmoid, 'detected:', params)
     pylab.plot(self.v_array, self.sigmoid, 'y-',
                self.v_array, hhfit.sigmoid(self.v_array, *self.p_sigmoid), 'b--',
                self.v_array, fn(self.v_array, *params), 'r-.')
     pylab.legend(('original sigmoid', 'computed', 'fitted %s' % (fn)))
     pylab.show()
     self.assertEqual(hhfit.sigmoid, fn)
     rms_error = np.sqrt(np.mean((self.sigmoid - fn(self.v_array, *params))**2))
     self.assertAlmostEqual(rms_error/max(abs(self.sigmoid)), 0.0, places=3)
Пример #4
0
 def test_sigmoid(self):
     print('Testing sigmoid')
     fn, params = hhfit.find_ratefn(self.v_array, self.sigmoid)
     print('Sigmoid params original:', self.p_sigmoid, 'detected:', params)
     pylab.plot(self.v_array, self.sigmoid, 'y-', 
                self.v_array, hhfit.sigmoid(self.v_array, *self.p_sigmoid), 'b--', 
                self.v_array, fn(self.v_array, *params), 'r-.')
     pylab.legend(('original sigmoid', 'computed', 'fitted %s' % (fn)))
     pylab.show()
     self.assertEqual(hhfit.sigmoid, fn)
     rms_error = np.sqrt(np.mean((self.sigmoid - fn(self.v_array, *params))**2))
     self.assertAlmostEqual(rms_error/max(abs(self.sigmoid)), 0.0, places=3)
Пример #5
0
 def test_dblexponential(self):
     print('Testing double exponential')
     fn, params = hhfit.find_ratefn(self.v_array, self.dblexp)
     fnval = fn(self.v_array, *params)
     pylab.plot(self.v_array, self.dblexp, 'y-',
                self.v_array, hhfit.double_exp(self.v_array, *self.p_dblexp), 'b--',
                self.v_array, fnval, 'r-.')
     pylab.legend(('original dblexp', 'computed', 'fitted %s' % (fn)))
     pylab.show()
     self.assertEqual(hhfit.double_exp, fn)
     rms_error = np.sqrt(np.mean((self.dblexp - fnval)**2))
     print(params, rms_error)
     self.assertAlmostEqual(rms_error/max(self.dblexp), 0.0, places=3)
Пример #6
0
 def test_dblexponential(self):
     print('Testing double exponential')
     fn, params = hhfit.find_ratefn(self.v_array, self.dblexp)
     fnval = fn(self.v_array, *params)
     pylab.plot(self.v_array, self.dblexp, 'y-', 
                self.v_array, hhfit.double_exp(self.v_array, *self.p_dblexp), 'b--',
                self.v_array, fnval, 'r-.')
     pylab.legend(('original dblexp', 'computed', 'fitted %s' % (fn)))
     pylab.show()
     self.assertEqual(hhfit.double_exp, fn)
     rms_error = np.sqrt(np.mean((self.dblexp - fnval)**2))
     print(params, rms_error)
     self.assertAlmostEqual(rms_error/max(self.dblexp), 0.0, places=3)
Пример #7
0
 def test_linoid(self):
     print 'Testing linoid'
     fn, params = hhfit.find_ratefn(self.v_array, self.linoid)
     print 'Linoid params original:', self.p_linoid, 'detected:', params
     pylab.plot(self.v_array, self.linoid, 'y-', 
                self.v_array, hhfit.linoid(self.v_array, *self.p_linoid), 'b--',
                self.v_array, fn(self.v_array, *params), 'r-.')
     pylab.legend(('original linoid', 'computed', 'fitted %s' % (fn)))
     pylab.show()
     self.assertEqual(hhfit.linoid, fn)
     fnval = fn(self.v_array, *params)
     rms_error = np.sqrt(np.mean((self.linoid - fnval)**2))
     self.assertAlmostEqual(rms_error/max(self.linoid), 0.0, places=3)
Пример #8
0
 def test_exponential(self):
     print('Testing exponential')
     fn, params = hhfit.find_ratefn(self.v_array, self.exp)
     print('Exponential params original:', self.p_exp, 'detected:', params)
     fnval = hhfit.exponential(self.v_array, *params)
     pylab.plot(self.v_array, self.exp, 'y-',
                self.v_array, hhfit.exponential(self.v_array, *self.p_exp), 'b--',
                self.v_array, fnval, 'r-.')
     pylab.legend(('original exp', 'computed', 'fitted %s' % (fn)))
     pylab.show()
     self.assertEqual(hhfit.exponential, fn)
     # The same exponential can be satisfied by an infinite number
     # of parameter values. Hence we cannot compare the parameters,
     # but only the fit
     rms_error = np.sqrt(np.sum((self.exp - fnval)**2))
     # pylab.plot(self.v_array, self.exp, 'b-')
     # pylab.plot(self.v_array, fnval, 'r-.')
     # pylab.show()
     print(rms_error, rms_error/max(self.exp))
     self.assertAlmostEqual(rms_error/max(self.exp), 0.0, places=3)
Пример #9
0
 def test_exponential(self):
     print('Testing exponential')
     fn, params = hhfit.find_ratefn(self.v_array, self.exp)
     print('Exponential params original:', self.p_exp, 'detected:', params)
     fnval = hhfit.exponential(self.v_array, *params)
     pylab.plot(self.v_array, self.exp, 'y-',
                self.v_array, hhfit.exponential(self.v_array, *self.p_exp), 'b--',
                self.v_array, fnval, 'r-.')
     pylab.legend(('original exp', 'computed', 'fitted %s' % (fn)))
     pylab.show()
     self.assertEqual(hhfit.exponential, fn)
     # The same exponential can be satisfied by an infinite number
     # of parameter values. Hence we cannot compare the parameters,
     # but only the fit
     rms_error = np.sqrt(np.sum((self.exp - fnval)**2))
     # pylab.plot(self.v_array, self.exp, 'b-')
     # pylab.plot(self.v_array, fnval, 'r-.') 
     # pylab.show()
     print(rms_error, rms_error/max(self.exp))
     self.assertAlmostEqual(rms_error/max(self.exp), 0.0, places=3)