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
#include <stdio.h> | |
#include <math.h> | |
double catenary(const double x, const double a) { | |
return a * cosh(x / a); | |
} | |
double catenary_with_eulers(const double x, const double a) { | |
return (a / 2.0) * (exp(x / a) + exp(-x / a)); | |
} |
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 fit_one_cycle(learn:Learner, | |
cyc_len:int, | |
max_lr:Union[Floats,slice]=default_lr, | |
moms:Tuple[float,float]=(0.95,0.85), | |
div_factor:float=25., | |
pct_start:float=0.3, | |
wd:float=None, | |
callbacks:Optional[CallbackList]=None, **kwargs) -> None: | |
"""Fit a model following the 1cycle policy.""" | |
max_lr = learn.lr_range(max_lr) |
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
import random | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# Udacity provided code | |
class Robot(object): | |
def __init__(self, length=20.0): | |
""" | |
Creates robot and initializes location/orientation to 0, 0, 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
from copy import deepcopy | |
def printpaths(path, newpath): | |
for old, new in zip(path, newpath): | |
print('[' + ', '.join('%.3f' % x for x in old) + | |
'] -> [' + ', '.join('%.3f' % x for x in new) + ']') | |
path = [[0, 0], [0, 1], [0, 2], [1, 2], [2, 2], [3, 2], [4, 2], [4, 3], [4, 4]] |
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
import numpy as np | |
from numpy.linalg import inv | |
x_observations = np.array([4000, 4260, 4550, 4860, 5110]) | |
v_observations = np.array([280, 282, 285, 286, 290]) | |
z = np.c_[x_observations, v_observations] | |
# Initial Conditions | |
a = 2 # Acceleration |
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
import numpy as np | |
# Initial Values | |
x = 50 | |
x_dot = 5 | |
# Standard Deviations | |
x_std = 0.5 | |
x_dot_std = 0.2 |
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
import numpy as np | |
A = np.array([[90, 80, 40], | |
[90, 60, 80], | |
[60, 50, 70], | |
[30, 40, 70], | |
[30, 20, 90]]) | |
ones = np.ones([5, 5]) | |
deviation = A - (ones.dot(A) / len(A)) |
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 predict(mean1, var1, mean2, var2): | |
new_mean = mean1 + mean2 | |
new_var = var1 + var2 | |
return [new_mean, new_var] |
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 updated_mean(mean1, var1, mean2, var2): | |
new_mean = (mean1 * var2 + mean2 * var1) / (var1 + var2) | |
return new_mean | |
def updated_var(var1, var2): | |
new_var = 1 / ((1 / var1) + (1 / var2)) | |
return new_var |
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 expectedReturn(state, action, stateValue): | |
# Initiate and populate returns with cost associated with moving cars | |
returns = 0.0 | |
returns -= COST_OF_MOVING * np.absolute(action) | |
# Number of cars to start the day | |
carsLoc1 = int(min(state[0] - action, MAX_CARS)) | |
carsLoc2 = int(min(state[1] + action, MAX_CARS)) | |
# Iterate over Rental Rates | |
for rentalsLoc1 in range(0, POISSON_UPPER_BOUND): | |
for rentalsLoc2 in range(0, POISSON_UPPER_BOUND): |