Exemple #1
0
def test_parametric_rep():
    """
    For fixed representations: test successful kernel function use, using
    varying number of features.
    Ensure get expected result.  Test normalization, ensure expected result.
    """
    for normalization in [False, True]:  # verify everything with/out norm

        kernel = gaussian_kernel
        domain = InfiniteTrackCartPole.InfTrackCartPole()  #2 continuous dims
        discretization = 20  # not used
        num = 1  # number of basis functions to use IN EACH DIMENSION
        resolution_min = 1
        resolution_max = 5
        rep = RandomLocalBases(domain,
                               kernel,
                               num,
                               resolution_min,
                               resolution_max,
                               seed=1,
                               normalization=normalization,
                               discretization=discretization)
        assert rep.features_num == num  # in reality, theres one in each dim.

        # Center lies within statespace limits
        assert np.all(domain.statespace_limits[:, 0] <= rep.centers[0])
        assert np.all(rep.centers[0] <= domain.statespace_limits[:, 1])

        # width lies within resolution bounds
        statespace_range = domain.statespace_limits[:,
                                                    1] - domain.statespace_limits[:,
                                                                                  0]
        assert np.all(statespace_range / resolution_max <=
                      rep.widths[0])  # widths[0] has `state_space_dims` cols
        assert np.all(rep.widths[0] <= statespace_range / resolution_min)

        phiVecOrigin = rep.phi(np.array([0, 0], dtype=np.float),
                               terminal=False)
        assert np.all(phiVecOrigin >= 0)  # nonnegative feat func values

        # feature func only dependent on own dimension
        phiVec2 = rep.phi(np.array([0, 1], dtype=np.float), terminal=False)

        if normalization:
            assert sum(phiVecOrigin) == 1
            assert sum(phiVec2) == 1
Exemple #2
0
def test_parametric_rep():
    """
    For fixed representations: test successful kernel function use, using
    varying number of features.
    Ensure get expected result.  Test normalization, ensure expected result.
    """
    for normalization in [False, True]: # verify everything with/out norm

        kernel = gaussian_kernel
        domain = InfiniteTrackCartPole.InfTrackCartPole() #2 continuous dims
        discretization = 20 # not used
        num = 1 # number of basis functions to use IN EACH DIMENSION
        resolution_min=1
        resolution_max=5
        rep = RandomLocalBases(domain, kernel, num, resolution_min,
                               resolution_max,
                               seed=1, normalization=normalization,
                               discretization=discretization)
        assert rep.features_num == num # in reality, theres one in each dim.

        # Center lies within statespace limits
        assert np.all(domain.statespace_limits[:,0] <= rep.centers[0])
        assert np.all(rep.centers[0] <= domain.statespace_limits[:,1])

        # width lies within resolution bounds
        statespace_range = domain.statespace_limits[:, 1] - domain.statespace_limits[:, 0]
        assert np.all(statespace_range / resolution_max <= rep.widths[0]) # widths[0] has `state_space_dims` cols
        assert np.all(rep.widths[0] <= statespace_range / resolution_min)

        phiVecOrigin = rep.phi(np.array([0,0], dtype=np.float), terminal=False)
        assert np.all(phiVecOrigin >= 0) # nonnegative feat func values

        # feature func only dependent on own dimension
        phiVec2 = rep.phi(np.array([0,1], dtype=np.float), terminal=False)

        if normalization:
            assert sum(phiVecOrigin) == 1
            assert sum(phiVec2) == 1