Skip to content

Commit

Permalink
new parameter added to choose between parallelization algorithms, but…
Browse files Browse the repository at this point in the history
… more testing needed
  • Loading branch information
alnf committed Aug 7, 2017
1 parent 904c1bd commit 1439ab5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
12 changes: 9 additions & 3 deletions BNfinder/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def get_prior(self,vertex,parent):
return self.prior.get((vertex.name,parent.name),self.prior.get(parent.name,1))


def learn(self,score,data_factor, prior=None,cores=False, subset=False, \
def learn(self,score,data_factor,alg,prior=None,cores=False,subset=False, \
verbose=None,n_min=1,limit=None,min_empty=None,min_optim=None,fpr=None,max_tries=None):

scr=score
Expand Down Expand Up @@ -689,8 +689,14 @@ class MyPool(multiprocessing.pool.Pool):
# In case of limit<=3 it is efficient to use hybrid alg
# There are two situations: number of cores >= number of vertices and opposite one.
# So, we need to handle it separately to distritube cores equaly
lim = 0
if (alg=="set"):
lim = 0
if (alg=="variable"):
lim = 999

pool=MyPool(1)
if (limit is not None) and (int(limit)<=3) and (cores>int(limit)):
if (limit is not None) and (int(limit)<=lim) and (cores>int(limit)):
if (cores>=len(vertices)):
pool=MyPool(len(vertices))
for counter in range(1, len(vertices)+1):
Expand Down Expand Up @@ -726,7 +732,7 @@ class MyPool(multiprocessing.pool.Pool):
# Need to check if we just want to concatenate previously obtained results
if (subset==False) or (subset != "concat"):
# Hybrid alg
if (limit is not None) and (int(limit)<=3) and (cores>int(limit)):
if (limit is not None) and (int(limit)<=lim) and (cores>int(limit)):
result=pool.map(learn_x,[(x,self,min_empty,min_optim,scr,verbose,n_min,limit,fpr_factor,max_tries, y) for x, y in zip(vertices, distribs)])
# Simple alg
else:
Expand Down
2 changes: 2 additions & 0 deletions bnf
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ if __name__=="__main__":
parser.add_option("-g", "--sloops", dest="sloops", action='store_true', default=False, help="Allow self-loops in Dynamic Bayesian Networks (no self-loops by default)")
parser.add_option("-k", "--cpu", dest="cores", type=int, default=0, help="Number of cores you want to use for parallelization")
parser.add_option("-j", "--subset", dest="subset", help="Specify the file with subset of genes (divided by space character), parents of which you want to find. Use 'concat' value to combine the results. BNFinder will automaticaly search for files 'genes_*'")
parser.add_option("-q", "--algorithm", dest="alg", default="set", help="Choose the parralelization algorithm:'set' (default, give all the cores to compute parents set of one variable) or 'variable' (evenly distributes cores between variables)")

(options, args) = parser.parse_args()

Expand Down Expand Up @@ -65,6 +66,7 @@ if __name__=="__main__":
min_empty=options.min_empty,\
min_optim=options.min_optim,\
cores=options.cores,\
alg=options.alg,\
subset=options.subset,\
fpr=options.fpr,
max_tries=options.max_tries,)
Expand Down

0 comments on commit 1439ab5

Please sign in to comment.