(inputfile, trials, datalength)
| 26 | |
| 27 | |
| 28 | def timer(inputfile, trials, datalength): |
| 29 | |
| 30 | # load nodedata and graphskeleton |
| 31 | nd = NodeData() |
| 32 | skel = GraphSkeleton() |
| 33 | #print "bp1" |
| 34 | nd.load(inputfile) |
| 35 | #print "bp2" |
| 36 | skel.load(inputfile) |
| 37 | #print "bp3" |
| 38 | |
| 39 | # msg = "%d, %d" % (asizeof(nd), asizeof(skel)) |
| 40 | # print >>op, msg |
| 41 | |
| 42 | # topologically order graphskeleton |
| 43 | skel.toporder() |
| 44 | |
| 45 | # load bayesian network |
| 46 | bn = DiscreteBayesianNetwork(skel, nd) |
| 47 | |
| 48 | # instantiate pgm learner |
| 49 | l = PGMLearner() |
| 50 | |
| 51 | # free unused memory |
| 52 | del nd |
| 53 | |
| 54 | #sum1 = summary.summarize(muppy.get_objects()) |
| 55 | #summary.print_(sum1) |
| 56 | |
| 57 | # TIME |
| 58 | totaltime = 0 |
| 59 | for _ in range(trials): |
| 60 | data = bn.randomsample(datalength) |
| 61 | start = time.clock() |
| 62 | ret = l.discrete_mle_estimateparams(skel, data) |
| 63 | elapsed = time.clock() - start |
| 64 | totaltime += elapsed |
| 65 | totaltime /= trials |
| 66 | |
| 67 | |
| 68 | print json.dumps(ret.Vdata, indent=1) |
| 69 | return totaltime |
| 70 | #timer("/home/ccabot/Documents/bayesian networks project/bayesian/v3_bayesian/PGMlibrary/unittestdict.txt", 10) |
| 71 |
no test coverage detected