# Path: AI.py
# class MultiClassifier:
#     def __init__(bins=10):
#     def fit(data):
#     def predict(test):
# def recognize(host):
# def learn(audio_in, audio_out, video_in, video_out, host):
# def live(audio_recognizer, audio_producer, audio2video, scaler, host):
# 
# Path: brain.py
# FACE_HAAR_CASCADE_PATH = opencv_prefix + '/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml'
# EYE_HAAR_CASCADE_PATH = opencv_prefix + '/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml'
# AUDIO_HAMMERTIME = 9
# RHYME_HAMMERTIME = 11
# FACE_HAMMERTIME = 15
# FRAME_SIZE = (160,120) # Neural network image size, 1/4 of full frame size.
# FACE_MEMORY_SIZE = 100
# AUDIO_MEMORY_SIZE = 500
# MAX_CATEGORY_SIZE = 10
# PROTECT_PERCENTAGE = .2
# NUMBER_OF_BRAINS = 5
#                         NAP = _extract_NAP(segstart, segend, soundfile)
#                     NAP = utils.trim_right(new_sentence[norm_segments[segment_id]:norm_segments[segment_id+1]])
#                         NAP = _extract_NAP(segstart, segend, soundfile)
#                     NAP = _extract_NAP(segstart, segend, audio_segment.wav_file)
#     NAP = NAP[:length:stride]
# class AudioMemory:
# class OneTrickPony:
#     def __init__(self):
#     def _digitize(self, NAP):
#     def _insert(self, D, key, value):
#     def find(self, NAP):
#     def learn(self, NAP, wav_file, segment_idxs):
#     def all_segments(self):
#     def forget(self, audio_segment):
#     def _cleanse_keys(self):
# def new_respond(control_host, learn_host, debug=False):
# def new_learn_audio(host, debug=False):
# def new_dream(audio_memory):
# def cognition(host):
# def face_extraction(host, extended_search=False, show=False):
# def train_network(x, y, output_dim=100, leak_rate=.9, bias_scaling=.2, reset_states=True, use_pinv=True):
# def cochlear(filename, stride, rate, db=-40, ears=1, a_1=-0.995, apply_filter=1, suffix='cochlear'):
# def _predict_id(classifier, M, counterQ = False, modality = None):
# def _hamming_distance_predictor(audio_classifier, NAP, maxlen, NAP_hashes):
# def _recognize_audio_id(audio_recognizer, NAP):
# def _project(audio_id, sound_to_face, NAP, video_producer):
# def _extract_NAP(segstart, segend, soundfile, suffix='cochlear'):
# def _train_audio_recognizer(signal):
# def _train_mixture_audio_recognizer(NAPs):
# def _train_global_audio_recognizer(NAPs):
# def _recognize_audio_id(audio_recognizer, NAP):
# def _recognize_mixture_audio_id(audio_recognizer, NAP):
# def _recognize_global_audio_id(audio_recognizer, NAP, plt):
#     def predict(self, x):
# def train_rPCA_SVM(x, y):
# def learn_video(host, debug=False):
# def learn_faces(host, debug=False):
# def _three_amigos(context, host):


import cPickle as pickle
import numpy as np
from pyevolve import G1DList, GSimpleGA, Mutators
from AI import _train_network
from brain import chop
#    as published by the Free Software Foundation.
#
#    [self.] is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with [self.].  If not, see <http://www.gnu.org/licenses/>.

''' [self.]

@author: Axel Tidemann, Øyvind Brandtsegg
@contact: axel.tidemann@gmail.com, obrandts@gmail.com
@license: GPL
'''

''' Finds the best parameters for the neural networks that performs audio recognition, using evolution.'''




audio_memories = pickle.load(open('counts.pickle'))

test = audio_memories[1::2]
train = audio_memories[:-1:2]

idxs = [0,6,7,8,9,12]

new_test = [chop(t[:,idxs]) for t in test ]

