function state_transitions(svg, history_g_bars, foci, color){ var state_transition_probabilities = [ [0, 1, 0, 0], [0, 0.90, 0.09, 0.01], [0, 0, 0.96, 0.04], [0, 0, 0.1, 0.90] ] var t = 0 var history_data = [] var state_machine_animation_interval = d3.interval(function(){ // *** SIMULATION *** // update time t += 1 // stop simulation after 40 timesteps if (t > 40) { state_machine_animation_interval.stop(); simulation.stop(); return true } // change node states according to transition probabilities matrix // (and compute updated foci counts while at it) var focus_node_count = [] foci.forEach(function(d){ focus_node_count.push(0) }) nodes.forEach(function(o, i) { var trans_probs = state_transition_probabilities[o.state] var cum_trans_probs = [] trans_probs.reduce(function(a,b,i) { return cum_trans_probs[i] = a+b },0) var r = Math.random() var new_state = cum_trans_probs.findIndex(function(d){ return d >= r }) if (new_state != -1) { o.previous_state = o.state o.state = new_state } focus_node_count[o.state] += 1 }) if (t > 1){ history_data.push({ t: t-1, n1: focus_node_count[1], n2: focus_node_count[2], n3: focus_node_count[3] }) } // possibly add some new nodes var num_new = 100 if (t > 1) { num_new = Math.floor(Math.random() * 5) } for (var i=0; i