Example #1
0
def test_5():
    G = numpy.array([[1, 1, 1,1], [1, 0, 1,1], [0, 1, 1,1]])
    print "Testing hard-decision decoding with no errors, G =", str(G.tolist())
    for i in range(100):
        message = numpy.random.random_integers(0, 1, 10)
        voltages = viterbi.convolutional_encode(message, G)
        decoded_message = decode(voltages, G)
        test_equality(message, decoded_message, voltages)
Example #2
0
def test_3():
    G = numpy.array([[1, 1, 1], [1, 1, 0]])
    print "Testing hard-decision decoding with errors, G =", str(G.tolist())
    for i in range(100):
        message = numpy.random.random_integers(0, 1, 10)
        voltages = viterbi.convolutional_encode(message, G)
        # Make sure the errors are spaced far apart, and not too close
        # to the end of the message.
        err1 = random.randint(0, 4)
        err2 = random.randint(11, 15)
        voltages[err1] = 1 - voltages[err1]
        voltages[err2] = 1 - voltages[err2]
        decoded_message = decode(voltages, G)
        test_equality(message, decoded_message, voltages)
Example #3
0
import PS3
import time

cont = PS3.Controller("/dev/input/js0")
cont.start()

try:
    while True:
        print(cont.analogVal)
        print(cont.isDActive)
        if cont.isDActive[cont.DButton.SELECT]:
            break
except KeyboardInterrupt:
    pass

cont.stop()
SS_tol = 1e-13

# nvec
nvec = np.zeros(S)
nvec[:int(round(2 * S / 3))] = 1
nvec[int(round(2 * S / 3)):] = 0.2

# L
L = nvec.sum()

params = (S, beta, sigma, L, A, alpha, delta, SS_tol)

# Question 1: Feasibility
# (a)
bvec_guess1 = np.ones(S - 1)
print("(a) : ", func.feasible(S, alpha, A, delta, bvec_guess1))

# (b)
bvec_guess2 = np.array([
    -0.01, 0.1, 0.2, 0.23, 0.25, 0.23, 0.2, 0.1, -0.01, 0.1, 0.2, 0.23, 0.25,
    0.23, 0.2, 0.1, -0.01, 0.1, 0.2, 0.23, 0.25, 0.23, 0.2, 0.1, -0.01, 0.1,
    0.2, 0.23, 0.25, 0.23, 0.2, 0.1, -0.01, 0.1, 0.2, 0.23, 0.25, 0.23, 0.2,
    0.1, -0.01, 0.1, 0.2, 0.23, 0.25, 0.23, 0.2, 0.1, -0.01, 0.1, 0.2, 0.23,
    0.25, 0.23, 0.2, 0.1, -0.01, 0.1, 0.2, 0.23, 0.25, 0.23, 0.2, 0.1, -0.01,
    0.1, 0.2, 0.23, 0.25, 0.23, 0.2, 0.1, -0.01, 0.1, 0.2, 0.23, 0.25, 0.23,
    0.2
])
print("(b) : ", func.feasible(S, alpha, A, delta, bvec_guess2))

# (c)
bvec_guess3 = np.array([