Se afișează postările cu eticheta Automated reasoning. Afișați toate postările
Se afișează postările cu eticheta Automated reasoning. Afișați toate postările

09 decembrie 2013

Perceptron AND/OR gate

threshold = 0.5 # any value
learning_rate = 0.1 # any value
weights = [1, 1, 1] # x0 = 1 is constant, x1, x2 any value

# AND GATE
training_set = [((1, 0, 0), 0), ((1, 0, 1), 0), ((1, 1, 0), 0), ((1, 1, 1), 1)]

# OR GATE
#training_set = [((1, 0, 0), 0), ((1, 0, 1), 1), ((1, 1, 0), 1), ((1, 1, 1), 1)]

def dot_product(values, weights):
return sum(value * weight for value, weight in zip(values, weights))

while True:
    print('-' * 60)
    error_count = 0
    for input_vector, desired_output in training_set:
        result = dot_product(input_vector, weights) > threshold
        error = desired_output - result
        if error != 0:
            error_count += 1
            for index, value in enumerate(input_vector):
                weights[index] += learning_rate * error * value
    if error_count == 0:
        break

print(str(weights[1]) + ", " + str(weights[2])) # w1 & w2
print(threshold-weights[0]) # threshold

23 noiembrie 2013

Bayesian Networks computation

Un mic proiect în Python pentru calcularea automată a probabilităților marginale sau condiționale dintr-o rețea Bayes.

19 octombrie 2013

Exemple Otter: truth tellers, liars & normal people

O serie de probleme rezolvate în Otter. Primele 7 implică o lume locuită doar de truth tellers și mincinoși, pe când în ultimele 3 sunt introduși și oamenii „normali” (care spun adevărul sau mint, la întâmplare). Enunț - să se afle A, B (și C) dacă:
1) A says: at least one of us (A. B) is a liar

2) A says: either I am a liar or B is a truth teller.

3) A says: all of us are liars (A, B, C)
B says: exactly one of us (from A, B, C) is a truth teller

4) A says: all of us are liars (A, B, C)
B says: exactly one of us is a liar

5) A says: B is a liar
B says: A, C are of the same type (both liars or both truth tellers)

6) A says: if I am a truth teller, then so is B

7) A says: if B is a truth teller, then I am a liar

8) A, B, C each of the following: liar, truth teller, normal
A: I am normal
B: that is true
C: I am not normal

9) A truth teller can marry a liar and vice versa. Normal person can marry only normal person. A couple says:
Mr. A: My wife is not normal
Mrs A: My husband is not normal

10) The same couple. They say:
Mr A: My wife is normal
Mrs A: My husband is normal

Soluțiile aici.