How to use hierarchy_depth method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

replay_buffers_test.py

Source:replay_buffers_test.py Github

copy

Full Screen

1"""Tests for alpacka.training_data.replay_buffers."""2import collections3import numpy as np4import pytest5from alpacka.trainers import replay_buffers6_TestTransition = collections.namedtuple('_TestTransition', ['test_field'])7# Keep _TestTransitions with a single number in the buffer.8_test_datapoint_spec = _TestTransition(test_field=())9def test_uniform_samples_added_transition():10 buf = replay_buffers.UniformReplayBuffer(_test_datapoint_spec, capacity=10)11 stacked_transitions = _TestTransition(np.array([123]))12 buf.add(stacked_transitions)13 assert buf.sample(batch_size=1) == stacked_transitions14def test_uniform_raises_when_sampling_from_an_empty_buffer():15 buf = replay_buffers.UniformReplayBuffer(_test_datapoint_spec, capacity=10)16 with pytest.raises(ValueError):17 buf.sample(batch_size=1)18def test_uniform_samples_all_transitions_eventually_one_add():19 buf = replay_buffers.UniformReplayBuffer(_test_datapoint_spec, capacity=10)20 buf.add(_TestTransition(np.array([0, 1])))21 sampled_transitions = set()22 for _ in range(100):23 sampled_transitions.add(buf.sample(batch_size=1).test_field.item())24 assert sampled_transitions == {0, 1}25def test_uniform_samples_all_transitions_eventually_two_adds():26 buf = replay_buffers.UniformReplayBuffer(_test_datapoint_spec, capacity=10)27 buf.add(_TestTransition(np.array([0, 1])))28 buf.add(_TestTransition(np.array([2, 3])))29 sampled_transitions = set()30 for _ in range(100):31 sampled_transitions.add(buf.sample(batch_size=1).test_field.item())32 assert sampled_transitions == {0, 1, 2, 3}33def test_uniform_samples_different_transitions():34 buf = replay_buffers.UniformReplayBuffer(_test_datapoint_spec, capacity=100)35 buf.add(_TestTransition(np.arange(100)))36 assert len(set(buf.sample(batch_size=3).test_field)) > 137def test_uniform_oversamples_transitions():38 buf = replay_buffers.UniformReplayBuffer(_test_datapoint_spec, capacity=10)39 stacked_transitions = _TestTransition(np.array([0, 1]))40 buf.add(stacked_transitions)41 assert set(buf.sample(batch_size=100).test_field) == {0, 1}42def test_uniform_overwrites_old_transitions():43 buf = replay_buffers.UniformReplayBuffer(_test_datapoint_spec, capacity=4)44 buf.add(_TestTransition(np.arange(3)))45 buf.add(_TestTransition(np.arange(3, 6)))46 # 0, 1 should get overriden.47 assert set(buf.sample(batch_size=100).test_field) == {2, 3, 4, 5}48@pytest.mark.parametrize('hierarchy_depth', [0, 1, 2])49def test_hierarchical_samples_added_transitions(hierarchy_depth):50 buf = replay_buffers.HierarchicalReplayBuffer(51 _test_datapoint_spec, capacity=10, hierarchy_depth=hierarchy_depth52 )53 stacked_transitions = _TestTransition(np.array([123]))54 buf.add(stacked_transitions, [0] * hierarchy_depth)55 assert buf.sample(batch_size=1) == stacked_transitions56def test_hierarchical_samples_buckets_uniformly():57 buf = replay_buffers.HierarchicalReplayBuffer(58 _test_datapoint_spec, capacity=10, hierarchy_depth=159 )60 # Add zeros and ones at a 10:1 ratio.61 buf.add(_TestTransition(np.zeros(10)), [0])62 buf.add(_TestTransition(np.ones(1)), [1])63 # Assert that sampled transitions have a mean value of 0.5.64 mean_value = np.mean(buf.sample(batch_size=1000).test_field)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful