def test_step_funciton(): input_vec = np.array([-1, 0, 1]) output_vec = OutputFunciton.step_function(input_vec) assert [0, 1, 1] == output_vec.tolist() input_vec = np.array([-1, 0, 1]) output_vec = OutputFunciton.step_function(input_vec, bottom=-1) assert [-1, 1, 1] == output_vec.tolist()
def test_probability_sigmoid_function(): input_vec = np.array([-100000]) output_vec = OutputFunciton.probability_sigmoid_function(input_vec) assert [0] == output_vec.tolist() input_vec = np.array([1]) output_vec = OutputFunciton.probability_sigmoid_function(input_vec) assert [1] == output_vec.tolist()
def test_function_apply(): input_vec = np.array([0]) # step output_vec = OutputFunciton.function_apply(input_vec, 0) assert [1] == output_vec.tolist() # sigmoid output_vec = OutputFunciton.function_apply(input_vec, 1) assert [0.5] == output_vec.tolist()
def get_updated_state(self, weight_mat, init_state, temperature=0.25): updated_state = np.dot(weight_mat, init_state.T) result = [] for d in updated_state: # hopfieldからの違い => 確率素子に変更 #result.append(OutputFunciton.step_function(d, bottom=-1)[0]) result.append(OutputFunciton.probability_sigmoid_function(d, alpha=1/temperature)[0]) return np.array([result])
def get_updated_state(self, weight_mat, init_state): # ここのみだとアソシアトロン updated_state = np.dot(weight_mat, init_state.T) # TODO : 1 or -1 を返すようにする. result = [] for d in updated_state: result.append(OutputFunciton.step_function(d, bottom=-1)[0]) return np.array([result])
def test_sigmoid_funciton(): input_vec = np.array([0]) output_vec = OutputFunciton.sigmoid_function(input_vec) assert [0.5] == output_vec.tolist()