def resolve_all_option_collections(self, info, **kwargs): field_map = { "option": ("option", "select"), } return helpers.optimize(OptionCollection.objects.all(), ast_to_dict(info.field_asts), field_map)
def resolve_jobs(self, args, context, info): field_map = { "buildPlatform": ("build_platform", "select"), "jobLog": ("job_log", "prefetch"), "jobType": ("job_type", "select"), "jobGroup": ("job_group", "select"), "failureClassification": ("failure_classification", "prefetch"), "failureLine": ("job_log__failure_line", "prefetch"), "group": ("job_log__failure_line__group", "prefetch"), "textLogStep": ("text_log_step", "prefetch"), "errors": ("text_log_step__errors", "prefetch"), } return helpers.optimize(Job.objects.filter(push=self, **args), ast_to_dict(info.field_asts), field_map)
def resolve_jobs(self, info, **kwargs): field_map = { "buildPlatform": ("build_platform", "select"), "jobLog": ("job_log", "prefetch"), "jobType": ("job_type", "select"), "jobGroup": ("job_group", "select"), "failureClassification": ("failure_classification", "prefetch"), "failureLine": ("job_log__failure_line", "prefetch"), "group": ("job_log__failure_line__group", "prefetch"), "textLogStep": ("text_log_step", "prefetch"), "errors": ("text_log_step__errors", "prefetch"), } return helpers.optimize(Job.objects.filter(push=self, **kwargs), ast_to_dict(info.field_asts), field_map)
def model(X_train, Y_train, X_test, Y_test, num_iter=2000, learn_rate=0.5, print_cost=False): ## PARAMETERS INIT ## w, b = init_with_zeros(X_train.shape[0]) ## GRADIENT DESCENT ## params, grads, costs = optimize(w, b, X_train, Y_train, num_iter, learn_rate, print_cost) ## RETRIEVE PARAMS ## w = params["w"] b = params["b"] ## PREDICTION ## Y_predict_test = predict(w, b, X_test) Y_predict_train = predict(w, b, X_train) print("train accuracy: {} %".format( 100 - np.mean(np.abs(Y_predict_train - Y_train)) * 100)) print( "test accuracy: {} %".format(100 - np.mean(np.abs(Y_predict_test - Y_test)) * 100)) d = { "costs": costs, "Y_predict_test": Y_predict_test, "Y_predict_train": Y_predict_train, "w": w, "b": b, "learn_rate": learn_rate, "num_iter": num_iter } return d
best_space = solution[1] best_items = solution[2] print('Best solution exercise A:') print('Wasted weight: ' + str(best_weight) + ', Wasted space: ' + str(best_space) + ', Unloaded cargo: ' + str(best_items) + '.') print('') # # opdracht B (Cargolist 1) # # loading cargo sorted by density sortedlist = sorted(cargolist, key = lambda x: [cargolist[x][2]]) helpers.ratio(cargolist, sortedlist, spacecrafts) solution = helpers.solution(spacecrafts, items) print('The solution found by sorting the cargo by density for exercise B is as follows:') print('Wasted weight: ' + str(solution[0]) + ', Wasted space: ' + str(solution[1]) + ', Unloaded cargo: ' + str(solution[2]) + '.') # # partly brute force on shortened cargolist optimized = helpers.optimize(cargolist, spacecrafts) bestscore = 10000; bestsolution = [] for bruteforce in range(0, 100000): randomlist = optimized.keys() random.shuffle(randomlist) helpers.ratio(optimized, randomlist, spacecrafts) solution = helpers.solution(spacecrafts, items) # score function score = solution[0] + 0.01 * solution[2] # remember best solution if score < bestscore: bestscore = score bestsolution = solution print("Best solution exercise B:") print('Score: ' + str(bestscore))