-
Couldn't load subscription status.
- Fork 3
Mind2019 #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
jeremymanning
merged 11 commits into
ContextLab:mind2019
from
paxtonfitzpatrick:mind2019
Aug 13, 2019
Merged
Mind2019 #6
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c094e57
Merge pull request #1 from ContextLab/eventseg
paxtonfitzpatrick dba3851
updated config
paxtonfitzpatrick d63abfc
updated submit file
paxtonfitzpatrick a5a2e74
updated main code
paxtonfitzpatrick 62f2610
cleared collector
paxtonfitzpatrick 0d63c20
renamed scripts, removed collector
paxtonfitzpatrick 769ae6a
quick readme update
paxtonfitzpatrick c50e3c3
updated jobname
paxtonfitzpatrick 94b2960
fixed job script in model_scripts_submit
paxtonfitzpatrick fa170bf
updated model scripts config options
paxtonfitzpatrick 3c85e14
wrote cluster scripts for event segmentation
paxtonfitzpatrick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,23 +1 @@ | ||
| #!/usr/bin/python | ||
|
|
||
| from eventseg_config import config | ||
| import os | ||
| import numpy as np | ||
| import pandas as pd | ||
|
|
||
| segments_df = pd.DataFrame() | ||
|
|
||
| for root, dirs, files in os.walk(eventseg_config['resultsdir']): | ||
| event_models = [f for f in files if f.endswith('.npy')] | ||
| if event_models: | ||
| ep_path, turkid = os.path.split(root) | ||
| ep_name = os.path.split(ep_path)[1] | ||
| multiindex = pd.MultiIndex.from_product([[ep_name], [turkid]]) | ||
| tmp_df = pd.DataFrame(index=multiindex, columns=[os.path.splitext(em)[0] for em in event_models]) | ||
| for e in event_models: | ||
| ev_mod = np.load(os.path.join(root,e)) | ||
| tmp_df.at[(ep_name,turkid), os.path.splitext(e)[0]] = ev_mod | ||
|
|
||
| segments_df = segments_df.append(tmp_df) | ||
|
|
||
| segments_df.to_pickle(os.path.join(config['resultsdir'],'segments_df.p') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,68 @@ | ||
| #!/usr/bin/python | ||
|
|
||
| import sys | ||
| import os | ||
| import sys | ||
| import pickle | ||
| import numpy as np | ||
| import brainiak.eventseg.event as event | ||
| from eventseg_config import config | ||
|
|
||
| filepath, k = sys.argv[1], sys.argv[2] | ||
| dir, f_name = os.path.split(filepath) | ||
| rectype = os.path.split(dir)[1] | ||
| trajectory = np.load(filepath) | ||
| savepath = os.path.join(config['resultsdir'], rectype, os.path.splitext(f_name)[0], 'k'+k+'.npy') | ||
| script_name, k = sys.argv[1], int(sys.argv[2]) | ||
|
|
||
| traj_path = os.path.join(config['datadir'], 'trajectories', f'{script_name}_traj.npy') | ||
| traj = np.load(traj_path) | ||
|
|
||
| ev = event.EventSegment(k) | ||
| ev.fit(traj) | ||
| w = (np.round(ev.segments_[0])==1).astype(bool) | ||
| segs = np.array([traj[wi, :].mean(0) for wi in w.T]) | ||
|
|
||
| segments_filepath = os.path.join(config['datadir'], 'segments', script_name, f'{script_name}_events_k{str(k)}.npy' | ||
| eventseg_filepath = os.path.join(config['datadir'], 'eventseg_models', script_name, f'{script_name}_eventseg_k{str(k)}.p' | ||
|
|
||
| np.save(segments_filepath, segs) | ||
| with open(eventseg_filepath, 'wb') as f: | ||
| pickle.dump(ev) | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| if not os.path.isfile(savepath): | ||
| ev = event.EventSegment(int(k)) | ||
| ev.fit(trajectory) | ||
|
|
||
| np.save(savepath, ev.segments_[0]) | ||
| # import sys | ||
| # import joblib | ||
| # import numpy as np | ||
| # import pandas as pd | ||
| # from scipy.signal import resample | ||
| # from eventseg_config import config | ||
| # from helpers import * | ||
| # | ||
| # id = sys.argv[1] | ||
| # wsize = 50 | ||
| # | ||
| # # load only single row to save time & memory | ||
| # skiprows = range(1, id) | ||
| # data = pd.read_csv(os.path.join(config['datadir'], 'data.csv'), skiprows=skiprows, nrows=1).T.squeeze() | ||
| # name = data.title | ||
| # | ||
| # # remove HTML formatting, clean script content | ||
| # clean_script = cleanup_text(wipe_formatting(data.script)) | ||
| # | ||
| # # don't model empty scripts (8,528 characters is length of shortest cleaned script) | ||
| # if len(clean_script) < 8528: | ||
| # sys.exit() | ||
| # | ||
| # cv = joblib.load(os.path.join(config['datadir'], 'fit_cv.joblib')) | ||
| # lda = joblib.load(os.path.join(config['datadir'], 'fit_lda_t100.joblib')) | ||
| # | ||
| # sentences = cleaned.split('.') | ||
| # windows = [] | ||
| # for ix, _ in enumerate(sentences): | ||
| # windows.append(' '.join(sentences[ix:ix+wsize])) | ||
| # | ||
| # | ||
| # script_tf = cv.transform(windows) | ||
| # script_traj = resample(lda.transform(script_tf), 1000) | ||
| # corrmat = np.corrcoef(script_traj) | ||
| # | ||
| # np.save(os.path.join(config['datadir'], 'trajectories', f'{name}_traj.npy'), script_traj) | ||
| # np.save(os.path.join(config['datadir'], 'corrmats', f'{name}_corrmat.npy'), corrmat) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import socket | ||
| import os | ||
|
|
||
| config = dict() | ||
|
|
||
| # ====== MODIFY ONLY THE CODE BETWEEN THESE LINES ====== | ||
| # job creation options | ||
|
|
||
| #add additional checks for your local machine here... | ||
| # ******** check kiewit hostname from eduroam ******** | ||
| if (socket.gethostname() == 'Paxtons-MacBook-Pro') or (socket.gethostname() == 'Paxtons-MacBook-Pro.kiewit.dartmouth.edu') or (socket.gethostname() == 'Paxtons-MacBook-Pro.local'): | ||
| config['datadir'] = '/Users/paxtonfitzpatrick/Documents/Dartmouth/CDL/MIND-2019/narrative_complexity/data' | ||
| config['workingdir'] = config['datadir'] | ||
| config['startdir'] = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) # directory to start the job in | ||
| config['template'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'run_job_local.sh') | ||
| else: | ||
| config['datadir'] = '/dartfs/rc/lab/D/DBIC/CDL/data/movie_scripts/' | ||
| config['startdir'] = '/dartfs/rc/lab/D/DBIC/CDL/f0028ph/MIND-narrative-modeling' | ||
| config['workingdir'] = os.path.join(startdir, 'cluster-scripts') | ||
| config['template'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'run_job_cluster.sh') | ||
|
|
||
| config['scriptdir'] = os.path.join(config['workingdir'], 'scripts') | ||
| config['lockdir'] = os.path.join(config['workingdir'], 'locks') | ||
| config['resultsdir'] = os.path.join(config['workingdir'], 'results') | ||
|
|
||
|
|
||
| # runtime options | ||
| config['jobname'] = "model_script" # default job name | ||
| config['q'] = "largeq" # options: default, test, largeq | ||
| config['nnodes'] = 1 # how many nodes to use for this one job | ||
| config['ppn'] = 1 # how many processors to use for this one job (assume 4GB of RAM per processor) | ||
| config['walltime'] = '1:00:00' # maximum runtime, in h:MM:SS | ||
| config['cmd_wrapper'] = "python" # replace with actual command wrapper (e.g. matlab, python, etc.) | ||
|
|
||
| #extra options | ||
|
|
||
| # ====== MODIFY ONLY THE CODE BETWEEN THESE LINES ====== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/python | ||
|
|
||
| import sys | ||
| import joblib | ||
| import numpy as np | ||
| import pandas as pd | ||
| from scipy.signal import resample | ||
| from eventseg_config import config | ||
| from helpers import * | ||
|
|
||
| id = sys.argv[1] | ||
| wsize = 50 | ||
|
|
||
| # load only single row to save time & memory | ||
| skiprows = range(1, id) | ||
| data = pd.read_csv(os.path.join(config['datadir'], 'data.csv'), skiprows=skiprows, nrows=1).T.squeeze() | ||
| name = data.title | ||
|
|
||
| # remove HTML formatting, clean script content | ||
| clean_script = cleanup_text(wipe_formatting(data.script)) | ||
|
|
||
| # don't model empty scripts (8,528 characters is length of shortest cleaned script) | ||
| if len(clean_script) < 8528: | ||
| sys.exit() | ||
|
|
||
| cv = joblib.load(os.path.join(config['datadir'], 'fit_cv.joblib')) | ||
| lda = joblib.load(os.path.join(config['datadir'], 'fit_lda_t100.joblib')) | ||
|
|
||
| sentences = cleaned.split('.') | ||
| windows = [] | ||
| for ix, _ in enumerate(sentences): | ||
| windows.append(' '.join(sentences[ix:ix+wsize])) | ||
|
|
||
|
|
||
| script_tf = cv.transform(windows) | ||
| script_traj = resample(lda.transform(script_tf), 1000) | ||
| corrmat = np.corrcoef(script_traj) | ||
|
|
||
| np.save(os.path.join(config['datadir'], 'trajectories', f'{name}_traj.npy'), script_traj) | ||
| np.save(os.path.join(config['datadir'], 'corrmats', f'{name}_corrmat.npy'), corrmat) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set to 10000 (cleaner)?