Advertisement
Guest User

main.py

a guest
Jul 6th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import numpy as np
  2. import test as t
  3. import itertools
  4. from multiprocessing import Pool
  5.  
  6. #Define the range of parameters 'alpha' and 'beta'.
  7. alpha, beta = np.arange(1,4), np.arange(1,4)
  8.  
  9. def calc(x):
  10.     i = alpha.tolist().index(x[0])
  11.     j = beta.tolist().index(x[1])
  12.    
  13.     #The print statement tests what values of a, b it sees.
  14.     print (t.a, t.b)
  15.     #New values for a, b are set and used to calculate t.f(s).
  16.     t.a, t.b = x[0], x[1]
  17.     return (i, j, t.f(2))
  18.  
  19. if __name__ == '__main__':
  20.     #Storage array for the results.
  21.     data = np.zeros((len(alpha), len(beta)))
  22.    
  23.     it = itertools.product(alpha, beta)
  24.     pool = Pool(processes=2)
  25.     results = pool.map(calc, it)
  26.     #Constructing data from results.
  27.     def constr(x):
  28.         i, j, res = x
  29.         #alpha index correspond to columns, beta index to rows.
  30.         data[i, j] = res
  31.     map(constr, results)
  32.     pool.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement