<jupyter_start><jupyter_text>The formal dynamic systems model of MD-------------------------------------- We begin developing the formal model of MD by assuming the following: 1) symptoms (Xi) can be ‘on’ (1; active) or ‘off’ (0; inactive); 2) symptom activation takes place over time (t) such that, for example, insomnia at timetmay cause activation of fatigue at timet+ 1; and 3) a symptom ireceives input from symptoms with which it is connected in the VATSPUD data (i.e., these are non-zero weight parameters). These weight parameters are collected in a matrix **W** for the J=14 symptoms: entry $\mathbf{W}_{ij}$ thus represents the logistic regression weight between symptomsiandjas estimated from the VATSPUD data (as one can see in Fig 2 the weight parameters from the data are used in the subsequent simulations with our model). Model formulation now proceeds along the following steps:  Total Activation FunctionWe assume that the total amount of activation a symptom *i* receives at time *t* is the weighted (by **W**) summation of all the neighboring symptoms **X** (i.e., the vector that contains the “0” and “1” values of being inactive and active respectively) at timet– 1. We call this the *total activation function* (boldfaced parameters are estimated from the VATSPUD data):$A^t_i = \sum^J_{j=1} \mathbf{W}_{ij}X_j^{t-1}$ Probability FunctionWe formulate a logistic function for computing the probability of symptomibecoming active at timet: the probability of symptomibecoming active at timetdepends on the difference between the total activation of its neighboring symptoms and the threshold of symptomi(in the formula below: $(b_i—A_i^t)$). This threshold is estimated from the VATSPUD data (see also Fig 2). Note that the parameter $\mathbf{b}_i$ denotes the absolute value of these estimated thresholds. The more the total activation exceeds the threshold of symptomiat timet, the higher the probability that symptomibecomes active (in the formula below: $P(X_i^t = 1)$) at timet. We call this the *probability function* (boldfaced parameters are estimated from the VATSPUD data):$P(X_i^t=1) = \frac{1}{1+e^{\mathbf{b_i}-A_i^t}}$**The simulation study**. To investigate our vulnerability hypothesis, we inserted a connectivity parameter *c* with which matrix **$W$** is multiplied. This results in the following modified *total activation function*:$A^t_i = \sum^J_{j=1} c\mathbf{W}_{ij}X_j^{t-1}$<jupyter_code># Simulation 1

I = 1500

W = np.asarray(weightsParam)
b = np.abs(np.asarray(thresholdParam).ravel())
c = 2

X = np.zeros(b.shape, np.bool)
D = np.empty(I, np.uint8)

for i in range(I):
    A = np.sum(c*W*X, axis=1)
    P = 1 / (1 + np.exp(b-A))
    X = P > np.random.uniform(0, 1, P.shape)
    
    D[i] = np.sum(X)

plt.plot(D)
plt.ylim(0, 14)
plt.axis('on')
plt.show()
# Init 
G = nx.Graph()
thresholds = {}
activationValues = {}
stateValues = {}

# Code for dataframe straight to graph (not enough options)
G = nx.from_pandas_adjacency(weightsParam)
# Fill graph
for key in keyArr:
    thresholds[key] = thresholdParam.at[key, "threshold"]
    activationValues[key] = 0
    stateValues[key] = 0

# Fill node attributes
nx.set_node_attributes(G, thresholds, name="threshold")
nx.set_node_attributes(G, activationValues, name="activationValues")
nx.set_node_attributes(G, stateValues, name="stateValues")
# Create bins for different edges
elarge = [(u, v) for (u, v, d) in G.edges(data=True) if d['weight'] > 1.5]
emedium = [(u, v) for (u, v, d) in G.edges(data=True) if d['weight'] <= 1.5 and d['weight'] > 0.5]
esmall = [(u, v) for (u, v, d) in G.edges(data=True) if d['weight'] <= 0.5]

pos = nx.spring_layout(G)  # positions for all nodes

# nodes
nx.draw_networkx_nodes(G, pos, node_size=1100)

# edges
nx.draw_networkx_edges(G, pos, edgelist=elarge,
                       width=6)
nx.draw_networkx_edges(G, pos, edgelist=emedium,
                       width=6, alpha=0.5, edge_color='y', style='dotted')
nx.draw_networkx_edges(G, pos, edgelist=esmall,
                       width=6, alpha=0.5, edge_color='b', style='dashed')

# labels
nx.draw_networkx_labels(G, pos, font_size=15, font_family='Times New Roman')
nx.spring_layout(G, k=None, pos=None, fixed=None, iterations=50, threshold=0.00001, weight='weight', scale=4, center=None, dim=2, random_state=None)

plt.axis('off')
plt.show()
# Some extra info for checking
print(G.number_of_nodes())
print(G.nodes())
print(G.number_of_edges())
print(G.edges())
print(G.neighbors("dep"))
print(G.node["int"]["threshold"])
nx.draw(G)
# To json format for site
data = nx.json_graph.node_link_data(G)
with open('data.json', 'w') as outfile:
    json.dump(data, outfile)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1307314992535722, 'fraction_numerical': 0.01471529110684581, 'mean_word_length': 4.677966101694915, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '566529', 'license': 'MIT', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1486, 'n_words': 537, 'path': 'code jupyter/Simulation 1.ipynb', 'repo_name': 'TamarTulp/Complex_systems', 'size': '4689'}