main.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. __author__ = "Olivier Vu thanh"
  2. __email__ = "olivier.vu-thanh@grenoble-inp.org"
  3. '''
  4. Run "python main.py --config_file=config.json"
  5. Available calibration methods are : emwnenmf (EM-W-NeNMF from [quote paper])
  6. : coming soon...
  7. '''
  8. import numpy as np
  9. import argparse
  10. import json
  11. from dataCreator import dataCreator
  12. # from calibrationStatistics import calibrationStatistics
  13. # from calibrationMethods.emwnenmf_updateinsideNNLS import emwnenmf
  14. # from calibrationMethods.emwnenmf_seprestart import emwnenmf
  15. from calibrationMethods.incal import incal
  16. from calibrationMethods.emwnenmf import emwnenmf
  17. from calibrationMethods.emwnenmf_comp import emwnenmf_comp
  18. from calibrationMethods.emwnenmf_restart import emwnenmf_restart
  19. from calibrationMethods.emwnenmf_break import emwnenmf_break
  20. from calibrationMethods.emwamsgrad import emwamsgrad
  21. from calibrationMethods.muem import muem
  22. from calibrationMethods.emwfnnls import emwfnnls
  23. from calibrationMethods.emwmunmf import emwmunmf
  24. from calibrationMethods.emwnenmf_m import emwnenmf_m
  25. from save2dat import save2dat
  26. print('Work in progress')
  27. '''
  28. Get the config (json) file, see "config.json" for default one
  29. '''
  30. parser = argparse.ArgumentParser(description='Parse location of config file (json).')
  31. parser.add_argument('--config_file', type=str, default='config.json',
  32. help='path to json config file, see config.json for default')
  33. args = parser.parse_args()
  34. with open(args.config_file) as json_data_file:
  35. config = json.load(json_data_file)
  36. '''
  37. Main loop
  38. '''
  39. data = dataCreator(config['sceneWidth'],
  40. config['sceneLength'],
  41. config['numSensor'],
  42. config['numRef'],
  43. config['rdvR'],
  44. config['mvR'],
  45. config['phenLowerBound'],
  46. config['phenUpperBound'],
  47. config['Mu_beta'],
  48. config['Mu_alpha'],
  49. config['Bound_beta'],
  50. config['Bound_alpha'])
  51. m = data.numArea
  52. n = data.numSensor + 1
  53. RMSE = {}
  54. T = {}
  55. for method in config['calibrationMethods']:
  56. RMSE.update({method: []})
  57. T.update({method: []})
  58. for run in range(config['numRuns']):
  59. data.create_scene(run+5)
  60. # ONLY EMWNENMF AND INCAL HAVE BEEN CODED FOR NOW
  61. print('run : ' + str(run))
  62. for method in config['calibrationMethods']:
  63. print('method : ' + method)
  64. calMethod = locals()[method]
  65. res = calMethod(data, data.Ginit, data.Finit, config['r'], config['Tmax'])
  66. if run == 0:
  67. RMSE[method] = res['RMSE']
  68. T[method] = res['T']
  69. else:
  70. RMSE[method] = np.vstack((RMSE[method], res['RMSE']))
  71. T[method] = np.vstack((T[method], res['T']))
  72. print('RMSE : ' + str(res['RMSE'][0][-1]) + ' ' + str(res['RMSE'][1][-1]))
  73. if config['save2dat']:
  74. save2dat(RMSE, T, config['calibrationMethods'], config['numRuns'])