Esempio n. 1
0
    def test_generator(self):

        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 2)
        dataManager.addDataEntry('Y', 2)
        f = DummyMapping(dataManager)

        dataManager.addFeatureMapping(f)

        data = dataManager.createDataObject(10)

        # features mapping gets called every time now when we access data.Y
        data[...].X = np.random.normal(0, 1, (10, 2))
        print('Features: ', data[...].Y)
        print('Features: ', data[...].Y)

        f.setLazyEvaluation(True)
        # mapping gets called only once
        print('Features: ', data[...].Y)
        print('Features: ', data[...].Y)
        print('Features: ', data[...].Y)

        # reset valid Tags
        data[...].Y_validFlag = np.vstack((np.ones(
            (5, 1), dtype=bool), np.zeros((5, 1), dtype=bool)))
        #Now mapping is only called for the last 5 elements
        print('Features: ', data[...].Y)
Esempio n. 2
0
    def test_nextAliases(self):
        dataManager = DataManager("manager", isTimeSeries=True)
        dataManager.addDataEntry("entry1", 1)
        dataManager.addDataEntry("entry2", 3)
        dataManager.addDataAlias("entries", [('entry1', ...), ('entry2', ...)])

        data1 = dataManager.createDataObject([10])
        dataMat = np.array(range(0, 11))
        dataMat.resize(11, 1)

        dataMatNext = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
        dataMatLast = np.array([0, 0, 1, 2, 3, 4, 5, 6, 7, 8])
        dataMatNext.resize(10, 1)
        dataMatLast.resize(10, 1)

        data1.setDataEntry("allEntry1", ..., dataMat)

        nextEntry1 = data1.getDataEntry("nextEntry1", ...)
        allDataEntry1 = data1.getDataEntry("allEntry1", ...)
        lastEntry1 = data1.getDataEntry("lastEntry1", ...)

        self.assertTrue((nextEntry1 == dataMatNext).all())
        self.assertTrue((allDataEntry1 == dataMat).all())
        self.assertTrue((lastEntry1 == dataMatLast).all())

        allDataEntries = data1.getDataEntry('allEntries', slice(0, 3))
        allDataEntriesMat = np.array([[0, 0, 0, 0], [1, 0, 0, 0], [2, 0, 0,
                                                                   0]])
        self.assertTrue((allDataEntries == allDataEntriesMat).all())
Esempio n. 3
0
    def test_dataSuffix(self):

        settings = SettingsManager.getDefaultSettings()
        settings.clean()
        dataManager = DataManager("manager")
        settings.pushSuffixStack('Agent1')

        dataManager.addDataEntry('parameters1', 1)
        dataManager.addDataEntry('parameters2', 1)

        dataManager.addDataAlias('parameters', [('parameters1', ...),
                                                ('parameters2', ...)])

        self.assertTrue(dataManager.isDataEntry("parameters1Agent1"))
        self.assertFalse(dataManager.isDataEntry("parameters1"))

        data = dataManager.createDataObject(10)
        data.setDataEntry('parameters1Agent1', ..., np.ones((10, 1)) * 5)

        dummyManipulator = TestSuffixManipulator(dataManager)
        data[...] >> dummyManipulator.dummyFunction >> data

        self.assertTrue(
            np.all(
                data.getDataEntry("parameters2Agent1") ==
                data.getDataEntry("parameters1Agent1") + 10))
        self.assertTrue(
            np.all(
                data.getDataEntry("parametersAgent1") == np.hstack((
                    data.getDataEntry("parameters1Agent1"),
                    data.getDataEntry("parameters2Agent1")))))

        settings.popSuffixStack()
