This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#getting the hexadecimal digits | |
def _getDecDigit(digit): | |
digits = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'] | |
for x in range(len(digits)): | |
if digit.lower() == digits[x]: | |
return(x) | |
#convert from hexadecimal to decimal | |
def hexToDec(hexNum): | |
decNum = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while True: | |
data, addr = sock.recvfrom(1024) | |
if 'alpha_absolute' in str(data): | |
#processing data here | |
#Gauging focus | |
if time.clock() - timer > 10: | |
measure = (sum(stock)/len(stock))/benchmark*100 | |
if measure>100: | |
print("Focused : 100%") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock = [] #keeping track of all the averages | |
benchmark = 0 #Use this to store the final focus metric | |
while True: | |
data, addr = sock.recvfrom(1024) #receiving data from socket | |
if 'alpha_absolute' in str(data): #checking for alpha | |
#preprocessing data here | |
if time.clock() - timer > 30: | |
benchmark = sum(stock)/len(stock) #determining the benchmark! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newerOut = [] | |
#Removing all the null values | |
for i in outData: | |
if type(i) == int and i>0: | |
newerOut += [i] | |
#If all the values are null, ignore the data! | |
if len(newerOut) == 0: | |
continue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Removing commas | |
newData = str(data).split(",") | |
#Removing x's | |
newData = newData[1].split("x") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UDP_IP = "172.0.0.1" #UDP IP adress | |
UDP_PORT = 6082 #UDP port for osc stream | |
sock = socket.socket(socket.AF_INET, # Internet | |
socket.SOCK_DGRAM) # UDP | |
sock.bind((UDP_IP, UDP_PORT)) #binding the name to the socket! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loss stats | |
if counter % print_every == 0: | |
# Get validation loss | |
val_h = net.init_hidden(batch_size) | |
val_losses = [] | |
net.eval() | |
for x, y in get_batches(val_data, batch_size, seq_length): | |
# One-hot encode our data and make them Torch tensors | |
x = one_hot_encode(x, n_chars) | |
x, y = torch.from_numpy(x), torch.from_numpy(y) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generating new text | |
print(sample(net, 1000, prime='A', top_k=5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def sample(net, size, prime='The', top_k=None): | |
if(train_on_gpu): | |
net.cuda() | |
else: | |
net.cpu() | |
net.eval() # eval mode | |
# First off, run through the prime characters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Defining a method to generate the next character | |
def predict(net, char, h=None, top_k=None): | |
''' Given a character, predict the next character. | |
Returns the predicted character and the hidden state. | |
''' | |
# tensor inputs | |
x = np.array([[net.char2int[char]]]) | |
x = one_hot_encode(x, len(net.chars)) | |
inputs = torch.from_numpy(x) |
NewerOlder