Ejemplo n.º 1
0
 def test_N_conflict_produces_error_message(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2,2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings(N = 1)
             
     # calculate dependencies
     with self.assertRaises(SystemExit, msg = 'Conflicting N'):
         ms._check_dependent_model_settings(data, options)
Ejemplo n.º 2
0
 def test_value_sigma2_wrt_nsos_raises_error(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings(sigma2 = [1,2])
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     nsos = 1
     with self.assertRaises(SystemExit, msg = 'sigma2 should not be larger than nsos'):
         ms._check_dependent_model_settings_wrt_nsos(nsos = nsos)
Ejemplo n.º 3
0
 def test_default_S20_dependent(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2,2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings()
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     self.assertAlmostEqual(ms.S20, ms.sigma2, msg='default is sigma2')
Ejemplo n.º 4
0
 def test_default_sigma2_dependent_for_non_default_N0(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2,2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings(N0 = 1)
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     self.assertEqual(ms.sigma2, np.ones(ms.nbatch), msg='default is ones(ms.nbatch)');
Ejemplo n.º 5
0
 def test_N_calc_from_data(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2,2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings()
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     self.assertTrue(np.array_equal(ms.N, np.array([2])), msg = 'N should equal total number of rows in each y set')
Ejemplo n.º 6
0
 def test_nbatch_calc_from_data_y_2d(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2,2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings()
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     self.assertEqual(ms.nbatch, 1, msg = 'nbatch should equal number of calls to ''add_data_set''')
Ejemplo n.º 7
0
 def test_print_these_none(self):
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2])
     data.add_data_set(x,y)
     
     options = SimulationOptions()
     
     ms = ModelSettings()
     ms.define_model_settings()
     ms._check_dependent_model_settings(data, options)
     ms._check_dependent_model_settings_wrt_nsos(nsos = 1)
     
     print_these = ms.display_model_settings(print_these = None)
     self.assertEqual(print_these, ['sos_function', 'model_function', 'sigma2', 'N', 'N0', 'S20', 'nsos', 'nbatch'], msg = 'Default print keys')
Ejemplo n.º 8
0
    def test_print_these_not_none(self):
        data = DataStructure()
        x = np.zeros([2])
        y = np.zeros([2])
        data.add_data_set(x,y)
        
        options = SimulationOptions()
        
        ms = ModelSettings()
        ms.define_model_settings()
        ms._check_dependent_model_settings(data, options)
        ms._check_dependent_model_settings_wrt_nsos(nsos = 1)
        
        print_these = ms.display_model_settings(print_these = ['model_function'])
        self.assertEqual(print_these, ['model_function'], msg = 'Specified print keys')
# -------------------------------------------
Ejemplo n.º 9
0
 def test_size_sigma2_wrt_nsos_for_non_default_sigma2_raises_error(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings(sigma2 = [1,2])
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     nsos = 3
     with self.assertRaises(SystemExit, msg = 'sigma2 size mismatch'):
         ms._check_dependent_model_settings_wrt_nsos(nsos = nsos)
Ejemplo n.º 10
0
 def test_size_N_wrt_nsos(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings()
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     nsos = 2
     ms._check_dependent_model_settings_wrt_nsos(nsos = nsos)
     
     self.assertEqual(len(ms.N), nsos, msg = 'length of N should equal number of elements returned from sos function')
Ejemplo n.º 11
0
 def test_default_sigma2_dependent_for_non_default_N0_S20_multiple_data_sets(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2,2])
     data.add_data_set(x,y)
     y = np.zeros([3,2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings(N0 = 1, S20 = 1)
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     comp = np.linalg.norm(ms.sigma2 - ms.S20)
     self.assertAlmostEqual(comp, 0, msg='default is S20')
Ejemplo n.º 12
0
 def test_value_N_wrt_nsos_for_non_default_N_and_nsos_equal_1(self):
     # create test data
     data = DataStructure()
     x = np.zeros([2])
     y = np.zeros([2])
     data.add_data_set(x,y)
     y = np.zeros([4,2])
     data.add_data_set(x,y)
     
     options = setup_simulation_options(nsimu = int(1000))
     ms = setup_model_settings(N = [2,4])
     
     # calculate dependencies
     ms._check_dependent_model_settings(data, options)
     
     nsos = 1
     ms._check_dependent_model_settings_wrt_nsos(nsos = nsos)
     
     self.assertEqual(ms.N, 6, msg = 'length of N should equal number of elements returned from sos function')
Ejemplo n.º 13
0
        'Gc': t[0],
        'Ge': t[1],
        'lam_max': t[2],
        'eta': t[3],
        'gamma': t[4]
    }
    stress = nonaffine_hyperelastic_model(
        theta, xdata[:, 1]) + linear_viscoelastic_model(
            theta, xdata[:, 1], xdata[:, 0])
    return stress


# plot wrt time
pdata = DataStructure()
pdata.add_data_set(x=time,
                   y=stress,
                   user_defined_object=vhbdata['data']['xdata'][0][0])
mcstat.PI.setup_prediction_interval_calculation(results=results,
                                                data=pdata,
                                                modelfunction=predmodelfun,
                                                burnin=burnin)
mcstat.PI.generate_prediction_intervals(nsample=500, calc_pred_int=True)
# plot prediction intervals
mcstat.PI.plot_prediction_intervals(adddata=True)
plt.xlabel('Time (sec)', fontsize=22)
plt.xticks(fontsize=22)
plt.ylabel('Nominal Stress (kPa)', fontsize=22)
plt.yticks(fontsize=22)
plt.xlim([0, time[-1]])
plt.ylim([0, 240])
Ejemplo n.º 14
0
def basic_data_structure():
    DS = DataStructure()
    x = np.random.random_sample(size=(100, 1))
    y = np.random.random_sample(size=(100, 1))
    DS.add_data_set(x=x, y=y)
    return DS