# -*- coding: utf-8 -*- """ Created on Tue Jun 5 10:50:24 2018 @author: thomas """ import glob from complexity import complexity, to_table if __name__ == "__main__": dir_shapes = ".\\shapes\\*.shp" dir_img = ".\\images\\*.png" shapes = glob.glob(dir_shapes) images = glob.glob(dir_img) coeff_ampl, coeff_conv = 0.8, 0.2 #Export to latex filename = "complexity.tex" tablefmt = "latex_raw" str_img = "\includegraphics[width=1cm]{{figures/{}.png}}" gdf = complexity(shapes, images, coeff_ampl, coeff_conv, str_img) to_table(gdf, tablefmt, filename, str_img) #Export to html filename = "complexity.html" tablefmt = "html" str_img = '<img src=".//images//{}.png" style="width:10%;">' to_table(gdf, tablefmt, filename, str_img)
def test_complexity(self): #test for complexity word8 = 'this text is simple and short' self.assertEqual(complexity.complexity(word8), 0.0) word9 = 'whether longer sentences or more words indicate greater complexity' self.assertEqual(complexity.complexity(word9), 0.1)
vprint( verbose, "[-] Sorry, time budget exceeded, skipping this task") execution_success = False continue # ========= Creating a model ========== vprint( verbose, "======== Creating model ==========") training_data = D.load_training_data() complexity_value = {} for mid in D.model_ids: if time_exceeded: complexity_value[mid] = 'EXCEEDED' continue tf.keras.backend.clear_session() model = D.load_model(mid) measure_val = complexity(model, training_data) try: measure_val = float(measure_val) except: raise TypeError('Measure should be a scalar float or numpy float but got type: {}'.format(type(measure_val))) complexity_value[mid] = measure_val time_left_over = time_budget - time.time() + start if time_left_over <= 0: time_exceeded = True if verbose: print(complexity_value) if time_exceeded: vprint(verbose, "[+] Time exceeded: time limit is {} but program has run for {}".format(time_budget, time.time() - start)) else:
# ========= Creating a model ========== vprint(verbose, "======== Creating model ==========") training_data = D.load_training_data() complexity_value = {} for mid in D.model_ids: if time_exceeded: complexity_value[mid] = 'EXCEEDED' continue tf.keras.backend.clear_session() model = D.load_model(mid) if should_pass_submission_dir: measure_val = complexity(model, training_data, program_dir=submission_dir) else: measure_val = complexity(model, training_data) try: measure_val = float(measure_val) except: print('Incorrect measure data type!') raise TypeError( 'Measure should be a scalar float or numpy float but got type: {}' .format(type(measure_val))) complexity_value[mid] = measure_val time_left_over = time_budget - time.time() + start if time_left_over <= 0:
def complexity(self, data): self.complexity = complexity.complexity(data)