def setUp(self): self.data = data.fromfile(testfile('testdata10.txt')) self.neteval = evaluator.NetworkEvaluator( self.data, network.fromdata(self.data), prior.UniformPrior(self.data.variables.size)) self.neteval.network.edges.add_many([(1,0),(2,0),(3,0)])
def setUp(self): a,b,c,d,e = 0,1,2,3,4 self.data = data.fromfile(testfile('testdata9.txt')) self.net = network.fromdata(self.data) self.net.edges.add_many([(a,c), (b,c), (c,d), (c,e)]) self.neteval1 = self.neteval_type(self.data, self.net, max_iterations="10*n**2")
def setUp(self): dat = data.fromfile(testfile("testdata5.txt")) dat.discretize() g = greedy.GreedyLearner(dat, max_iterations=100) g.run() self.result = g.result self.tempdir = tempfile.mkdtemp() self.result.tohtml(self.tempdir)
def test_arity_checking2(): try: # arity specified is MORE than number of unique values. this is ok. dataset = data.fromfile(testfile('testdata7.txt')) except: assert False assert [v.arity for v in dataset.variables] == [3,4,3,6]
def test_arity_checking(): try: # arity specified is less than number of unique values!! dataset = data.fromfile(testfile('testdata6.txt')) except data.IncorrectArityError: assert True else: assert False
def test_arity_checking2(): try: # arity specified is MORE than number of unique values. this is ok. dataset = data.fromfile(testfile('testdata7.txt')) except: assert False assert [v.arity for v in dataset.variables] == [3, 4, 3, 6]
def test_tc(self): d = data.fromfile(testfile("testdata5.txt")) d.discretize() tasks = [greedy.GreedyLearner(d) for x in range(5)] tc = ipy1.IPython1Controller("127.0.0.1:10113") results = tc.run(tasks) results = result.merge(results) assert isinstance(results, result.LearnerResult)
def setUp(self): self.data = data.fromfile(testfile('testdata4.txt')) # no tab before variable names self.expected_observations = N.array([[0, 0], [1, 1], [1,2]]) self.expected_missing = N.array([[0, 0], [0, 0], [0, 0]], dtype=bool) self.expected_interventions = N.array([[1, 1], [0, 1], [0, 0]], dtype=bool) self.expected_varnames = ['shh', 'ptchp'] self.expected_samplenames = ['sample1', 'sample2', 'sample3'] self.expected_arities = [2,3] self.expected_dtype = N.dtype(int)
def setUp(self): a, b, c, d, e = 0, 1, 2, 3, 4 self.data = data.fromfile(testfile('testdata9.txt')) self.net = network.fromdata(self.data) self.net.edges.add_many([(a, c), (b, c), (c, d), (c, e)]) self.neteval1 = self.neteval_type(self.data, self.net, max_iterations="10*n**2")
def test_example1(self): outdir = os.path.join(self.tmpdir, "example1-result") dataset = data.fromfile(testfile("pebl-tutorial-data1.txt")) dataset.discretize() learner = greedy.GreedyLearner(dataset) ex1result = learner.run() ex1result.tohtml(outdir) assert os.path.exists(os.path.join(outdir, 'index.html'))
def setUp(self): self.data = data.fromfile(testfile('testdata3.txt')) self.expected_observations = N.array([[0, 0], [1, 1], [1, 2]]) self.expected_missing = N.array([[0, 0], [0, 0], [0, 0]], dtype=bool) self.expected_interventions = N.array([[1, 1], [0, 1], [0, 0]], dtype=bool) self.expected_varnames = ['shh', 'ptchp'] self.expected_samplenames = ['sample1', 'sample2', 'sample3'] self.expected_arities = [2, 3] self.expected_dtype = N.dtype(int)
def bayesian_structure(): # dataset = data.fromfile("/home/work/pebl-tutorial-data2.txt") # dataset = Dataset(points.transpose(), None, None, ['in','tar'], None, None) dataset = data.fromfile('/home/work/Projects/EclipseProjects/thesis/Scripts/elements.csv') dataset.discretize() # dataset.discretize() # learners = [ greedy.GreedyLearner(dataset, max_iterations=1000000) for i in range(5) ] + \ # [ simanneal.SimulatedAnnealingLearner(dataset) for i in range(5) ] # merged_result = result.merge([learner.run() for learner in learners]) learner = greedy.GreedyLearner(dataset) merged_result = learner.run() merged_result.tohtml("example-result")
def setUp(self): self.data = data.fromfile(testfile('testdata1.txt')) self.expected_observations = N.array([[2.5, 0., 1.7], [1.1, 1.7, 2.3], [4.2, 999.3, 12.]]) self.expected_dtype = N.dtype(float) self.expected_varnames = ['var1', 'var2', 'var3'] self.expected_missing = N.array( [[False, True, False], [False, False, False], [False, False, False]], dtype=bool) self.expected_interventions = N.array( [[True, True, False], [False, True, False], [False, False, False]], dtype=bool) self.expected_arities = [-1, -1, -1]
def setUp(self): self.data = data.fromfile(testfile('testdata2.txt')) self.expected_observations = N.array([[ 0. , 0. , 1.25, 0. ], [ 1. , 1. , 1.1 , 1. ], [ 1. , 2. , 0.45, 1. ]]) self.expected_dtype = N.dtype(float) # because one continuous variable self.expected_varnames = ['shh', 'ptchp', 'smo', 'outcome'] self.expected_interventions = N.array([[ True, True, False, False], [False, True, False, False], [False, False, False, False]], dtype=bool) self.expected_missing = N.array([[False, False, False, False], [False, False, False, False], [False, False, False, False]], dtype=bool) self.expected_arities = [2, 3, -1, 2]
def setUp(self): self.data = data.fromfile(testfile('testdata1.txt')) self.expected_observations = N.array([[ 2.5, 0. , 1.7], [ 1.1, 1.7, 2.3], [ 4.2, 999.3, 12. ]]) self.expected_dtype = N.dtype(float) self.expected_varnames = ['var1', 'var2', 'var3'] self.expected_missing = N.array([[False, True, False], [False, False, False], [False, False, False]], dtype=bool) self.expected_interventions = N.array([[ True, True, False], [False, True, False], [False, False, False]], dtype=bool) self.expected_arities = [-1,-1,-1]
def setUp(self): self.data = data.fromfile(testfile('testdata2.txt')) self.expected_observations = N.array([[0., 0., 1.25, 0.], [1., 1., 1.1, 1.], [1., 2., 0.45, 1.]]) self.expected_dtype = N.dtype(float) # because one continuous variable self.expected_varnames = ['shh', 'ptchp', 'smo', 'outcome'] self.expected_interventions = N.array( [[True, True, False, False], [False, True, False, False], [False, False, False, False]], dtype=bool) self.expected_missing = N.array( [[False, False, False, False], [False, False, False, False], [False, False, False, False]], dtype=bool) self.expected_arities = [2, 3, -1, 2]
def setUp(self): self.data = data.fromfile(testfile('testdata5m.txt')) self.data.discretize() self.expected_original = \ N.array([[ 1.2, 1.4, 2.1, 2.2, 1.1], [ 2.3, 1.1, 2.1, 3.2, 1.3], [ 3.2, 0. , 1.2, 2.5, 1.6], [ 4.2, 2.4, 3.2, 2.1, 2.8], [ 2.7, 1.5, 0. , 1.5, 1.1], [ 1.1, 2.3, 2.1, 1.7, 3.2], [ 2.3, 1.1, 4.3, 2.3, 1.1], [ 3.2, 2.6, 1.9, 1.7, 1.1], [ 2.1, 1.5, 3. , 1.4, 1.1], [ 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. ]]) self.expected_discretized = \ N.array([[0, 1, 1, 1, 0], [1, 0, 1, 2, 1], [2, 0, 0, 2, 2], [2, 2, 2, 1, 2], [1, 1, 0, 0, 0], [0, 2, 1, 0, 2], [1, 0, 2, 2, 0], [2, 2, 0, 0, 0], [0, 1, 2, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) self.expected_arities = [3,3,3,3,3] self.expected_missing = N.array([[False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [True , True , True , True , True ], [True , True , True , True , True ], [True , True , True , True , True ]], dtype=bool)
def setUp(self): self.data = data.fromfile(testfile('testdata5m.txt')) self.data.discretize() self.expected_original = \ N.array([[ 1.2, 1.4, 2.1, 2.2, 1.1], [ 2.3, 1.1, 2.1, 3.2, 1.3], [ 3.2, 0. , 1.2, 2.5, 1.6], [ 4.2, 2.4, 3.2, 2.1, 2.8], [ 2.7, 1.5, 0. , 1.5, 1.1], [ 1.1, 2.3, 2.1, 1.7, 3.2], [ 2.3, 1.1, 4.3, 2.3, 1.1], [ 3.2, 2.6, 1.9, 1.7, 1.1], [ 2.1, 1.5, 3. , 1.4, 1.1], [ 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. ], [ 0. , 0. , 0. , 0. , 0. ]]) self.expected_discretized = \ N.array([[0, 1, 1, 1, 0], [1, 0, 1, 2, 1], [2, 0, 0, 2, 2], [2, 2, 2, 1, 2], [1, 1, 0, 0, 0], [0, 2, 1, 0, 2], [1, 0, 2, 2, 0], [2, 2, 0, 0, 0], [0, 1, 2, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) self.expected_arities = [3, 3, 3, 3, 3] self.expected_missing = N.array( [[False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [False, False, False, False, False], [True, True, True, True, True], [True, True, True, True, True], [True, True, True, True, True]], dtype=bool)
def setUp(self): self.data = data.fromfile(testfile('testdata5.txt')) self.data.discretize(excludevars=[0, 1]) self.expected_original = \ N.array([[ 1.2, 1.4, 2.1, 2.2, 1.1], [ 2.3, 1.1, 2.1, 3.2, 1.3], [ 3.2, 0. , 1.2, 2.5, 1.6], [ 4.2, 2.4, 3.2, 2.1, 2.8], [ 2.7, 1.5, 0. , 1.5, 1.1], [ 1.1, 2.3, 2.1, 1.7, 3.2], [ 2.3, 1.1, 4.3, 2.3, 1.1], [ 3.2, 2.6, 1.9, 1.7, 1.1], [ 2.1, 1.5, 3. , 1.4, 1.1]]) self.expected_discretized = \ N.array([[ 1.2, 1.4, 1. , 1. , 0. ], [ 2.3, 1.1, 1. , 2. , 1. ], [ 3.2, 0. , 0. , 2. , 2. ], [ 4.2, 2.4, 2. , 1. , 2. ], [ 2.7, 1.5, 0. , 0. , 0. ], [ 1.1, 2.3, 1. , 0. , 2. ], [ 2.3, 1.1, 2. , 2. , 0. ], [ 3.2, 2.6, 0. , 0. , 0. ], [ 2.1, 1.5, 2. , 0. , 0. ]]) self.expected_arities = [-1, -1, 3, 3, 3]
def setUp(self): self.data = data.fromfile(testfile('testdata5.txt')) self.data.discretize() self.expected_original = \ N.array([[ 1.2, 1.4, 2.1, 2.2, 1.1], [ 2.3, 1.1, 2.1, 3.2, 1.3], [ 3.2, 0. , 1.2, 2.5, 1.6], [ 4.2, 2.4, 3.2, 2.1, 2.8], [ 2.7, 1.5, 0. , 1.5, 1.1], [ 1.1, 2.3, 2.1, 1.7, 3.2], [ 2.3, 1.1, 4.3, 2.3, 1.1], [ 3.2, 2.6, 1.9, 1.7, 1.1], [ 2.1, 1.5, 3. , 1.4, 1.1]]) self.expected_discretized = \ N.array([[0, 1, 1, 1, 0], [1, 0, 1, 2, 1], [2, 0, 0, 2, 2], [2, 2, 2, 1, 2], [1, 1, 0, 0, 0], [0, 2, 1, 0, 2], [1, 0, 2, 2, 0], [2, 2, 0, 0, 0], [0, 1, 2, 0, 0]]) self.expected_arities = [3, 3, 3, 3, 3]
def setUp(self): self.data = data.fromfile(testfile('testdata5.txt')) self.data.discretize() self.expected_original = \ N.array([[ 1.2, 1.4, 2.1, 2.2, 1.1], [ 2.3, 1.1, 2.1, 3.2, 1.3], [ 3.2, 0. , 1.2, 2.5, 1.6], [ 4.2, 2.4, 3.2, 2.1, 2.8], [ 2.7, 1.5, 0. , 1.5, 1.1], [ 1.1, 2.3, 2.1, 1.7, 3.2], [ 2.3, 1.1, 4.3, 2.3, 1.1], [ 3.2, 2.6, 1.9, 1.7, 1.1], [ 2.1, 1.5, 3. , 1.4, 1.1]]) self.expected_discretized = \ N.array([[0, 1, 1, 1, 0], [1, 0, 1, 2, 1], [2, 0, 0, 2, 2], [2, 2, 2, 1, 2], [1, 1, 0, 0, 0], [0, 2, 1, 0, 2], [1, 0, 2, 2, 0], [2, 2, 0, 0, 0], [0, 1, 2, 0, 0]]) self.expected_arities = [3,3,3,3,3]
def setUp(self): self.data = data.fromfile(testfile('testdata5.txt')) self.data.discretize(excludevars=[0,1]) self.expected_original = \ N.array([[ 1.2, 1.4, 2.1, 2.2, 1.1], [ 2.3, 1.1, 2.1, 3.2, 1.3], [ 3.2, 0. , 1.2, 2.5, 1.6], [ 4.2, 2.4, 3.2, 2.1, 2.8], [ 2.7, 1.5, 0. , 1.5, 1.1], [ 1.1, 2.3, 2.1, 1.7, 3.2], [ 2.3, 1.1, 4.3, 2.3, 1.1], [ 3.2, 2.6, 1.9, 1.7, 1.1], [ 2.1, 1.5, 3. , 1.4, 1.1]]) self.expected_discretized = \ N.array([[ 1.2, 1.4, 1. , 1. , 0. ], [ 2.3, 1.1, 1. , 2. , 1. ], [ 3.2, 0. , 0. , 2. , 2. ], [ 4.2, 2.4, 2. , 1. , 2. ], [ 2.7, 1.5, 0. , 0. , 0. ], [ 1.1, 2.3, 1. , 0. , 2. ], [ 2.3, 1.1, 2. , 2. , 0. ], [ 3.2, 2.6, 0. , 0. , 0. ], [ 2.1, 1.5, 2. , 0. , 0. ]]) self.expected_arities = [-1,-1,3,3,3]
def setUp(self): self.data = data.fromfile(testfile('testdata10.txt')) self.neteval = evaluator.NetworkEvaluator( self.data, network.fromdata(self.data), prior.UniformPrior(self.data.variables.size)) self.neteval.network.edges.add_many([(1, 0), (2, 0), (3, 0)])
def setUp(self): config.set('evaluator.missingdata_evaluator', 'exact') self.data = data.fromfile( testfile('testdata13.txt')).subset(samples=range(5)) self.learner = greedy.GreedyLearner(self.data, max_iterations=10)
def setUp(self): config.set('evaluator.missingdata_evaluator', self.missing_evaluator) self.data = data.fromfile(testfile('testdata13.txt')) self.learner = self.learnertype(self.data)
def setUp(self): self.data = data.fromfile( testfile('testdata5.txt')).subset(samples=range(5)) self.data.discretize() self.learner = self.learnertype(self.data)
def setUp(self): self.data = data.fromfile(testfile('testdata5.txt')) self.data.discretize()
print "=" * 80 print "test statistics: " if verbose: fail_breakdown(merged_result.detail) print "Max score: %s" % max(scores) print "Min score: %s" % min(scores) avg_score = sum(scores) / len(scores) print "Average score: %s" % avg_score # final_score = sum([r.num_pass for r in results])/\ # float(sum([r.num_testcase for r in results])) final_score = merged_result.score(score_type)[1] print "Normalized score: %s" % final_score return final_score if __name__ == "__main__": # run a cross validation from pebl import data # test parameters data_file = "/home/drli/code/ml/iris.pebl" classifier_type = "tan" test_ratio = 0.3 runs = 2 verbose = True dataset = data.fromfile(data_file) # dataset.discretize(numbins=3, excludevars=[dataset.variables.size-1]) cross_validate(dataset, classifier_type, test_ratio, runs, verbose)
args = parser.parse_args() for f in os.listdir(args.directory)[args.start:args.end]: if 'struct' in f: continue structfile = open(args.directory + '/' + f.replace('.txt', '_struct.txt')) peblfile = open(args.directory + '/' + f) nodenames = peblfile.readline().strip().split('\t') peblfile.close() if len(nodenames) > 30: continue nodes = [data.Variable(name) for name in nodenames] edges = [[int(x) for x in l.strip().split('\t')] for l in structfile.readlines()] print 'Doing %s' % f print nodes print edges net = network.Network(nodes, edges=edges) dataset = data.fromfile(args.directory + '/' + f) try: dataset.discretize() if len(nodenames) <= 10: learner = greedy.GreedyLearner(dataset, seed=net) else: learner = greedy.GreedyLearner(dataset) res = learner.run() # res.outdir = args.directory + '/' res.tohtml(args.prefix + '/' + f.replace('.txt', '_html')) except Exception as e: print 'Could not process %s: exception was %s' % (f, e)
def setUp(self): self.data = data.fromfile(testfile("greedytest1-200.txt"))
def setUp(self): config.set('evaluator.missingdata_evaluator', 'exact') self.data = data.fromfile(testfile('testdata13.txt')).subset(samples=range(5)) self.learner = greedy.GreedyLearner(self.data, max_iterations=10)
def setUp(self): self.data = data.fromfile(testfile('testdata5.txt')).subset(samples=range(5)) self.data.discretize() self.learner = self.learnertype(self.data)
start_time = time.time() classifyUsingNB(trainList, classVariable, testList, testClassVariable) elapsed_time = time.time() - start_time print("Time elapsed Gaussian Naive Bayes : ", elapsed_time) #Decision tree start_time = time.time() classifyUsingDecisionTree(trainList, classVariable, testList, testClassVariable) elapsed_time = time.time() - start_time print("Time elapsed Decision : ", elapsed_time) #logistic regression solver = 'sag' multiclass = 'ovr' start_time = time.time() classifyUsingLogisticRegression(trainList, classVariable, testList, testClassVariable, solver, multiclass) elapsed_time = time.time() - start_time print("Time elapsed Logistic Regression : ", elapsed_time) #Bayesian Network using PEBL for the data start_time = time.time() dataset = data.fromfile(trainFileNameForBayesian) dataset.discretize() learner = greedy.GreedyLearner(dataset) ex1result = learner.run() ex1result.tohtml("dataset") elapsed_time = time.time() - start_time print("Time elapsed Bayesian Network : ", elapsed_time)
def setUp(self): self.data = data.fromfile(testfile('testdata10.txt')) self.neteval = evaluator.NetworkEvaluator(self.data, network.fromdata(self.data)) self.neteval.network.edges.add_many([(1, 0), (2, 0), (3, 0)]) # {1,2,3} --> 0
''' from pebl import data, result from pebl.learner import * from pebl_interface import graph2pebl from pebl_interface import render_pebl_graph import numpy as np from time import gmtime, strftime #TODO: this should take as arguments # data : txt file # labels: node names and types of attributes # conf : configuration file - type of learnerm number of learners if __name__ == "__main__": dataset = data.fromfile('../datasets/diabetes/diabetes_pebl_train.txt') dataset.discretize(numbins=5) learner = greedy.GreedyLearner(dataset, max_iterations = 10000) #nodes_list = ["SAT","Difficulty","Intelligence","Grade","Letter"] #adjacency_matrix = np.array([[0,0,0,0,0],[0,0,0,1,0],[1,0,0,1,0],[0,0,0,0,1],[0,0,0,0,0]]) #g = graph2pebl(nodes_list, adjacency_matrix) #learner.seed = g #render_pebl_graph(learner.seed,"initial") #~ learners = [ greedy.GreedyLearner(dataset, max_iterations=1000000) for i in range(5) ] + \ #~ [ simanneal.SimulatedAnnealingLearner(dataset) for i in range(5) ] #~ merged_result = result.merge([learner.run() for learner in learners]) results = learner.run() result_folder_str = "../experiments/diabetes_" + strftime("%Y-%m-%d_%H:%M:%S", gmtime()) results.tohtml(result_folder_str)
DATA_PATH = "data/HR_tab_sep.pebl.tsv" import numpy as np from pebl import data from pebl.prior import Prior dataset = data.fromfile(DATA_PATH) n_vars = len(dataset.variables) def prohibit_from_left(energy): return energy[6].sum() <= 0 for i in range(n_vars): if type(dataset.variables[i]) == data.ContinuousVariable: dataset.discretize(i, numbins=10) if type(dataset.variables[i]) == data.ClassVariable: dataset.discretize(i, numbins=dataset.variables[i].arity) prohibited_edges = [ (6, i) for i in range(6) + range(6, 10) ] prior = Prior(len(dataset.variables), #np.ones((n_vars, n_vars)) / (n_vars * n_vars)) #constraints=[prohibit_from_left]) prohibited_edges=prohibited_edges)
from pebl import data, result from pebl.learner import greedy, simanneal import numpy as np from pebl.taskcontroller import multiprocess dataset = data.fromfile("zinc.txt") dataset.discretize() learner1 = greedy.GreedyLearner(dataset, max_iterations=1000) result1 = learner1.run() learner2 = greedy.GreedyLearner(dataset, max_iterations=1000) result2 = learner2.run() #learners = [ greedy.GreedyLearner(dataset, max_iterations=100) for i in range(5) ] #+ \ # [ simanneal.SimulatedAnnealingLearner(dataset) for i in range(5) ] result1.tohtml('example2.out') result2.tohtml('example3.out') merged_result = result.merge(result1, result2) merged_result.tohtml("zinc",) merged_result.tofile('example.out')
from pebl import data from pebl import prior from pebl.learner import greedy dataset = data.fromfile("output.txt") dataset.discretize(numbins=3) node_src = [32 for ii in range(32)] + [3 for ii in range(32)] + [ 30 for ii in range(32) ] + [31 for ii in range(32)] node_dest = range(32) + range(32) + range(32) + range(32) prior = prior.Prior(33, prohibited_edges=zip(node_src, node_dest)) learner = greedy.GreedyLearner(dataset, prior, max_iterations=120000) result = learner.run() result.tohtml()
from pebl.learner import greedy from pebl.taskcontroller import ec2 from pebl.test import testfile help = """Test the EC2 TaskController. USAGE: test_ec2.py configfile You need to provide the configfile for use with EC2Controller. ############################################################################### WARNING for pebl devs: Do NOT put your configfile under svn. It contains sensitve information. ############################################################################### """ if len(sys.argv) < 2: print help sys.exit(1) d = data.fromfile(testfile("testdata5.txt")) d.discretize() tc = ec2.EC2Controller(config=sys.argv[1], min_count=3) results = tc.run([greedy.GreedyLearner(d, max_time=10) for i in xrange(10)]) results = result.merge(results) print results print[r.host for r in results.runs]
def setUp(self): d = data.fromfile(testfile("testdata5.txt")) d.discretize() self.proc = subprocess.Popen("ipcluster -n 2 </dev/null 1>&0 2>&0", shell=True) time.sleep(5)
def setUp(self): self.data = data.fromfile(testfile('testdata10.txt')) self.ne = evaluator.SmartNetworkEvaluator( self.data, network.fromdata(self.data))
def run_benchmarks(datafile): print datafile dat = data.fromfile(datafile) l = greedy.GreedyLearner(dat) l.run()
def setUp(self): self.data = data.fromfile(testfile('testdata10.txt')) self.ne = evaluator.SmartNetworkEvaluator(self.data, network.fromdata(self.data))
def setUp(self): self.data = data.fromfile(testfile('testdata10.txt')) self.neteval = evaluator.NetworkEvaluator(self.data, network.fromdata(self.data)) self.neteval.network.edges.add_many([(1,0), (2,0), (3,0)]) # {1,2,3} --> 0
#!/usr/bin/env python # Bayesian with five greedy and 5 simulated annearling learners serially # http://pythonhosted.org/pebl/tutorial.html from pebl import data, result from pebl.learner import greedy, simanneal from pebl.taskcontroller import multiprocess dataset = data.fromfile("pebl-tutorial-data2.txt") learners = [ greedy.GreedyLearner(dataset, max_iterations=1000000) for i in range(5) ] + \ [ simanneal.SimulatedAnnealingLearner(dataset) for i in range(5) ] tc = multiprocess.MultiProcessController(poolsize=2) results = tc.run(learners) merged_result = result.merge(results) merged_result.tofile("example4-result")
from pebl.taskcontroller import xgrid from pebl.test import testfile help = """Test the Xgrid TaskController. USAGE: test_xgrid.py configfile You need to provide the configfile for use with XGridController. ############################################################################### WARNING for pebl devs: Do NOT put your configfile under svn. It contains sensitve information. ############################################################################### """ if len(sys.argv) < 2: print help sys.exit(1) config.read(sys.argv[1]) d = data.fromfile(testfile("testdata5.txt")) d.discretize() tc = xgrid.XgridController() results = tc.run([greedy.GreedyLearner(d, max_time=10) for i in xrange(10)]) results = result.merge(results) print results print [r.host for r in results.runs]
def setUp(self): d = data.fromfile(testfile("testdata5.txt")) d.discretize() self.tc = self.tctype(*self.args) self.tasks = [greedy.GreedyLearner(d, max_iterations=100) for i in xrange(6)]