#select classifier
learner = RulesLearner('tree_learner', mySet, 'on')
learner.setTemplateRuleLearnerName("[WiFi] <= When [Location] ")
learner.setFieldNames(map(str, parameters))

print map(str, parameters)

# [on] <= When [morning, home] 
for a in range(1,300):
    learner.addSample(['on', 'morning', 'home'] + map( lambda x: x.sample(), parameters[3:]), parameters)

# [off] <= When [morning, work] 
for a in range(1,200):
    learner.addSample(['off', 'morning', 'work'] + map( lambda x: x.sample(), parameters[3:]), parameters)

# [on] <= When [afternoon, work] 
for a in range(1,200):
    learner.addSample(['on', 'afternoon', 'work'] + map( lambda x: x.sample(), parameters[3:]), parameters)

# [off] <= When [night, home]
for a in range(1,200):
    learner.addSample(['off', 'night', 'home'] + map( lambda x: x.sample(), parameters[3:]), parameters)

# add some random noise 
for a in range(1, 70):
    learner.addSample(map( lambda x: x.sample(), parameters), parameters)
    
rules = learner.infer(parameters)
for rule in rules:
    print rule
    
parameters = [att.getName(), att3.getName()]

learner.setFieldNames(parameters)

learner.setTreshold(0.7)
learner.setMinSamples(2)

#add "on" <- "home", 4 times
sn1 = ["on", "home"]
map(learner.addSample, [sn1] * 4)

#add "off" <- "home", 1 times
s4 = ["off", "home"]
learner.addSample(s4)

#add "on" <- "work", 1 times
sn3 = ["on", "work"]
learner.addSample(sn3)

#add "off" <- "work", 2 times
s5 = ["off", "work"]
map(learner.addSample, [s5] * 2)

print("Likelihood: " + learner.getLearner.infer(parameters))

# Parameters: WiFi->location
learner.computeLearning(parameters)
learner.getLearner().getSamplesTable()
print("Likelihood: " + learner.infer(parameters))