# Path: spearmint_salad/pkl_trace.py
# def get_sys_info():
# def get_default_trace_path():
#     def __init__(self, trace_path=None, trace_level=10):
#     def write(self, trace_level, collection, info  ):
#     def __call__(self, info ):
#     def __init__(self):
#     def docs(self):
#     def insert(self, doc):
#     def find(self, query={}):
#     def __init__(self):
#     def get_collection_list(self):
#     def __getattr__(self, key):
#     def __getitem__(self, key ):
# def get_column_dict( collection, *column_names):
# def get_column_list( collection, *col_names):
#     def __init__(self, trace_path=None):
#     def update_trace(self):
# def get_latest_trace(dir='/tmp'):
# def get_recursif(struct, path ):
# def get_recursif_(struct, path ):
# def plot_stats(collection, axes, x_key, *y_key_list):
# class Trace:
# class Collection:
# class DB:
# class TraceDB(object):
# class TraceDBFile(TraceDB):
# 
# Path: spearmint_salad/base.py
# def argmin_with_ties( eLoss_kN ):
# def aB_prob(w_km, loss_mN):
# def rand_arg_min(val_n):
# def arg_min_prob( loss_mN ):
#     def apply_async(self, func, args=(), kwds={}, callback=None):
#     def close(self): pass
#     def __init__(self, value):
#     def get(self):
#     def __enter__(self):
#     def __exit__(self,*args):
#     def __init__(self, ds_partition):
#     def __call__(self, hp_id, hp_config ):
#     def get_y_dict(self):
#     def ds_name(self):
# def eval_learner(learner, ds_partition):
# def get_tmp_dir():
# def build_bootstrap_matrix(k_bootstrap, m, essr, rng=None):
# def bootstrap_weight(n, essr=1.0, rng=None):
#     def add_point(self, point):
#     def get_point(self, hp_id):
#     def size(self):
#     def _shuffle(self):
#     def __init__(self, grid_size=10000, shuffle=True):
#     def __str__(self):
#     def init_grid(self,n_dims):
#     def __init__(self, dim_size=10, shuffle=True ):
#     def init_grid(self,n_dims):
#     def next(self, grid, values, durations,
#             candidates, pending, complete):
# def BasicGridOptimizer(hp_space, dim_size=10):
#     def __init__(self, *args, **kwargs ):
#     def __call__(self):
# def GPEIOptimizer(hp_space, grid_size=10000, mcmc_iters=0, **kwargs):
# def RandomSobol(hp_space, grid_size=10000 ):
#     def __init__(self, hp_space, Chooser = None, grid = None ):
#     def __str__(self):
#     def _init(self):
#     def next(self, result_list, pending):
#     def get_chooser_state(self):
#     def _build_grid_info(self, result_list, pending ):
# class NotAPool:
# class ApplyResult:
# class Profiler:
# class Evaluator:
# class Grid(object):
# class SobolGrid(Grid):
# class EvenGrid(Grid):
# class RandomChooser(object):
# class GPEIChooseWrapper:
# class Optimizer:
# 
# Path: spearmint_salad/greedy.py
# def agnostic_bayes_prob( eLoss_kN ):
# def greedy_prob( eLoss_kN, ensemble_d ):
# def greedy_ensemble( loss_mN, w_km, ensemble_size=10 ):
#     N = eLoss_kN.shape[1]


import numpy as np
import os, fnmatch
from spearmint_salad import pkl_trace, base, greedy
from os import path
# -*- coding: utf-8 -*-
'''
Created on Dec 10, 2013

@author: alexandre
'''



def load_eval_info(trace_path):
    """
    Extract from the trace the predictions on the test and the validation sets for
    every models. 
    """
    trace = pkl_trace.TraceDBFile(trace_path)
    y_tst_N, y_val_N = pkl_trace.get_column_list(trace.db.eval_info, 'tst.y', 'val.y')
    y_tst_m, y_val_m = pkl_trace.get_column_list( trace.db.y, 'tst', 'val' )

# Path: spearmint_salad/pkl_trace.py
# def get_sys_info():
# def get_default_trace_path():
#     def __init__(self, trace_path=None, trace_level=10):
#     def write(self, trace_level, collection, info  ):
#     def __call__(self, info ):
#     def __init__(self):
#     def docs(self):
#     def insert(self, doc):
#     def find(self, query={}):
#     def __init__(self):
#     def get_collection_list(self):
#     def __getattr__(self, key):
#     def __getitem__(self, key ):
# def get_column_dict( collection, *column_names):
# def get_column_list( collection, *col_names):
#     def __init__(self, trace_path=None):
#     def update_trace(self):
# def get_latest_trace(dir='/tmp'):
# def get_recursif(struct, path ):
# def get_recursif_(struct, path ):
# def plot_stats(collection, axes, x_key, *y_key_list):
# class Trace:
# class Collection:
# class DB:
# class TraceDB(object):
# class TraceDBFile(TraceDB):
# 
# Path: spearmint_salad/base.py
# def argmin_with_ties( eLoss_kN ):
# def aB_prob(w_km, loss_mN):
# def rand_arg_min(val_n):
# def arg_min_prob( loss_mN ):
#     def apply_async(self, func, args=(), kwds={}, callback=None):
#     def close(self): pass
#     def __init__(self, value):
#     def get(self):
#     def __enter__(self):
#     def __exit__(self,*args):
#     def __init__(self, ds_partition):
#     def __call__(self, hp_id, hp_config ):
#     def get_y_dict(self):
#     def ds_name(self):
# def eval_learner(learner, ds_partition):
# def get_tmp_dir():
# def build_bootstrap_matrix(k_bootstrap, m, essr, rng=None):
# def bootstrap_weight(n, essr=1.0, rng=None):
#     def add_point(self, point):
#     def get_point(self, hp_id):
#     def size(self):
#     def _shuffle(self):
#     def __init__(self, grid_size=10000, shuffle=True):
#     def __str__(self):
#     def init_grid(self,n_dims):
#     def __init__(self, dim_size=10, shuffle=True ):
#     def init_grid(self,n_dims):
#     def next(self, grid, values, durations,
#             candidates, pending, complete):
# def BasicGridOptimizer(hp_space, dim_size=10):
#     def __init__(self, *args, **kwargs ):
#     def __call__(self):
# def GPEIOptimizer(hp_space, grid_size=10000, mcmc_iters=0, **kwargs):
# def RandomSobol(hp_space, grid_size=10000 ):
#     def __init__(self, hp_space, Chooser = None, grid = None ):
#     def __str__(self):
#     def _init(self):
#     def next(self, result_list, pending):
#     def get_chooser_state(self):
#     def _build_grid_info(self, result_list, pending ):
# class NotAPool:
# class ApplyResult:
# class Profiler:
# class Evaluator:
# class Grid(object):
# class SobolGrid(Grid):
# class EvenGrid(Grid):
# class RandomChooser(object):
# class GPEIChooseWrapper:
# class Optimizer:
# 
# Path: spearmint_salad/greedy.py
# def agnostic_bayes_prob( eLoss_kN ):
# def greedy_prob( eLoss_kN, ensemble_d ):
# def greedy_ensemble( loss_mN, w_km, ensemble_size=10 ):
#     N = eLoss_kN.shape[1]


# Path: spearmint_salad/loss_info.py
import numpy as np
import os, fnmatch
from spearmint_salad import pkl_trace, base, greedy
from os import path

# -*- coding: utf-8 -*-
'''
Created on Dec 10, 2013

@author: alexandre
'''



def load_eval_info(trace_path):
    """
    Extract from the trace the predictions on the test and the validation sets for
    every models. 
    """
    trace = pkl_trace.TraceDBFile(trace_path)
    y_tst_N, y_val_N = pkl_trace.get_column_list(trace.db.eval_info, 'tst.y', 'val.y')
    y_tst_m, y_val_m = pkl_trace.get_column_list( trace.db.y, 'tst', 'val' )

    metric, ds_name, hp_space = pkl_trace.get_column_list( trace.db.main, '__dict__.metric', 'ds_name', 'hp_space' )