https://classroom.udacity.com/courses/cs215/lessons/48739297/concepts/487342830923
LESSON 4
# animal speed weight lifespan brain
# (mph) (kg) (years) mass (g)
animals = [("dog", 46, 35, 13, 280 ),
("elephant", 30, 3500, 50, 6250 ),
("frog", 5, 0.5, 8, 3 ),
("hippopotamus", 45, 1600, 45, 573 ),
("horse", 40, 385, 30, 642 ),
("human", 27, 80, 78, 2000 ),
("lion", 50, 250, 30, 454 ),
("mouse", 8, 0.025, 2, 0.625),
("rabbit", 25, 4, 12, 40 ),
("shark", 26, 230, 20, 92 ),
("sparrow", 16, 0.024, 7, 2 )]
def importance_rank(items, weights):
names = [item[0] for item in items] # get the list of animal names
scores = [sum([a*b for (a,b) in zip(item[1:], weights)]) for item in items] # get the list of overall scores for each animal
results = zip(scores,names) # make a list of tuple
res2 = sorted(results) # sort the tuple based on the score
return res2
answer = importance_rank(animals, (2,3,7,1))
for i in range(len(answer)):
print i, answer[i][1], "(", answer[i][0], ")"
0 mouse ( 30.7 )
1 frog ( 70.5 )
2 sparrow ( 83.072 )
3 rabbit ( 186 )
4 dog ( 568 )
5 shark ( 974 )
6 lion ( 1514 )
7 horse ( 2087 )
8 human ( 2840 )
9 hippopotamus ( 5778 )
10 elephant ( 17160 )
In graph theory and network analysis, indicators of centrality identify the most important vertices within a graph. Applications include identifying the most influential person(s) in a social network, key infrastructure nodes in the Internet or urban networks, and super-spreaders of disease. Centrality concepts were first developed in social network analysis, and many of the terms used to measure centrality reflect their sociological origin.
Degree (node) centrality:
"An important node is involved in large number of interactions"
Historically first and conceptually simplest is degree centrality, which is defined as the number of links incident upon a node (i.e., the number of ties that a node has). The degree can be interpreted in terms of the immediate risk of a node for catching whatever is flowing through the network (such as a virus, or some information). In the case of a directed network (where ties have direction), we usually define two separate measures of degree centrality, namely indegree and outdegree.
Closeness centrality
In connected graphs there is a natural distance metric between all pairs of nodes, defined by the length of their shortest paths.
The information centrality of Stephenson and Zelen (1989) is another closeness measure, which computes the harmonic mean of the resistance distances towards a vertex x, which is smaller if x has many paths of small resistance connecting it to other vertices.
Betweenness is a centrality measure of a vertex within a graph. It quantifies the number of times a node acts as a bridge along the shortest path between two other nodes. It was introduced as a measure for quantifying the control of a human on the communication between other humans in a social network by Linton Freeman. In his conception, vertices that have a high probability to occur on a randomly chosen shortest path between two randomly chosen vertices have a high betweenness.
Eigenvector centrality (also called eigencentrality) is a measure of the influence of a node in a network. It assigns relative scores to all nodes in the network based on the concept that connections to high-scoring nodes contribute more to the score of the node in question than equal connections to low-scoring nodes. Google's PageRank is a variant of the eigenvector centrality measure.
###################################################################
21 57 midpoint
43 51 median
48 54 mean C1&C2
49
50
51
75
77
79
87
93
The Sorter: http://www.youtube.com/watch?v=2HjspVV0jK4
def max(L):
maxL = L[0]
for i in range(1, len(L)):
if L[i] >= maxL:
maxL = L[i]
return maxL
def test():
L = [1, 2, 3, 4]
assert 4 == max(L)
L = [3, 6, 10, 9, 3]
assert 10 == max(L)
print test()
#############################################################################
f = open("yob1995.txt", "r")
def find_count_f(a):
max_count = 0
for line in a:
name,sex,count = line.split(",")
count = int(count)
if sex == "F" and max_count < count:
max_count = count
fmost_popular = name
return fmost_popular, max_count
print find_count_f(f)
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>>
======= RESTART: /Users/olgabelitskaya/Desktop/course7/hello world.py =======
('Jessica', 27931)
>>>
f = open("yob1995.txt", "r")
def second_count_f(a):
first_count = 0
second_count = 0
first_name = None
second_name = None
for line in a:
name,sex,count = line.split(",")
count = int(count)
if sex == "F":
if first_count < count:
second_count = first_count
second_name = first_name
first_count = count
first_name = name
return second_name
print second_count_f(f)
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.
======= RESTART: /Users/olgabelitskaya/Desktop/course7/hello world.py =======
Ashley
>>>
#
# Write partition to return a new array with
# all values less then `v` to the left
# and all values greater then `v` to the right
#
def partition(L, v):
p1 = []
p2 = []
for element in L:
if element < v:
p1.append(element)
elif element > v:
p2.append(element)
p1.append(v)
# your code here
return p1 + p2
L = [12, 24, 98, 35, 73, 76, 18, 65]
print partition(L,65)
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: If A is a parent node of B then the key (the value) of node A is ordered with respect to the key of node B with the same ordering applying across the heap. A heap can be classified further as either a "max heap" or a "min heap". In a max heap, the keys of parent nodes are always greater than or equal to those of the children and the highest key is in the root node. In a min heap, the keys of parent nodes are less than or equal to those of the children and the lowest key is in the root node. Heaps are crucial in several efficient graph algorithms such as Dijkstra's algorithm, and in the sorting algorithm heapsort. A common implementation of a heap is the binary heap, in which the tree is a complete binary tree (see figure).
In a heap, the highest (or lowest) priority element is always stored at the root. A heap is not a sorted structure and can be regarded as partially ordered. As visible from the heap-diagram, there is no particular relationship among nodes on any given level, even among the siblings. When a heap is a complete binary tree, it has a smallest possible height—a heap with N nodes always has log N height. A heap is a useful data structure when you need to remove the object with the highest (or lowest) priority.
A binary heap is a heap data structure created using a binary tree. It can be seen as a binary tree with two additional constraints:
Shape property
A binary heap is a complete binary tree; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.
Heap property
All nodes are either greater than or equal to or less than or equal to each of their children, according to a comparison predicate defined for the heap.
Heaps with a mathematical "greater than or equal to" (≥) comparison predicate are called max-heaps; those with a mathematical "less than or equal to" (≤) comparison predicate are called min-heaps. Min-heaps are often used to implement priority queues.
#
# Implement remove_min
#
def remove_min(L):
if len(L) == 1:
return []
L[0] = L.pop()
down_heapify(L, 0)
# your code here
return L
def parent(i):
return (i-1)/2
def left_child(i):
return 2*i+1
def right_child(i):
return 2*i+2
def is_leaf(L,i):
return (left_child(i) >= len(L)) and (right_child(i) >= len(L))
def one_child(L,i):
return (left_child(i) < len(L)) and (right_child(i) >= len(L))
# Call this routine if the heap rooted at i satisfies the heap property
# *except* perhaps i to its immediate children
def down_heapify(L, i):
# If i is a leaf, heap property holds
if is_leaf(L, i):
return
# If i has one child...
if one_child(L, i):
# check heap property
if L[i] > L[left_child(i)]:
# If it fails, swap, fixing i and its child (a leaf)
(L[i], L[left_child(i)]) = (L[left_child(i)], L[i])
return
# If i has two children...
# check heap property
if min(L[left_child(i)], L[right_child(i)]) >= L[i]:
return
# If it fails, see which child is the smaller
# and swap i's value into that child
# Afterwards, recurse into that child, which might violate
if L[left_child(i)] < L[right_child(i)]:
# Swap into left child
(L[i], L[left_child(i)]) = (L[left_child(i)], L[i])
down_heapify(L, left_child(i))
return
else:
(L[i], L[right_child(i)]) = (L[right_child(i)], L[i])
down_heapify(L, right_child(i))
return
#########
# Testing Code
#
# build_heap
def build_heap(L):
for i in range(len(L)-1, -1, -1):
down_heapify(L, i)
return L
def test():
L = range(10)
build_heap(L)
remove_min(L)
# now, the new minimum should be 1
assert L[0] == 1
print test()
olgabelitskaya (master) ~ $ cd version-control
olgabelitskaya (master *) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: reflections-cs215/lesson3_reflections_ob.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
reflections-cs215/lesson4_reflections_ob.txt
no changes added to commit (use "git add" and/or "git commit -a")
olgabelitskaya (master *) version-control $ git add 'reflections-cs215/lesson3_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git commit -m "Update lesson3_reflections_ob.txt"
[master 1a4653b] Update lesson3_reflections_ob.txt
1 file changed, 45 insertions(+)
olgabelitskaya (master) version-control $ git add 'reflections-cs215/lesson4_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git commit -m "Add reflections lesson 4"
[master 3814483] Add reflections lesson 4
1 file changed, 251 insertions(+)
create mode 100644 reflections-cs215/lesson4_reflections_ob.txt
olgabelitskaya (master) version-control $ git status
On branch master
Your branch is ahead of 'exercises/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
olgabelitskaya (master) version-control $ git push exercises master
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 5.27 KiB | 0 bytes/s, done.
Total 8 (delta 5), reused 0 (delta 0)
To https://github.com/OlgaBelitskaya/my-exercises.git
4443845..3814483 master -> master
PROBLEM SET 4
#1
heap = []
for v in vals:
insert_heap(heap,v)
Θ(n*log(n))
#2
#
# Given a list of numbers, L, find a number, x, that
# minimizes the sum of the absolute value of the difference
# between each element in L and x: SUM_{i=0}^{n-1} |L[i] - x|
#
# Your code should run in Theta(n) time
#
L = [12,83,15,27,35,7,64]
def minimize_absolute(L):
S = []
for element in L:
se = 0
for i in range(len(L)):
se = se + abs(L[i] - element)
S.append(se)
print S
k = min(S)
print k
ik = S.index(k)
# your code here
return L[ik]
print minimize_absolute(L)
#3
#
# Given a list of numbers, L, find a number, x, that
# minimizes the sum of the square of the difference
# between each element in L and x: SUM_{i=0}^{n-1} (L[i] - x)^2
#
# Your code should run in Theta(n) time
#
L = [2,2,3,4]
def minimize_square(L):
S = []
for element in L:
sq = 0
for j in range(len(L)):
se = element - L[j]
sq = sq + se*se
S.append(sq)
print S
k = min(S)
print k
ik = S.index(k)
# your code here
return L[ik]
print minimize_square(L)
#################################################################
L = [2,2,3,4]
def minimize_square(L):
S = {}
print L
for element in L:
sq = 0
for j in range(len(L)):
se = element - L[j]
sq = sq + se*se
S[element] = sq
print S
for key, value in S.iteritems():
if value == min(S.values()):
return key
print minimize_square(L)
#4
4.1
#
# Given a list L of n numbers, find the mode
# (the number that appears the most times).
# Your algorithm should run in Theta(n).
# If there are ties - just pick one value to return
#
from operator import itemgetter
def mode(L):
counts = {}
maxelement = None
maxn = 0
for element in L:
if element not in counts:
counts[element] = 1
else:
counts[element] += 1
if counts[element] > maxn:
maxelement = element
maxn = counts[element]
return maxelement
# your code here
####
# Test
#
import time
from random import randint
def test():
assert 5 == mode([1, 5, 2, 5, 3, 5])
iterations = (10, 20, 30, 100, 200, 300, 1000, 5000, 10000, 20000, 30000)
times = []
for i in iterations:
L = []
for j in range(i):
L.append(randint(1, 10))
start = time.clock()
for j in range(500):
mode(L)
end = time.clock()
print start, end
times.append(float(end - start))
slopes = []
for (x1, x2), (y1, y2) in zip(zip(iterations[:-1], iterations[1:]), zip(times[:-1], times[1:])):
print (x1, x2), (y1, y2)
slopes.append((y2 - y1) / (x2 - x1))
# if mode runs in linear time,
# these factors should be close (kind of)
print slopes
print test()
RESET TEST RUN SUBMIT
0.013615 0.014496
0.014539 0.016172
0.016212 0.018655
0.01876 0.027141
0.027386 0.04383
0.044145 0.068484
0.069518 0.150515
0.15572 0.553299
0.563656 1.339508
1.360104 2.902613
2.933505 5.293337
(10, 20) (0.0008809999999999998, 0.001632999999999999)
(20, 30) (0.001632999999999999, 0.0024430000000000007)
(30, 100) (0.0024430000000000007, 0.008381)
(100, 200) (0.008381, 0.016444)
(200, 300) (0.016444, 0.024339000000000006)
(300, 1000) (0.024339000000000006, 0.08099700000000001)
(1000, 5000) (0.08099700000000001, 0.397579)
(5000, 10000) (0.397579, 0.7758519999999999)
(10000, 20000) (0.7758519999999999, 1.5425090000000001)
(20000, 30000) (1.5425090000000001, 2.3598320000000004)
[7.519999999999992e-05, 8.100000000000017e-05, 8.482857142857141e-05, 8.063e-05, 7.895000000000006e-05, 8.094000000000001e-05, 7.914550000000001e-05, 7.565459999999997e-05, 7.666570000000002e-05, 8.173230000000003e-05]
None
##########################################################
4.2
from operator import itemgetter
from collections import defaultdict
def mode(L):
counts = defaultdict(int)
mode = None
maxn = 0
for e in L:
counts[e] += 1
current = counts[e]
if current > maxn:
mode = e
maxn = current
return mode
0.01416 0.01542
0.015468 0.017476
0.017512 0.020281
0.020391 0.027656
0.027869 0.041363
0.041676 0.061522
0.062561 0.12634
0.131508 0.457904
0.468202 1.123113
1.143701 2.454703
2.485846 4.46365
(10, 20) (0.001259999999999999, 0.0020079999999999976)
(20, 30) (0.0020079999999999976, 0.0027690000000000006)
(30, 100) (0.0027690000000000006, 0.007265000000000001)
(100, 200) (0.007265000000000001, 0.013493999999999996)
(200, 300) (0.013493999999999996, 0.019846000000000003)
(300, 1000) (0.019846000000000003, 0.063779)
(1000, 5000) (0.063779, 0.32639599999999996)
(5000, 10000) (0.32639599999999996, 0.654911)
(10000, 20000) (0.654911, 1.3110019999999998)
(20000, 30000) (1.3110019999999998, 1.9778040000000003)
[7.479999999999987e-05, 7.61000000000003e-05, 6.422857142857144e-05, 6.228999999999995e-05, 6.352000000000007e-05, 6.276142857142857e-05, 6.565425e-05, 6.570300000000002e-05, 6.560909999999998e-05, 6.668020000000006e-05]
None
#######################################################################
4.3
from operator import itemgetter
from collections import defaultdict
def mode(L):
amounts = defaultdict(int)
for v in L:
amounts[v] +=1
return max(amounts, key = lambda x: amounts[x])
0.014366 0.016016
0.016062 0.018403
0.018443 0.021367
0.021478 0.026966
0.027181 0.036292
0.036608 0.049343
0.050382 0.088166
0.093351 0.281401
0.297654 0.713603
0.734345 1.498868
1.529933 2.681095
(10, 20) (0.0016499999999999987, 0.0023409999999999993)
(20, 30) (0.0023409999999999993, 0.0029239999999999995)
(30, 100) (0.0029239999999999995, 0.005488)
(100, 200) (0.005488, 0.009110999999999998)
(200, 300) (0.009110999999999998, 0.012734999999999996)
(300, 1000) (0.012734999999999996, 0.03778399999999999)
(1000, 5000) (0.03778399999999999, 0.18805)
(5000, 10000) (0.18805, 0.415949)
(10000, 20000) (0.415949, 0.7645230000000001)
(20000, 30000) (0.7645230000000001, 1.151162)
[6.910000000000007e-05, 5.830000000000002e-05, 3.6628571428571435e-05, 3.622999999999998e-05, 3.6239999999999985e-05, 3.578428571428571e-05, 3.75665e-05, 4.557980000000001e-05, 3.48574e-05, 3.8663899999999994e-05]
None
##########################################################################
4.4
from operator import itemgetter
def mode(L):
values = set(L)
return max(values, key = lambda x: L.count(x))
0.013503 0.014766
0.014812 0.016569
0.016608 0.019108
0.019215 0.024997
0.025211 0.035604
0.035921 0.050884
0.051921 0.099694
0.104897 0.342236
0.352604 0.82273
0.843408 1.783683
1.814736 3.228627
(10, 20) (0.0012630000000000002, 0.0017569999999999999)
(20, 30) (0.0017569999999999999, 0.0024999999999999988)
(30, 100) (0.0024999999999999988, 0.005781999999999999)
(100, 200) (0.005781999999999999, 0.010392999999999996)
(200, 300) (0.010392999999999996, 0.014962999999999997)
(300, 1000) (0.014962999999999997, 0.047773)
(1000, 5000) (0.047773, 0.23733899999999997)
(5000, 10000) (0.23733899999999997, 0.470126)
(10000, 20000) (0.470126, 0.9402749999999999)
(20000, 30000) (0.9402749999999999, 1.413891)
[4.939999999999997e-05, 7.429999999999988e-05, 4.688571428571429e-05, 4.610999999999997e-05, 4.570000000000001e-05, 4.687142857142858e-05, 4.739149999999999e-05, 4.65574e-05, 4.701489999999999e-05, 4.736160000000002e-05]
None
###########################################################################
4.5
from operator import itemgetter
def mode(L):
return max(set(L), key = lambda x: L.count(x))
TEST RUN
0.013792 0.014963
0.015015 0.016845
0.016882 0.019399
0.019513 0.025268
0.025498 0.035938
0.036287 0.051412
0.052471 0.100546
0.105764 0.344642
0.355091 0.830679
0.851587 1.797449
1.828574 3.2462
(10, 20) (0.0011710000000000002, 0.0018299999999999983)
(20, 30) (0.0018299999999999983, 0.0025169999999999984)
(30, 100) (0.0025169999999999984, 0.005755)
(100, 200) (0.005755, 0.010439999999999998)
(200, 300) (0.010439999999999998, 0.015125)
(300, 1000) (0.015125, 0.048075)
(1000, 5000) (0.048075, 0.238878)
(5000, 10000) (0.238878, 0.47558799999999996)
(10000, 20000) (0.47558799999999996, 0.9458620000000001)
(20000, 30000) (0.9458620000000001, 1.417626)
[6.589999999999981e-05, 6.870000000000002e-05, 4.625714285714288e-05, 4.684999999999998e-05, 4.6850000000000014e-05, 4.707142857142857e-05, 4.770075e-05, 4.734199999999999e-05, 4.702740000000002e-05, 4.71764e-05]
None
#########################################################################
#5
#
# write up_heapify, an algorithm that checks if
# node i and its parent satisfy the heap
# property, swapping and recursing if they don't
#
# L should be a heap when up_heapify is done
#
def parent(i):
return (i-1)/2
def left_child(i):
return 2*i+1
def right_child(i):
return 2*i+2
def is_leaf(L,i):
return (left_child(i) >= len(L)) and (right_child(i) >= len(L))
def one_child(L,i):
return (left_child(i) < len(L)) and (right_child(i) >= len(L))
def up_heapify(L, i):
while L[i] < L[parent(i)] and parent(i) != -1:
print L
print i, L[i]
print parent(i), L[parent(i)]
(L[parent(i)], L[i]) = (L[i], L[parent(i)])
i = parent(i)
# your code here
return L
def test():
L = [2, 4, 3, 5, 9, 7, 7]
L.append(1)
up_heapify(L, 7)
assert 1 == L[0]
assert 2 == L[1]
print test()
TEST RUN
[2, 4, 3, 5, 9, 7, 7, 1]
7 1
3 5
[2, 4, 3, 1, 9, 7, 7, 5]
3 1
1 4
[2, 1, 3, 4, 9, 7, 7, 5]
1 1
0 2
None
#######################################################################
#6
import random
import csv
def make_link(G, node1, node2):
if node1 not in G:
G[node1] = {}
(G[node1])[node2] = 1
if node2 not in G:
G[node2] = {}
(G[node2])[node1] = 1
return G
def make_data(file_name):
data = scv.reader(open(file_name), delimiter='\t')
G = {}
actors = {}
movies = {}
for (actor, movie, year) in data:
movie_year = str(movie) + "," + str(year)
actors[actor] = 1
movies[movie_year] = 1
make_link(G, actor, movie_year)
return (G,actors,movies)
def centrality(G, v):
distance_from_start = {}
open_list = [v]
distance_from_start[v] = 0
while len(open_list) > 0:
current = open_list.pop(0)
for neighbor in G[current].keys():
if neighbor not in distance_from_start:
distance_from_start[neighbor] = distance_from_start[current] + 1
open_list.append(neighbor)
return (float(sum(distance_from_start.values())))/len(distance_from_start)
def rank(L,v):
rank = 0
for element in L:
if element < v:
rank += 1
return rank
def find_rank(L, t):
less_t = {}
equal_t = {}
greater_t = {}
v = random.choice(L.keys())
for t in L.keys():
if L[l] < L[v]:
less_t[t] = L[t]
elif L[t] == L[v]:
equal_t[t] = L[t]
elif L[t] > L[v]:
greater_t[t] = L[t]
if len(less_t) >= t: return find_rank(less_t,t)
elif len(less_t) + len(equal_t) >= t: return v
else: return find_rank(greater_t, t - len(less_t) - len(equal_t))
(G, actors, movies) = make_data(actors.tsv)
centralities = {}
for actor in actors.key():
centralities[actor] = centrality(G, actor)
actor_rank = firn_rank(centralities, 20)
print actor_rank
print centralities[actor_rank]
#######################################################################
Last login: Tue Jun 21 09:16:40 on console
olgabelitskaya (master) ~ $ cd version-control
olgabelitskaya (master *) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: reflections-cs215/lesson4_reflections_ob.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
reflections-cs215/lesson5_reflections_ob.rtf
no changes added to commit (use "git add" and/or "git commit -a")
olgabelitskaya (master *) version-control $ git add 'reflections-cs215/lesson4_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git commit -m "Update lesson4_reflections_ob.txt"
[master b1ee03c] Update lesson4_reflections_ob.txt
1 file changed, 411 insertions(+), 1 deletion(-)
olgabelitskaya (master) version-control $ git add 'reflections-cs215/lesson5_reflections_ob.rtf'
olgabelitskaya (master +) version-control $ git commit -m "Create lesson5_reflections_ob.rtf"
[master 2ebe71b] Create lesson5_reflections_ob.rtf
1 file changed, 13 insertions(+)
create mode 100644 reflections-cs215/lesson5_reflections_ob.rtf
olgabelitskaya (master) version-control $ git push exercises master
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 8.07 KiB | 0 bytes/s, done.
Total 8 (delta 4), reused 0 (delta 0)
To https://github.com/OlgaBelitskaya/my-exercises.git
3814483..2ebe71b master -> master
Last login: Tue Jun 21 17:24:48 on ttys000
olgabelitskaya (master) ~ $ cd version-control
olgabelitskaya (master *) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: reflections-cs215/lesson3_reflections_ob.txt
modified: reflections-cs215/lesson4_reflections_ob.txt
no changes added to commit (use "git add" and/or "git commit -a")
olgabelitskaya (master *) version-control $ git add 'reflections-cs215/lesson3_reflections_ob.txt'
olgabelitskaya (master *+) version-control $ git add 'reflections-cs215/lesson4_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: reflections-cs215/lesson3_reflections_ob.txt
modified: reflections-cs215/lesson4_reflections_ob.txt
olgabelitskaya (master +) version-control $ git commit -m "Update lesson3_reflections_ob.txt and lesson4_reflections_ob.txt"
[master cfaa476] Update lesson3_reflections_ob.txt and lesson4_reflections_ob.txt
2 files changed, 120 insertions(+)
olgabelitskaya (master) version-control $ git push exercises master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 8.32 KiB | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
To https://github.com/OlgaBelitskaya/my-exercises.git
2ebe71b..cfaa476 master -> master
LESSON 4
# animal speed weight lifespan brain
# (mph) (kg) (years) mass (g)
animals = [("dog", 46, 35, 13, 280 ),
("elephant", 30, 3500, 50, 6250 ),
("frog", 5, 0.5, 8, 3 ),
("hippopotamus", 45, 1600, 45, 573 ),
("horse", 40, 385, 30, 642 ),
("human", 27, 80, 78, 2000 ),
("lion", 50, 250, 30, 454 ),
("mouse", 8, 0.025, 2, 0.625),
("rabbit", 25, 4, 12, 40 ),
("shark", 26, 230, 20, 92 ),
("sparrow", 16, 0.024, 7, 2 )]
def importance_rank(items, weights):
names = [item[0] for item in items] # get the list of animal names
scores = [sum([a*b for (a,b) in zip(item[1:], weights)]) for item in items] # get the list of overall scores for each animal
results = zip(scores,names) # make a list of tuple
res2 = sorted(results) # sort the tuple based on the score
return res2
answer = importance_rank(animals, (2,3,7,1))
for i in range(len(answer)):
print i, answer[i][1], "(", answer[i][0], ")"
0 mouse ( 30.7 )
1 frog ( 70.5 )
2 sparrow ( 83.072 )
3 rabbit ( 186 )
4 dog ( 568 )
5 shark ( 974 )
6 lion ( 1514 )
7 horse ( 2087 )
8 human ( 2840 )
9 hippopotamus ( 5778 )
10 elephant ( 17160 )
In graph theory and network analysis, indicators of centrality identify the most important vertices within a graph. Applications include identifying the most influential person(s) in a social network, key infrastructure nodes in the Internet or urban networks, and super-spreaders of disease. Centrality concepts were first developed in social network analysis, and many of the terms used to measure centrality reflect their sociological origin.
Degree (node) centrality:
"An important node is involved in large number of interactions"
Historically first and conceptually simplest is degree centrality, which is defined as the number of links incident upon a node (i.e., the number of ties that a node has). The degree can be interpreted in terms of the immediate risk of a node for catching whatever is flowing through the network (such as a virus, or some information). In the case of a directed network (where ties have direction), we usually define two separate measures of degree centrality, namely indegree and outdegree.
Closeness centrality
In connected graphs there is a natural distance metric between all pairs of nodes, defined by the length of their shortest paths.
The information centrality of Stephenson and Zelen (1989) is another closeness measure, which computes the harmonic mean of the resistance distances towards a vertex x, which is smaller if x has many paths of small resistance connecting it to other vertices.
Betweenness is a centrality measure of a vertex within a graph. It quantifies the number of times a node acts as a bridge along the shortest path between two other nodes. It was introduced as a measure for quantifying the control of a human on the communication between other humans in a social network by Linton Freeman. In his conception, vertices that have a high probability to occur on a randomly chosen shortest path between two randomly chosen vertices have a high betweenness.
Eigenvector centrality (also called eigencentrality) is a measure of the influence of a node in a network. It assigns relative scores to all nodes in the network based on the concept that connections to high-scoring nodes contribute more to the score of the node in question than equal connections to low-scoring nodes. Google's PageRank is a variant of the eigenvector centrality measure.
###################################################################
21 57 midpoint
43 51 median
48 54 mean C1&C2
49
50
51
75
77
79
87
93
The Sorter: http://www.youtube.com/watch?v=2HjspVV0jK4
def max(L):
maxL = L[0]
for i in range(1, len(L)):
if L[i] >= maxL:
maxL = L[i]
return maxL
def test():
L = [1, 2, 3, 4]
assert 4 == max(L)
L = [3, 6, 10, 9, 3]
assert 10 == max(L)
print test()
#############################################################################
f = open("yob1995.txt", "r")
def find_count_f(a):
max_count = 0
for line in a:
name,sex,count = line.split(",")
count = int(count)
if sex == "F" and max_count < count:
max_count = count
fmost_popular = name
return fmost_popular, max_count
print find_count_f(f)
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>>
======= RESTART: /Users/olgabelitskaya/Desktop/course7/hello world.py =======
('Jessica', 27931)
>>>
f = open("yob1995.txt", "r")
def second_count_f(a):
first_count = 0
second_count = 0
first_name = None
second_name = None
for line in a:
name,sex,count = line.split(",")
count = int(count)
if sex == "F":
if first_count < count:
second_count = first_count
second_name = first_name
first_count = count
first_name = name
return second_name
print second_count_f(f)
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 12:54:16)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.
======= RESTART: /Users/olgabelitskaya/Desktop/course7/hello world.py =======
Ashley
>>>
#
# Write partition to return a new array with
# all values less then `v` to the left
# and all values greater then `v` to the right
#
def partition(L, v):
p1 = []
p2 = []
for element in L:
if element < v:
p1.append(element)
elif element > v:
p2.append(element)
p1.append(v)
# your code here
return p1 + p2
L = [12, 24, 98, 35, 73, 76, 18, 65]
print partition(L,65)
In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: If A is a parent node of B then the key (the value) of node A is ordered with respect to the key of node B with the same ordering applying across the heap. A heap can be classified further as either a "max heap" or a "min heap". In a max heap, the keys of parent nodes are always greater than or equal to those of the children and the highest key is in the root node. In a min heap, the keys of parent nodes are less than or equal to those of the children and the lowest key is in the root node. Heaps are crucial in several efficient graph algorithms such as Dijkstra's algorithm, and in the sorting algorithm heapsort. A common implementation of a heap is the binary heap, in which the tree is a complete binary tree (see figure).
In a heap, the highest (or lowest) priority element is always stored at the root. A heap is not a sorted structure and can be regarded as partially ordered. As visible from the heap-diagram, there is no particular relationship among nodes on any given level, even among the siblings. When a heap is a complete binary tree, it has a smallest possible height—a heap with N nodes always has log N height. A heap is a useful data structure when you need to remove the object with the highest (or lowest) priority.
A binary heap is a heap data structure created using a binary tree. It can be seen as a binary tree with two additional constraints:
Shape property
A binary heap is a complete binary tree; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.
Heap property
All nodes are either greater than or equal to or less than or equal to each of their children, according to a comparison predicate defined for the heap.
Heaps with a mathematical "greater than or equal to" (≥) comparison predicate are called max-heaps; those with a mathematical "less than or equal to" (≤) comparison predicate are called min-heaps. Min-heaps are often used to implement priority queues.
#
# Implement remove_min
#
def remove_min(L):
if len(L) == 1:
return []
L[0] = L.pop()
down_heapify(L, 0)
# your code here
return L
def parent(i):
return (i-1)/2
def left_child(i):
return 2*i+1
def right_child(i):
return 2*i+2
def is_leaf(L,i):
return (left_child(i) >= len(L)) and (right_child(i) >= len(L))
def one_child(L,i):
return (left_child(i) < len(L)) and (right_child(i) >= len(L))
# Call this routine if the heap rooted at i satisfies the heap property
# *except* perhaps i to its immediate children
def down_heapify(L, i):
# If i is a leaf, heap property holds
if is_leaf(L, i):
return
# If i has one child...
if one_child(L, i):
# check heap property
if L[i] > L[left_child(i)]:
# If it fails, swap, fixing i and its child (a leaf)
(L[i], L[left_child(i)]) = (L[left_child(i)], L[i])
return
# If i has two children...
# check heap property
if min(L[left_child(i)], L[right_child(i)]) >= L[i]:
return
# If it fails, see which child is the smaller
# and swap i's value into that child
# Afterwards, recurse into that child, which might violate
if L[left_child(i)] < L[right_child(i)]:
# Swap into left child
(L[i], L[left_child(i)]) = (L[left_child(i)], L[i])
down_heapify(L, left_child(i))
return
else:
(L[i], L[right_child(i)]) = (L[right_child(i)], L[i])
down_heapify(L, right_child(i))
return
#########
# Testing Code
#
# build_heap
def build_heap(L):
for i in range(len(L)-1, -1, -1):
down_heapify(L, i)
return L
def test():
L = range(10)
build_heap(L)
remove_min(L)
# now, the new minimum should be 1
assert L[0] == 1
print test()
olgabelitskaya (master) ~ $ cd version-control
olgabelitskaya (master *) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: reflections-cs215/lesson3_reflections_ob.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
reflections-cs215/lesson4_reflections_ob.txt
no changes added to commit (use "git add" and/or "git commit -a")
olgabelitskaya (master *) version-control $ git add 'reflections-cs215/lesson3_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git commit -m "Update lesson3_reflections_ob.txt"
[master 1a4653b] Update lesson3_reflections_ob.txt
1 file changed, 45 insertions(+)
olgabelitskaya (master) version-control $ git add 'reflections-cs215/lesson4_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git commit -m "Add reflections lesson 4"
[master 3814483] Add reflections lesson 4
1 file changed, 251 insertions(+)
create mode 100644 reflections-cs215/lesson4_reflections_ob.txt
olgabelitskaya (master) version-control $ git status
On branch master
Your branch is ahead of 'exercises/master' by 2 commits.
(use "git push" to publish your local commits)
nothing to commit, working directory clean
olgabelitskaya (master) version-control $ git push exercises master
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 5.27 KiB | 0 bytes/s, done.
Total 8 (delta 5), reused 0 (delta 0)
To https://github.com/OlgaBelitskaya/my-exercises.git
4443845..3814483 master -> master
PROBLEM SET 4
#1
heap = []
for v in vals:
insert_heap(heap,v)
Θ(n*log(n))
#2
#
# Given a list of numbers, L, find a number, x, that
# minimizes the sum of the absolute value of the difference
# between each element in L and x: SUM_{i=0}^{n-1} |L[i] - x|
#
# Your code should run in Theta(n) time
#
L = [12,83,15,27,35,7,64]
def minimize_absolute(L):
S = []
for element in L:
se = 0
for i in range(len(L)):
se = se + abs(L[i] - element)
S.append(se)
print S
k = min(S)
print k
ik = S.index(k)
# your code here
return L[ik]
print minimize_absolute(L)
#3
#
# Given a list of numbers, L, find a number, x, that
# minimizes the sum of the square of the difference
# between each element in L and x: SUM_{i=0}^{n-1} (L[i] - x)^2
#
# Your code should run in Theta(n) time
#
L = [2,2,3,4]
def minimize_square(L):
S = []
for element in L:
sq = 0
for j in range(len(L)):
se = element - L[j]
sq = sq + se*se
S.append(sq)
print S
k = min(S)
print k
ik = S.index(k)
# your code here
return L[ik]
print minimize_square(L)
#################################################################
L = [2,2,3,4]
def minimize_square(L):
S = {}
print L
for element in L:
sq = 0
for j in range(len(L)):
se = element - L[j]
sq = sq + se*se
S[element] = sq
print S
for key, value in S.iteritems():
if value == min(S.values()):
return key
print minimize_square(L)
#4
4.1
#
# Given a list L of n numbers, find the mode
# (the number that appears the most times).
# Your algorithm should run in Theta(n).
# If there are ties - just pick one value to return
#
from operator import itemgetter
def mode(L):
counts = {}
maxelement = None
maxn = 0
for element in L:
if element not in counts:
counts[element] = 1
else:
counts[element] += 1
if counts[element] > maxn:
maxelement = element
maxn = counts[element]
return maxelement
# your code here
####
# Test
#
import time
from random import randint
def test():
assert 5 == mode([1, 5, 2, 5, 3, 5])
iterations = (10, 20, 30, 100, 200, 300, 1000, 5000, 10000, 20000, 30000)
times = []
for i in iterations:
L = []
for j in range(i):
L.append(randint(1, 10))
start = time.clock()
for j in range(500):
mode(L)
end = time.clock()
print start, end
times.append(float(end - start))
slopes = []
for (x1, x2), (y1, y2) in zip(zip(iterations[:-1], iterations[1:]), zip(times[:-1], times[1:])):
print (x1, x2), (y1, y2)
slopes.append((y2 - y1) / (x2 - x1))
# if mode runs in linear time,
# these factors should be close (kind of)
print slopes
print test()
RESET TEST RUN SUBMIT
0.013615 0.014496
0.014539 0.016172
0.016212 0.018655
0.01876 0.027141
0.027386 0.04383
0.044145 0.068484
0.069518 0.150515
0.15572 0.553299
0.563656 1.339508
1.360104 2.902613
2.933505 5.293337
(10, 20) (0.0008809999999999998, 0.001632999999999999)
(20, 30) (0.001632999999999999, 0.0024430000000000007)
(30, 100) (0.0024430000000000007, 0.008381)
(100, 200) (0.008381, 0.016444)
(200, 300) (0.016444, 0.024339000000000006)
(300, 1000) (0.024339000000000006, 0.08099700000000001)
(1000, 5000) (0.08099700000000001, 0.397579)
(5000, 10000) (0.397579, 0.7758519999999999)
(10000, 20000) (0.7758519999999999, 1.5425090000000001)
(20000, 30000) (1.5425090000000001, 2.3598320000000004)
[7.519999999999992e-05, 8.100000000000017e-05, 8.482857142857141e-05, 8.063e-05, 7.895000000000006e-05, 8.094000000000001e-05, 7.914550000000001e-05, 7.565459999999997e-05, 7.666570000000002e-05, 8.173230000000003e-05]
None
##########################################################
4.2
from operator import itemgetter
from collections import defaultdict
def mode(L):
counts = defaultdict(int)
mode = None
maxn = 0
for e in L:
counts[e] += 1
current = counts[e]
if current > maxn:
mode = e
maxn = current
return mode
0.01416 0.01542
0.015468 0.017476
0.017512 0.020281
0.020391 0.027656
0.027869 0.041363
0.041676 0.061522
0.062561 0.12634
0.131508 0.457904
0.468202 1.123113
1.143701 2.454703
2.485846 4.46365
(10, 20) (0.001259999999999999, 0.0020079999999999976)
(20, 30) (0.0020079999999999976, 0.0027690000000000006)
(30, 100) (0.0027690000000000006, 0.007265000000000001)
(100, 200) (0.007265000000000001, 0.013493999999999996)
(200, 300) (0.013493999999999996, 0.019846000000000003)
(300, 1000) (0.019846000000000003, 0.063779)
(1000, 5000) (0.063779, 0.32639599999999996)
(5000, 10000) (0.32639599999999996, 0.654911)
(10000, 20000) (0.654911, 1.3110019999999998)
(20000, 30000) (1.3110019999999998, 1.9778040000000003)
[7.479999999999987e-05, 7.61000000000003e-05, 6.422857142857144e-05, 6.228999999999995e-05, 6.352000000000007e-05, 6.276142857142857e-05, 6.565425e-05, 6.570300000000002e-05, 6.560909999999998e-05, 6.668020000000006e-05]
None
#######################################################################
4.3
from operator import itemgetter
from collections import defaultdict
def mode(L):
amounts = defaultdict(int)
for v in L:
amounts[v] +=1
return max(amounts, key = lambda x: amounts[x])
0.014366 0.016016
0.016062 0.018403
0.018443 0.021367
0.021478 0.026966
0.027181 0.036292
0.036608 0.049343
0.050382 0.088166
0.093351 0.281401
0.297654 0.713603
0.734345 1.498868
1.529933 2.681095
(10, 20) (0.0016499999999999987, 0.0023409999999999993)
(20, 30) (0.0023409999999999993, 0.0029239999999999995)
(30, 100) (0.0029239999999999995, 0.005488)
(100, 200) (0.005488, 0.009110999999999998)
(200, 300) (0.009110999999999998, 0.012734999999999996)
(300, 1000) (0.012734999999999996, 0.03778399999999999)
(1000, 5000) (0.03778399999999999, 0.18805)
(5000, 10000) (0.18805, 0.415949)
(10000, 20000) (0.415949, 0.7645230000000001)
(20000, 30000) (0.7645230000000001, 1.151162)
[6.910000000000007e-05, 5.830000000000002e-05, 3.6628571428571435e-05, 3.622999999999998e-05, 3.6239999999999985e-05, 3.578428571428571e-05, 3.75665e-05, 4.557980000000001e-05, 3.48574e-05, 3.8663899999999994e-05]
None
##########################################################################
4.4
from operator import itemgetter
def mode(L):
values = set(L)
return max(values, key = lambda x: L.count(x))
0.013503 0.014766
0.014812 0.016569
0.016608 0.019108
0.019215 0.024997
0.025211 0.035604
0.035921 0.050884
0.051921 0.099694
0.104897 0.342236
0.352604 0.82273
0.843408 1.783683
1.814736 3.228627
(10, 20) (0.0012630000000000002, 0.0017569999999999999)
(20, 30) (0.0017569999999999999, 0.0024999999999999988)
(30, 100) (0.0024999999999999988, 0.005781999999999999)
(100, 200) (0.005781999999999999, 0.010392999999999996)
(200, 300) (0.010392999999999996, 0.014962999999999997)
(300, 1000) (0.014962999999999997, 0.047773)
(1000, 5000) (0.047773, 0.23733899999999997)
(5000, 10000) (0.23733899999999997, 0.470126)
(10000, 20000) (0.470126, 0.9402749999999999)
(20000, 30000) (0.9402749999999999, 1.413891)
[4.939999999999997e-05, 7.429999999999988e-05, 4.688571428571429e-05, 4.610999999999997e-05, 4.570000000000001e-05, 4.687142857142858e-05, 4.739149999999999e-05, 4.65574e-05, 4.701489999999999e-05, 4.736160000000002e-05]
None
###########################################################################
4.5
from operator import itemgetter
def mode(L):
return max(set(L), key = lambda x: L.count(x))
TEST RUN
0.013792 0.014963
0.015015 0.016845
0.016882 0.019399
0.019513 0.025268
0.025498 0.035938
0.036287 0.051412
0.052471 0.100546
0.105764 0.344642
0.355091 0.830679
0.851587 1.797449
1.828574 3.2462
(10, 20) (0.0011710000000000002, 0.0018299999999999983)
(20, 30) (0.0018299999999999983, 0.0025169999999999984)
(30, 100) (0.0025169999999999984, 0.005755)
(100, 200) (0.005755, 0.010439999999999998)
(200, 300) (0.010439999999999998, 0.015125)
(300, 1000) (0.015125, 0.048075)
(1000, 5000) (0.048075, 0.238878)
(5000, 10000) (0.238878, 0.47558799999999996)
(10000, 20000) (0.47558799999999996, 0.9458620000000001)
(20000, 30000) (0.9458620000000001, 1.417626)
[6.589999999999981e-05, 6.870000000000002e-05, 4.625714285714288e-05, 4.684999999999998e-05, 4.6850000000000014e-05, 4.707142857142857e-05, 4.770075e-05, 4.734199999999999e-05, 4.702740000000002e-05, 4.71764e-05]
None
#########################################################################
#5
#
# write up_heapify, an algorithm that checks if
# node i and its parent satisfy the heap
# property, swapping and recursing if they don't
#
# L should be a heap when up_heapify is done
#
def parent(i):
return (i-1)/2
def left_child(i):
return 2*i+1
def right_child(i):
return 2*i+2
def is_leaf(L,i):
return (left_child(i) >= len(L)) and (right_child(i) >= len(L))
def one_child(L,i):
return (left_child(i) < len(L)) and (right_child(i) >= len(L))
def up_heapify(L, i):
while L[i] < L[parent(i)] and parent(i) != -1:
print L
print i, L[i]
print parent(i), L[parent(i)]
(L[parent(i)], L[i]) = (L[i], L[parent(i)])
i = parent(i)
# your code here
return L
def test():
L = [2, 4, 3, 5, 9, 7, 7]
L.append(1)
up_heapify(L, 7)
assert 1 == L[0]
assert 2 == L[1]
print test()
TEST RUN
[2, 4, 3, 5, 9, 7, 7, 1]
7 1
3 5
[2, 4, 3, 1, 9, 7, 7, 5]
3 1
1 4
[2, 1, 3, 4, 9, 7, 7, 5]
1 1
0 2
None
#######################################################################
#6
import random
import csv
def make_link(G, node1, node2):
if node1 not in G:
G[node1] = {}
(G[node1])[node2] = 1
if node2 not in G:
G[node2] = {}
(G[node2])[node1] = 1
return G
def make_data(file_name):
data = scv.reader(open(file_name), delimiter='\t')
G = {}
actors = {}
movies = {}
for (actor, movie, year) in data:
movie_year = str(movie) + "," + str(year)
actors[actor] = 1
movies[movie_year] = 1
make_link(G, actor, movie_year)
return (G,actors,movies)
def centrality(G, v):
distance_from_start = {}
open_list = [v]
distance_from_start[v] = 0
while len(open_list) > 0:
current = open_list.pop(0)
for neighbor in G[current].keys():
if neighbor not in distance_from_start:
distance_from_start[neighbor] = distance_from_start[current] + 1
open_list.append(neighbor)
return (float(sum(distance_from_start.values())))/len(distance_from_start)
def rank(L,v):
rank = 0
for element in L:
if element < v:
rank += 1
return rank
def find_rank(L, t):
less_t = {}
equal_t = {}
greater_t = {}
v = random.choice(L.keys())
for t in L.keys():
if L[l] < L[v]:
less_t[t] = L[t]
elif L[t] == L[v]:
equal_t[t] = L[t]
elif L[t] > L[v]:
greater_t[t] = L[t]
if len(less_t) >= t: return find_rank(less_t,t)
elif len(less_t) + len(equal_t) >= t: return v
else: return find_rank(greater_t, t - len(less_t) - len(equal_t))
(G, actors, movies) = make_data(actors.tsv)
centralities = {}
for actor in actors.key():
centralities[actor] = centrality(G, actor)
actor_rank = firn_rank(centralities, 20)
print actor_rank
print centralities[actor_rank]
#######################################################################
Last login: Tue Jun 21 09:16:40 on console
olgabelitskaya (master) ~ $ cd version-control
olgabelitskaya (master *) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: reflections-cs215/lesson4_reflections_ob.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
reflections-cs215/lesson5_reflections_ob.rtf
no changes added to commit (use "git add" and/or "git commit -a")
olgabelitskaya (master *) version-control $ git add 'reflections-cs215/lesson4_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git commit -m "Update lesson4_reflections_ob.txt"
[master b1ee03c] Update lesson4_reflections_ob.txt
1 file changed, 411 insertions(+), 1 deletion(-)
olgabelitskaya (master) version-control $ git add 'reflections-cs215/lesson5_reflections_ob.rtf'
olgabelitskaya (master +) version-control $ git commit -m "Create lesson5_reflections_ob.rtf"
[master 2ebe71b] Create lesson5_reflections_ob.rtf
1 file changed, 13 insertions(+)
create mode 100644 reflections-cs215/lesson5_reflections_ob.rtf
olgabelitskaya (master) version-control $ git push exercises master
Counting objects: 8, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (8/8), done.
Writing objects: 100% (8/8), 8.07 KiB | 0 bytes/s, done.
Total 8 (delta 4), reused 0 (delta 0)
To https://github.com/OlgaBelitskaya/my-exercises.git
3814483..2ebe71b master -> master
Last login: Tue Jun 21 17:24:48 on ttys000
olgabelitskaya (master) ~ $ cd version-control
olgabelitskaya (master *) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: reflections-cs215/lesson3_reflections_ob.txt
modified: reflections-cs215/lesson4_reflections_ob.txt
no changes added to commit (use "git add" and/or "git commit -a")
olgabelitskaya (master *) version-control $ git add 'reflections-cs215/lesson3_reflections_ob.txt'
olgabelitskaya (master *+) version-control $ git add 'reflections-cs215/lesson4_reflections_ob.txt'
olgabelitskaya (master +) version-control $ git status
On branch master
Your branch is up-to-date with 'exercises/master'.
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: reflections-cs215/lesson3_reflections_ob.txt
modified: reflections-cs215/lesson4_reflections_ob.txt
olgabelitskaya (master +) version-control $ git commit -m "Update lesson3_reflections_ob.txt and lesson4_reflections_ob.txt"
[master cfaa476] Update lesson3_reflections_ob.txt and lesson4_reflections_ob.txt
2 files changed, 120 insertions(+)
olgabelitskaya (master) version-control $ git push exercises master
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 8.32 KiB | 0 bytes/s, done.
Total 5 (delta 3), reused 0 (delta 0)
To https://github.com/OlgaBelitskaya/my-exercises.git
2ebe71b..cfaa476 master -> master
Комментариев нет:
Отправить комментарий