# Path: telluride_decoding/brain_data.py
# class BrainData(object):
# class TestBrainData(BrainData):
# class TFExampleData(BrainData):
#   def __init__(self, in_fields, out_field,
#                frame_rate,
#                pre_context=0,
#                post_context=0,
#                in2_fields=None,
#                in2_pre_context=0,
#                in2_post_context=0,
#                attended_field=None,
#                initial_batch_size=1000,
#                final_batch_size=1000,
#                repeat_count=1,
#                shuffle_buffer_size=1000,
#                data_dir=None,
#                data_pattern='',
#                train_file_pattern='',
#                validate_file_pattern='',
#                test_file_pattern=''):
#   def all_files(self, max_count=0):
#   def set_file_patterns(self, train, validate, test):
#   def create_dataset(self, mode='train', temporal_context=True):
#   def _get_data_file_names(self):
#   def filter_file_names(self, mode):
#   def final_shuffle_and_batch(self, mode, input_dataset, mixup_batch=False):
#       def mixup_batch_function(x, x2, y, a):
#   def add_temporal_context(self, dataset_without_context):
#     def window_one_stream_new(x, pre_context, post_context):
#     def window_data(x, x2, y, a, pre_context=0, post_context=0,
#                     in2_pre_context=0, in2_post_context=0):
#   def input_fields_width(self, input_number=1):
#   def output_field_width(self):
#   def create_dataset(self, mode='train', temporal_context=True,
#                      mixup_batch=False):
#   def preserve_test_data(self, input_data, output_data,
#                          input2_data=None, attention_data=None):
#   def _get_data_file_names(self):
#   def create_dataset(self, mode='train', temporal_context=True,
#                      mixup_batch=False):
#   def read_data_into_dataset(self, filenames, temporal_context=True):
#   def preprocess_list(self, name_params_list, frame_rate):
#   def parse_and_select_from_tfrecord(self, raw_proto):
#   def parse_and_select_from_tfrecord2(self, raw_proto):
# def discover_feature_shapes(tfrecord_file_name):
# def count_tfrecords(tfrecord_file_name):
# def create_brain_dataset(data_type, in_fields, out_field, frame_rate,
#                          pre_context=0,
#                          post_context=0,
#                          in2_fields=None,
#                          in2_pre_context=0,
#                          in2_post_context=0,
#                          attended_field=None,
#                          initial_batch_size=1000,
#                          final_batch_size=1000,
#                          repeat_count=1,
#                          shuffle_buffer_size=1000,
#                          data_dir=None,
#                          data_pattern='',
#                          train_file_pattern=None,
#                          validate_file_pattern=None,
#                          test_file_pattern=None):
# 
# Path: telluride_decoding/csv_util.py
# def write_results(file_name, regularization_list, all_results):
# def _read_results(file_name, skip_header=False):
# def read_all_results_from_directory(dir_name, skip_header=False, pattern=''):
# def plot_csv_results(test_name,
#                      results,
#                      golden_mean_std_dict=None,
#                      png_file_name=None,
#                      show_plot=False):
# 
# Path: telluride_decoding/decoding.py
# class DecodingOptions(object):
#   def set_flags(self, all_flags=flags.FLAGS):
#   def experiment_parameters(self, delimiter=','):
#   def set_from_dict(self, new_values):
# def create_brain_model(model_flags, input_dataset):
# def train_and_test(my_flags, test_brain_data, test_brain_model, epochs=1):
# def write_experiment_summary(my_flags, train_results, test_results,
#                              dprime=None):
# def check_files(exp_data_dir, tfexample_pattern='.tfrecords'):
# def train_lda_model(brain_dataset, trained_model, my_flags):
# def run_decoding_experiment(my_flags):
# def main(argv):
# FLAGS = flags.FLAGS
# 
# Path: telluride_decoding/plot_util.py
# def matplotlib_pyplot():
# def plot_mean_std(test_name,
#                   regularization_list,
#                   run_mean,
#                   run_std,
#                   golden_mean_std_dict=None,
#                   png_file_name=None,
#                   show_plot=False):


import collections
import os
import sys
import numpy as np
import tensorflow.compat.v2 as tf
from absl import app
from absl import flags
from absl import logging
from telluride_decoding import brain_data
from telluride_decoding import csv_util
from telluride_decoding import decoding
from telluride_decoding import plot_util
                        max_test_count=-1,
                        test_name='telluride4',
                        trial_number=0,
                        summary_file=None,
                        test_file=None):
  """Function for running a jack knife experiment.

  This routine trains and tests a model on multiple independent training and
  test sets.  In the usual case, each possible file is used a test set, and
  all the other files are used for training. Just one value of all parameters,
  including regularization. Can be used for linear as well as CCA.
  Args:
    test_brain_data: BrainData object containing data
    test_brain_model: BrainModel object describing the ML model to run
    model_dir: Directory to save out the model
    my_flags: Decoding flags for this test.
    max_test_count: Max files to iterate over during jack knifing. -1 iterates
      through all files in the directory.
    test_name: data for which test is being run
    trial_number: Number printed out in the summary file to distinguish
      between trials.  (There are multiple trials per run, all trials go into
      the same summary file.)
    summary_file: Where to summarize the performance (either file pointer or
      file name)
    test_file: Just run this one test file (not the full jackknife)

  Returns:
    all_cor: List of float correlation values for the jack knifed run,
      one result per test file.
  """

