Exemplo n.º 1
0
    def test_tabular_data(self):
        tdata = hce.read_tabular_data(_TEST_NAME + ".dat")
        metadata = ["%eval_id", "interface"]
        variables = ["x1", "x2", "x3"]
        responses = ["f", "c"]
        descriptors = metadata + variables + responses
        self.assertItemsEqual(descriptors, tdata.keys())

        with h5py.File(_TEST_NAME + ".h5", "r") as h:
            # Variables
            hvars = h["/models/simulation/NO_MODEL_ID/variables/continuous"]
            self.assertItemsEqual(variables, hvars.dims[1][0][:])
            for i, v in enumerate(variables):
                for eid, tv, hv in zip(tdata["%eval_id"], tdata[v], hvars[:,
                                                                          i]):
                    self.assertAlmostEqual(
                        tv,
                        hv,
                        msg="Bad comparison for variable '%s' for eval %d" %
                        (v, eid),
                        places=9)
            hresps = h["/models/simulation/NO_MODEL_ID/responses/functions"]
            # Responses
            self.assertItemsEqual(responses, hresps.dims[1][0][:])
            for i, r in enumerate(responses):
                for eid, tr, hr in zip(tdata["%eval_id"], tdata[r], hresps[:,
                                                                           i]):
                    self.assertAlmostEqual(
                        tr,
                        hr,
                        msg="Bad comparison for response '%s'" % r,
                        places=9)
Exemplo n.º 2
0
    def test_tabular_data(self):
        tdata = hce.read_tabular_data(_TEST_NAME + ".dat")
        metadata = ["%eval_id", "interface"]
        variables = ["x1", "x2", "Y"]
        responses = ['displacement01', 'displacement02', 'g']        
        descriptors = metadata + variables + responses
        self.assertListEqual(descriptors, list(tdata.keys()))

        with h5py.File(_TEST_NAME + ".h5", "r") as h:
            # Variables
            hvars = h["/models/simulation/NO_MODEL_ID/variables/continuous"]
            hasv = h["/models/simulation/NO_MODEL_ID/metadata/active_set_vector"]
            self.assertListEqual(variables, hvars.dims[1][0][:].tolist())
            hindex = 0
            for i, eid in enumerate(tdata["%eval_id"]):
                while not all((a & 1 for a in hasv[hindex,:])):
                    hindex += 1
                for vi, v in enumerate(variables):
                    tv = tdata[v][i]
                    hv = hvars[hindex,vi]
                    self.assertAlmostEqual(tv, hv, msg="Bad comparison for variable '%s' for eval %d" % (v,eid), places=9)
                hindex += 1
                    
            # Responses
            hresps = h["/models/simulation/NO_MODEL_ID/responses/functions"]
            self.assertListEqual(responses, hresps.dims[1][0][:].tolist())
            hindex = 0
            for i, eid in enumerate(tdata["%eval_id"]):
                while not all((a & 1 for a in hasv[hindex,:])):
                    hindex += 1
                for ri, r in enumerate(responses):
                    tr = tdata[r][i]
                    hr = hresps[hindex,ri]
                    self.assertAlmostEqual(tr, hr, msg="Bad comparison for response '%s' for eval %d" % (r, eid), places=9)
                hindex += 1
Exemplo n.º 3
0
    def test_tabular_data(self):
        tdata = hce.read_tabular_data(_TEST_NAME + ".dat")
        metadata = ["%eval_id", "interface"]
        variables = ["x3"]
        responses = ['f_mean',
                     'f_stddev', 
                     'f_p1',
                     'f_p2',
                     'f_p3',
                     'f_r1',
                     'c_mean', 
                     'c_stddev',
                     'c_p1',
                     'c_p2',
                     'c_p3',
                     'c_r1']
        descriptors = metadata + variables + responses
        self.assertListEqual(descriptors, list(tdata.keys()))

        with h5py.File(_TEST_NAME + ".h5", "r") as h:
            # Variables
            hvars = h["/models/nested/nested_m/variables/continuous"]
            self.assertListEqual(variables, hvars.dims[1][0][:].tolist())
            for i, v in enumerate(variables):
                for eid, tv, hv in zip(tdata["%eval_id"], tdata[v], hvars[:,i]):
                    self.assertAlmostEqual(tv, hv, msg="Bad comparison for variable '%s' for eval %d" % (v,eid), places=9)
            hresps = h["/models/nested/nested_m/responses/functions"]
            # Responses
            self.assertListEqual(responses, hresps.dims[1][0][:].tolist())
            for i, r in enumerate(responses):
                for eid, tr, hr in zip(tdata["%eval_id"], tdata[r], hresps[:,i]):
                    self.assertAlmostEqual(tr, hr, msg="Bad comparison for response '%s' for eval %d" % (r, eid), places=9)
