def test_seed(self):
     ga_opts = {'maxiter': 10}
     ps_opts = {'maxiter': 5}
     # Run 1
     session1 = Estimation(self.tmpdir, self.fmu_path, self.inp,
                           self.known, self.est, self.ideal,
                           lp_n=1, lp_len=3600, lp_frame=(0, 3600),
                           vp=(20000, 40000), ic_param={'Tstart': 'T'},
                           methods=('GA', ),
                           ga_opts=ga_opts, ps_opts=ps_opts,
                           seed=1, ftype='RMSE')
     estimates1 = session1.estimate()
     # Run 2
     session2 = Estimation(self.tmpdir, self.fmu_path, self.inp,
                           self.known, self.est, self.ideal,
                           lp_n=1, lp_len=3600, lp_frame=(0, 3600),
                           vp=(20000, 40000), ic_param={'Tstart': 'T'},
                           methods=('GA', ),
                           ga_opts=ga_opts, ps_opts=ps_opts,
                           seed=1, ftype='RMSE')
     estimates2 = session2.estimate()
     # Check if estimates are the same
     same = True
     for key in estimates1:
         if estimates1[key] != estimates2[key]:
             same = False
     self.assertTrue(
         same,
         "Different estimates obtained despite the same seed"
         )
 def test_ps_only(self):
     ga_opts = {'maxiter': 0}
     ps_opts = {'maxiter': 1}
     session = Estimation(self.tmpdir, self.fmu_path, self.inp,
                          self.known, self.est, self.ideal,
                          lp_n=1, lp_len=3600, lp_frame=(0, 3600),
                          vp=(20000, 40000), ic_param={'Tstart': 'T'},
                          methods=('PS', ),
                          ga_opts=ga_opts, ps_opts=ps_opts, seed=1,
                          ftype='RMSE')
     session.estimate()
    def test_estimation_basic_parallel(self):
        """Will use default methods ('MODESTGA', 'PS')"""
        modestga_opts = {
            "generations": 2,
            "workers": 2,
            "pop_size": 16,
            "trm_size": 3
        }
        ps_opts = {"maxiter": 2}
        session = Estimation(
            self.tmpdir,
            self.fmu_path,
            self.inp,
            self.known,
            self.est,
            self.ideal,
            modestga_opts=modestga_opts,
            ps_opts=ps_opts,
            default_log=False,
        )
        estimates = session.estimate()
        err, res = session.validate()

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
    def test_estimation_rmse(self):
        modestga_opts = {"generations": 8}
        ps_opts = {"maxiter": 16}

        session = Estimation(
            self.tmpdir,
            self.fmu_path,
            self.inp,
            self.known,
            self.est,
            self.ideal,
            lp_n=1,
            lp_len=3600,
            lp_frame=(0, 3600),
            vp=(20000, 40000),
            ic_param={"Tstart": "T"},
            methods=("MODESTGA", "PS"),
            modestga_opts=modestga_opts,
            ps_opts=ps_opts,
            ftype="RMSE",
            default_log=False,
        )

        estimates = session.estimate()
        err, res = session.validate()

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
        self.assertLess(err["tot"], 1.48)
    def test_estimation_rmse(self):
        ga_opts = {'maxiter': 3, 'pop_size': 8, 'trm_size': 3}
        ps_opts = {'maxiter': 3}

        session = Estimation(self.tmpdir,
                             self.fmu_path,
                             self.inp,
                             self.known,
                             self.est,
                             self.ideal,
                             lp_n=1,
                             lp_len=3600,
                             lp_frame=(0, 3600),
                             vp=(20000, 40000),
                             ic_param={'Tstart': 'T'},
                             methods=('GA', 'PS'),
                             ga_opts=ga_opts,
                             ps_opts=ps_opts,
                             seed=1,
                             ftype='RMSE')

        estimates = session.estimate()
        err, res = session.validate()

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
        self.assertLess(err['tot'], 1.48)
    def test_estimation_all_args(self):
        ga_opts = {'maxiter': 3, 'pop_size': 10, 'trm_size': 5, 'lhs': True}
        ps_opts = {'maxiter': 3}
        session = Estimation(self.tmpdir, self.fmu_path, self.inp,
                             self.known, self.est, self.ideal,
                             lp_n=2, lp_len=3600, lp_frame=(0, 3600),
                             vp=(20000, 40000), ic_param={'Tstart': 'T'},
                             methods=('GA', 'PS'),
                             ga_opts=ga_opts, ps_opts=ps_opts,
                             seed=1, ftype='NRMSE')

        estimates = session.estimate()
        err, res = session.validate()  # Standard validation period
        err2, res2 = session.validate(vp=(25000, 28600))

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertIsNotNone(err2)
        self.assertIsNotNone(res2)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
        self.assertGreater(len(res2.index), 1)
        self.assertGreater(len(res2.columns), 0)
        self.assertEqual(session.lp[0][0], 0)
        self.assertEqual(session.lp[0][1], 3600)
        # Enabling next line triggers the Matplotlib error (issue #20)
        # raw_input('Continue...')
        self.assertLess(err['tot'], 1.7)  # NRMSE
