if __name__ == "__main__":

    mapped_bouts = pd.read_csv(os.path.join(experiment.subdirs['analysis'],
                                            'mapped_bouts.csv'),
                               index_col=0,
                               dtype={
                                   'ID': str,
                                   'video_code': str
                               })

    # Re-weighting in isomap space
    isomap = np.load(
        os.path.join(experiment.parent.subdirs['analysis'],
                     'isomap.npy'))[:, :3]
    W = generate_weights(isomap)

    # Create paths for saving
    transition_directory = create_folder(experiment.subdirs['analysis'],
                                         'transitions')
    # Compute the transition matrix for each fish
    T = fish_transition_matrices(mapped_bouts,
                                 state_col='exemplar',
                                 n_states=len(isomap),
                                 shuffle=False)
    np.save(os.path.join(transition_directory, 'transition_matrices.npy'), T)
    print T.shape
    # Redistribute transitions
    WTW = redistribute_transitions(T, W)
    np.save(
        os.path.join(transition_directory, 'smoothed_transition_matrices.npy'),
Beispiel #2
0
    experiment.data.loc[experiment.data[experiment.data['condition'].
                                        isin(['left', 'right'])].index,
                        'condition'] = 'unilateral'
    mapped_bouts = pd.read_csv(os.path.join(experiment.subdirs['analysis'],
                                            'mapped_bouts.csv'),
                               index_col=0,
                               dtype={
                                   'ID': str,
                                   'video_code': str
                               })

    # Re-weighting in isomap space
    isomap = np.load(
        os.path.join(experiment.parent.subdirs['analysis'],
                     'isomap.npy'))[:, :3]
    W = generate_weights(isomap)

    # Create paths for saving
    transition_directory = create_folder(experiment.subdirs['analysis'],
                                         'transitions')
    for condition, fish_info in experiment.data.groupby('condition'):
        print condition
        condition_directory = create_folder(transition_directory, condition)
        condition_bouts = mapped_bouts[mapped_bouts['ID'].isin(
            fish_info['ID'])]
        # Compute the transition matrix for each fish
        T = fish_transition_matrices(condition_bouts,
                                     state_col='exemplar',
                                     n_states=len(isomap),
                                     shuffle=False)
        np.save(os.path.join(condition_directory, 'transition_matrices.npy'),
Beispiel #3
0
 def redistribute_transitions(self, bandwidth):
     self.W = generate_weights(self.points, bandwidth=bandwidth)
     self.T_ = np.dot(np.dot(self.W, self.T), self.W.T)