hparams.root, hparams.emb_save_dir,
        hparams.text_encoder + "_" + hparams.embedding_type + "_" +
        hparams.context_mode + "_" + str(hparams.past_window) + "-" +
        str(hparams.future_window) + "_onlypast-" + str(hparams.only_past))
    print("brain data dir: ", hparams.brain_data_dir)
    print("saving dir: ", saving_dir)

    TextEncoderDic = {
        'bert': BertEncoder(hparams),
    }

    tf.logging.set_verbosity(tf.logging.INFO)

    # Define how we want to read the brain data
    print("1. initialize brain data reader ...")
    brain_data_reader = HarryPotterReader(data_dir=hparams.brain_data_dir)

    # Define how we want to computationaly represent the stimuli
    print("2. initialize text encoder ...")
    stimuli_encoder = TextEncoderDic[hparams.text_encoder]

    # Explain Brain object with no mapper
    print("4. initialize Explainer...")
    explain_brain = ExplainBrain(hparams, brain_data_reader, stimuli_encoder,
                                 None)

    # Load the brain data
    tf.logging.info('Loading brain data ...')
    time_steps, brain_activations, stimuli, start_steps, end_steps = explain_brain.load_brain_experiment(
    )
Ejemplo n.º 2
0
if __name__ == '__main__':
    hparams = FLAGS
    print("roots", hparams.root)

    hparams.brain_data_dir = os.path.join(hparams.root, hparams.brain_data_dir)
    hparams.emb_save_dir = os.path.join(hparams.root, hparams.emb_save_dir)

    saving_dir = os.path.join(
        hparams.root, hparams.emb_save_dir,
        hparams.text_encoder + "_" + hparams.embedding_type + "_" +
        hparams.context_mode + "_" + str(hparams.past_window) + "-" +
        str(hparams.future_window) + "_onlypast-" + str(hparams.only_past))
    print("brain data dir: ", hparams.brain_data_dir)
    print("saving dir: ", saving_dir)

    brain_data_reader = HarryPotterReader(data_dir=hparams.brain_data_dir)

    story_features = np.load('story_features.npy').item()
    delay = 2  #2,0,3,1
    blocks = [1, 2, 3, 4]
    selected_steps = {}
    selecting_feature = 'quote'

    voxel_to_regions = {}
    regions_to_voxels = {}
    brain_fs = {}
    for subject in [1, 2, 3, 4, 5, 6, 7, 8]:
        voxel_to_regions[subject], regions_to_voxels[
            subject] = brain_data_reader.get_voxel_to_region_mapping(
                subject_id=subject)
        brain_fs[subject] = VarianceFeatureSelection()