# Path: telluride_decoding/brain_data.py
# class BrainData(object):
# class TestBrainData(BrainData):
# class TFExampleData(BrainData):
#   def __init__(self, in_fields, out_field,
#                frame_rate,
#                pre_context=0,
#                post_context=0,
#                in2_fields=None,
#                in2_pre_context=0,
#                in2_post_context=0,
#                attended_field=None,
#                initial_batch_size=1000,
#                final_batch_size=1000,
#                repeat_count=1,
#                shuffle_buffer_size=1000,
#                data_dir=None,
#                data_pattern='',
#                train_file_pattern='',
#                validate_file_pattern='',
#                test_file_pattern=''):
#   def all_files(self, max_count=0):
#   def set_file_patterns(self, train, validate, test):
#   def create_dataset(self, mode='train', temporal_context=True):
#   def _get_data_file_names(self):
#   def filter_file_names(self, mode):
#   def final_shuffle_and_batch(self, mode, input_dataset, mixup_batch=False):
#       def mixup_batch_function(x, x2, y, a):
#   def add_temporal_context(self, dataset_without_context):
#     def window_one_stream_new(x, pre_context, post_context):
#     def window_data(x, x2, y, a, pre_context=0, post_context=0,
#                     in2_pre_context=0, in2_post_context=0):
#   def input_fields_width(self, input_number=1):
#   def output_field_width(self):
#   def create_dataset(self, mode='train', temporal_context=True,
#                      mixup_batch=False):
#   def preserve_test_data(self, input_data, output_data,
#                          input2_data=None, attention_data=None):
#   def _get_data_file_names(self):
#   def create_dataset(self, mode='train', temporal_context=True,
#                      mixup_batch=False):
#   def read_data_into_dataset(self, filenames, temporal_context=True):
#   def preprocess_list(self, name_params_list, frame_rate):
#   def parse_and_select_from_tfrecord(self, raw_proto):
#   def parse_and_select_from_tfrecord2(self, raw_proto):
# def discover_feature_shapes(tfrecord_file_name):
# def count_tfrecords(tfrecord_file_name):
# def create_brain_dataset(data_type, in_fields, out_field, frame_rate,
#                          pre_context=0,
#                          post_context=0,
#                          in2_fields=None,
#                          in2_pre_context=0,
#                          in2_post_context=0,
#                          attended_field=None,
#                          initial_batch_size=1000,
#                          final_batch_size=1000,
#                          repeat_count=1,
#                          shuffle_buffer_size=1000,
#                          data_dir=None,
#                          data_pattern='',
#                          train_file_pattern=None,
#                          validate_file_pattern=None,
#                          test_file_pattern=None):
# 
# Path: telluride_decoding/csv_util.py
# def write_results(file_name, regularization_list, all_results):
# def _read_results(file_name, skip_header=False):
# def read_all_results_from_directory(dir_name, skip_header=False, pattern=''):
# def plot_csv_results(test_name,
#                      results,
#                      golden_mean_std_dict=None,
#                      png_file_name=None,
#                      show_plot=False):
# 
# Path: telluride_decoding/decoding.py
# class DecodingOptions(object):
#   def set_flags(self, all_flags=flags.FLAGS):
#   def experiment_parameters(self, delimiter=','):
#   def set_from_dict(self, new_values):
# def create_brain_model(model_flags, input_dataset):
# def train_and_test(my_flags, test_brain_data, test_brain_model, epochs=1):
# def write_experiment_summary(my_flags, train_results, test_results,
#                              dprime=None):
# def check_files(exp_data_dir, tfexample_pattern='.tfrecords'):
# def train_lda_model(brain_dataset, trained_model, my_flags):
# def run_decoding_experiment(my_flags):
# def main(argv):
# FLAGS = flags.FLAGS
# 
# Path: telluride_decoding/plot_util.py
# def matplotlib_pyplot():
# def plot_mean_std(test_name,
#                   regularization_list,
#                   run_mean,
#                   run_std,
#                   golden_mean_std_dict=None,
#                   png_file_name=None,
#                   show_plot=False):


# Path: telluride_decoding/regression.py
import collections
import os
import sys
import numpy as np
import tensorflow.compat.v2 as tf
from absl import app
from absl import flags
from absl import logging
from telluride_decoding import brain_data
from telluride_decoding import csv_util
from telluride_decoding import decoding
from telluride_decoding import plot_util

                        max_test_count=-1,
                        test_name='telluride4',
                        trial_number=0,
                        summary_file=None,
                        test_file=None):
  """Function for running a jack knife experiment.

  This routine trains and tests a model on multiple independent training and
  test sets.  In the usual case, each possible file is used a test set, and
  all the other files are used for training. Just one value of all parameters,
  including regularization. Can be used for linear as well as CCA.
  Args:
    test_brain_data: BrainData object containing data
    test_brain_model: BrainModel object describing the ML model to run
    model_dir: Directory to save out the model
    my_flags: Decoding flags for this test.
    max_test_count: Max files to iterate over during jack knifing. -1 iterates
      through all files in the directory.
    test_name: data for which test is being run
    trial_number: Number printed out in the summary file to distinguish
      between trials.  (There are multiple trials per run, all trials go into
      the same summary file.)
    summary_file: Where to summarize the performance (either file pointer or
      file name)
    test_file: Just run this one test file (not the full jackknife)

  Returns:
    all_cor: List of float correlation values for the jack knifed run,
      one result per test file.
  """

  if not isinstance(my_flags, decoding.DecodingOptions):