Skip to content

Commit ab66bcd

Browse files
committed
Adding missing file
1 parent 518bd1b commit ab66bcd

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

files/declining_fashion.R

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
declining_fashion <- function(expo, cumadopt, time) {
2+
3+
# Number of behaviors
4+
num_of_behaviors <- dim(cumadopt)[3]
5+
6+
# Number of nodes
7+
num_of_nodes <- dim(cumadopt)[1]
8+
9+
# Making room for the disadopted nodes
10+
list_disadopt <- list()
11+
12+
sigmoide <- function(x, midpoint = 4, steepness = 1) {
13+
1 / (1 + exp(-steepness * (x - midpoint)))
14+
}
15+
16+
# We iterate through the behaviors
17+
for (q in 1:num_of_behaviors) {
18+
19+
# Cumulative adoption matrix for behavior Q
20+
cumadopt_q <- cumadopt[, , q]
21+
22+
# Calculating the total time of adoption
23+
cumulative_time <- sapply(seq_len(num_of_nodes), function(i) {
24+
25+
if (any(cumadopt_q[i, ] == 1)) {
26+
27+
# Length of the vector from the first adoption to the currect
28+
length(seq(which(cumadopt_q[i, ] == 1)[1], time))
29+
30+
} else {
31+
32+
0
33+
}
34+
})
35+
36+
# Looking the adopters
37+
adopters_q <- which(cumadopt[, time, q] == 1)
38+
39+
# Calculating probability of disadoption based on cumulative_time
40+
prob_dis <- rep(0, num_of_nodes)
41+
prob_dis[adopters_q] <- sigmoide(cumulative_time[adopters_q], midpoint = 4, steepness = 1)
42+
43+
# We select 2 nodes based on prob_dis
44+
disadopters_q <- sample(seq_len(num_of_nodes), size = 2, prob = prob_dis)
45+
46+
# Adding disadopters_q to list_disadopt
47+
if (length(disadopters_q) != 0){
48+
set.seed(123)
49+
list_disadopt[[q]] <- disadopters_q
50+
} else {
51+
list_disadopt[[q]] <- integer()
52+
}
53+
}
54+
55+
return(list_disadopt)
56+
}
57+
58+
59+
set.seed(1231)
60+
61+
n <- 200
62+
t <- 10
63+
64+
diffnet_7 <- rdiffnet(
65+
n, t,
66+
seed.p.adopt = list(0.1, 0.15),
67+
disadopt = declining_fashion
68+
)
69+
70+
diffnet_7

0 commit comments

Comments
 (0)