def main(): speedKn = 4 # sailing 18 hours a day, 1.852 km is a knot ~~ 90 km per day speedKmDay = speedKn*1.852*18 costFile = '../data/costMatrix.csv' sitesFile = '../data/cities_weights.csv' baseCost = entropy.loadLandCostsInMeters(costFile) sites = entropy.loadHistoricalSites(sitesFile) seaCostFile = '../data/costMatrixSea.csv' seaCost = open(seaCostFile, 'w') seaCost.write('code;cost\n') for fromSite in sites: print('checking sea connections for:',fromSite) for toSite in sites: code = str(fromSite.ident)+'_'+str(toSite.ident) if toSite is fromSite: seaCost.write(code+';0\n') continue # write land values elif not fromSite.isHarbour or not toSite.isHarbour: seaCost.write(code+';'+str(entropy.Site.cost[code])+'\n') continue print('\tfrom:',fromSite.ident,'to:',toSite.ident,'sea connection') distance = math.sqrt(math.pow(toSite.x-fromSite.x,2)+math.pow(toSite.y-fromSite.y,2))/1000 travelDays = distance/speedKmDay print('\tland cost',entropy.Site.cost[code],'sea cost:',travelDays,'with distance:',distance) finalDist = min(travelDays, entropy.Site.cost[code]) seaCost.write(code+';'+str(finalDist)+'\n') seaCost.close()
def singleRun(): # values for best run alpha = 0.98397717 beta = 0.02777806 harbourBonus = 4.01043467 # weights = [100, 24, 38, 12, 10.020869332157805, 445.9286852810223, 93, 96, 60.125215992946828, 140.29217065020927, 64, 7, 28, 1, 47, 56, 44, 90, 10, 15, 78, 15, 55, 100.20869332157804, 12, 17, 486.0121626096535, 16, 52, 41, 79, 10.020869332157805, 30, 10.020869332157805, 360.75129595768095, 24, 370.77216528983877, 69, 17, 1, 24, 53, 95, 26, 28, 87, 14, 68, 51, 57, 33, 37, 67, 47, 16, 55.114781326867927, 24, 73, 42, 34, 21, 165.34434398060378, 43, 72, 215.4486906413928, 255.53216797002401, 135.28173598413036, 65.135650659025728, 70.146085325104636, 26, 98, 65.135650659025728, 270.56347196826073, 65.135650659025728, 250.52173330394513, 265.55303730218179, 44, 52, 440.91825061494342, 70.146085325104636, 95.198258655499146, 71, 79, 330.68868796120756, 98, 215.4486906413928, 40, 70, 73, 30, 160.33390931452487, 89, 18, 34, 435.90781594886448, 20.041738664315609, 60, 34, 95.198258655499146, 62, 17, 100, 72, 345.71999195944426, 40, 130.27130131805146, 41, 46, 22, 115.23999731981475, 70.146085325104636, 81, 61, 100.20869332157804, 405.84520795239109, 95.198258655499146, 86, 6, 55, 33, 460.95998927925899, 66, 10, 41, 93, 400.83477328631216, 55, 72, 87, 180.37564797884048, 54, 9, 470.98085861141681, 70.146085325104636, 98, 295.61564529865524, 65.135650659025728, 90, 481.00172794357462, 66] entropy.loadCosts('../data/costMatrixSea.csv') sites = '../data/cities_weights.csv' data = entropy.loadHistoricalSites(sites) # weights = np.full(len(data), 1) experiment = entropy.Experiment(0,alpha,beta,harbourBonus, None) result = entropy.runEntropy(experiment, sites, True) dist = entropy.distAbs(data, result)
def singleRun(): # values for best run alpha = 0.98397717 beta = 0.02777806 harbourBonus = 4.01043467 # weights = [100, 24, 38, 12, 10.020869332157805, 445.9286852810223, 93, 96, 60.125215992946828, 140.29217065020927, 64, 7, 28, 1, 47, 56, 44, 90, 10, 15, 78, 15, 55, 100.20869332157804, 12, 17, 486.0121626096535, 16, 52, 41, 79, 10.020869332157805, 30, 10.020869332157805, 360.75129595768095, 24, 370.77216528983877, 69, 17, 1, 24, 53, 95, 26, 28, 87, 14, 68, 51, 57, 33, 37, 67, 47, 16, 55.114781326867927, 24, 73, 42, 34, 21, 165.34434398060378, 43, 72, 215.4486906413928, 255.53216797002401, 135.28173598413036, 65.135650659025728, 70.146085325104636, 26, 98, 65.135650659025728, 270.56347196826073, 65.135650659025728, 250.52173330394513, 265.55303730218179, 44, 52, 440.91825061494342, 70.146085325104636, 95.198258655499146, 71, 79, 330.68868796120756, 98, 215.4486906413928, 40, 70, 73, 30, 160.33390931452487, 89, 18, 34, 435.90781594886448, 20.041738664315609, 60, 34, 95.198258655499146, 62, 17, 100, 72, 345.71999195944426, 40, 130.27130131805146, 41, 46, 22, 115.23999731981475, 70.146085325104636, 81, 61, 100.20869332157804, 405.84520795239109, 95.198258655499146, 86, 6, 55, 33, 460.95998927925899, 66, 10, 41, 93, 400.83477328631216, 55, 72, 87, 180.37564797884048, 54, 9, 470.98085861141681, 70.146085325104636, 98, 295.61564529865524, 65.135650659025728, 90, 481.00172794357462, 66] entropy.loadCosts('../data/costMatrixSea.csv') sites = '../data/cities_weights.csv' data = entropy.loadHistoricalSites(sites) # weights = np.full(len(data), 1) experiment = entropy.Experiment(0, alpha, beta, harbourBonus, None) result = entropy.runEntropy(experiment, sites, True) dist = entropy.distAbs(data, result)
import numpy as np import entropy import os import sys def postfn(params): # print('postfn, params:',params) entropy.loadCosts('../data/costMatrixSea.csv') sites = '../data/cities_weights.csv' experiment = entropy.Experiment(0, params[0], params[1], params[2]) simSites = entropy.runEntropy(experiment, sites, False) return simSites sites = '../data/cities_weights.csv' data = entropy.loadHistoricalSites(sites) eps = threshold.LinearEps(15, 200, 150) priors = sampler.TophatPrior([0,0,0],[2,2,10]) sampler = sampler.Sampler(N=200, Y=data, postfn=postfn, dist=entropy.distRelative, threads=16) for pool in sampler.sample(priors, eps): print("T: {0}, eps: {1:>.4f}, ratio: {2:>.4f}".format(pool.t, pool.eps, pool.ratio)) for i, (mean, std) in enumerate(zip(np.mean(pool.thetas, axis=0), np.std(pool.thetas, axis=0))): print(u" theta[{0}]: {1:>.4f} \u00B1 {2:>.4f}".format(i, mean,std)) np.savetxt("result_"+str('%.2f')%pool.eps+'.csv', pool.thetas, delimiter=";", fmt='%1.5f') print(pool.thetas) np.savetxt("foo.csv", pool.thetas, delimiter=";", fmt='%1.5f')