示例#1
0
def test_audio_env():
    # Shoebox Room
    room = room_types.ShoeBox(x_length=10, y_length=10)

    agent_loc = np.array([3, 8])

    # Set up the audio/gym environment
    env = gym.make(
        "audio-room-v0",
        room_config=room.generate(),
        agent_loc=agent_loc,
        corners=room.corners,
        max_order=10,
        step_size=1.0,
        acceptable_radius=0.5,
    )

    # store initial room obj
    init_room = env.room

    # test step (taking actions)
    # remember: 0,0 is at the bottom left
    env.step(action=0)  # step left
    assert (np.allclose(env.agent_loc, np.array([2, 8])))
    env.step(action=1)  # step right
    assert (np.allclose(env.agent_loc, np.array([3, 8])))
    env.step(action=2)  # step up
    assert (np.allclose(env.agent_loc, np.array([3, 9])))
    env.step(action=3)  # step down
    assert (np.allclose(env.agent_loc, np.array([3, 8])))

    # test move function
    env._move_agent([5, 5])
    assert (env.agent_loc == [5, 5])

    # ensure the room is the same dimensions
    # even though its a different q object
    new_room = env.room
    for idx, wall in enumerate(init_room.walls):
        assert (np.allclose(wall.corners, new_room.walls[idx].corners))
示例#2
0
def test_experiment_shoebox():
    """
    Testing a run with ShoeBox room

    TODO
    """
    # Shoebox Room
    room = room_types.ShoeBox(x_length=10, y_length=10)

    agent_loc = np.array([3, 8])

    # Set up the gym environment
    env = gym.make(
        "audio-room-v0",
        room_config=room.generate(),
        agent_loc=agent_loc,
        corners=room.corners,
        max_order=10,
        step_size=1.0,
        acceptable_radius=0.8,
    )

    # create buffer data folders
    utils.create_buffer_data_folders()

    tfm = nussl.datasets.transforms.Compose([
        nussl.datasets.transforms.GetAudio(mix_key='new_state'),
        nussl.datasets.transforms.ToSeparationModel(),
        nussl.datasets.transforms.GetExcerpt(excerpt_length=32000, tf_keys=['mix_audio'], time_dim=1),
    ])

    # create dataset object (subclass of nussl.datasets.BaseDataset)
    dataset = BufferData(folder=constants.DIR_DATASET_ITEMS, to_disk=True, transform=tfm)

    # Load the agent class
    a = agent.RandomAgent(env=env, dataset=dataset, episodes=2, max_steps=10, plot_reward_vs_steps=False)
    a.fit()
示例#3
0
def test_shoebox():
    """
    Testing (our) ShoeBox room class
    """
    # 2d shoebox room is a rectangle (4 walls)
    room = room_types.ShoeBox()
    points = room.generate()

    # sanity, rectangles only have two different lengths
    assert (len(points) == 2)

    # ensure class variables equal points returned by generate
    assert (room.x_length == points[0])
    assert (room.y_length == points[1])

    # not sure how this would fail
    assert ((room.x_length * room.y_length) == (points[0] * points[1]))

    # create pra room
    pra_room = ShoeBox(points)

    # test whether it is a convex hull (this should be ensured by pra)
    pra_room.convex_hull()
    assert (len(pra_room.obstructing_walls) == 0)
示例#4
0
import utils
import constants
import nussl
from datasets import BufferData
import time
import audio_processing
from models import RnnAgent
import transforms

"""
One of our main experiments for OtoWorld introductory paper 
"""

# Shoebox Room
nussl.utils.seed(0)
room = room_types.ShoeBox(x_length=8, y_length=8)

# Uncomment for Polygon Room
#room = room_types.Polygon(n=6, r=2, x_center=5, y_center=5)

source_folders_dict = {'../sounds/phone/': 1,
                        '../sounds/siren/': 1}

# Set up the gym environment
env = gym.make(
    "audio-room-v0",
    room_config=room.generate(),
    source_folders_dict=source_folders_dict,
    corners=room.corners,
    max_order=10,
    step_size=.5,