Random Search in hyperparam
This commit is contained in:
parent
ad1205121d
commit
87a50c1342
@ -365,42 +365,46 @@ def mutation_random_search(individual, **kwargs):
|
|||||||
:param pmut: individual probability o
|
:param pmut: individual probability o
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
import copy
|
||||||
|
|
||||||
|
new = copy.deepcopy(individual)
|
||||||
|
|
||||||
vars = kwargs.get('variables', None)
|
vars = kwargs.get('variables', None)
|
||||||
tvar = kwargs.get('target_variable', None)
|
tvar = kwargs.get('target_variable', None)
|
||||||
l = len(vars)
|
l = len(vars)
|
||||||
|
|
||||||
il = len(individual['explanatory_variables'])
|
il = len(new['explanatory_variables'])
|
||||||
#
|
#
|
||||||
if il > 1:
|
if il > 1:
|
||||||
for l in range(il):
|
for l in range(il):
|
||||||
il = len(individual['explanatory_variables'])
|
il = len(new['explanatory_variables'])
|
||||||
rnd = random.uniform(0, 1)
|
rnd = random.uniform(0, 1)
|
||||||
if rnd > .5:
|
if rnd > .5:
|
||||||
rnd = random.randint(0, il-1)
|
rnd = random.randint(0, il-1)
|
||||||
val = individual['explanatory_variables'][rnd]
|
if rnd < il and il > 1:
|
||||||
individual['explanatory_variables'].remove(val)
|
val = individual['explanatory_variables'][rnd]
|
||||||
individual['explanatory_params'].pop(rnd)
|
new['explanatory_variables'].remove(val)
|
||||||
|
new['explanatory_params'].pop(rnd)
|
||||||
else:
|
else:
|
||||||
rnd = random.randint(0, l-1)
|
rnd = random.randint(0, l-1)
|
||||||
while rnd in individual['explanatory_variables']:
|
while rnd in new['explanatory_variables']:
|
||||||
rnd = random.randint(0, l-1)
|
rnd = random.randint(0, l-1)
|
||||||
individual['explanatory_variables'].append(rnd)
|
new['explanatory_variables'].append(rnd)
|
||||||
individual['explanatory_params'].append(random_param(vars[rnd]))
|
new['explanatory_params'].append(random_param(vars[rnd]))
|
||||||
|
|
||||||
for ct in np.arange(len(individual['explanatory_variables'])):
|
for ct in np.arange(len(new['explanatory_variables'])):
|
||||||
rnd = random.uniform(0, 1)
|
rnd = random.uniform(0, 1)
|
||||||
if rnd > .5:
|
if rnd > .5:
|
||||||
mutate_variable_params(individual['explanatory_params'][ct], vars[ct])
|
mutate_variable_params(new['explanatory_params'][ct], vars[ct])
|
||||||
|
|
||||||
rnd = random.uniform(0, 1)
|
rnd = random.uniform(0, 1)
|
||||||
if rnd > .5:
|
if rnd > .5:
|
||||||
mutate_variable_params(individual['target_params'], tvar)
|
mutate_variable_params(new['target_params'], tvar)
|
||||||
|
|
||||||
individual['f1'] = None
|
new['f1'] = None
|
||||||
individual['f2'] = None
|
new['f2'] = None
|
||||||
|
|
||||||
return individual
|
return new
|
||||||
|
|
||||||
|
|
||||||
def mutate_variable_params(param, var):
|
def mutate_variable_params(param, var):
|
||||||
|
@ -66,9 +66,7 @@ def execute( dataset, **kwargs):
|
|||||||
new[key] = ret[key]
|
new[key] = ret[key]
|
||||||
new_stat[key] = ret[key]
|
new_stat[key] = ret[key]
|
||||||
|
|
||||||
print(new)
|
if new['f1'] < individual['f1'] or (new['f1'] == individual['f1'] and new['f2'] < individual['f2']):
|
||||||
|
|
||||||
if new['f1'] <= individual['f1'] and new['f2'] <= individual['f2']:
|
|
||||||
individual = new
|
individual = new
|
||||||
no_improvement_count = 0
|
no_improvement_count = 0
|
||||||
stat[i] = new_stat
|
stat[i] = new_stat
|
||||||
|
@ -58,7 +58,7 @@ target_variable = {'name': 'Load', 'data_label': 'load', 'type': 'common'}
|
|||||||
nodes=['192.168.28.38']
|
nodes=['192.168.28.38']
|
||||||
|
|
||||||
deho_mv.random_search(datsetname, dataset,
|
deho_mv.random_search(datsetname, dataset,
|
||||||
ngen=200, mgen=200,
|
ngen=200, mgen=70,
|
||||||
window_size=2000, train_rate=.9, increment_rate=1,
|
window_size=2000, train_rate=.9, increment_rate=1,
|
||||||
experiments=1,
|
experiments=1,
|
||||||
fts_method=wmvfts.WeightedMVFTS,
|
fts_method=wmvfts.WeightedMVFTS,
|
||||||
|
Loading…
Reference in New Issue
Block a user