def update_music_data(self): analyzer = Analyzer() music_list = self.banshee.get_tracks() # delete previously analyzed songs no longer existing in Banshee for mp3 in self.music_shelve: if mp3 not in music_list: del self.music_shelve[mp3] self.music_shelve.sync() song_count = len(music_list) progress = Progress("Analyzing Songs", song_count) # calculate and save features of new songs for mp3 in music_list: if mp3 not in self.music_shelve: features = analyzer.compute_features(mp3) if analyzer.valid_features(features): self.music_shelve[mp3] = features self.music_shelve.sync() progress.display() # convert music data to array self.music_data = np.array(self.music_shelve.values())
def train(self, data): # Some initial logistics samples, dims = data.shape # Check shape assert(dims == self.dims) # Set parameters rate_lower = 0.1 rate_upper = 0.5 spread_lower = 0.01 if self.new: # Large spread for fresh weights spread_upper = self.edge_length / 3.0 else: # Small spread for trained weights spread_upper = spread_lower * 1.05 shuffled = range(samples) np.random.shuffle(shuffled) # Create progress object progress = Progress("Training MusicCube", samples) for ix in range(samples): # Pick a random vector sample = data[shuffled[ix], :] # Figure out who's the closest weight vector # and calculate distances between weights and the sample winner = get_winner(sample, self.nodes, self.dims, self.weights, self.distances) # Calculate the new learning rate and new learning spread self.progress = float(ix) / float(samples) self.rate = self.scale(rate_upper, rate_lower) self.spread = self.scale(spread_upper, spread_lower) # Update those weights update_weights(sample, winner, self.nodes, self.dims, self.rate, self.spread, self.weights, self.indices) # Display progress progress.display()
def update_banshee(self): self.counter = {} positions = {} paths = self.get_paths() song_count = len(paths) progress = Progress("Updating Banshee", song_count) for song in paths: position = self.get_position(song) positions[song] = position # count song positions for plotting if position not in self.counter: self.counter[position] = 1 else: self.counter[position] += 1 progress.display() # update song positions in Banshee self.banshee.update_tracks(positions)