# 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
# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
r"""Regression Tests.

Test the decoding software with published data. This program reads and decodes
data from several different sources.  This code then builds a decoder, using
jackknifing to get a reliable estimate.

Results are computed for jackknifed experiments, each of which computes
correlation values for all the regularization_values using jackknifing over
max_test_count files

Example command line:

  regression --test_name 'telluride4_cca' --max_test_count 2 \
  --base_cache_dir /tmp/raw_data_storage/ --summary_base_dir /tmp/summary/ \
  --model_base_dir /tmp/models/ --logtostderr True \
  --tensorboard_dir '/tmp/tensorboard/' \

# 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

# Copyright 2019 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
r"""Regression Tests.

Test the decoding software with published data. This program reads and decodes
data from several different sources.  This code then builds a decoder, using
jackknifing to get a reliable estimate.

Results are computed for jackknifed experiments, each of which computes
correlation values for all the regularization_values using jackknifing over
max_test_count files

Example command line:

  regression --test_name 'telluride4_cca' --max_test_count 2 \
  --base_cache_dir /tmp/raw_data_storage/ --summary_base_dir /tmp/summary/ \
  --model_base_dir /tmp/models/ --logtostderr True \
  --tensorboard_dir '/tmp/tensorboard/' \

  --input2_pre_context=3 --input2_post_context=3 --post_context=3