Esempio n. 4
0
    def test_init_givenNoInputNoOutputNoName_expectNoException(self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        mapping = Mapping(dataManager)

        self.assertIsInstance(mapping, Mapping)
Esempio n. 5
0
    def test_getInputVariables_given_expectInputVariablesGivenToConstructor(
            self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        self.assertEqual(mapping.getInputVariables(), ['X'])
Esempio n. 6
0
    def test_init_givenSingleInputSingleOutputNoName_expectNoException(self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        self.assertIsInstance(mapping, Mapping)
        self.assertEqual(mapping.name, 'TestMapping')
Esempio n. 7
0
    def test_setInputVariables_givenIntputvariablesString_expectDeprecationWarning(
            self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        self.assertRaises(DeprecationWarning, mapping.setInputVariables,
                          'var1')
Esempio n. 8
0
    def test_setOutputVariables_givenMultipleOutputVariables_expectRuntimeError(
            self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        self.assertRaises(ValueError,
                          lambda: mapping.setOutputVariables(['A', 'B']))
Esempio n. 9
0
    def test_init_givenSingleInputMultipleOutputNoName_expectRuntimeError(
            self):
        # note that this test may start failing if multiple output variables
        # are getting allowed
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        self.assertRaises(
            ValueError,
            lambda: Mapping(dataManager, ['Y', 'Z'], ['X'], "TestMapping"))
Esempio n. 10
0
    def testMappingData(self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        mapping = DummyMapping(dataManager)
        data = dataManager.createDataObject(10)

        data >> mapping

        self.assertTrue((data.getDataEntry('Y') == np.ones((10, 1))).all())
Esempio n. 11
0
    def test_setOutputDimension(self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        mapping.setOutputDimension(4324)

        self.assertEqual(4324, mapping.dimOutput)
        self.assertEqual([], mapping.outputVariables)
Esempio n. 12
0
    def testMatrixEntries(self):
        manager = DataManager('episodes')
        manager.addDataEntry('matrixEntry', (10, 10))

        data = manager.createDataObject(5)

        data.setDataEntry('matrixEntry', slice(0, 2), np.ones((2, 10, 10)))
        testMatrix = np.zeros((5, 10, 10))
        testMatrix[slice(0, 2)] = np.ones((2, 10, 10))

        testMatrix = testMatrix - data.getDataEntry('matrixEntry')
        self.assertTrue((testMatrix == 0).all())
Esempio n. 13
0
    def test_setOutputVariables_givenSingleOutputVariable_expectSetOutputVariables(
            self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)
        dataManager.addDataEntry('A', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        mapping.setOutputVariables(['A'])

        self.assertEqual(mapping.getOutputVariables(), ['A'])
Esempio n. 14
0
    def test_getElementNames(self):
        dataManager = DataUtil.createTestManager()
        self.assertEqual(sorted(dataManager.getEntryNames()), [
            'actions', 'contexts', 'parameters', 'states', 'subActions',
            'subStates'
        ])

        dataManager = DataManager('testDM')
        dataManager.addDataEntry('a', 5)
        dataManager.addDataEntry('b', 10)
        self.assertEqual(sorted(dataManager.getEntryNames()),
                         sorted(['a', 'b']))
    def test_init(self):
        self.assertRaises(ValueError, FunctionLinearInFeatures, None, [], None,
                          None, None)

        self.assertRaises(ValueError, FunctionLinearInFeatures, None, None,
                          None, None, [])

        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)
        f = FunctionLinearInFeatures(dataManager, ['X'], ['Y'], None, None,
                                     False)
        self.assertEqual(None, f.bias)
Esempio n. 16
0
    def test_setInputVariables_givenInputVariablesAppend_expectConstructorAndSetInputVariables(
            self):
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)
        dataManager.addDataEntry('A', 1)
        dataManager.addDataEntry('B', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        mapping.setInputVariables(['A', 'B'], None, True)

        self.assertEqual(mapping.getInputVariables(), ['X', 'A', 'B'])
Esempio n. 17
0
    def test_setInputVariables_givenNumDim_expectNotSupportet(self):
        '''
        This test may fail if the functionality gets implemented
        '''
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)
        dataManager.addDataEntry('A', 1)
        dataManager.addDataEntry('B', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        self.assertRaises(NotImplementedError,
                          lambda: mapping.setInputVariables(['A', 'B'], 5))
Esempio n. 18
0
    def __init__(self, gymEnvironment, useRender=False):

        dataManager = DataManager(['episodes', 'steps'])

        dataManager.subDataManager.addDataEntry('rewards', 1)
        dataManager.subDataManager.addDataEntry('isTerminalState',
                                                1,
                                                dataType=DataType.discrete)

        if isinstance(gymEnvironment.observation_space, spaces.Box):
            low = gymEnvironment.observation_space.low
            high = gymEnvironment.observation_space.high
            dataManager.addDataEntry('states', low.shape, low, high, level=1)
        elif isinstance(gymEnvironment.observation_space, spaces.Discrete):
            dataManager.addDataEntry('states',
                                     1,
                                     np.array([1]),
                                     np.array(
                                         [gymEnvironment.observation_space.n]),
                                     dataType=DataType.discrete,
                                     level=1)

        if isinstance(gymEnvironment.action_space, spaces.Box):
            low = gymEnvironment.action_space.low
            high = gymEnvironment.action_space.high
            dataManager.addDataEntry('actions', low.shape, low, high, level=1)
        elif isinstance(gymEnvironment.observation_space, spaces.Discrete):
            dataManager.addDataEntry('actions',
                                     1,
                                     np.array([1]),
                                     np.array([gymEnvironment.action_space.n]),
                                     dataType=DataType.discrete,
                                     level=1)

        # get one step to check the info
        gymEnvironment.reset()
        observation, reward, done, info = gymEnvironment.step(
            gymEnvironment.action_space.sample())

        self.outputArgumentsStep = ['nextStates', 'rewards', 'isTerminalState']
        for key, value in info.items():
            if (isinstance(value, np.ndarray)):
                dataManager.addDataEntry(key, value.shape, level=1)
                self.outputArgumentsStep.append(key)

        super().__init__(self, dataManager)
        self.gymEnvironment = gymEnvironment

        self._parallelSampling = False
Esempio n. 19
0
    def test_get_alias_data(self):
        dataManager = DataManager('episodes')
        dataManager.addDataEntry('parameters', 5)
        dataManager.addDataEntry('contexts', 5)
        dataManager.addDataAlias('parameterAlias',
                                 [('parameters', slice(0, 2))])

        dataManager.addDataAlias('twoAlias', [('parameters', slice(0, 2)),
                                              ('contexts', slice(2, 5))])

        myData = dataManager.createDataObject([10, 5, 1])

        myData.dataStructure['parameters'] = np.ones((10, 5))
        myData.dataStructure['contexts'] = np.ones((10, 5)) * 2

        paramAlias = myData.dataStructure['parameterAlias']
        paramAlias[:] = np.ones(2) * 3
        paramAlias[0][1] = 10
        myData.dataStructure['parameterAlias'] = paramAlias

        self.assertEqual(myData.dataStructure['parameters'][0][1], 10)
        self.assertEqual(myData.dataStructure['parameters'][0][2], 1)
        self.assertEqual(myData.dataStructure['parameters'][3][1], 3)
        self.assertEqual(myData.dataStructure['parameters'][5][3], 1)

        twoAlias = myData.dataStructure['twoAlias']
        twoAlias[4] = np.ones(5) * 4
        twoAlias[5] = np.ones(5) * 5
        twoAlias[6] = np.ones(5) * 6
        twoAlias[-1] = np.ones(5) * 9

        myData.dataStructure['twoAlias'] = twoAlias

        self.assertEqual(myData.dataStructure['twoAlias'][0][3], 2)
        self.assertEqual(myData.dataStructure['twoAlias'][-1][3], 9)
        self.assertEqual(myData.dataStructure['twoAlias'][4][2], 4)
        self.assertEqual(myData.dataStructure['twoAlias'][5][2], 5)
        self.assertEqual(myData.dataStructure['parameters'][0][0], 3)
        self.assertEqual(myData.dataStructure['parameters'][0][1], 10)
        self.assertEqual(myData.dataStructure['parameters'][0][2], 1)
        self.assertEqual(myData.dataStructure['parameters'][4][2], 1)
        self.assertEqual(myData.dataStructure['parameters'][5][2], 1)
        self.assertEqual(myData.dataStructure['contexts'][1][3], 2)
        self.assertEqual(myData.dataStructure['contexts'][6][3], 6)
        self.assertEqual(myData.dataStructure['contexts'][-1][3], 9)
        self.assertEqual(myData.dataStructure['contexts'][4][0], 2)
        self.assertEqual(myData.dataStructure['contexts'][5][1], 2)
        self.assertEqual(myData.dataStructure['contexts'][4][2], 4)
        self.assertEqual(myData.dataStructure['contexts'][5][2], 5)
Esempio n. 20
0
    def test_setgetDataEntryLocalLayer(self):
        dataManager = DataManager('episodes')
        dataManager.addDataEntry('parameters', 5, -5, 5)

        myData = dataManager.createDataObject([10])

        # set the data for the parameters of all episodes
        myData.setDataEntry(['parameters'], [], np.ones((10, 5)))
        myData.setDataEntry(['parameters'], [slice(0, 5)], np.ones((5, 5)))

        # the first episode should have different parameters
        myData.setDataEntry(['parameters'], [0], np.array([1, 2, 3, 4, 5]))

        self.assertTrue(
            (myData.dataStructure['parameters'][0] == np.array([1, 2, 3, 4,
                                                                5])).all())
        self.assertTrue(
            (myData.dataStructure['parameters'][1] == np.array([1, 1, 1, 1,
                                                                1])).all())
        self.assertTrue(
            (myData.dataStructure['parameters'][9] == np.array([1, 1, 1, 1,
                                                                1])).all())

        # this should not change anything
        myData.setDataEntry(['parameters'], [], np.ones((10, 5)))
        myData.setDataEntry(['parameters'], [0], np.array([1, 2, 3, 4, 5]))

        self.assertTrue(
            (myData.dataStructure['parameters'][0] == np.array([1, 2, 3, 4,
                                                                5])).all())
        self.assertTrue(
            (myData.dataStructure['parameters'][1] == np.array([1, 1, 1, 1,
                                                                1])).all())
        self.assertTrue(
            (myData.dataStructure['parameters'][9] == np.array([1, 1, 1, 1,
                                                                1])).all())

        # tests for getDataEntry
        self.assertTrue((myData.getDataEntry('parameters') ==
                         myData.dataStructure['parameters']).all())

        self.assertTrue((myData.getDataEntry(
            'parameters', ...) == myData.dataStructure['parameters']).all())

        self.assertTrue((myData.getDataEntry('parameters')[4] ==
                         myData.dataStructure['parameters'][4]).all())

        self.assertTrue((myData.getDataEntry(
            'parameters', [4]) == myData.dataStructure['parameters'][4]).all())
Esempio n. 21
0
    def test_addDataEntry(self):
        dataManager = DataManager('episodes')
        dataManager.addDataEntry('parameters', 5, -1 * np.ones(5),
                                 np.array([1, 1, 3, 1, 1]))

        self.assertIsInstance(dataManager.dataEntries, dict)
        self.assertIsInstance(dataManager.dataEntries['parameters'], DataEntry)
        self.assertEqual(dataManager.dataEntries['parameters'].numDimensions,
                         (5, ))
        self.assertTrue((dataManager.dataEntries['parameters'].minRange == [
            -1, -1, -1, -1, -1
        ]).all())
        self.assertTrue(
            (dataManager.dataEntries['parameters'].maxRange == [1, 1, 3, 1,
                                                                1]).all())
Esempio n. 22
0
    def test_mergeDataFrontNoSubmanager(self):
        dataManager = DataManager("manager")
        dataManager.addDataEntry("entry1", 2)

        data1 = dataManager.createDataObject([10, 10])
        data1.setDataEntry("entry1", ..., np.ones((10, 2)))

        data2 = dataManager.createDataObject([5, 5])
        data2.setDataEntry("entry1", ..., np.zeros((5, 2)))

        data1.mergeData(data2, True)

        self.assertEqual(data1.getNumElements("entry1"), 15)
        self.assertTrue((data1.getDataEntry("entry1", ...) == np.vstack(
            (np.zeros((5, 2)), np.ones((10, 2))))).all())
Esempio n. 23
0
    def test_restrictedEntry(self):
        dataManager = DataManager("manager", isTimeSeries=False)
        dataManager.addDataEntry("entry1", 1)
        dataManager.addDataEntry("entry2", 3, isPeriodic=[True, False, True])
        dataManager.addDataAlias("entries", [('entry1', ...), ('entry2', ...)])

        data = dataManager.createDataObject(2)
        data.setDataEntry('entries', ...,
                          np.array([[0, 8, 0, 2], [0, 2, 0, -8]]))

        entryRestricted = data.getDataEntry('entries_restricted')
        self.assertTrue(
            sum(
                sum(
                    np.abs(entryRestricted -
                           np.array([[0, 1, 0, 1], [0, 1, 0, -1]])))) < 0.001)
Esempio n. 24
0
    def testSparseEntries(self):
        manager = DataManager('episodes')
        manager.addDataEntry('matrixEntry', 10, dataType=DataType.sparse)

        data = manager.createDataObject(5)

        sparseMatrix = csr_matrix((2, 10))
        sparseMatrix[0, 4] = 4
        sparseMatrix[1, 2] = 1

        data.setDataEntry('matrixEntry', slice(0, 2), sparseMatrix)
        testMatrix = csr_matrix((5, 10))
        testMatrix[slice(0, 2)] = sparseMatrix

        testMatrix = testMatrix - data.getDataEntry('matrixEntry')
        self.assertTrue(np.abs(testMatrix).sum() == 0)
Esempio n. 25
0
    def test_setInputVariables_givenNumberInInputvariables_expectNotSupportet(
            self):
        '''
        This test may fail if the functionality gets implemented
        '''
        dataManager = DataManager('values')
        dataManager.addDataEntry('X', 1)
        dataManager.addDataEntry('Y', 1)
        dataManager.addDataEntry('A', 1)
        dataManager.addDataEntry('B', 1)

        mapping = Mapping(dataManager, ['X'], ['Y'], "TestMapping")

        self.assertRaises(
            DeprecationWarning,
            lambda: mapping.setInputVariables([5, 'A', 'B'], None, True))
Esempio n. 26
0
    def test_reserveStorage(self):
        dataManager = DataManager('episodes')
        dataManager.addDataEntry('parameters', 5)
        dataManager.addDataEntry('contexts', 2)

        subDataManager = DataManager('steps')
        subDataManager.addDataEntry('states', 2)
        subDataManager.addDataEntry('actions', 2)

        dataManager.subDataManager = subDataManager

        data = dataManager.createDataObject([100, 20])

        data.reserveStorage([20, 20])

        self.assertEqual(data.dataStructure['contexts'].shape[0], 20)
        self.assertEqual(data.dataStructure['parameters'].shape[0], 20)

        for i in range(0, 20):
            self.assertEqual(data.dataStructure['steps'][i]['states'].shape[0],
                             20)
            self.assertEqual(
                data.dataStructure['steps'][i]['actions'].shape[0], 20)

        data.reserveStorage([50, 100])

        self.assertEqual(data.dataStructure['contexts'].shape[0], 50)
        self.assertEqual(data.dataStructure['parameters'].shape[0], 50)

        for i in range(0, 50):
            self.assertEqual(data.dataStructure['steps'][i]['states'].shape[0],
                             100)
            self.assertEqual(
                data.dataStructure['steps'][i]['actions'].shape[0], 100)

        data.reserveStorage([50, 0])

        self.assertEqual(data.dataStructure['contexts'].shape[0], 50)
        self.assertEqual(data.dataStructure['parameters'].shape[0], 50)

        for i in range(0, 50):
            self.assertEqual(data.dataStructure['steps'][i]['states'].shape[0],
                             0)
            self.assertEqual(
                data.dataStructure['steps'][i]['actions'].shape[0], 0)

        data.reserveStorage(15, ...)

        self.assertEqual(data.dataStructure['contexts'].shape[0], 50)
        self.assertEqual(data.dataStructure['parameters'].shape[0], 50)

        for i in range(0, 50):
            self.assertEqual(data.dataStructure['steps'][i]['states'].shape[0],
                             15)
            self.assertEqual(
                data.dataStructure['steps'][i]['actions'].shape[0], 15)
Esempio n. 27
0
    def test_getNumElementsForIndex(self):
        manager = DataUtil.createTestManager()
        data = manager.createDataObject([3, 4, 5])

        self.assertEqual(data.getNumElementsForIndex(0), 3)
        self.assertEqual(data.getNumElementsForIndex(0, [...]), 3)
        self.assertEqual(data.getNumElementsForIndex(1), 12)
        self.assertEqual(data.getNumElementsForIndex(1, [...]), 12)
        self.assertEqual(data.getNumElementsForIndex(1, [..., ...]), 12)
        self.assertEqual(data.getNumElementsForIndex(1, [..., slice(0, 2)]), 6)
        self.assertEqual(
            data.getNumElementsForIndex(1,
                                        [slice(2, 3), slice(0, 2)]), 2)
        self.assertEqual(data.getNumElementsForIndex(2), 60)
        self.assertEqual(
            data.getNumElementsForIndex(2, ...),
            60)  # test implicit cast to array of second argument (deprecated)
        self.assertEqual(data.getNumElementsForIndex(2, [...]),
                         60)  # this should be the standart way
        self.assertEqual(data.getNumElementsForIndex(2, [..., ...]), 60)
        self.assertEqual(data.getNumElementsForIndex(2, [..., ..., ...]), 60)
        self.assertEqual(
            data.getNumElementsForIndex(2, [..., ..., slice(0, 2)]), 24)
        self.assertEqual(
            data.getNumElementsForIndex(
                2, [..., slice(1, 4), slice(0, 2)]), 18)
        self.assertEqual(
            data.getNumElementsForIndex(
                2, [slice(0, 1), slice(2, 3),
                    slice(0, 2)]), 2)

        dataManager = DataManager('episodes')
        subDataManager = DataManager('steps')
        dataManager.subDataManager = subDataManager
        dataManager.addDataEntry('parameters', 5)
        dataManager.addDataAlias('pAlias', [('parameters', ...)])
        dataManager.addDataEntry('contexts', 2)
        data = dataManager.createDataObject([3, 4, 5])

        self.assertEqual(data.getNumElementsForIndex(0), 3)
        self.assertEqual(data.getNumElementsForIndex(0, [...]), 3)
        self.assertEqual(data.getNumElementsForIndex(1), 12)
        self.assertEqual(data.getNumElementsForIndex(1, [...]), 12)
        self.assertEqual(data.getNumElementsForIndex(1, [..., ...]), 12)
        self.assertEqual(data.getNumElementsForIndex(1, [slice(2, 3)]), 4)
Esempio n. 28
0
    def test_setgetDataEntryRanges(self):
        dataManager = DataManager('episodes')
        dataManager.addDataEntry('parameters', 5)  # implicit ranges ([-1 1])
        dataManager.addDataEntry('temperature', 24, -20, 100)

        myData = dataManager.createDataObject([10, 5, 3])

        # this should not raise any exception
        myData.setDataEntry(['parameters'], [], np.ones((10, 5)))
        myData.setDataEntry(['parameters'], [], -np.ones((10, 5)))
        myData.setDataEntry(['parameters'], [slice(0, 5)], 0.97 * np.ones(
            (5, 5)))
        myData.setDataEntry(['parameters'], [slice(0, 5)], -0.5 * np.ones(
            (5, 5)))
        myData.setDataEntry('temperature', [], -20 * np.ones((10, 24)))
        myData.setDataEntry('temperature', [], -19 * np.ones((10, 24)))
        myData.setDataEntry('temperature', [], 99 * np.ones((10, 24)))
        myData.setDataEntry('temperature', [], np.zeros((10, 24)))
Esempio n. 29
0
    def test_setDataEntryList(self):
        dataManager = DataManager('episodes')
        dataManager.addDataEntry('parameters', 5, -10, 10)
        dataManager.addDataEntry('contexts', 3, -10, 10)
        myData = dataManager.createDataObject([10])

        # set the data for the parameters and context of all episodes
        myData.setDataEntry(['parameters'], [...], np.ones((10, 5)))
        myData.setDataEntry(['contexts'], [...], np.ones((10, 3)))

        myData.setDataEntryList(
            ['parameters', 'contexts'], [...],
            [np.zeros((10, 5)), np.zeros((10, 3))])

        self.assertTrue((myData.getDataEntry('parameters', [...]) == np.zeros(
            (10, 5))).all())
        self.assertTrue((myData.getDataEntry('contexts', [...]) == np.zeros(
            (10, 3))).all())

        myData.setDataEntryList(
            [('parameters', ['contexts'])], [...],
            [np.hstack((np.ones((10, 5)), 2 * np.ones((10, 3))))])

        self.assertTrue((myData.getDataEntry('parameters', [...]) == np.ones(
            (10, 5))).all())
        self.assertTrue((myData.getDataEntry('contexts', [...]) == 2 * np.ones(
            (10, 3))).all())

        myData.setDataEntryList([('parameters', ['contexts'])], [...],
                                [6 * np.ones((10, 8))])

        self.assertTrue((myData.getDataEntry('parameters',
                                             [...]) == 6 * np.ones(
                                                 (10, 5))).all())
        self.assertTrue((myData.getDataEntry('contexts', [...]) == 6 * np.ones(
            (3))).all())

        myData.setDataEntryList([('parameters', ['contexts'])], [3],
                                7 * np.ones((1, 8)))

        self.assertTrue((myData.getDataEntry('parameters', [3]) == 7 * np.ones(
            (5))).all())
        self.assertTrue((myData.getDataEntry('contexts', 3) == 7 * np.ones(
            (3))).all())
Esempio n. 30
0
    def test_getDataProbabilities_given3DExpAndDiagonalSigma_NoError(
            self):
        class DistributionWithMeanAndVarianceTest(
                DistributionWithMeanAndVariance):

            def DistributionWithMeanAndVarianceTest(self, dataManager):
                DistributionWithMeanAndVariance.__init__(self, dataManager)

            def getExpectationAndSigma(self, inputData, *args):
                return (np.zeros((2, 2, 1)), np.ones((2, 2, 1)))

        dataManager = DataManager("TestDataManager")
        dataManager.addDataEntry("Out", 3)
        dataManager.addDataEntry("In", 3)
        distribution = DistributionWithMeanAndVarianceTest(dataManager)
        distribution.setOutputVariables(["Out"])
        distribution.setInputVariables(["In"])

        qData = distribution.getDataProbabilities(None, np.zeros((2, 1, 3)))