Skip to content

Commit

Permalink
Merge pull request #16 from estefanysuarez/test/workflow
Browse files Browse the repository at this point in the history
Test/workflow
  • Loading branch information
estefanysuarez authored Mar 27, 2023
2 parents 65f2fd9 + bb1becb commit 823c0d0
Show file tree
Hide file tree
Showing 14 changed files with 832 additions and 923 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# other files
examples/task_structure.py
examples/esn_multiple_tasks.py
examples/esn_multiple_subjs_and_tasks.py
examples/ohbm_plot.py
examples/ohbm_sim.py
examples/data
examples/mami
examples/results
examples/tmp_examples

*figs/

# data files
Expand Down
16 changes: 9 additions & 7 deletions conn2res/coding.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def get_modules(module_assignment):


def encoder(reservoir_states, target, readout_modules=None,
readout_nodes=None, metric='score', return_model=True, **kwargs):
readout_nodes=None, metric='score', return_model=False, **kwargs):
"""
Function that defines the set(s) of readout nodes based on whether
'readout_nodes', 'readout_modules' or None is provided. It then calls
Expand All @@ -42,10 +42,9 @@ def encoder(reservoir_states, target, readout_modules=None,
reservoir_states : list or tuple of numpy.ndarrays
simulated reservoir states for training and test; the shape of each
numpy.ndarray is n_samples, n_reservoir_nodes
target : listo or tuple of numpy.ndarrays
target : list or tuple of numpy.ndarrays
training and test targets or output labels; the shape of each
numpy.ndarray is n_samples, n_labels
# TODO update readout_modules doc
readout_modules : (N,) list or numpy.ndarray, optional
an array that specifies to which module each of the nodes in the
Expand All @@ -66,6 +65,7 @@ def encoder(reservoir_states, target, readout_modules=None,
"""

# use multiple subsets of readout nodes designated by readout_modules
if readout_modules is not None:

if isinstance(readout_modules, np.ndarray):
Expand All @@ -88,7 +88,7 @@ def encoder(reservoir_states, target, readout_modules=None,

# create temporal dataframe
df_module, model_module = run_task(reservoir_states=(
reservoir_states[0][:, readout_nodes], reservoir_states[1][:, readout_nodes]), target=target, metric=metric, **kwargs) # reservoir_states[:,:,readout_nodes],
reservoir_states[0][:, readout_nodes], reservoir_states[1][:, readout_nodes]), y=target, metric=metric, **kwargs) # reservoir_states[:,:,readout_nodes],

df_module['module'] = module_ids[i]
df_module['n_nodes'] = len(readout_nodes)
Expand All @@ -100,14 +100,16 @@ def encoder(reservoir_states, target, readout_modules=None,
df_encoding = pd.concat(df_encoding)

elif readout_nodes is not None:
# use a subset of output nodes as readout nodes
df_encoding, model = run_task(reservoir_states=(
reservoir_states[0][:, readout_nodes], reservoir_states[1][:, readout_nodes]), target=target, metric=metric, **kwargs)
reservoir_states[0][:, readout_nodes], reservoir_states[1][:, readout_nodes]), y=target, metric=metric, **kwargs)

df_encoding['n_nodes'] = len(readout_nodes)

else:
# use all output nodes as readout nodes
df_encoding, model = run_task(reservoir_states=reservoir_states,
target=target, metric=metric, **kwargs)
y=target, metric=metric, **kwargs)

if return_model:
return df_encoding, model
Expand Down Expand Up @@ -140,7 +142,7 @@ def time_average_samples(seq_len, data, sample_weight, operation=None):
elif isinstance(data, np.ndarray):
data = [data]

if len(data) != len(data):
if len(data) != len(sample_weight):
raise ValueError(
'data and sample_weight should have the same number of assigned variables')

Expand Down
Loading

0 comments on commit 823c0d0

Please sign in to comment.