# Path: preimage/utils/position.py
# def compute_position_weights(position_index, max_position, sigma_position):
#     position_penalties = numpy.array([(position_index - j) ** 2 for j in range(max_position)], dtype=numpy.float)
#     position_penalties /= -2. * (sigma_position ** 2)
#     return numpy.exp(position_penalties)
# 
# def compute_position_weights_matrix(max_position, sigma_position):
#     position_penalties = numpy.array([(i - j) for i in range(max_position) for j in range(max_position)],
#                                      dtype=numpy.float)
#     position_penalties = position_penalties.reshape(max_position, max_position)
#     position_penalties = numpy.square(position_penalties) / (-2 * (sigma_position ** 2))
#     return numpy.exp(position_penalties)


import unittest2
import numpy.testing
from preimage.utils.position import compute_position_weights, compute_position_weights_matrix
__author__ = 'amelie'




class TestPosition(unittest2.TestCase):
    def setUp(self):
        self.position_weights_one_sigma_p_index_zero = [1., 0.6065307, 0.1353353]
        self.position_weights_one_sigma_p_index_one = [0.6065307, 1., 0.6065307]
        self.position_weights_half_sigma_p_index_zero = [1., 0.1353353, 0.0003355]
        self.position_matrix_one_sigma_p_three_positions = [[1., 0.6065307, 0.1353353], [0.6065307, 1., 0.6065307],
                                                            [0.1353353, 0.6065307, 1.]]
        self.position_weights_half_sigma_p_two_positions = [[1., 0.1353353], [0.1353353, 1.]]

    def test_one_sigma_p_index_zero_to_one_compute_position_weights_returns_expected_weights(self):
        position_weights = compute_position_weights(position_index=0, max_position=1, sigma_position=1)

        numpy.testing.assert_array_almost_equal(position_weights, [1.])

    def test_one_sigma_p_index_zero_compute_position_weights_returns_expected_weights(self):

# Path: preimage/utils/position.py
# def compute_position_weights(position_index, max_position, sigma_position):
#     position_penalties = numpy.array([(position_index - j) ** 2 for j in range(max_position)], dtype=numpy.float)
#     position_penalties /= -2. * (sigma_position ** 2)
#     return numpy.exp(position_penalties)
# 
# def compute_position_weights_matrix(max_position, sigma_position):
#     position_penalties = numpy.array([(i - j) for i in range(max_position) for j in range(max_position)],
#                                      dtype=numpy.float)
#     position_penalties = position_penalties.reshape(max_position, max_position)
#     position_penalties = numpy.square(position_penalties) / (-2 * (sigma_position ** 2))
#     return numpy.exp(position_penalties)


# Path: preimage/tests/utils/test_position.py
import unittest2
import numpy.testing
from preimage.utils.position import compute_position_weights, compute_position_weights_matrix

__author__ = 'amelie'




class TestPosition(unittest2.TestCase):
    def setUp(self):
        self.position_weights_one_sigma_p_index_zero = [1., 0.6065307, 0.1353353]
        self.position_weights_one_sigma_p_index_one = [0.6065307, 1., 0.6065307]
        self.position_weights_half_sigma_p_index_zero = [1., 0.1353353, 0.0003355]
        self.position_matrix_one_sigma_p_three_positions = [[1., 0.6065307, 0.1353353], [0.6065307, 1., 0.6065307],
                                                            [0.1353353, 0.6065307, 1.]]
        self.position_weights_half_sigma_p_two_positions = [[1., 0.1353353], [0.1353353, 1.]]

    def test_one_sigma_p_index_zero_to_one_compute_position_weights_returns_expected_weights(self):
        position_weights = compute_position_weights(position_index=0, max_position=1, sigma_position=1)

        numpy.testing.assert_array_almost_equal(position_weights, [1.])

    def test_one_sigma_p_index_zero_compute_position_weights_returns_expected_weights(self):

        position_weights = compute_position_weights(position_index=0, max_position=3, sigma_position=1)