Exemple #7
0
    def test_estimation_basic(self):
        """Will use default methods ('MODESTGA', 'PS')"""
        modestga_opts = {
            'generations': 2,
            'workers': 1,
            'pop_size': 8,
            'trm_size': 3
        }
        ps_opts = {'maxiter': 2}
        session = Estimation(self.tmpdir,
                             self.fmu_path,
                             self.inp,
                             self.known,
                             self.est,
                             self.ideal,
                             modestga_opts=modestga_opts,
                             ps_opts=ps_opts,
                             default_log=False)
        estimates = session.estimate()
        err, res = session.validate()

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
Exemple #8
0
    def test_estimation_rmse(self):
        modestga_opts = {'generations': 8}
        ps_opts = {'maxiter': 16}

        session = Estimation(self.tmpdir,
                             self.fmu_path,
                             self.inp,
                             self.known,
                             self.est,
                             self.ideal,
                             lp_n=1,
                             lp_len=3600,
                             lp_frame=(0, 3600),
                             vp=(20000, 40000),
                             ic_param={'Tstart': 'T'},
                             methods=('MODESTGA', 'PS'),
                             modestga_opts=modestga_opts,
                             ps_opts=ps_opts,
                             ftype='RMSE',
                             default_log=False)

        estimates = session.estimate()
        err, res = session.validate()

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
        self.assertLess(err['tot'], 1.48)
Exemple #9
0
 def test_ps_only(self):
     modestga_opts = {'generations': 0}
     ps_opts = {'maxiter': 1}
     session = Estimation(self.tmpdir,
                          self.fmu_path,
                          self.inp,
                          self.known,
                          self.est,
                          self.ideal,
                          lp_n=1,
                          lp_len=3600,
                          lp_frame=(0, 3600),
                          vp=(20000, 40000),
                          ic_param={'Tstart': 'T'},
                          methods=('PS', ),
                          modestga_opts=modestga_opts,
                          ps_opts=ps_opts,
                          ftype='RMSE',
                          default_log=False)
     session.estimate()
