def submit_vector(): # best_vec = [] # GET THE VALUE HERE best_vecs = [{ 'vector': [ -1.5900117634696895e-18, -1.1089152508024613e-12, -2.5448264472393646e-13, 5.156495819895334e-11, -1.4685999507818116e-10, -1.7336464013051853e-15, 7.588385881788844e-16, 2.7525165125385616e-05, -1.8852756204130466e-06, -1.5953841373151045e-08, 8.741325830954951e-10 ], 'results': [116101460426.6661, 87860031424.50586], 'generation': 32 }] i = 0 f = open("last_vector_8th.txt", "a") for best_vec in best_vecs: # break x = submit(TEAM_KEY, best_vec["vector"]) print(x) rank = input() # SAVING THE VECTOR IN LAST VECTOR f.write(str(best_vec)) f.write("\n") f.write(rank) f.write("\n") # IF THIS VECTOR GETS THE BEST RANK YET, DO: # bash save_this_vector.sh f.close()
def main(): np.set_printoptions(formatter={'float_kind':'{:f}'.format}) population = generate_population() while 1: fitness = fitness_function(population) np.save('example',population) np.save('error',fitness) print(population,fitness) offspring = np.zeros((16,11)) offspring[0:2]= sel.rank_selection(population,fitness) offspring[0:2]= sel.rank_selection2(population,fitness) for i in range(4,10): offspring[i] = mut.random_setting_mutation(offspring[rand.randint(0,4)]) for i in range(10,16): first = rand.randint(0,4) second = rand.randint(0,4) while first is not second: second = rand.randint(0,4) offspring[i] = cs.mutation_crossover(np.array([offspring[first],offspring[second]])) population = np.copy(offspring) print(cl.submit(key,np.ndarray.tolist(offspring[0]))) print(cl.submit(key,np.ndarray.tolist(offspring[1]))) print(cl.submit(key,np.ndarray.tolist(offspring[2]))) print(cl.submit(key,np.ndarray.tolist(offspring[3])))
def clean(self, values): super(ReCaptchaField, self).clean(values[1]) recaptcha_challenge_value = smart_unicode(values[0]) recaptcha_response_value = smart_unicode(values[1]) if settings.DEBUG and recaptcha_response_value == 'PASSED': return values[0] check_captcha = client.submit(recaptcha_challenge_value, \ recaptcha_response_value, private_key=self.private_key, \ remoteip=self.get_remote_ip(), use_ssl=self.use_ssl) if not check_captcha.is_valid: raise forms.util.ValidationError( self.error_messages['captcha_invalid'] ) return values[0]
def clean(self,values): ''' values[0]= requestID values[1]= codefromuser ''' super(NexmoField, self).clean(values[1]) nexmo_challenge_value = smart_unicode(values[1]) request_id=smart_unicode(values[0]) try: responce = client.submit( request_id, nexmo_challenge_value) except socket.error: # Catch timeouts, etc raise ValidationError( 'network error' ) if responce.status!=0: raise ValidationError( responce.error_text ) return values[1]
generation = Gene.generate_population(POPULATION_SIZE) assert all([type(person) is Gene for person in generation]) for i in range(ITERATIONS): print('****************************') couples = Gene.pairing(generation) children = Gene.mating(couples) generation = Gene.selection(generation + children) assert all([type(person) is Gene for person in generation]) # Checking if the change in hyperparameters is useful print("Best Soln : ") print(BEST_WEIGHTS, BEST_ERROR) # Submitting it regardless client.submit(SECRET_KEY, list(BEST_WEIGHTS)) # ## Sample Ouput # # The format is [gene] , training error, validation error. # # A single generation output is : # # [ 0.00000000e+00 1.24051937e-01 -6.21157191e+00 4.93390104e-02<br> # 3.81066382e-02 8.13198767e-05 -6.01791626e-05 -1.25163350e-07<br> # 3.48379719e-08 4.16166196e-11 -6.73266866e-12] 79068.35618656754 3625009.2445584373<br> # # [ 0.00000000e+00 2.48074052e-01 -6.21227586e+00 4.93420788e-02<br> # 3.81088826e-02 8.13320094e-05 -6.01862275e-05 -1.25174854e-07<br> # 3.48411764e-08 4.16121405e-11 -6.73257744e-12] 78564.99206532972 3599264.6284862114<br> #
# ] # tempv = [ # -0.010352359899980625, # -1.4938708798725434e-12, # -2.1344537013801585e-13, # 4.754606122495976e-11, # -1.7513765845712067e-10, # -2.9750369207778414e-20, # 2.216842207753494e-20, # 8.683381211976487e-15, # -6.662021179304016e-09, # -2.6599123253785434e-14, # 3.026701227755296e-17 # ] # tempv = [ # -0.00924596659365373, # -1.494818150350766e-12, # -2.211532640173319e-13, # 5.039657579364812e-11, # -1.6753978508012588e-10, # -9.080082588227132e-25, # 7.257195414468184e-26, # 4.605087763217074e-20, # -1.3071635934940838e-11, # -1.4401903358063287e-17, # 2.7501251088023155e-21 # ] server.submit(TEAM_ID, tempv) # In[ ]:
def runEvolution(self, steps: int) -> None: """Run step iterations of genetic algorithm""" population = self.initializePopulation() for iteration in range(steps): fitness, testFitness = self.calculateFitness(population) sortedIndices = (abs(fitness + testFitness)).argsort() population = population[sortedIndices] fitness = fitness[sortedIndices] testFitness = testFitness[sortedIndices] print("Fitness: ", np.array([fitness[0]])) print("Test Fitness: ", np.array([testFitness[0]])) print("Vector: ", population[0]) # print("\n", population[0]) submit(population.tolist()[0]) with open("generations.txt", "a") as outfile: pprint( f"-----------GENERATION: {iteration}--------------", stream=outfile, ) pprint(population, stream=outfile) pprint( f"---Train Fitness: {iteration}---", stream=outfile, ) pprint(fitness, stream=outfile) pprint( f"---Test Fitness: {iteration}---", stream=outfile, ) pprint(testFitness, stream=outfile) input() # Gurantee that top two will be selected without any mutation or # crossover: 9 = 8 + 1 nextGeneration = population[:1] nonMutatedNextGen = population[:1] for crossoverIteration in range(self.populationSize): # Select two parents from population index_a, index_b = self.selectTwo(population) # Cross them offspring_a, offspring_b = self.crossOver( population[index_a], population[index_b], fitness[index_a], fitness[index_b], ) nonMutatedNextGen = np.concatenate( (nonMutatedNextGen, [offspring_a, offspring_b]), axis=0 ) # Mutate offspring_a = self.mutateOffspring(offspring_a) offspring_b = self.mutateOffspring(offspring_b) # Add to next generation nextGeneration = np.concatenate( (nextGeneration, [offspring_a, offspring_b]), axis=0 ) population = nextGeneration[:self.populationSize] with open("generations.txt", "a") as outfile: pprint( f"---After crossover population: {iteration}---", stream=outfile, ) pprint(nonMutatedNextGen, stream=outfile) pprint( f"---After mutation population: {iteration}---", stream=outfile, ) pprint(nextGeneration, stream=outfile) pprint( f"---After Selection population: {iteration}---", stream=outfile, ) pprint(population, stream=outfile)
-1.155594498963827e-06, -1.4123701076309361e-09, 4.27567136105673e-10 ] # "errorTuple": [ # 39607118493.38789, # 82107826837.5237 # ] 8 star v = [ -1.2011582262254875e-22, -4.841884920942542e-13, -3.3920520574732524e-13, 5.7520186415565817e-11, -1.2165314793847423e-09, -2.732620328430599e-16, 7.837772952003539e-17, 6.543320242559382e-06, -1.1555982661911288e-06, -1.1821086653098595e-09, 4.199995041318772e-10 ] # "errorTuple": [ # 41208277820.35068, # 97512445787.4025 # ] 19 res = client.submit(secrets.KEY, v) print(res)
# -1.83977009e-10, -1.47605324e-15, 7.40791508e-16, 2.41394471e-05, # -1.90069755e-06, -1.58002421e-08, 9.01600023e-10] #[ 0.00000000e+00, -1.43185174e-12, -2.71229788e-13, 4.15487720e-11, # -1.74740805e-10, -1.49297563e-15, 7.57681374e-16, 2.38883785e-05, # -1.87813527e-06, -1.60177440e-08, 8.96744048e-10] #[ 0.00000000e+00, -1.50721525e-12, -2.38330355e-13, 4.60972509e-11, # -1.89423828e-10, -1.73086769e-15, 9.13556565e-16, 2.42086504e-05, # -1.99153311e-06, -1.49579921e-08, 9.24081436e-10] #[ 0.00000000e+00, -1.56391135e-12, -2.44028674e-13, 3.93282451e-11, # -1.83236407e-10, -1.63784812e-15, 8.96217971e-16, 2.54014231e-05, # -1.99701550e-06, -1.52996086e-08, 9.21303663e-10] #best: best-submission-7 # [ 0.00000000e+00, -1.55976128e-12, -2.34784495e-13, 4.29084694e-11, # -1.89954128e-10, -1.61562430e-15, 8.62092675e-16, 2.42243848e-05, # -1.99597630e-06, -1.47379698e-08, 9.22303588e-10] #[ 0.00000000e+00,-1.20706058e-12, -2.32612320e-13 , 4.50071868e-11, # -1.88160202e-10, -1.85757143e-15, 8.83139750e-16, 2.49351778e-05, # -1.90201334e-06, -1.75150969e-08, 9.37418225e-10] #best: #[ 0.00000000e+00, -1.56391135e-12, -2.44028674e-13, 3.93282451e-11, # -1.83236407e-10, -1.63784812e-15, 8.96217971e-16, 2.54014231e-05, # -1.99701550e-06, -1.52996086e-08, 9.21303663e-10] print( client.submit('GU0MCOlKFoi0lk7HmBpwjhFGlcTTZvO77FA3FVMq0m4lYCMIho', weights))
import client import constants v = [ -1.3675704081705325e-09, -4.08138881979391e-13, -2.5005644219889285e-10, 4.662859881370373e-12, 6.150047217005676e-12, -9.161738820014592e-16, 7.340163120738338e-10, 5.018644203347845e-06, -1.2133184934354136e-06, -6.572866429792964e-10, 4.4955546296023274e-10, ] res = client.submit(constants.SECRET_KEY, v) print(res)
wt2 = [ 9.913269136508803e-19, -1.3651432220474988e-12, -2.298198393159188e-13, 5.0168495585679045e-11, -1.9142692264536784e-10, -5.708139268721448e-16, 9.222307658340838e-16, 3.2077307818350485e-05, -2.1023487765642816e-06, -1.3862270237706852e-08, 8.640892314427145e-10 ] wt2 = [ 9.915672591936594e-19, -1.3654972148183978e-12, -2.3013915250437e-13, 5.0202893139928207e-11, -1.9197681316495378e-10, -5.695747268129501e-16, 9.247415970198904e-16, 3.204237015306432e-05, -2.0963811355424884e-06, -1.3922304080398685e-08, 8.619693246341732e-10 ] # wt2 = [9.919603226020886e-19, -1.3643039330187416e-12, -2.300025187475665e-13, 5.01420607948874e-11, -1.9171213875705204e-10, -5.704916302387945e-16, 9.249323842424032e-16, 3.2018325502112234e-05, -2.092484885878187e-06, -1.3842788049128266e-08, 8.640308071699504e-10] # wt2 = [1.0152006490722198e-18, -1.2675221413533424e-12, -2.219456862667535e-13, 5.2746185700513954e-11, -2.048741688083159e-10, -5.906269772197416e-16, 9.464899300647767e-16, 3.105910784304104e-05, -2.055769267289396e-06, -1.6494805651419324e-08, 9.224439203791275e-10] status = server.submit(TEAM_ID, list(wt2)) print(status) # for i in range(10): # weights[7] -= 0.02e-05 train_err, valid_err = server.get_errors(TEAM_ID, list(wt2)) tot_err = train_err + valid_err # print(wt2) print('fitness:') print("{:e}".format(-tot_err), "{:e}".format(train_err), "{:e}".format(valid_err)) # INITIAL_WEIGHTS = [1.0016758736507022e-18, -1.3696155264603411e-12, -2.300768584393704e-13, 4.617028826499339e-11, -1.7627848513209744e-10, -1.7730847899381538e-15, 8.38639892842589e-16, 2.2778568625222342e-05, -1.9784050209132108e-06, -1.5846641527483793e-08, 9.522475355911996e-10]