Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. import DDC_python as ddp
  2.  
  3.  
  4. # helper function
  5. def __index(x, vec, default):
  6. for i in range(0, len(vec)):
  7. if x == vec[i]:
  8. return i + 1
  9. return default
  10.  
  11.  
  12. def DDC(X, DDCpars = {}):
  13.  
  14. if DDCpars == None:
  15. DDCpars = []
  16.  
  17. if not isinstance(DDCpars, dict):
  18. raise TypeError('DDCpars must be a dictionary')
  19.  
  20. if not 'numDiscrete' in DDCpars.keys():
  21. DDCpars['numDiscrete'] = 3
  22.  
  23. if not 'precScale' in DDCpars.keys():
  24. DDCpars['precScale'] = 1e-12
  25.  
  26. if not 'cleanNAfirst' in DDCpars.keys():
  27. DDCpars['cleanNAfirst'] = 'automatic'
  28.  
  29. if not 'tolProb' in DDCpars.keys():
  30. DDCpars['tolProb'] = 0.99
  31.  
  32. if not 'corrlim' in DDCpars.keys():
  33. DDCpars['corrlim'] = 0.5
  34.  
  35. if not 'combinRule' in DDCpars.keys():
  36. DDCpars['combinRule'] = 'wmean'
  37.  
  38. if not 'returnBigXimp' in DDCpars.keys():
  39. DDCpars['returnBigXimp'] = False
  40.  
  41. if not 'silent' in DDCpars.keys():
  42. DDCpars['silent'] = False
  43.  
  44. if not 'nLocScale' in DDCpars.keys():
  45. DDCpars['nLocScale'] = 25000
  46.  
  47. if not 'fastDDC' in DDCpars.keys():
  48. if X.shape[2] < 750:
  49. fastDDC = 0
  50. DDCpars['fastDDC'] = False
  51. else:
  52. fastDDC = 1
  53. DDCpars['fastDDC'] = True
  54. else:
  55. fastDDC = DDCpars['fastDDC'] + 1
  56.  
  57. if DDCpars['fastDDC']:
  58. if X.shape[2] < 500:
  59. fastDDC = 0
  60. else:
  61. if X.shape[2] < 2000:
  62. print("Consider using the option 'fastDDC == TRUE' which runs much faster on datasets with many variables.")
  63.  
  64. if not 'standType' in DDCpars.keys():
  65. DDCpars['standType'] = '1stepM'
  66.  
  67. if not 'corrType' in DDCpars.keys():
  68. DDCpars['corrType'] = 'gkwls'
  69.  
  70. if not 'nbngbrs' in DDCpars.keys():
  71. DDCpars['nbngbrs'] = 100
  72.  
  73. # other parameters
  74. if not 'coreOnly' in DDCpars.keys():
  75. DDCpars['coreOnly'] = False
  76.  
  77. if not 'tolProbCell' in DDCpars.keys():
  78. DDCpars['tolProbCell'] = DDCpars['tolProb']
  79.  
  80. if not 'tolProbRow' in DDCpars.keys():
  81. DDCpars['tolProbRow'] = DDCpars['tolProb']
  82.  
  83. if not 'tolProbReg' in DDCpars.keys():
  84. DDCpars['tolProbReg'] = DDCpars['tolProb']
  85.  
  86. if not 'tolProbCorr' in DDCpars.keys():
  87. DDCpars['tolProbCorr'] = DDCpars['tolProb']
  88.  
  89. if not 'includeSelf' in DDCpars.keys():
  90. DDCpars['includeSelf'] = 1
  91.  
  92. if not 'numiter' in DDCpars.keys():
  93. DDCpars['numiter'] = 1
  94.  
  95. if not 'qdim' in DDCpars.keys():
  96. DDCpars['qdim'] = 30
  97.  
  98. if not 'nCorr' in DDCpars.keys():
  99. DDCpars['nCorr'] = 100
  100.  
  101. transFun = __index(DDCpars['transFun'], ['Huber', 'wrap', 'rank'], 2)
  102. standType = __index(DDCpars['standType'], ['1stepM','hubhub','wrap','mcd', 'rawmcd', 'wrapmedmad'], 1) - 1
  103. corrType = __index(DDCpars['corrType'], ['wrap', 'rank', 'gkwls'], 3)
  104. combiRule = __index(DDCpars['combiRule'], ['wmean','wmedian','mean','median'], 1)
  105.  
  106. fracNA = DDCpars['fracNA']
  107. numDiscrete = DDCpars['numDiscrete']
  108. preScale = DDCpars['preScale']
  109. returnBigXimp = DDCpars['returnBigXimp']
  110. silent = DDCpars['silent']
  111. cleanNAfirst = DDCpars['cleanNAfirst']
  112.  
  113. if DDCpars['coreOnly'] == False:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement