示例#1
0
def main():
    """ Entry of my program, ask user to input two strings,
    first one is the stable string, the other one is the initial string. """
    
    stable_str = raw_input("Please type the stable string, which you want the system to converge to: ")
    stable_str = prune_input(stable_str)
    
    matrix = matrix_creator(state_factory(stable_str))
    
    init_str = raw_input("Please type the initial string for the system: ")
    init_str = prune_input(init_str)
    
    init_state = state_factory(init_str)
    
    state = init_state[:]

    update_str = ''
    step = 0
    while(update_str != stable_str):
        neuron, output = random_update(state, matrix)
        state[neuron] = output
        
        step += 1
        
        print "This is STEP '" + str(step) + "'"
        
        print "neuron " + str(neuron) + " is updating"
        
        print "The value of energy function is: " + str(energy_func(state, matrix))
    
        update_str = state2string(state)
        
        if update_str == stable_str:
            print "====== Come to Stable ======"
            print "'" + update_str + "'"
            print "============================"
        else:
            print "Current state interpreted to string is: '" + update_str + "'"
        print
示例#2
0
 def testMatrixCreator(self):
     self.assertEqual(70, len(matrix_creator(state_factory("helloworld"))))
示例#3
0
 def testStableStateContent(self):
     stable_state = state_factory("hello world!")
     for ch in stable_state:
         self.assert_(ch in [0, 1])
示例#4
0
 def testStableStateLength(self):
     self.assertEqual(70, len(state_factory("helloworld")))