def train():
    global parsed_args
    test_sequence = 'Mix'
    measurement_costs = [(0.1 * i) for i in range(0, 15)]
    measurement_costs.extend([(0.01 * i) for i in range(1, 15)])
    loader = dataloader.DataLoaderSpectrogram()
    features = [f'PC_{i}' for i in range(n_pca_components)]
    classifiers = [(ObservationsConditionsClassifier(features, discriminant_model='calibrated_Gaussian', n_angle_bins=8), 'Conditioned on $\\phi$', 'Isotonic calibration'), (ObservationsConditionsClassifier(features, discriminant_model='Gaussian', n_angle_bins=8), 'Conditioned on $\\phi$', 'Uncalibrated'), (ClassifierComposition(features, discriminant_model='Gaussian'), 'Not conditioned on $\\phi$', 'Uncalibrated'), (ClassifierComposition(features, discriminant_model='calibrated_Gaussian'), 'Not conditioned on $\\phi$', 'Isotonic calibration')]
    rows = []
    for cost in measurement_costs:
        for (i_model, (classifier, observation_condition, discriminant_model)) in enumerate(classifiers):
            if parsed_args.rebuild:
                track.state_estimation(load_directory='./data/dataset/RD')
                dataset_path = 'C:\\Users\\peter\\Documents\\pulseON'
                loader = dataloader.DataLoaderSpectrogram()
                loader.build(dataset_path, 'PCA')
            else:
                loader.load('./data/dataset_df')
            result_df = evaluate_classifier(classifier, loader.df, test_persons=loader.df.person.unique(), test_sequence=test_sequence, measurement_cost=cost)
            predictions = result_df.loc[(result_df['sequence_type'] == test_sequence)]['prediction'].to_numpy()
            lables = result_df.loc[(result_df['sequence_type'] == test_sequence)]['lable'].to_numpy()
            accuracy = accuracy_score(lables, predictions)
            rows.append({'Accuracy': accuracy, 'Balanced accuracy': balanced_accuracy_score(lables, predictions), 'Macro-averaged Jaccard index': jaccard_score(lables, predictions, average='macro'), 'Observation conditions': observation_condition, 'Calibration': discriminant_model, 'Cost': cost, 'result_df': result_df, 'model_index': i_model})
    sns.lineplot(data=pd.DataFrame(rows), x='Cost', y='Accuracy', style='Observation conditions', hue='Calibration')
    plt.tight_layout()
    plt.show()
def train():
    global parsed_args
    test_sequence = 'Mix'
    measurement_costs = [(0.1 * i) for i in range(0, 15)]
    measurement_costs.extend([(0.01 * i) for i in range(1, 15)])
    loader = dataloader.DataLoaderSpectrogram()
    features = [f'PC_{i}' for i in range(n_pca_components)]
    classifiers = [(ObservationsConditionsClassifier(features, discriminant_model='calibrated_Gaussian', n_angle_bins=8), 'Conditioned on $\\phi$', 'Isotonic calibration'), (ObservationsConditionsClassifier(features, discriminant_model='Gaussian', n_angle_bins=8), 'Conditioned on $\\phi$', 'Uncalibrated'), (ClassifierComposition(features, discriminant_model='Gaussian'), 'Not conditioned on $\\phi$', 'Uncalibrated'), (ClassifierComposition(features, discriminant_model='calibrated_Gaussian'), 'Not conditioned on $\\phi$', 'Isotonic calibration')]
    rows = []
    for cost in measurement_costs:
        for (i_model, (classifier, observation_condition, discriminant_model)) in enumerate(classifiers):
            if parsed_args.rebuild:
                track.state_estimation(load_directory='./data/dataset/RD')
                dataset_path = 'C:\\Users\\peter\\Documents\\pulseON'
                loader = dataloader.DataLoaderSpectrogram()
                loader.build(dataset_path, 'PCA')
            else:
                loader.load('./data/dataset_df')
            result_df = evaluate_classifier(classifier, loader.df, test_persons=loader.df.person.unique(), test_sequence=test_sequence, measurement_cost=cost)
            predictions = result_df.loc[(result_df['sequence_type'] == test_sequence)]['prediction'].to_numpy()
            lables = result_df.loc[(result_df['sequence_type'] == test_sequence)]['lable'].to_numpy()
            accuracy = accuracy_score(lables, predictions)
            rows.append({'Accuracy': accuracy, 'Balanced accuracy': balanced_accuracy_score(lables, predictions), 'Macro-averaged Jaccard index': jaccard_score(lables, predictions, average='macro'), 'Observation conditions': observation_condition, 'Calibration': discriminant_model, 'Cost': cost, 'result_df': result_df, 'model_index': i_model})
    sns.lineplot(data=pd.DataFrame(rows), x='Cost', y='Accuracy', style='Observation conditions', hue='Calibration')
    plt.tight_layout()
    plt.show()