示例#1
0
    def test_interactions(self):
        simulation = MemorySimulation([
            Interaction(1, [1, 2, 3], [0, 1, 2]),
            Interaction(2, [4, 5, 6], [2, 3, 4])
        ])
        interactions = list(simulation.read())

        self.assertEqual(interactions[0], interactions[0])
        self.assertEqual(interactions[1], interactions[1])
示例#2
0
    def test_interactions(self):
        interactions = [Interaction(1, [1,2,3], 0), Interaction(2,[4,5,6],1)]
        reward_sets  = [[0,1,2], [2,3,4]]

        simulation = MemorySimulation(interactions, reward_sets)

        self.assertEqual(1      , simulation.interactions[0].context)
        self.assertEqual([1,2,3], simulation.interactions[0].actions)
        self.assertEqual([0,1,2], simulation.reward([(0,0),(0,1),(0,2)]))

        self.assertEqual(2      , simulation.interactions[1].context)
        self.assertEqual([4,5,6], simulation.interactions[1].actions)
        self.assertEqual([2,3,4], simulation.reward([(1,0),(1,1),(1,2)]))
示例#3
0
    def test_count_batch3(self):
        interactions = [
            Interaction(1,[1,2],0),
            Interaction(1,[1,2],1),
            Interaction(1,[1,2],2)
        ]
        rewards = [
            [3,3],
            [4,4],
            [5,5]
        ]

        simulation = MemorySimulation(interactions,rewards)
        batch_simulation = Batch(count=3).filter(simulation)

        self.assertEqual(3, len(batch_simulation.interaction_batches))

        self.assertEqual(1, len(batch_simulation.interaction_batches[0]))
        self.assertEqual(0, batch_simulation.interaction_batches[0][0].key)

        self.assertEqual(1, len(batch_simulation.interaction_batches[1]))
        self.assertEqual(1, batch_simulation.interaction_batches[1][0].key)

        self.assertEqual(1, len(batch_simulation.interaction_batches[2]))
        self.assertEqual(2, batch_simulation.interaction_batches[2][0].key)
示例#4
0
    def test_PCA(self):
        interactions = [
            Interaction((1,2), [1], 0),
            Interaction((1,9), [1], 1),
            Interaction((7,3), [1], 2)
        ]

        mem_sim = MemorySimulation(interactions, [[1],[1],[1]])
        pca_sim = PCA().filter(mem_sim)

        self.assertEqual((1,2), mem_sim.interactions[0].context)
        self.assertEqual((1,9), mem_sim.interactions[1].context)
        self.assertEqual((7,3), mem_sim.interactions[2].context)

        self.assertNotEqual((1,2), pca_sim.interactions[0].context)
        self.assertNotEqual((1,9), pca_sim.interactions[1].context)
        self.assertNotEqual((7,3), pca_sim.interactions[2].context)
示例#5
0
    def test_sort2(self) -> None:

        interactions = [
            Interaction((1,2), [1], 0),
            Interaction((1,9), [1], 1),
            Interaction((1,3), [1], 2)
        ]

        mem_sim = MemorySimulation(interactions, [[1],[1],[1]])
        srt_sim = Sort([0,1]).filter(mem_sim)

        self.assertEqual((1,2), mem_sim.interactions[0].context)
        self.assertEqual((1,9), mem_sim.interactions[1].context)
        self.assertEqual((1,3), mem_sim.interactions[2].context)

        self.assertEqual((1,2), srt_sim.interactions[0].context)
        self.assertEqual((1,3), srt_sim.interactions[1].context)
        self.assertEqual((1,9), srt_sim.interactions[2].context)
示例#6
0
 def test_take4(self):
     interactions = [
         Interaction(1,[1,2],0),
         Interaction(1,[1,2],1),
         Interaction(1,[1,2],2)
     ]
     rewards = [
         [3,3],
         [4,4],
         [5,5]
     ]
     
     simulation = MemorySimulation(interactions,rewards)
     
     take_simulation = Take(4).filter(simulation)
     
     self.assertEqual(3, len(simulation.interactions))
     self.assertEqual(0, len(take_simulation.interactions))
示例#7
0
    def test_take1(self):
        interactions = [
            Interaction(1,[1,2],0),
            Interaction(1,[1,2],1),
            Interaction(1,[1,2],2)
        ]
        rewards = [
            [3,3],
            [4,4],
            [5,5]
        ]
        
        simulation = MemorySimulation(interactions,rewards)
        take_simulation = Take(1).filter(simulation)

        self.assertEqual(1, len(take_simulation.interactions))
        self.assertEqual(0, take_simulation.interactions[0].key)
        
        self.assertEqual(3, len(simulation.interactions))
        self.assertEqual(0, simulation.interactions[0].key)
        self.assertEqual(1, simulation.interactions[1].key)
        self.assertEqual(2, simulation.interactions[2].key)
示例#8
0
    def test_shuffle(self):
        interactions = [
            Interaction(1,[1,2],0),
            Interaction(1,[1,2],1),
            Interaction(1,[1,2],2)
        ]
        rewards = [
            [3,3],
            [4,4],
            [5,5]
        ]
        
        simulation = MemorySimulation(interactions,rewards)
        shuffled_simulation = Shuffle(40).filter(simulation)

        self.assertEqual(len(shuffled_simulation.interactions), len(simulation.interactions))
        self.assertEqual(1, shuffled_simulation.interactions[0].key)
        self.assertEqual(2, shuffled_simulation.interactions[1].key)
        self.assertEqual(0, shuffled_simulation.interactions[2].key)
        self.assertEqual(0, simulation.interactions[0].key)
        self.assertEqual(1, simulation.interactions[1].key)
        self.assertEqual(2, simulation.interactions[2].key)