def get_histogram_bins(nb_bins=NB_BINS): name = 'all_bins' try: bins = get_histogram_bins.BINS except AttributeError: try: print('Loading histogram bins.') bins = load_variables(name) except FileNotFoundError: print('Computing histogram bins.') ext = first_layer_extractor st_desc, _, _ = homogenized_description(ext, homogenize=False) all_val = concatenate_all(st_desc) all_val[np.isnan(all_val)] = 0 length = all_val.shape[0] if type(nb_bins) == int: nb_bins = nb_bins * np.ones(length) bins = [[] for k in range(length)] for k in range(length): val = all_val[k, :] bins[k] = empirical_bins(val, nb_bins=nb_bins[k]) save_variables(name, bins) get_histogram_bins.BINS = bins return bins
def get_small_design(name): save_name = 'small_design_' + name try: design, labels, ids, explanation = load_variables(save_name) except FileNotFoundError: design, labels, ids, explanation = get_design(name) design, explanation = small_design(design, labels, explanation) save_variables(save_name, [design, labels, ids, explanation]) return design, labels, ids, np.array(explanation)
def get_design(name): save_name = 'design_' + name try: design, labels, ids, explanation = load_variables(save_name) except FileNotFoundError: st_data, labels, ids, explanation = get_layer(name) design, explanation = cast_design(st_data, explanation) save_variables(save_name, [design, labels, ids, explanation]) return design, labels, ids, np.array(explanation)
def get_center(event): name = event[1] try: center, mean, std = load_variables(name) except FileNotFoundError: try: st_data, _, _, _ = load_variables('preprocess') except FileNotFoundError: extractor = preprocess_extractor explanation = FACE_PARAMETERIZATION st_data, labels, ids = homogenized_description(extractor) save_variables('preprocess', [st_data, labels, ids, explanation]) center, mean, std = perform_clustering(st_data, event) save_variables(name, [center, mean, std]) return center, mean, std
def get_layer(name): try: data, labels, ids, explanation = load_variables(name) except FileNotFoundError: if name == 'face_parameterization': extractor = face_parameterization_extractor explanation = FACE_PARAMETERIZATION elif name == 'preprocess': extractor = preprocess_extractor explanation = FACE_PARAMETERIZATION elif name == 'event': extractor = event_extractor explanation = EVENT elif name == 'video_response': extractor = video_response_extractor explanation = VIDEO_RESPONSE elif name == 'pattern_response': extractor = pattern_response_extractor explanation = PATTERN_RESPONSE elif name == 'patterns_response': extractor = patterns_response_extractor explanation = PATTERNS_RESPONSE elif name == 'first_layer': extractor = first_layer_extractor explanation = FIRST_LAYER elif name == 'second_layer': extractor = second_layer_extractor explanation = SECOND_LAYER elif name == 'assignation': extractor = assignation_extractor explanation = ASSIGNATION elif name == 'histogram': extractor = histogram_extractor explanation = HISTOGRAM elif name == "motor_behaviors": extractor = motor_behaviors_extractor explanation = MOTOR_BEHAVIORS else: print(name, 'not implemented yet') raise ValueError data, labels, ids = homogenized_description(extractor) save_variables(name, [data, labels, ids, explanation]) return data, labels, ids, explanation
def get_standard_design(preprocess = False, proba = False, small = False): save_name = 'st_design' if proba: if preprocess: save_name = 'st_design_proba' elif small: save_name = 'small_st_design_proba' else: save_name = 'st_design_all_proba' try: design, labels, ids, explanation = load_variables(save_name) except FileNotFoundError: design, labels, ids, explanation = get_standard_design( preprocess = preprocess, proba = False, small = small) design = proba_design(design) save_variables(save_name, [design, labels, ids, explanation]) else: if preprocess: save_name = 'st_design' try: design, labels, ids, explanation = load_variables(save_name) except FileNotFoundError: design, labels, ids, explanation = get_standard_design( preprocess = False, proba = False, small = False) design,explanation=preprocess_design(design,labels,explanation) save_variables(save_name, [design, labels, ids, explanation]) elif small: save_name = 'small_st_design' try: design, labels, ids, explanation = load_variables(save_name) except FileNotFoundError: design, labels, ids, explanation = get_standard_design( preprocess = False, proba = False, small = False) design, explanation = small_design(design, labels, explanation) save_variables(save_name, [design, labels, ids, explanation]) else: save_name = 'st_design_all' try: design, labels, ids, explanation = load_variables(save_name) except FileNotFoundError: names = ['second_layer', 'motor_behaviors'] designs, explanations = [], [] for name in names: design, labels, ids, explanation = get_design(name) designs.append(design) explanations.append(explanation) design, explanation = concatenate_design(designs, explanations) save_variables(save_name, [design, labels, ids, explanation]) return design, labels, ids, explanation