Exemplo n.º 4
0
    def setUp(self):
        try:
            self._variables
        except:
            self._tdata = hce.read_tabular_data(_TEST_NAME + ".dat")
            self._metadata = ["%eval_id", "interface"]
            self._variables = [
                "cdv_1",  #0 
                "cdv_2",  #1
                "ddsiv_1",  #2
                "ddsiv_2",  #3
                "ddssv_1",  #4
                "ddssv_2",  #5
                "ddsrv_1",  #6 
                "ddsrv_2",  #7
                "uuv_1",  #8
                "uuv_2",  #9 
                "dusiv_1",  #10
                "dusiv_2",  #11
                "dussv_1",  #12
                "dussv_2",  #13
                "dusrv_1",  #14 
                "dusrv_2"
            ]  #15
            self._responses = ["response_fn_1"]
            self._c_vars = self._variables[:2] + self._variables[8:10]
            self._di_vars = self._variables[2:4] + self._variables[10:12]
            self._ds_vars = self._variables[4:6] + self._variables[12:14]
            self._dr_vars = self._variables[6:8] + self._variables[14:]

            self._c_var_types = 2*["CONTINUOUS_DESIGN"] + \
                                2*["UNIFORM_UNCERTAIN"]
            self._di_var_types = 2*["DISCRETE_DESIGN_SET_INT"] + \
                                 2*["DISCRETE_UNCERTAIN_SET_INT"]
            self._ds_var_types = 2*["DISCRETE_DESIGN_SET_STRING"] + \
                                  2*["DISCRETE_UNCERTAIN_SET_STRING"]
            self._dr_var_types = 2*["DISCRETE_DESIGN_SET_REAL"] + \
                                  2*["DISCRETE_UNCERTAIN_SET_REAL"]

            self._c_var_ids = [1, 2, 9, 10]
            self._di_var_ids = [3, 4, 11, 12]
            self._ds_var_ids = [5, 6, 13, 14]
            self._dr_var_ids = [7, 8, 15, 16]
Exemplo n.º 5
0
    def test_tabular_data(self):
        # normally we'd compare to the top method's model, but models are turned off
        # for this test. Instead we'll compare to the approx interface. No recasts
        # occur in this test, so they should be the same.
        tdata = hce.read_tabular_data(_TEST_NAME + ".dat")
        metadata = ["%eval_id", "interface"]
        variables = ["x1", "x2", "x3"]
        responses = ["f"]
        descriptors = metadata + variables + responses
        self.assertListEqual(descriptors, list(tdata.keys()))

        with h5py.File(_TEST_NAME + ".h5", "r") as h:
            # Variables
            hvars = h[
                "/interfaces/APPROX_INTERFACE_1/surr/variables/continuous"]
            self.assertListEqual(variables, hvars.dims[1][0][:].tolist())
            for i, v in enumerate(variables):
                for eid, tv, hv in zip(tdata["%eval_id"], tdata[v], hvars[:,
                                                                          i]):
                    self.assertAlmostEqual(
                        tv,
                        hv,
                        msg="Bad comparison for variable '%s' for eval %d" %
                        (v, eid),
                        places=9)
            hresps = h[
                "/interfaces/APPROX_INTERFACE_1/surr/responses/functions"]
            # Responses
            self.assertListEqual(responses, hresps.dims[1][0][:].tolist())
            for i, r in enumerate(responses):
                for eid, tr, hr in zip(tdata["%eval_id"], tdata[r], hresps[:,
                                                                           i]):
                    self.assertAlmostEqual(
                        tr,
                        hr,
                        msg="Bad comparison for response '%s'" % r,
                        places=9)