Exemple #10
0
 def test_ps_only(self):
     modestga_opts = {"generations": 0}
     ps_opts = {"maxiter": 1}
     session = Estimation(
         self.tmpdir,
         self.fmu_path,
         self.inp,
         self.known,
         self.est,
         self.ideal,
         lp_n=1,
         lp_len=3600,
         lp_frame=(0, 3600),
         vp=(20000, 40000),
         ic_param={"Tstart": "T"},
         methods=("PS", ),
         modestga_opts=modestga_opts,
         ps_opts=ps_opts,
         ftype="RMSE",
         default_log=False,
     )
     session.estimate()
    def test_estimation_basic(self):
        ga_opts = {'maxiter': 3}
        ps_opts = {'maxiter': 3}
        session = Estimation(self.tmpdir, self.fmu_path, self.inp,
                             self.known, self.est, self.ideal,
                             ga_opts=ga_opts, ps_opts=ps_opts)
        estimates = session.estimate()
        err, res = session.validate()

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
Exemple #12
0
    def test_estimation_all_args(self):
        modestga_opts = {
            "generations": 2,
            "workers": 2,
            "pop_size": 16,
            "trm_size": 3
        }
        ps_opts = {"maxiter": 3}
        session = Estimation(
            self.tmpdir,
            self.fmu_path,
            self.inp,
            self.known,
            self.est,
            self.ideal,
            lp_n=2,
            lp_len=3600,
            lp_frame=(0, 3600),
            vp=(20000, 40000),
            ic_param={"Tstart": "T"},
            methods=("MODESTGA", "PS"),
            modestga_opts=modestga_opts,
            ps_opts=ps_opts,
            ftype="NRMSE",
            default_log=False,
        )

        estimates = session.estimate()
        err, res = session.validate()  # Standard validation period
        err2, res2 = session.validate(vp=(25000, 28600))

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertIsNotNone(err2)
        self.assertIsNotNone(res2)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
        self.assertGreater(len(res2.index), 1)
        self.assertGreater(len(res2.columns), 0)
        self.assertEqual(session.lp[0][0], 0)
        self.assertEqual(session.lp[0][1], 3600)
        self.assertLess(err["tot"], 1.7)  # NRMSE
Exemple #13
0
    def test_estimation_all_args(self):
        modestga_opts = {
            'generations': 2,
            'workers': 2,
            'pop_size': 16,
            'trm_size': 3
        }
        ps_opts = {'maxiter': 3}
        session = Estimation(self.tmpdir,
                             self.fmu_path,
                             self.inp,
                             self.known,
                             self.est,
                             self.ideal,
                             lp_n=2,
                             lp_len=3600,
                             lp_frame=(0, 3600),
                             vp=(20000, 40000),
                             ic_param={'Tstart': 'T'},
                             methods=('MODESTGA', 'PS'),
                             modestga_opts=modestga_opts,
                             ps_opts=ps_opts,
                             ftype='NRMSE',
                             default_log=False)

        estimates = session.estimate()
        err, res = session.validate()  # Standard validation period
        err2, res2 = session.validate(vp=(25000, 28600))

        self.assertIsNotNone(estimates)
        self.assertGreater(len(estimates), 0)
        self.assertIsNotNone(err)
        self.assertIsNotNone(res)
        self.assertIsNotNone(err2)
        self.assertIsNotNone(res2)
        self.assertGreater(len(res.index), 1)
        self.assertGreater(len(res.columns), 0)
        self.assertGreater(len(res2.index), 1)
        self.assertGreater(len(res2.columns), 0)
        self.assertEqual(session.lp[0][0], 0)
        self.assertEqual(session.lp[0][1], 3600)
        self.assertLess(err['tot'], 1.7)  # NRMSE
Exemple #14
0
    # MODEL IDENTIFICATION ==========================================
    session = Estimation(workdir,
                         fmu_path,
                         inp,
                         known,
                         est,
                         ideal,
                         lp_n=2,
                         lp_len=50000,
                         lp_frame=(0, 50000),
                         vp=(0, 50000),
                         ic_param={'Tstart': 'T'},
                         methods=('GA', 'PS'),
                         ga_opts={
                             'maxiter': 5,
                             'tol': 0.001,
                             'lhs': True
                         },
                         ps_opts={
                             'maxiter': 500,
                             'tol': 1e-6
                         },
                         scipy_opts={},
                         ftype='RMSE',
                         seed=1,
                         default_log=True,
                         logfile='simple.log')

    estimates = session.estimate()
    err, res = session.validate()