Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
# The Gaussian probability density function is equal to: | |
# (1 / sqrt(2 * pi * sigma^2)) * e^ ((-(x - mu)^2) / 2 * sigma^2) | |
# - mu = the average | |
# - sigma = standard deviation | |
import math | |
import numpy as np | |
def gaussian_density(x, mu, sigma): | |
two_pi_sigma_squared = 2 * np.pi * np.power(sigma, 2) |
This file contains hidden or 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
#Calculate the area under a Gaussian curve between 2 points, given their x-values and y-values (probability density functions). | |
#scipy norm() uses a Z-distribution table approach (standard normal table) to calculate the area under the curve between x1 and x2. | |
#NOTE: The area under the curve is the probability of the scenario happeniing between x1 and x2. | |
# example: how likely will San Francisco fluctuate between 20 to 30 degrees celsius on a random day? | |
from scipy.stats import norm | |
import numpy as np | |
import math |
This file contains hidden or 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 central_limit_theorem(population, sample_size, iterations): | |
sample_means = [] | |
for i in range(iterations): | |
random_sample = np.random.choice(population, size = sample_size) | |
sample_mean = np.mean(random_sample) | |
sample_means.append(sample_mean) | |
return sample_means |
This file contains hidden or 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
p=[0.2, 0.2, 0.2, 0.2, 0.2] | |
world=['green', 'red', 'red', 'green', 'green'] | |
Z = 'red' | |
pHit = 0.6 | |
pMiss = 0.2 | |
def sense(p, Z): | |
for i in range(len(p)): | |
at_Z = (Z == world[i]) | |
This file contains hidden or 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
#######################APPROACH 1####################### | |
def shift1(lst, shift_by): | |
shift_by = shift_by % len(lst) | |
#retrieves last -U number of elements (counting backwards) | |
last_elements_shifted = lst[-shift_by:] | |
#removes last -U number of elements (retrieves front of list) | |
first_elements_shifted = lst[:-shift_by] | |
This file contains hidden or 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
p=[0.2, 0.2, 0.2, 0.2, 0.2] | |
#sense variables | |
world=['green', 'red', 'red', 'green', 'green'] | |
measurements = ['red', 'red'] | |
pHit = 0.6 | |
pMiss = 0.2 | |
#move variables | |
motions = [1,1] |
This file contains hidden or 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
#measurement | |
def update(mean1, var1, mean2, var2): | |
new_mean = float(var2 * mean1 + var1 * mean2) / (var1 + var2) | |
new_var = 1./(1./var1 + 1./var2) | |
return [new_mean, new_var] | |
#motion | |
def predict(mean1, var1, mean2, var2): | |
new_mean = mean1 + mean2 | |
new_var = var1 + var2 |
This file contains hidden or 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
#state = initial state, [intial_x_pos, velocity] | |
#dt = change in time | |
#predicted_state = change in state. | |
#constant velocity model, displacement | |
def predict_state_mtx(state, dt): | |
const_vel_matrix = matrix.Matrix([ [1, dt], | |
[0, 1] ]) | |
predicted_state = const_vel_matrix * state | |
return predicted_state |
This file contains hidden or 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
#Vector Addition | |
def add(vector_1, vector_2): | |
if len(vector_1) != len(vector_2): | |
print("error! vectors must be same size to add") | |
return | |
new_vector = [] | |
for i in range(len(vector_1)): | |
new_vector.append(vector_1[i] + vector_2[i]) | |
OlderNewer