# Path: AI.py
# class MultiClassifier:
#     def __init__(bins=10):
#     def fit(data):
#     def predict(test):
# def recognize(host):
# def learn(audio_in, audio_out, video_in, video_out, host):
# def live(audio_recognizer, audio_producer, audio2video, scaler, host):
# 
# Path: brain.py
# FACE_HAAR_CASCADE_PATH = opencv_prefix + '/share/OpenCV/haarcascades/haarcascade_frontalface_default.xml'
# EYE_HAAR_CASCADE_PATH = opencv_prefix + '/share/OpenCV/haarcascades/haarcascade_eye_tree_eyeglasses.xml'
# AUDIO_HAMMERTIME = 9
# RHYME_HAMMERTIME = 11
# FACE_HAMMERTIME = 15
# FRAME_SIZE = (160,120) # Neural network image size, 1/4 of full frame size.
# FACE_MEMORY_SIZE = 100
# AUDIO_MEMORY_SIZE = 500
# MAX_CATEGORY_SIZE = 10
# PROTECT_PERCENTAGE = .2
# NUMBER_OF_BRAINS = 5
#                         NAP = _extract_NAP(segstart, segend, soundfile)
#                     NAP = utils.trim_right(new_sentence[norm_segments[segment_id]:norm_segments[segment_id+1]])
#                         NAP = _extract_NAP(segstart, segend, soundfile)
#                     NAP = _extract_NAP(segstart, segend, audio_segment.wav_file)
#     NAP = NAP[:length:stride]
# class AudioMemory:
# class OneTrickPony:
#     def __init__(self):
#     def _digitize(self, NAP):
#     def _insert(self, D, key, value):
#     def find(self, NAP):
#     def learn(self, NAP, wav_file, segment_idxs):
#     def all_segments(self):
#     def forget(self, audio_segment):
#     def _cleanse_keys(self):
# def new_respond(control_host, learn_host, debug=False):
# def new_learn_audio(host, debug=False):
# def new_dream(audio_memory):
# def cognition(host):
# def face_extraction(host, extended_search=False, show=False):
# def train_network(x, y, output_dim=100, leak_rate=.9, bias_scaling=.2, reset_states=True, use_pinv=True):
# def cochlear(filename, stride, rate, db=-40, ears=1, a_1=-0.995, apply_filter=1, suffix='cochlear'):
# def _predict_id(classifier, M, counterQ = False, modality = None):
# def _hamming_distance_predictor(audio_classifier, NAP, maxlen, NAP_hashes):
# def _recognize_audio_id(audio_recognizer, NAP):
# def _project(audio_id, sound_to_face, NAP, video_producer):
# def _extract_NAP(segstart, segend, soundfile, suffix='cochlear'):
# def _train_audio_recognizer(signal):
# def _train_mixture_audio_recognizer(NAPs):
# def _train_global_audio_recognizer(NAPs):
# def _recognize_audio_id(audio_recognizer, NAP):
# def _recognize_mixture_audio_id(audio_recognizer, NAP):
# def _recognize_global_audio_id(audio_recognizer, NAP, plt):
#     def predict(self, x):
# def train_rPCA_SVM(x, y):
# def learn_video(host, debug=False):
# def learn_faces(host, debug=False):
# def _three_amigos(context, host):


# Path: determine_parameters.py
import cPickle as pickle
import numpy as np
from pyevolve import G1DList, GSimpleGA, Mutators
from AI import _train_network
from brain import chop

#    as published by the Free Software Foundation.
#
#    [self.] is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with [self.].  If not, see <http://www.gnu.org/licenses/>.

''' [self.]

@author: Axel Tidemann, Øyvind Brandtsegg
@contact: axel.tidemann@gmail.com, obrandts@gmail.com
@license: GPL
'''

''' Finds the best parameters for the neural networks that performs audio recognition, using evolution.'''




audio_memories = pickle.load(open('counts.pickle'))

test = audio_memories[1::2]
train = audio_memories[:-1:2]

idxs = [0,6,7,8,9,12]

new_test = [chop(t[:,idxs]) for t in test ]

new_train = [chop(t[:,idxs]) for t in train ]