def concat(self, other): """Create new reception parameters by combining this set of reception parameters with another. """ # Combine the filters if self.filter is None: new_filter = other.filter elif other.filter is None: new_filter = self.filter elif (isinstance(self.filter, LinearFilter) and isinstance(other.filter, LinearFilter)): # Combine linear filters by multiplying their numerators and # denominators. new_filter = LinearFilter( np.polymul(self.filter.num, other.filter.num), np.polymul(self.filter.den, other.filter.den)) else: raise NotImplementedError( "Cannot combine filters of type {} and {}".format( type(self.filter), type(other.filter))) # Combine the learning rules if self.learning_rule is not None and other.learning_rule is not None: raise NotImplementedError( "Cannot combine learning rules {} and {}".format( self.learning_rule, other.learning_rule)) new_learning_rule = self.learning_rule or other.learning_rule # Create the new reception parameters return ReceptionParameters(new_filter, other.width, new_learning_rule)
def test_synapses(): check_init_args(LinearFilter, ["num", "den", "analog", "method"]) check_repr(LinearFilter([1, 2], [3, 4])) check_repr(LinearFilter([1, 2], [3, 4], analog=False)) assert (repr(LinearFilter( [1], [0.03, 1 ])) == "LinearFilter(num=array([1.]), den=array([0.03, 1. ]))") check_init_args(Lowpass, ["tau"]) check_repr(Lowpass(0.3)) assert repr(Lowpass(0.01)) == "Lowpass(tau=0.01)" check_init_args(Alpha, ["tau"]) check_repr(Alpha(0.3)) assert repr(Alpha(0.02)) == "Alpha(tau=0.02)" check_init_args(Triangle, ["t"]) check_repr(Triangle(0.3)) assert repr(Triangle(0.03)) == "Triangle(t=0.03)"