write_par.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # !/usr/bin/env python3.7
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on 27.07.21
  5. @author yannan su
  6. """
  7. import yaml
  8. import numpy as np
  9. def write_par_set(file_path, stim, noise_condition, noise_level=0.):
  10. """
  11. Write parameters to a YAML file.
  12. :param file_path: par-file path
  13. :param stim: example: stim = {'hue_1': 22.5, ' hue_5': 202.5}
  14. :param seed: seed for random permutation of the stimuli
  15. :param hue_num: hue numbers
  16. :param theta: customize a theta value list
  17. :param min_max: [min value, max value] for simple and quest methods
  18. :param start_val: start value for simple and quest methods
  19. :param std: stimulus noise level (a single number or a list of numbers)
  20. :param step_type: 'db', 'lin', 'log' (None if method is not 'simple')
  21. :param up_down: tuple with the up-down rule settings (up, down)
  22. :param p_threshold: targeting probability threshold for the quest method
  23. Example:
  24. write_par('config/cn2x2x8_crs_test.yaml', noise='cross', method='quest', hue_num=8, std=5.06)
  25. """
  26. idx = 0
  27. par_dict = {}
  28. for key, val in stim.items():
  29. for ii in range(2):
  30. stim_num = 'stimulus_' + str(idx)
  31. idx += 1
  32. par_dict[stim_num] = {}
  33. if idx % 2 == 0:
  34. par_dict[stim_num]['label'] = key + 'm'
  35. par_dict[stim_num]['stairDirection'] = -1.0
  36. else:
  37. par_dict[stim_num]['label'] = key + 'p'
  38. par_dict[stim_num]['stairDirection'] = 1.0
  39. par_dict[stim_num]['noise_condition'] = noise_condition
  40. par_dict[stim_num]['standard'] = val
  41. par_dict[stim_num]['width'] = noise_level
  42. par_dict[stim_num]['hue_range'] = [val - 30., val + 30.]
  43. par_dict[stim_num]['hue_num'] = 45
  44. par_dict[stim_num]['stairType'] = 'simple'
  45. par_dict[stim_num]['stepType'] = 'lin'
  46. par_dict[stim_num]['startVal'] = 5.
  47. par_dict[stim_num]['minVal'] = .5
  48. par_dict[stim_num]['maxVal'] = 20.
  49. par_dict[stim_num]['nUp'] = 1
  50. par_dict[stim_num]['nDown'] = 2
  51. par_dict[stim_num]['stepSizes'] = [2.0, 1.0, 0.5]
  52. par_dict[stim_num]['nReversals'] = 2
  53. with open(file_path, 'w') as file:
  54. yaml.dump(par_dict, file, default_flow_style=False, sort_keys=False)
  55. # write_par_set('config/par_a/LL_2x2_set5.yaml', {'hue_9': 0., 'hue_13': 180.}, 'L-L', noise_level=0.)
  56. # write_par_set('config/par_a/LL_2x2_set6.yaml', {'hue_11': 90., 'hue_15': 270.}, 'L-L', noise_level=0.)
  57. # write_par_set('config/par_a/LL_2x2_set7.yaml', {'hue_10': 45., 'hue_14': 225.}, 'L-L', noise_level=0.)
  58. # write_par_set('config/par_a/LL_2x2_set8.yaml', {'hue_12': 135., 'hue_16': 315.}, 'L-L', noise_level=0.)