# Probability Density Function (pdf) of standard normal distribution
plot(1/sqrt(2 *pi) * exp(-x^2/2), (x,-5,5))
# zoom in
plot(1/sqrt(2 *pi) * exp(-x^2/2), (x,-5,-4))
# never actually reaches 0, but gets super small very quickly if |x| large
# What is prob that standard normal r.v. lies in (2,3)?
N(integral(1/sqrt(2 *pi) * exp(-x^2/2), (x,2,3)))
# N() does numerical approximation
N(integral(1/sqrt(2 *pi) * exp(-x^2/2), (x,-1,1)))
# Above means that for any normal distribution,
# the probability of lying within one
# standard deviation of the average is 0.68...
N(integral(1/sqrt(2 *pi) * exp(-x^2/2), (x,-2,2)))
N(integral(1/sqrt(2 *pi) * exp(-x^2/2), (x,-3,3)))
# 68, 95, 99.7 Rule from Statistics
# probabilities that normally dist r.v. lies within
# 1,2,3 standard deviations, respectively, of average value
# Let's verify that average of standard normal is 0
# average of dist given by pdf f is:
# integral(x f(x), (x, -infty, infty))
integral(x* 1/sqrt(2 *pi) * exp(-x^2/2), (x,-oo,oo))
# Variance (when average is 0)
# integral( x^2 f(x), (x, -infty, infty))
integral(x^2* 1/sqrt(2 *pi) * exp(-x^2/2), (x,-oo,oo))
# total probability should be 1
integral(1/sqrt(2 *pi) * exp(-x^2/2), (x,-oo,oo))
# Defining and drawing graphs
import networkx as nx
# Python package that we'll use for drawing pictures of graphs
G = nx.Graph() # command to make new empty graph
nx.draw(G) # command for drawing graph (empty, since graph is still empty)
G.add_nodes_from([0,1,2]) # add some vertices labeled 0,1,2
nx.draw(G)
G.add_edges_from([(0,1),(1,2)]) # add two edges connecting 0,1 and 1,2
nx.draw(G)
# Usually will represent graph as an adjacency matrix A
# A is an nxn matrix, where n is the number of vertices
# vertices are labelled as 0,1,...,n-1
# A[i,j] = 1 if i,j are connected, and A[i,j]=0 otherwise
# For G above (n=3)
A = [[0,1,0], [1,0,1], [0,1,0]]
import numpy as np # allows us to use numpy array
H=nx.Graph(np.array(A))
nx.draw(H)