def model(self, param): """Метод для моделирования исходных данных""" if param[2] == "N": return distr.normal(param[0], param[1], param[3]) elif param[2] == "LN": return distr.logNormal(param[0], param[1], param[3]) elif param[2] == "R": return distr.uniform(param[0], param[1], param[3]) elif param[2] == "G": return distr.gamma(param[0], param[1], param[3]) elif param[2] == "BS": return distr.birnbaumSaunders(param[0], param[1], param[3]) elif param[2] == "P": return distr.pareto(param[0], param[1], param[3]) else: return 0
centralities = { 'Degree' : centrality.degree(network), 'Betweenness' : centrality.betweenness(network), 'Closeness' : centrality.closeness(network) } centralities['Hybrid'] = centrality.hybrid( [centralities[name] for name in centralities] ) results = 0 print '' for trial in range(numTrials): thresholds = [] if distro == 'UNIFORM': thresholds = distribution.uniform(network) elif distro == 'NORMAL': thresholds = distribution.normal(network) elif distro == 'LONGTAIL': thresholds = distribution.longtail(network, 20) else: print '\nDistribution should be UNIFORM, NORMAL, or LONGTAIL' quit() for i in range(len(thresholds)): #print 'thresholds[' + str(i) + '] = ' + str(thresholds[i]) network[i]['threshold'] = thresholds[i] if results == 0: results = {budget:{method:[] for method in centralities} for budget in budgets} for i in range(len(budgets)): budget = budgets[i]
def reward(self, employer): #かなり小さい値になると思うので、標準偏差は小さくする必要がある rw = distribution.normal((employer.remained_work() + 1) / (employer.assigned_work() + employer.processed_work() + 1), 0, 0.01) return rw
# FRANCE if __name__ == '__main__': import numpy as np import matplotlib #matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG,SOM,DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(123) samples = normal(n=N) print 'Neural Gas' np.random.seed(123) ng = NG((n,n,2)) ng.learn(samples,epochs) print 'Self-Organizing Map' np.random.seed(123) som = SOM((n,n,2)) som.learn(samples,epochs) print 'Dynamic Self-Organizing Map' np.random.seed(123) dsom = DSOM((n,n,2), elasticity=1.75) dsom.learn(samples,epochs) fig = plt.figure(figsize=(21,8))
# FRANCE if __name__ == '__main__': import numpy as np import matplotlib #matplotlib.use('Agg') import matplotlib.pyplot as plt from network import NG, SOM, DSOM from distribution import uniform, normal, ring n = 8 epochs = 20000 N = 10000 np.random.seed(123) samples = normal(n=N) print 'Neural Gas' np.random.seed(123) ng = NG((n, n, 2)) ng.learn(samples, epochs) print 'Self-Organizing Map' np.random.seed(123) som = SOM((n, n, 2)) som.learn(samples, epochs) print 'Dynamic Self-Organizing Map' np.random.seed(123) dsom = DSOM((n, n, 2), elasticity=1.75) dsom.learn(samples, epochs) fig = plt.figure(figsize=(21, 8))