Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. # coding: utf-8
  2. Example_Codes/SES591_SampleCode/code/updating_rule.py
  3. 5308a3c 4 hours ago
  4. @SaraImari SaraImari added additional comments and changed plotting
  5. 1 contributor
  6. RawBlameHistory 70 lines (53 sloc) 1.99 KB
  7. #!/usr/bin/python
  8. #attractor-analysis.py
  9. #last update: 17 DEC 2015
  10.  
  11. __author__ = '''Hyunju Kim'''
  12.  
  13.  
  14. import os
  15. import sys
  16. import numpy as np
  17. import networkx as nx
  18. from collections import OrderedDict
  19.  
  20. import input_net as inet
  21.  
  22.  
  23.  
  24. ################# begin: sigmoid_updating ######################
  25. def sigmoid_updating(net, prevState):
  26. """Update according to fixed thresholds for each node"""
  27.  
  28. '''
  29. Arguments:
  30. 1. net
  31. 2. prevState
  32. Return:
  33. 1. currState
  34. '''
  35.  
  36. currState = {}
  37. #### compute the current states of nodes in the net ####
  38. for v in net.nodes():
  39. #### compute weighted sum for node v over its neighbors u ####
  40. eSum = 0
  41. for u in net.predecessors_iter(v):
  42. #iterate over input nodes u to node v
  43. w_uv = 1.0*net[u][v]['weight']
  44. eSum += w_uv * prevState[u]
  45. #### determine the current state for v as a function of eSum and threshold of v ####
  46. if eSum < net.node[v]['threshold']:
  47. currState[v] = 0
  48. if eSum > net.node[v]['threshold']:
  49. currState[v] = 1
  50. if eSum == net.node[v]['threshold']:
  51. currState[v] = prevState[v]
  52.  
  53. return currState
  54.  
  55. ################# end: sigmoid_updating ########################
  56.  
  57. def main():
  58. print "updating_rule module is the main code."
  59. EDGE_FILE = '../data/example/example-net-edges.dat'
  60. NODE_FILE = '../data/example/example-net-nodes.dat'
  61.  
  62. net = inet.read_network_from_file(EDGE_FILE, NODE_FILE)
  63.  
  64. #prevState = {'a':0.0, 'b':0.0, 'c':1.0}
  65. prevState = {}
  66. prevState['a'] = float(sys.argv[1])
  67. prevState['b'] = float(sys.argv[2])
  68. prevState['c'] = float(sys.argv[3])
  69. print "network state @ previous step", OrderedDict(sorted(prevState.items(), key=lambda t: t[0]))
  70.  
  71. currState = sigmoid_updating(net, prevState)
  72. print "network state @ current step", OrderedDict(sorted(currState.items(), key=lambda t: t[0]))
  73.  
  74. if __name__=='__main__':
  75. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement