def _warn_deprecated_params(swapped_args, end_version, lib_name, kwargs): used_args = set(kwargs).intersection(swapped_args) for deprecated_arg in used_args: swapped_arg = swapped_args[deprecated_arg] depracation_message = f'The argument "{deprecated_arg}" will be removed in {end_version} release of {lib_name}. \nPlease use the argument "{swapped_arg}" instead.' warnings.filterwarnings("always", message=depracation_message) warnings.warn(category=DeprecationWarning, message=depracation_message)
def samples_per_note(self, note_dur): """Get sample width of a note of the given duration at current bpm. Currently, it is assumed that a quarter note is 1 beat. Args: note_dur - recipricol of note value (i.e. quarter note is 4) Returns: number of samples required to represent the note duration """ if note_dur != 1 and note_dur % 2 != 0: warnings.warn("nonstandard note duration: 1/{}".format(note_dur)) if note_dur < 1: note_dur = 1 def_note_per_sec = 60 / self.bpm note_per_sec = self._def_note_dur / note_dur * def_note_per_sec return int(note_per_sec * config.DEF_SAMPLE_RATE)
def _add_swc_population(self, neurons): ''' add population ''' from .io.data_swc import GetSWCStructure as _get_swc_struct for neuron in neurons: gid = neurons[neuron]['gid'] axon, dendrites = _get_swc_struct(neuron=neurons[neuron]['data']) try: position = self.info["neurons"][str( neurons[neuron]['gid'])]['position'] except KeyError: _warn.warn("Cannot retrieve `position` from info.json file " "setting default position to [0, 0].") position = [0, 0] try: soma_radius = self.info["neurons"][str( neurons[neuron]['gid'])]['soma_radius'] except KeyError: _warn.warn("Cannot retrieve `soma_radius` from info.json file " "setting default radius to 8.") soma_radius = 8. super(Population, self).append( Neuron(gid, position=position, soma_radius=soma_radius)) if isinstance(axon, list): self[gid].axon = Neurite([Branch(ax) for ax in axon], neurite_type="axon", name="axon") else: raise Exception("Axon is expected to be a list of segments.") if dendrites is not None: if isinstance(dendrites, list): dendrite = Neurite([Branch(dend) for dend in dendrites], neurite_type="dendrite", name="dendrite") self[gid].dendrites[str(dendrite)] = dendrite else: raise Exception( "Dendrites are expected to be a list of segments.")
def new_func(*args, **kwargs): warnings.warn("Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning) return func(*args, **kwargs)
def warn(msg, *args, **kwargs): warnings.warn( "The 'warn' function is deprecated, " "use 'warning' instead", DeprecationWarning, 2) warning(msg, *args, **kwargs)
def calculate_fid_score(sample_feature_iterator, testset_feature_iterator): """ To be implemented by you! p: target--> testset q: generator-> sample """ sample_feature_iterator = sample_f testset_feature_iterator = test_f sample = [] testset = [] for i in sample_feature_iterator: sample.append(np.array(i).reshape(1, -1)) for j in testset_feature_iterator: testset.append(np.array(j).reshape(1, -1)) testset = np.concatenate(testset, 0) sample = np.concatenate(sample, 0) print("testset: ", testset.shape) print("sample: ", sample.shape) print("testset max: %f and min: %f " % (np.max(testset), np.min(testset))) print("sample max: %f and min: %f " % (np.max(sample), np.min(sample))) mu1 = np.mean(testset, axis=0) mu2 = np.mean(sample, axis=0) sigma1 = np.cov(testset, rowvar=False) sigma2 = np.cov(sample, rowvar=False) print(sigma1.shape) print(sigma2.shape) mu1 = np.atleast_1d(mu1) mu2 = np.atleast_1d(mu2) sigma1 = np.atleast_2d(sigma1) sigma2 = np.atleast_2d(sigma2) assert mu1.shape == mu2.shape, "Training and test mean vectors have different lengths" assert sigma1.shape == sigma2.shape, "Training and test covariances have different dimensions" diff = mu1 - mu2 # product might be almost singular covmean, _ = linalg.sqrtm(sigma1.dot(sigma2), disp=False) if not np.isfinite(covmean).all(): msg = "fid calculation produces singular product; adding %s to diagonal of cov estimates" % eps warnings.warn(msg) offset = np.eye(sigma1.shape[0]) * eps covmean = linalg.sqrtm((sigma1 + offset).dot(sigma2 + offset)) # numerical error might give slight imaginary component if np.iscomplexobj(covmean): if not np.allclose(np.diagonal(covmean).imag, 0, atol=1e-3): m = np.max(np.abs(covmean.imag)) raise ValueError("Imaginary component {}".format(m)) covmean = covmean.real tr_covmean = np.trace(covmean) d2 = diff.dot(diff) + np.trace(sigma1) + np.trace(sigma2) - 2 * tr_covmean print(diff.dot(diff)) print(np.trace(sigma1)) print(np.trace(sigma2)) print(2 * tr_covmean) return d2 raise NotImplementedError("TO BE IMPLEMENTED." "Part of Assignment 3 Quantitative Evaluations")
def bpm(bpm): if bpm <= 0: raise ValueError('{}bpm is at or below 0'.format(bpm)) if not MIN_BPM < bpm <= MAX_BPM: warnings.warn('{}bpm is out of bounds ({},{}]hz' .format(bpm, MIN_BPM, MAX_BPM))
def octave(octave): if octave < 0: raise ValueError('octave {} is below 0'.format(octave)) if not MIN_OCTAVE <= octave <= MAX_OCTAVE: warnings.warn('octave {} is out of bounds [{},{}]' .format(octave, MIN_OCTAVE, MAX_OCTAVE))
def sample_rate(rate): if rate < NYQUIST_RATE: warnings.warn('sample rate {} is below the nyquist rate {} for' + ' the max frequency {}hz' .format(rate, NYQUIST_RATE, MAX_FREQ))
def vol(vol): if not MIN_VOL <= vol <= MAX_VOL: warnings.warn('volume {} is out of bounds [{},{}]' .format(vol, MIN_VOL, MAX_VOL))
def freq(hz): if hz <= 0: raise ValueError('{}hz is at or below 0hz'.format(hz)) if not MIN_FREQ <= hz <= MAX_FREQ: warnings.warn('{}hz is out of bounds ({},{}]hz' .format(hz, MIN_FREQ, MAX_FREQ))
def init_pos(self, init_pos): if init_pos < 0: init_pos = 0 warnings.warn('initial phase position is negative;'\ ' setting to {}'.format(init_pos)) self._init_pos = init_pos
def pos(self, pos): if pos < 0: pos = 0 warnings.warn('phase position is negative;'\ ' setting to {}'.format(pos)) self._pos = pos
def width(self, width): if not 0 <= width <= 1: width = 1 warnings.warn('width is out of bounds [0,1]; setting to'\ '{}'.format(width)) self._width = width
def duty(self, duty): if not 0 < duty < 1: duty = 0.5 warnings.warn('Duty is out of bounds (0,1); setting to {}'.format( duty)) self._duty = duty
def dur(self, dur): if dur < 0: warnings.warn('duration of oscillator is below 0') self._dur = dur