Evaluation.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from CertainTrust import Opinion
  2. from CSVReader import CSVReader
  3. class Evaluator:
  4. @staticmethod
  5. def evaluate_system(packagefile, months):
  6. '''
  7. Evaluates a system, based on its packages and months to evaluate
  8. :param packagefile: packages installed on the system
  9. :param months: for how many months the prediction is done
  10. :return: system evaluation
  11. '''
  12. packages=CSVReader.readCSVPackages(packagefile)
  13. model=CSVReader.readCSVModel(months)
  14. system={}
  15. for p in packages:
  16. if p in model:
  17. system[p]=model[p]
  18. return Opinion._cum_and(list(system.values()))
  19. @staticmethod
  20. def fuse_models_equal_weights(*models):
  21. '''
  22. Fuses models , assume models have equal lists of packages
  23. :param models: list of model-dictionaries
  24. :return: fused model-dictionary
  25. '''
  26. result_dict = {}
  27. package_list = list(models[0].keys())
  28. for p in package_list:
  29. # get list of items to fuse
  30. p_ops = []
  31. for model in models:
  32. p_ops.append(model[p])
  33. print(p_ops)
  34. weights = [1]*len(p_ops)
  35. # fusion
  36. fused_op = Opinion._internal_fusion(p_ops, weights)
  37. result_dict[p]=fused_op
  38. return result_dict
  39. '''
  40. print( Evaluator.fuse_models_equal_weights(CSVReader.readCSVModel(9),CSVReader.readCSVModel(12)))
  41. print(Evaluator.evaluate_system("inputs/dummy_input_package.csv", 9))
  42. '''