Skip to content

Instantly share code, notes, and snippets.

@emuccino
Created July 11, 2019 16:43
Show Gist options
  • Save emuccino/8c3c4b8decbf2721e258262973703358 to your computer and use it in GitHub Desktop.
Save emuccino/8c3c4b8decbf2721e258262973703358 to your computer and use it in GitHub Desktop.
Training Recurrent Neural Networks on Long Sequences
import numpy as np
#function for getting coordinates given an angle
def get_cartesian_coords(nums):
theta = nums
x = np.cos(theta)
y = np.sin(theta)
return [x,y]
#generate random starting coordinate
angle = np.random.uniform(-np.pi, np.pi)
coordinates = get_cartesian_coords(random_angle)
amplitudes = [abs(coord) for coord in coordinates]
random_walk = [amplitudes]
for _ in range(9999):
#generate random small change in angle
direction = 0.01 * np.random.uniform(-1, 1)
angle += direction
coordinates = get_cartesian_coords(angle)
amplitudes = [abs(coord) for coord in coordinates]
random_walk.append(amplitudes)
timestep = list(range(20000))
#create sequence using generated amplitudes
sequence = list(map(lambda i: np.round((((random_walk[i][0])*-1)*np.sin((0.0002)*i)) + \
((random_walk[i][1])*np.sin(0.0002*i)))+ 100 + np.random.normal(0, 0.01),decimals=2),timestep)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment