an object in the real world that is distinguishable from other objects. ( can be same category)
described using a set of attributes.
Entity set is a collection of entities of the same type. All entities in a given entity set have the same attributes ( the values may be different).
Domain: domain of possible values of each attribute in an entity set.
Key
superkey: any set of attributes which can uniquely identify an entity
key (candidate key): a minimal set of attributes whose values can uniquely identify an entity in the set. (should depend on the real life possibility 即使还有entity 加入/删除, 这个key永远identify an entity)
primary key: a candidate key chosen to serve as the key for the entity set
Relationships
an association among two or more entities.
eg. Teach: (John,CENG4567) ,(David, CSCI1234)
relationship set: a set of similar relationships: {(John,CENG4567) ,(David, CSCI1234)}
relationships can also have descriptive attributes
SELECT S.sname FROM Sailors S, Reserves R WHERE S.sid=R.sid AND R.bid=103 = SELECT S.sname FROM Sailors S NATURALJOIN Reserves R WHERE R.bid=103
#IN operator SELECT B.bname FROM Boats B WHERE B.color IN (‘red’, ‘blue’, ’green’)
#Nested Queries Find names of sailors who’ve reserved boat #103: SELECT S.sname FROM Sailors S WHERE S.sid IN (SELECT R.sid FROM Reserves R WHERE R.bid=103) #innerfunction can use the relation inouterfunction >ANY : 比某一些大就行
Expressions and string
LIKE for string matching. _ = any one character, % = 0 or more arbitrary characters
Aggregate Operators
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
COUNT([DISTINCT] A) SUM ( [DISTINCT] A) AVG ([DISTINCT] A) MAX (A) MIN (A) A: anycolumnof a relation # cannot be netsted!MIN(AVG(A)) isnot allowed! eg.Find the name and age of the oldest sailor SELECT S.sname, S.age FROM Sailors S WHERE S.age = (SELECTMAX (S2.age) FROM Sailors S2) eg.Find the names of sailors who are older than the oldest sailor with a rating of10. SELECT S.name FROM Sailors S WHERE S.age > ( SELECTMAX (S2.age) FROM Sailors S2 WHERE S2.rating =10)
GROUP BY and Having
1 2 3 4 5 6 7 8 9 10
eg Find the age of the youngest sailor foreach rating level. SELECT S.rating, MIN (S.age) FROM Sailors S GROUPBY S.rating
SELECT [DISTINCT] target-list STEP 2//target list = attribute names + terms with ahhregate operations, The attribute names must be a subsetofgrouping-list. FROM relation-list STEP 1 WHERE qualification STEP 2 GROUPBYgrouping-list STEP3 HAVINGgroup-qualification STEP 4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
SELECT R.day FROM Reserves R GROUPBY R.day HAVINGCOUNT(DISTINCT R.sid) =1
Example: Find the average age of sailors foreach rating level that has at least two sailors. SELECT S.rating, AVG(S.age) AS avgage FROM Sailor S GROUPBY S.rating HAVINGCOUNT (*) >1
Example:Find those ratings for which the average age is the minimum overall ratings SELECT Temp.rating, Temp.avgage FROM (SELECT S.rating, AVG (S.age) AS avgage FROM Sailors S GROUPBY S.rating) AS Temp WHERE Temp.avgage = (SELECTMIN (Temp.avgage) FROM Temp)
Division
CREATE VIEW
Delete view:DROP VIEW Temp
Outer Join
S LEFT OUTER JOIN R: S 中不对应 R的也会加进去。 只是R的field就是 NULL
There are hundreds of programming languages to use now, which make it difficult for programmers to decide which language is the most suitable for them.
Below picture (cited from Quora) also shows that many people, no matter they are experienced programmers or not, have the question:
Which programming language should I learn next?
Motivation
Motivated by the wide range of discussion: “ best programming language to learn” and our former hesitant experience when deciding which programming course to enroll, we decided to design a Fuzzy expert system to solve these kinds of problems.
Problem Definition
The users do not have a clear knowledge on different programming language, which make them hard to select the best/ most suitable programming language for them to learn.
System Design
The Fuzzy system is designed for recommending suitable programming languages for users to learn. And rules are provided for inference so that users need to answer some simple programming habits questions, which are used as facts in the system.
Implementation
Fuzzy type
Difficulty the expected difficulty of programming language.
Time the expected time spent to learn programming language every week.
Resource the expected learning resource of programming language.
Experience the former programming experience of the user.
Efficiency the expected efficiency of programming language.
Package the expected package(eg. numpy in python) requirements of programming language.
Debug the debugging ability and willing of user.
Objects
(conclusion)
preset values of the result
expectation_of_difficulty
time_spent_on_learning
available_resource
experience
package_requirement
efficiency_requirement
upset_when_debug
market_requirement
whether the reason user learns programming is for finding a job.
company_orientation
the expected IT companies the user wants to work for.
interest_field
the expected programming field the user wants to work in.
compiled_language_or_not
whether the user is suitable for compiled language or not.
Rules
Rules in the system is divided into two perspectives: Facts and languages.
For the facts perspective, the rules help to inference the conclusion and other objects such as expectation of difficulty by facts. Here are some examples:
1 2 3 4 5 6 7 8 9 10 11
RULE CODE:difficulty_rule_easy_111 IF time_spent_on_learning is little AND available_resource is little AND experience is little THEN expectation_of_difficulty is easy WITH CERTAINTY: 0.9 //help to inference expectation_of_difficulty
RULE CODE:difficulty_rule_1 IF expectation_of_difficulty is easy THEN programming_language is Python WITH CERTAINTY: 0.75 //help to inference programming_language
For the languages perspective, the rules help to inference the conclusion by languages, this kind of rule makes use of the key features of different programming language. Here is one example:
1 2 3 4
RULE CODE:js_rule_2 IF expectation_of_difficulty is easy AND efficiency_requirement is high AND interest_field is Web_programming THEN programming_language is Javascript WITH CERTAINTY: 0.95
Our system has done a basic programming language recommendation task, which covers almost all possibilities. And the result is really practical for uses.
However, the system can not solve a few specific language requirements well, such as Database programmer and so on.
Further improvements
According to what we mentioned above, the system can be still improved by importing more language-based rules so that the system can handle some specific language requirements better.
A path in a graph is a sequence of nodes with the property that each consecutive pair in the sequence is connected by an edge.
A path can have repeat nodes;
Path without repeat nodes is a simple path
Cycle
A cycle is a path with at least three edges, in which the first and last nodes are the same, but otherwise all nodes are distinct.
Bridge
the edge joining two nodes if deleting that edge would cause the two nodes in two different components.
Local Bridge
Bridge is rare
the edge joining nodes A and B, if its endpoints A and B have no friends in common.
Span of a local bridge:
the distance between the end points if that edge were deleted.(original:1)
Embeddedness(edge)
Embeddedness of an edge in a network is the number of common neighbors the two endpoints have.
Embeddedness(Local bridge) =0
Structure hole (几个不同contacts的中间人)
access information originating in multiple, non-interacting parts of the network.
have opportunities for innovations arose from the unexpected synthesis of multiple ideas, each of them on their own perhaps well-known, but well-known in distinct and unrelated bodies of expertise.
have an opportunity for a kind of social “gate-keeping”; a source of power in the organization.
Connected
A graph is connected if for every pair of nodes, there is a path between them
Traffic in a Network
For each pair of nodes A and B: 1 unit of traffic “flow” from A to B if A and B belong to same component. the flow divides itself evenly along all the possible shortest paths from A to B
Betweenness
Edge: total amount of flow that the edge carries, counting flow between all pairs of nodes using this edge.
Node: total amount of flow that the node carries, when a unit of flow between each pair of nodes is divided up evenly over shortest paths
Triadic closure
朋友的朋友更容易成为朋友
cluster coefficient(a)
a的朋友们也互相是朋友的概率
Strong Triadic Closure Property
如果a 和bc关系很好,那么bc会成为朋友。
如果不是(no matter strong or weak),violate the property
Strength of weak ties
neighborhood overlap (edge)
no of nodes who are neighbors of both A and B**/** no of nodes who are neighbors of at least one of A of B.
Neighborhood overlap increases with the strength
Local level : tie strength increases with neighborhood
Global level : weak ties serve to link together different tightly-knit communities ?
Weak ties provide the more crucial(关键) connective structure • for holding together disparate communities and • for keeping the global structure of the giant components intact.
Graph patitioning
division
移除最可能连接两大块的(betweenness最大值)
agglomerative(凝聚)
把nodes that are likely to belong to the same region merge起来
Girvan-Newman Method
Find the edge of highest betweenness and remove these edges from the graph.
Recalculate all betweennesses, again remove the edge or edges of highest betweenness.
C2 Networks in their Surrounding Contexts
Homophily
The tendency of individuals to associate and bond with similar others
Friendship that forms because two people
have a common friend (intrinsic network structure, triadic closure)
attend the same school or work for the same company (contextual factor)情境因素
Measuring Homophily
Homophily Test: If the fraction of cross-gender edges is significantly less than 2pq(p = fraction of males,q = fraction of females), then there is evidence for homophily.
The edge is heterogeneous(异质) if two end nodes do not share the same characteristic
Mechanisms Underlying Homophily
Selection
select friends with similar characteristic. tends to drive the network towards smaller clusters of like-minded individuals (balkanization)
individual characteristics drive the formation of links (邻居)
involves immutable(不变) characteristics (determined at birth)
物以类聚。
Socialization and social influence
modify their behaviors to bring them more closely into alignment with the behaviors of their friends.
– reverse of selection – Involves mutable characteristics – 近朱者赤, 近墨者黑/lies down with dogs, rises with fleas
Social influence
can produce network-wide uniformity, as new behavior spreads across the links.
Affiliation(联系) Networks 17
Include the contextual factors (the set of activities) into the network. expressed as a bipartite(even) graph.
node: person or focus(activity)
edge: (person,focus)
• A graph is bipartite if its nodes can be divided into two sets in such a way that every edge connects a node in one set to a node in the other set
• Two people sharing the same focus → an opportunity to become friends.
– For each k, identify all pairs of nodes who have exactly k friends in common, but who are not directly connected by an edge.
(Difference time with step1 ) T (k) = the fraction of these pairs that have formed an edge.
Triadic Closure: HIGH comon friends -> higher fraction
Focal closure: high -> not so high
The Schelling Model
How global patterns of spatial segregation can arise from the effect of homophily operating at a local level (Thomas Schelling)
Each agent(population) wants to have at least t agents of its own type as neighbors
Unsatisfied agents: – fewer than t neighbors of the same type as itself and move to a new cell
homophily draws people together along immutable characteristics
The Schelling model creates a natural tendency for mutable characteristics
C3 Positive and Negative Relationships
clique/complete graph: graph which an edge connecting each pair of nodes
Balanced Structure(triangle)
Three mutual(相互的) friends
A third mutual enemy
Unbalanced Structure(triangle)
A,和BC 玩的好。BC仇敌。
All are enermies
A complete graph is structurally balanced if its everyone triangle is balanced.
Balance Theorem
If a labeled complete graph is balanced, then
either all pairs of nodes are friends,
or else the nodes can be divided into two groups, X and Y ,
Weak Structural Balance Property:
There is no set of three nodes such that the edges among them consist of exactly two positive edges and one negative edge . ( all are enermy are possible)
Structural Balance in Arbitrary (Non-Complete) Networks
A signed graph is balanced if and only if it contains no cycle with an odd number of negative edges.
Searching for balanced division
find the connected components using positive edges. Declare each component to be a supernode.
the supernodes form the reduced graph (negative edges only)
BFS: edges connect two nodes in the same layer: a cycle with odd number of nodes
Generalizing the Definition of Structural Balance
Approximately Balance Theorem
If at least 99.9% (1-$\epsilon$)of all triangles in a labeled complete graph are balanced, then
either there is a set consisting of at least 90%(1-$\epsilon^{1/3}$)of the nodes in which at least 90% of all pairs are friends
or else the nodes can be divided into two groups, X and Y ,
at least 90% of the pairs in X like each other
at least 90% of the pairs in Y like each other, and
at least 90% of the pairs with one end in X and the other end in Y are enemies.
C4 Information cascade 17
Reasons why individual might imitate the behavior of others
– Informational effect :
The behavior of others conveys information about what they know
Peer pressure
Imitate what others (e.g. idols) are doing
Network effect (direct benefit effect) :(C5)
you incur an explicit benefit when you align behavior with the behavior of others.
posterior probability Pr [G | S] is greater than the prior Pr [G] (p) when a > b;
C5 Network Effects
Externalities(和外部坏境联系的场景 如 交通事故?party)
situation that the welfare of an individual is affected by the actions of other individuals
Positive: welfare increases when others are joining
Negative: 相反。
Without network effect, only consider Reservation price
the max amount one is willing to pay for one unit of the good. If consumer x (0 ≤ x ≤ 1) has a higher reservation pricer(x) than consumer y, then x < y.
**r: strictly decreasing **
p’: production cost of one unit of the good (the minimum price a producer is willing to accept to sell a good)
x’: equilibrium quantity of the good so that r(x’) = p’
The Economy with Network Effects
intrinsic interest. r(x). eg. r(1 ) = 0
the no. of other people using the good
( z: fraction of people in use).
f(z) measures the benefit to each consumer from those who use the good.f(z) is increasing in z, f(0) = 0
reservation price of consumer x = r(x)f(z) . here z is the fraction expected by x
0 < z < z’ 买家不想买。“downward pressure” on the consumption of the good : this would push demand downward.
z’ < z < z” 买家想买。 “upward pressure” on the consumption of the good: this would drive demand upward
z” < z < 1 “downward pressure”
z’ : critical point/tipping point
A Dynamic View of the Market
z^: fraction of population who buy the product (actual buyer)
r(z^)f(z) = p = >
z^ = $r^{-1}(p/f(z))$ = g(z)
For goods with network effects, the equilibria are typically not social optimal.(社会所有人的总利益)
Being the first to reach this tipping point is more important than being “best”.
Mixing Individual Effects with Population-Level Effects
f(Z) = 1 + az^2
r(X) = 1-x
C6 Power Laws and Rich-Get-Richer Models 17
Central Limit Theorem says that if we take any sequence of small independent random quantities, then in the limit their sum (or average) will be distributed according to the normal distribution.
A function that decreases as k to some fixed power, such as 1/k 2(fraction) is called a power law
Rich-Get-Richer Models
Model the growth of the popularity.
Created pages in order : 1, 2, 3, . . . , j.
When j is created, With probability p, page j, chooses a page i uniformly at random from among all earlier pages, and creates a link to this page i.
With probability 1-p, page j creates a link to the page that i links to. (i also uniformly random distributed)
new version:with probability 1 − p, page j chooses a page l with probability proportional to l ’s current number of in-links, and creates a link to l.
preferential attachment: : “preferentially” to pages that already have high popularity. (人们更愿意打开已经火了的页面,copy别人的)
No. of in-links of node j = $x_j = p/q[(t/j)^q-1]$ . t: simulated steps. q = 1-p
At time t, we have nodes x1, x2, … xt. The fraction of nodes with at least k links is
$[\frac{q}{p}k +1]^{-1/q}$
f(k) = the fraction of nodes with exactly k links = $1/p [1+\frac{1-p}{p}k]^{-(1+\frac{1}{1-p})}$. when p -0, power law exponent is 2.
The long tail
a small set of items that are enormously popular
Zipf’s Law : the frequency of the j th most common word in English (or most other widespread human languages) is proportional to 1/j.
C6 Cascading behavior in networks 17
Structure of the network and how individuals are influenced by their particular network neighbors (instead of everyone else in C5)
Why an innovation can fail to spread through a population ?
tightly-knit(严密) social community;
complexity
observability observe别人也在用
trialability 可试验性。(一步一步慢慢来)
compatibility with social system
the set of initial adopters causes a complete cascade at threshold q(大于百分之多少才换).
cluster of density p
cluster of density p = a set of nodes such that each node in the set has at least a p fraction of its network neighbors in the set.
cluster of density 1:
The Relationship between Clusters and Cascades
If the remaining network contains a cluster of density greater than 1 − q, then the set of initial adopters will not cause a complete cascade.(cluster 是cascade的阻碍 必要条件)
Moreover, whenever a set of initial adopters does not cause a complete cascade with threshold q, the remaining network must contain a cluster of density greater than 1 − q(充分条件)
Extensions of the Basic Cascade Model 17
Heterogeneous Thresholds: each node has a specific payoff and hence threshold
A blocking cluster in the network is a set of nodes for which each node v has more than a 1 − qv fraction of its friends also in the set.
cascade capacity of the network: 有限初始集能造成complete cascade的最大threshold
最大值:1/2
proof number of AB edges is decreasing when switching w from B to A
payoff from choosing A = a’(两边都是A/AB) 则double a payoff from choosing B = b’ payoff from choosing AB= a’+b’-c
C7 Small World Phenomenon
Watts-Strogatz model
Two type of links:
Homophily(和其他r个小格内点相连的link)and
Weak ties(剩余的k 个远link).
d(v, w) :the number of grid steps between nodes v and w
Probability of an edge is proportional to d(v, w)^-q (Small q, more long distances edges)
time: at most a2(log n)^2
A Rough Calculation Motivating the Inverse-Square Network
The probability that a random edge from center point v links into any node in this group is approximately independent of the value of d. ( in d - 2d circles)
Rank-Based Friendship
rank(w) = the number of other nodes that are closer to v than w is. (比w 还离v近一点的)
social distance
dist(v, w) = the social distance between nodes v and w = the size of the smallest focus that contains both v and w
A link between each pair of nodes v and w with probability proportional to dist(v,w)^-p
Efficient decentralized search when p = 1. 17
C8 Epidemics
•The basic reproductive number ( R0) = the expected number of new cases of the disease caused by a single individual = p(probability)k(new meet num).
Percolation : static view of the model. edge v-w is open is w is infected by v
transient contacts — contact networks in which each edge is annotated with the period of time during which it existed
Analysis of Branching Processes
qn = the probability that the epidemic survives for at least n waves
q∗ = qn when n is infinite = the probability that the epidemic persists indefinitely.
Wright-Fisher model
每一代 N个人
每个孩子都只有一个家长。一个家长可以有多个孩子也可能没有。
consider the time that k个个体是一个祖先
C9 Link Analysis and Web Search
• Ranking of web pages
Information Retrieval
1960s: Search repositories of newspaper articles, scientific papers, patents, legal abstracts, and other document collections in response to keyword queries.
vote by link 缺点:offtopic, criticism, advertisement
each page有两种score
authorities 权威网站 更新: 所有指向他的page的hub score和
hub 首页 更新 类似
1 2 3 4 5 6
initial are score = 1 select k steps for i in k: update auth update hub normalize hub and auth