def evaluate(net, data_loader): """ compute the eer equal error rate :param net: network :param data_loader: test dataset, contains audio files in a numpy array format :return eer """ net.reset() target_scores = [] non_target_scores = [] for data in tqdm(data_loader): sample_input, output = data[0], data[1] sample_input = whiten(sample_input) xo = gate_mfcc(net, sample_input) if output == 1: target_scores.append(xo) else: non_target_scores.append(xo) target_scores = np.array(target_scores) non_target_scores = np.array(non_target_scores) pmiss, pfa = rocch(target_scores, non_target_scores) eer = rocch2eer(pmiss, pfa) return eer
def evaluate(net, data_loader): correct = 0 total = 0 net.reset() target_scores = [] non_target_scores = [] for data in tqdm(data_loader): inputs, output = data[0], data[1] """ score_weight, score = gate_activation(net, inputs) selected_score = score[mask] selected_score = gate_activation(net, inputs) if selected_score.size == 0: xo = 0.5 else: xo = np.sum(selected_score) / selected_score.size """ xo = gate_mfcc(net, inputs) total += 1 correct += ((xo > 0.5) == output) if output == 1: target_scores.append(xo) else: non_target_scores.append(xo) target_scores = np.array(target_scores) non_target_scores = np.array(non_target_scores) pmiss, pfa = rocch(target_scores, non_target_scores) eer = rocch2eer(pmiss, pfa) return float(correct) / total, eer
def evaluate(net, data_loader): """ compute the eer equal error rate :param net: list of networks :param data_loader: dataset, contains audio files or extracted features in a numpy array format :return eer """ nb_net = len(net) target_scores_sum = [] non_target_scores_sum = [] target_scores_prod = [] non_target_scores_prod = [] target_scores_min = [] non_target_scores_min = [] target_scores_max = [] non_target_scores_max = [] target_scores_median = [] non_target_scores_median = [] for data in tqdm(data_loader): for i in range(nb_net): net[i].reset() sample_input, output = data[0], data[1] sample_input = whiten(sample_input) xo = np.zeros(nb_net) for i in range(nb_net): xo[i] = gate_mfcc(net[i], sample_input) if output == 1: target_scores_sum.append(xo.mean()) target_scores_prod.append(xo.prod()) target_scores_min.append(xo.min()) target_scores_max.append(xo.max()) target_scores_median.append(np.median(xo)) else: non_target_scores_sum.append(xo.mean()) non_target_scores_prod.append(xo.prod()) non_target_scores_min.append(xo.min()) non_target_scores_max.append(xo.max()) non_target_scores_median.append(np.median(xo)) eer_sum = compute_eer(target_scores_sum, non_target_scores_sum) eer_prod = compute_eer(target_scores_prod, non_target_scores_prod) eer_min = compute_eer(target_scores_min, non_target_scores_min) eer_max = compute_eer(target_scores_max, non_target_scores_max) eer_median = compute_eer(target_scores_median, non_target_scores_median) return eer_sum, eer_prod, eer_min, eer_max, eer_median
def eval_genome(genome, config, batch_data): """ Most important part of NEAT since it is here that we adapt NEAT to our problem. We tell what is the phenotype of a genome and how to calculate its fitness (same idea than a loss) :param config: config from the config file :param genome: one genome to get evaluated :param batch_data: data to use to evaluate the genomes :return fitness: returns the fitness of the genome this version is intented to use ParallelEvaluator and should be much faster """ net = neat.nn.RecurrentNetwork.create(genome, config) target_scores = [] non_target_scores = [] l_s_n = np.zeros(len(batch_data)) for data in batch_data: inputs, output = data[0], data[1] inputs = whiten(inputs) net.reset() """ mask, score = gate_mfcc(net, inputs) selected_score = score[mask] if selected_score.size == 0: xo = 0.5 else: xo = np.sum(selected_score) / selected_score.size """ xo = gate_mfcc(net, inputs) if output == 1: target_scores.append(xo) else: non_target_scores.append(xo) target_scores = np.array(target_scores) non_target_scores = np.array(non_target_scores) for i in range(batch_size // 2): l_s_n[i] = (non_target_scores >= target_scores[i]).sum() / (batch_size // 2) for i in range(non_target_scores.size): l_s_n[i + batch_size // 2] = ( target_scores <= non_target_scores[i]).sum() / (batch_size // 2) return 1 - l_s_n
def eval_genome(genome, config, batch_data): """ Most important part of NEAT since it is here that we adapt NEAT to our problem. We tell what is the phenotype of a genome and how to calculate its fitness (same idea than a loss) :param config: config from the config file :param genome: one genome to get evaluated :param batch_data: data to use to evaluate the genomes :return fitness: returns the fitness of the genome this version is intented to use ParallelEvaluator and should be much faster """ net = neat.nn.RecurrentNetwork.create(genome, config) target_scores = [] non_target_scores = [] for data in batch_data: inputs, output = data[0], data[1] inputs = whiten(inputs) net.reset() """ score_weight, score = gate_activation(net, inputs) selected_score = score[mask] selected_score = gate_activation(net, inputs) if selected_score.size == 0: xo = 0.5 else: xo = np.sum(selected_score) / selected_score.size """ xo = gate_mfcc(net, inputs) if output == 1: target_scores.append(xo) else: non_target_scores.append(xo) target_scores = np.array(target_scores) non_target_scores = np.array(non_target_scores) pmiss, pfa = rocch(target_scores, non_target_scores) eer = rocch2eer(pmiss, pfa) return 2*(.5 - eer)