Example #1
0
 def onInterest_StartDE(self, prefix, interest, face, interestFilterId, filter):
     interestName = interest.getName()
     print "Interest Name: %s" %interestName
     interest_name_components = interestName.toUri().split("/")
     if "start_de" in interest_name_components:
         #print 'Query database'
         print 'Call decision engine algorithm'
         parent_dir = os.path.split(self.script_dir)[0]
         monitor_path = os.path.join(self.script_dir, parent_dir, 'Monitoring', 'Monitoring_DB')
         print monitor_path
         myDE = de(monitor_path)
         json_lst_dict = myDE.get_lst_of_dictionaries()
         json_server_Spec = self.json_server_Spec_default
         node_name = myDE.selectHost_to_deploy_firstInstance(json_lst_dict, json_server_Spec)
         print 'Selected Host Name %s' %node_name
         ### User will add this parameter via trigger
         service_name = 'uhttpd.tar'
         print 'Start service deployment'
         deployService = self.prefix_deployService + node_name + '/' + service_name
         config_prefix_deployService = Name(deployService)
         interest = Interest(config_prefix_deployService)
         interest.setInterestLifetimeMilliseconds(self.interestLifetime)
         interest.setMustBeFresh(True)
         self.face.expressInterest(interest, None, None)  ## set None --> sent out only, don't wait for Data and Timeout
         print "Sent Push Interest to SEG %s" % config_prefix_deployService
     else:
         print "Interest name mismatch"
Example #2
0
def func(Dimension_number):
    Time = []
    for i in range(Dimension_number):
        Fn = 20  # Function to be evaluated
        Dimension = i + 1

        popsize = 20
        mut = 0.9
        crossp = 0.9
        iter_max = 1500
        func_eval = fobj  # func to be evaluated
        ca = 512

        # Execution
        start = time.time()
        target, fitness = de(func_eval, mut, crossp, popsize, iter_max, Fn, ca,
                             Dimension)
        end = time.time()
        Time.append(end - start)
        print('Time taken to Execute this code = {} seconds'.format(end -
                                                                    start))

    return Time
Example #3
0
num_input = 15
num_hidden = 60
num_output = 6

weight_interval = 2000
pop_size = 200
gen_limit = 500

inps = loader.load('paru.xlsx')
inps = loader.stringifyVar(inps,loader.normalizeVar(loader.getVar(inps)))
# inps = loader.loadDat('titanic.dat')

start = time.time()

weights = ann.decodeWeights(de.de((num_output*num_hidden)+(num_hidden*num_input),weight_interval,pop_size,gen_limit))

end = time.time()
print end - start

<<<<<<< HEAD
# match = 0
# for i in range(len(inps)):
# 	if(ann.correct(inps[i],weights)):
# 		match += 1
# print match,len(inps)

# print num_hidden,weight_interval,pop_size,gen_limit,'ret = 1/(1+np.exp((-0.001*x)))'
=======
num_input = 3
num_hidden = 10
Example #4
0
import time
from de import de
from func import fobj
from figure_plot import figure_plot
import matplotlib.pyplot as plt

# Inputs

Fn = 3  # Function to be evaluated
popsize = 50
mut = 0.9
crossp = 0.9
iter_max = 25
func_eval = fobj  # func to be evaluated
ca = 512

# Execution
start = time.time()
target, fitness = de(func_eval, mut, crossp, popsize, iter_max, Fn, ca)
end = time.time()

print('Time taken to Execute this code = {} seconds'.format(end - start))

if len(target[0]) == 2:
    plt.title('Target vector after {} iteration'.format(
        iter_max))  # plot for reference
    figure_plot(target, popsize, Fn, ca)  # comment if unnecessary
Example #5
0
import time
from de import de
from func import fobj
from figure_plot import figure_plot
import matplotlib.pyplot as plt

# Inputs

Fn           = 11                                                               # Function to be evaluated
popsize      = 20
mut          = 0.9
crossp       = 0.9
iter_max     = 50
func_eval    = fobj                                                           # func to be evaluated
ca =512
# Execution
start = time.time()
a , b  = de(func_eval, mut, crossp, popsize, iter_max, Fn,ca)
end = time.time()

print('Time taken to Execute this code = {} seconds'.format(end - start))

if len(a[0]) == 2:
    plt.title('Target vector after {} iteration'.format(iter_max))             # plot for reference 
    figure_plot(a , popsize ,Fn,ca )                                                  # comment if unnecessary
                SBX_parents[j][1],
                c=parent_color,
                s=parent_size)
plt.xticks([])
plt.yticks([])
plt.title('Simulated Binary Crossover')

# create DE plot
plt.subplot(232)
for j in range(len(DE_parents)):
    plt.scatter(DE_parents[j][0],
                DE_parents[j][1],
                c=parent_color,
                s=parent_size)
for i in range(10):
    (cx, cy) = de.de(DE_parents, DE_crossover_rate, DE_scaling_factor)
    plt.scatter(cx, cy, c=child_color, s=child_size)
plt.xticks([])
plt.yticks([])
plt.title('Differential Evolution')

# create UM plot
plt.subplot(233)
for i in range(num_samples):
    child = um.um(UM_parent, bounds, UM_probability)
    plt.scatter(child[0], child[1], c=child_color, s=child_size)
plt.scatter(UM_parent[0], UM_parent[1], c=parent_color, s=parent_size)
plt.axhline(y=UM_parent[1], xmin=bounds[0][0], xmax=bounds[0][1], c='black')
plt.axvline(x=UM_parent[0], ymin=bounds[1][0], ymax=bounds[1][1], c='black')
plt.xticks([])
plt.yticks([])
Example #7
0
import loader
import ann
import de
import time

num_input = 15
num_hidden = 60
num_output = 6

inps = loader.load('paru.xlsx')
inps = loader.stringifyVar(inps,loader.normalizeVar(loader.getVar(inps)))
# inps = loader.loadDat('titanic.dat')
# print inps

start = time.time()
weights = ann.decodeWeights(de.de((num_output*num_hidden)+(num_hidden*num_input),2000,200,3,0.5,0.5,10))

end = time.time()
print end - start
# # print weights
# # print inps[0]
# match = 0
# for i in range(len(inps)):
# 	if(ann.correct(inps[i],weights)):
# 		match += 1
# print match,len(inps)
# print num_hidden,2000,500,'ret = 1/(1+np.exp((-0.001*x)))'
Example #8
0
import loader
import jst
import de
import sys
import numpy as np

num_input = int(sys.argv[1])
num_hidden = int(sys.argv[2])
num_output = int(sys.argv[3])

weight_interval = int(sys.argv[4])
pop_size = int(sys.argv[5])
gen_limit = int(sys.argv[6])

data_learning = sys.argv[7]

format = data_learning[-4:-1]+data_learning[-1]

save_weights_to = sys.argv[8]

if (format == '.dat'):
	inps = loader.loadDat(data_learning)
elif (format == '.csv'):
	inps = loader.loadCsv(data_learning)

inps = loader.stringifyVar(inps,loader.normalizeVar(loader.getVar(inps)))

weights = de.de((num_output*num_hidden)+(num_hidden*num_input),weight_interval,pop_size,gen_limit,num_input,num_hidden,num_output,data_learning)

np.savetxt(save_weights_to, np.array(weights), delimiter=',')