コード例 #1
0
 def test_memory_cache_load(self):
     cache = MemoryCache.from_simulator(model, prior)
     with tempfile.TemporaryDirectory() as td:
         cache.save(td)
         loaded = MemoryCache.load(td)
         assert loaded.params == cache.params
         assert cache.store.root == loaded.store.root
コード例 #2
0
 def test_init_memory_cache(self):
     cache = MemoryCache(["a", "b", "c"], {"x": (10, )})
     assert cache.params == ["a", "b", "c"]
     assert {
         k: v.shape[1:]
         for k, v in cache.root[Cache._filesystem.obs].items()
     } == {
         "x": (10, )
     }
コード例 #3
0
    def test_memory_cache_simulate(self):
        simulator = Simulator(model)
        cache = MemoryCache.from_simulator(model, prior)
        indices = cache.sample(prior, 200)
        ind_sim = indices[:50]
        cache.simulate(simulator, ind_sim)

        assert cache.x["x"][49].sum() != 0
        assert cache.x["x"][50].sum() == 0
コード例 #4
0
 def test_memory_cache_save(self):
     cache = MemoryCache.from_simulator(model, prior)
     with tempfile.TemporaryDirectory() as td:
         cache.save(td)
         td_path = Path(td)
         items = [
             p.relative_to(td).as_posix() for p in td_path.rglob("*")
             if p.is_dir()
         ]
         assert all([truth in items for truth in Cache._filesystem])
コード例 #5
0
 def test_init_memory_cache_multi_outputs(self):
     cache = MemoryCache(["a", "b"], {"x1": (10, ), "x2": (20, 20)})
     assert cache.params == ["a", "b"]
     assert {
         k: v.shape[1:]
         for k, v in cache.root[Cache._filesystem.obs].items()
     } == {
         "x1": (10, ),
         "x2": (20, 20)
     }
コード例 #6
0
 def test_memory_cache_sample(self):
     cache = MemoryCache.from_simulator(model, prior)
     indices = cache.sample(prior, 1000)
     assert len(indices) == len(cache)