def __repr__(self): r = [] for (i, tone) in enumerate(self.tones): degree = numeral.int2roman(i + 1, only_ascii=True) r += [f"{degree}={tone.full_name}"] r = " ".join(r) return f"<Scale {r}>"
def predictions(X: np.ndarray, site_names: List[str]): # pylint:disable=invalid-name """Format the predictions""" ( prediction, max_probas, base_predictions, ) = RUNNER._make_predictions( # pylint:disable=protected-access X) nearest_neighbors = get_nearest_neighbors(X) prediction_output = [] for i, pred in enumerate(prediction): agreement = base_predictions[i].count(pred) / len( base_predictions[i]) * 100 if agreement > 80: bartype = "progress-bar bg-success" elif agreement < 60: bartype = "progress-bar bg-danger" else: bartype = "progress-bar bg-warning" prediction_output.append([ site_names[i], int2roman(pred), max_probas[i], ", ".join([int2roman(j) for j in base_predictions[i]]), agreement, bartype, nearest_neighbors[i], ], ) prediction_labels = [] for i, pred in enumerate(prediction): prediction_labels.append("{} ({})".format(site_names[i], int2roman(pred))) class_idx = [] for pred in prediction: class_idx.append(np.argwhere(RUNNER.model.classes == pred)[0][0]) return prediction_output, prediction_labels, class_idx
def __getitem__(self, item): # Degree–style reference (e.g. "IV"). if isinstance(item, str): degrees = [] for (i, tone) in enumerate(self.tones): degrees.append(numeral.int2roman(i + 1, only_ascii=True)) if item in degrees: item = degrees.index(item) # List/Tuple–style reference. if isinstance(item, int) or isinstance(item, slice): return self.tones[item]
def degree(self, item, major=None, minor=False): # TODO: cleanup degrees. # Ensure that both major and minor aren't passed. if all((major, minor)): raise ValueError( "You can only specify one of the following: major, minor.") # Roman–style degree reference (e.g. "IV"). if isinstance(item, str): degrees = [] for (i, tone) in enumerate(self.tones): degrees.append(numeral.int2roman(i + 1, only_ascii=True)) if item in degrees: item = degrees.index(item) # If we're still a string, attempt to grab degree name. if isinstance(item, str): # Default to major mode, because that's how people do it, I think. if not minor and major is None: major = True for i, _degree in enumerate(self.system.degrees): # "tonic / octave" comp = _degree[0] if major: comp = _degree[1][0] elif minor: comp = _degree[1][1] if item == comp: item = i # List/Tuple–style reference. if isinstance(item, int) or isinstance(item, slice): return self.tones[item]
def to_human(self, value): return numeral.int2roman(int(value), only_ascii=True)