Beispiel #1
0
 def test_first(self):
     df = data.df_diamonds >> gr.tf_select(X.cut, X.x) >> gr.tf_head(5)
     # straight summarize
     t = df >> gr.tf_summarize(f=gr.first(X.x))
     df_truth = pd.DataFrame({"f": [3.95]})
     self.assertTrue(t.equals(df_truth))
     # grouped summarize
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(f=gr.first(X.x))
     df_truth = pd.DataFrame({
         "cut": ["Good", "Ideal", "Premium"],
         "f": [4.05, 3.95, 3.89]
     })
     self.assertTrue(t.equals(df_truth))
     # summarize with order_by
     t = df >> gr.tf_summarize(f=gr.first(X.x, order_by=gr.desc(X.cut)))
     df_truth = pd.DataFrame({"f": [3.89]})
     # straight mutate
     t = df >> gr.tf_mutate(f=gr.first(X.x))
     df_truth = df.copy()
     df_truth["f"] = df_truth.x.iloc[0]
     self.assertTrue(t.equals(df_truth))
     # grouped mutate
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_mutate(f=gr.first(X.x))
     df_truth["f"] = pd.Series([3.95, 3.89, 4.05, 3.89, 4.05])
     self.assertTrue(t.sort_index().equals(df_truth))
Beispiel #2
0
 def test_n(self):
     df = data.df_diamonds >> gr.tf_select(X.cut, X.x) >> gr.tf_head(5)
     # straight summarize
     t = df >> gr.tf_summarize(n=gr.n(X.x))
     df_truth = pd.DataFrame({"n": [5]})
     self.assertTrue(t.equals(df_truth))
     # grouped summarize
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(n=gr.n(X.x))
     df_truth = pd.DataFrame({
         "cut": ["Good", "Ideal", "Premium"],
         "n": [2, 1, 2]
     })
     self.assertTrue(t.equals(df_truth))
     # straight mutate
     t = df >> gr.tf_mutate(n=gr.n(X.x))
     df_truth = df.copy()
     df_truth["n"] = 5
     self.assertTrue(t.equals(df_truth))
     # grouped mutate
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_mutate(n=gr.n(X.x))
     df_truth["n"] = pd.Series([1, 2, 2, 2, 2, 2])
     self.assertTrue(t.sort_index().equals(df_truth))
     # Implicit mode summarize
     t = df >> gr.tf_summarize(n=gr.n())
     df_truth = pd.DataFrame({"n": [5]})
     self.assertTrue(t.equals(df_truth))
     # Implicit mode mutate
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_mutate(n=gr.n())
     df_truth = df.copy()
     df_truth["n"] = pd.Series([1, 2, 2, 2, 2, 2])
     self.assertTrue(t.sort_index().equals(df_truth))
Beispiel #3
0
 def test_last(self):
     df = data.df_diamonds >> gr.tf_select(X.cut, X.x) >> gr.tf_head(5)
     # straight summarize
     t = df >> gr.tf_summarize(l=gr.last(X.x))
     df_truth = pd.DataFrame({"l": [4.34]})
     self.assertTrue(t.equals(df_truth))
     # grouped summarize
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(l=gr.last(X.x))
     df_truth = pd.DataFrame({
         "cut": ["Good", "Ideal", "Premium"],
         "l": [4.34, 3.95, 4.20]
     })
     self.assertTrue(t.equals(df_truth))
     # summarize with order_by
     t = df >> gr.tf_summarize(f=gr.last(
         X.x, order_by=[gr.desc(X.cut), gr.desc(X.x)]))
     df_truth = pd.DataFrame({"f": [4.05]})
     assert df_truth.equals(t)
     # straight mutate
     t = df >> gr.tf_mutate(l=gr.last(X.x))
     df_truth = df.copy()
     df_truth["l"] = df_truth.x.iloc[4]
     self.assertTrue(t.equals(df_truth))
     # grouped mutate
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_mutate(l=gr.last(X.x))
     df_truth["l"] = pd.Series([3.95, 4.20, 4.34, 4.20, 4.34])
     self.assertTrue(t.sort_index().equals(df_truth))
Beispiel #4
0
 def test_nth(self):
     df = data.df_diamonds >> gr.tf_select(X.cut, X.x) >> gr.tf_head(10)
     # straight summarize
     t = df >> gr.tf_summarize(second=gr.nth(X.x, 1))
     df_truth = pd.DataFrame({"second": [3.89]})
     self.assertTrue(t.equals(df_truth))
     # grouped summarize
     t = df >> gr.tf_group_by(
         X.cut) >> gr.tf_summarize(first=gr.nth(X.x, 0))
     df_truth = pd.DataFrame({
         "cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"],
         "first": [3.87, 4.05, 3.95, 3.89, 3.94],
     })
     self.assertTrue(t.equals(df_truth))
     # summarize with order_by
     t = df >> gr.tf_summarize(last=gr.nth(
         X.x, -1, order_by=[gr.desc(X.cut), gr.desc(X.x)]))
     df_truth = pd.DataFrame({"last": [3.87]})
     self.assertTrue(df_truth.equals(t))
     # straight mutate
     t = df >> gr.tf_mutate(out_of_range=gr.nth(X.x, 500))
     df_truth = df.copy()
     df_truth["out_of_range"] = np.nan
     self.assertTrue(t.equals(df_truth))
     # grouped mutate
     t = df >> gr.tf_group_by(
         X.cut) >> gr.tf_mutate(penultimate=gr.nth(X.x, -2))
     df_truth = df.copy()
     df_truth["penultimate"] = pd.Series(
         [np.nan, 3.89, 4.05, 3.89, 4.05, 4.07, 4.07, 4.07, np.nan, 4.07])
     self.assertTrue(t.sort_index().equals(df_truth))
Beispiel #5
0
 def test_sd(self):
     df = (
         data.df_diamonds
         >> gr.tf_group_by(X.cut)
         >> gr.tf_head(3)
         >> gr.tf_select(X.cut, X.x)
         >> gr.tf_ungroup()
     )
     # straight summarize
     t = df >> gr.tf_summarize(s=gr.sd(X.x))
     df_truth = pd.DataFrame({"s": [0.829091]})
     test_vector = abs(t.s - df_truth.s)
     self.assertTrue(all(test_vector < 0.00001))
     # grouped summarize
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(s=gr.sd(X.x))
     df_truth = pd.DataFrame(
         {
             "cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"],
             "s": [1.440417, 0.148436, 0.236925, 0.181934, 0.072342],
         }
     )
     test_vector = abs(t.s - df_truth.s)
     self.assertTrue(all(test_vector < 0.00001))
     # straight mutate
     t = df >> gr.tf_mutate(s=gr.sd(X.x))
     df_truth = df.copy()
     df_truth["s"] = 0.829091
     test_vector = abs(t.s - df_truth.s)
     self.assertTrue(all(test_vector < 0.00001))
     # grouped mutate
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_mutate(s=gr.sd(X.x))
     # df_truth['s'] = pd.Series([1.440417, 1.440417, 1.440417, 0.148436, 0.148436, 0.148436,
     #                            0.236925, 0.236925, 0.236925, 0.181934, 0.181934, 0.181934,
     #                            0.072342, 0.072342, 0.072342],
     #                           index=t.index)
     # test_vector = abs(t.s - df_truth.s)
     # print(t)
     # print(df_truth)
     self.assertTrue(all(test_vector < 0.00001))
     # test with single value (var undefined)
     df = (
         data.df_diamonds
         >> gr.tf_group_by(X.cut)
         >> gr.tf_head(1)
         >> gr.tf_select(X.cut, X.x)
     )
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(s=gr.sd(X.x))
     df_truth = pd.DataFrame(
         {
             "cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"],
             "s": [np.nan, np.nan, np.nan, np.nan, np.nan],
         }
     )
     self.assertTrue(t.equals(df_truth))
Beispiel #6
0
    def test_var(self):
        df = (
            data.df_diamonds
            >> gr.tf_group_by(X.cut)
            >> gr.tf_head(3)
            >> gr.tf_select(X.cut, X.x)
            >> gr.tf_ungroup()
        )

        # straight summarize
        t = df >> gr.tf_summarize(v=gr.var(X.x))
        df_truth = pd.DataFrame({"v": [0.687392]})
        test_vector = abs(t.v - df_truth.v)
        self.assertTrue(all(test_vector < 0.00001))

        # grouped summarize
        t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(v=gr.var(X.x))
        df_truth = pd.DataFrame(
            {
                "cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"],
                "v": [2.074800, 0.022033, 0.056133, 0.033100, 0.005233],
            }
        )
        test_vector = abs(t.v - df_truth.v)
        self.assertTrue(all(test_vector < 0.00001))
        # straight mutate
        t = df >> gr.tf_mutate(v=gr.var(X.x))
        df_truth = df.copy()
        df_truth["v"] = 0.687392
        test_vector = abs(t.v - df_truth.v)
        self.assertTrue(all(test_vector < 0.00001))
        # grouped mutate
        # t = df >> group_by(X.cut) >> mutate(v=var(X.x))
        # df_truth['v'] = pd.Series([2.074800, 2.074800, 2.074800, 0.022033, 0.022033, 0.022033,
        #                            0.056133, 0.056133, 0.056133, 0.033100, 0.033100, 0.033100,
        #                            0.005233, 0.005233, 0.005233],
        #                           index=t.index)
        # test_vector = abs(t.v - df_truth.v)
        # assert all(test_vector < .00001)
        # test with single value (var undefined)
        df = (
            data.df_diamonds
            >> gr.tf_group_by(X.cut)
            >> gr.tf_head(1)
            >> gr.tf_select(X.cut, X.x)
        )
        t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(v=gr.var(X.x))
        df_truth = pd.DataFrame(
            {
                "cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"],
                "v": [np.nan, np.nan, np.nan, np.nan, np.nan],
            }
        )
        self.assertTrue(t.equals(df_truth))
Beispiel #7
0
    def test_quant(self):
        df = pd.DataFrame(data={"x": [0, 0.25, 0.5, 0.75, 1]})

        df_t_25 = pd.DataFrame({"q": [0.25]})
        df_t_50 = pd.DataFrame({"q": [0.50]})
        df_t_75 = pd.DataFrame({"q": [0.75]})

        df_c_25 = df >> gr.tf_summarize(q=gr.quant(X.x, p=0.25))
        df_c_50 = df >> gr.tf_summarize(q=gr.quant(X.x, p=0.50))
        df_c_75 = df >> gr.tf_summarize(q=gr.quant(X.x, p=0.75))

        self.assertTrue(df_t_25.equals(df_c_25))
        self.assertTrue(df_t_50.equals(df_c_50))
        self.assertTrue(df_t_75.equals(df_c_75))
Beispiel #8
0
    def test_median(self):
        df = (
            data.df_diamonds
            >> gr.tf_group_by(X.cut)
            >> gr.tf_head(3)
            >> gr.tf_select(X.cut, X.x)
            >> gr.tf_ungroup()
        )
        # straight summarize
        t = df >> gr.tf_summarize(m=gr.median(X.x))
        df_truth = pd.DataFrame({"m": [4.05]})
        self.assertTrue(t.equals(df_truth))

        # grouped summarize
        t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(m=gr.median(X.x))
        df_truth = pd.DataFrame(
            {
                "cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"],
                "m": [6.27, 4.25, 3.95, 3.89, 3.95],
            }
        )
        self.assertTrue(t.equals(df_truth))
        # straight mutate
        t = df >> gr.tf_mutate(m=gr.median(X.x))
        df_truth = df.copy()
        df_truth["m"] = 4.05
        self.assertTrue(t.equals(df_truth))
        # grouped mutate
        # t = df >> group_by(X.cut) >> mutate(m=median(X.x))
        # df_truth['m'] = pd.Series(
        #     [6.27, 6.27, 6.27, 4.25, 4.25, 4.25, 3.95, 3.95, 3.95, 3.89, 3.89, 3.89, 3.95, 3.95, 3.95],
        #     index=t.index)
        # assert t.equals(df_truth)
        # make sure it handles case with even counts properly
        df = (
            data.df_diamonds
            >> gr.tf_group_by(X.cut)
            >> gr.tf_head(2)
            >> gr.tf_select(X.cut, X.x)
        )
        t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(m=gr.median(X.x))
        df_truth = pd.DataFrame(
            {
                "cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"],
                "m": [5.160, 4.195, 3.940, 4.045, 3.945],
            }
        )
        test_vector = abs(t.m - df_truth.m)
        self.assertTrue(all(test_vector < 0.000000001))
Beispiel #9
0
    def test_mean_ci(self):
        # Basic functionality
        y = pd.Series([-1, -1, 0, +1, +1])  # sd == 1
        lo_true = 0 - (-norm.ppf(0.005)) * 1 / np.sqrt(5)
        up_true = 0 + (-norm.ppf(0.005)) * 1 / np.sqrt(5)

        self.assertTrue((lo_true - gr.mean_lo(y, alpha=0.005)) < 1e-6)
        self.assertTrue((up_true - gr.mean_up(y, alpha=0.005)) < 1e-6)

        # Grouped functionality
        df = (gr.df_grid(
            y=[-1, -1, 0, +1, +1],
            x=[0, 1],
        ) >> gr.tf_mutate(y=X.y + X.x) >> gr.tf_group_by(X.x) >>
              gr.tf_summarize(
                  mean_lo=gr.mean_lo(X.y),
                  mean_up=gr.mean_up(X.y),
              ))

        self.assertTrue((df[df.x == 0].mean_lo.values[0] - lo_true) < 1e-6)
        self.assertTrue((df[df.x == 0].mean_up.values[0] - up_true) < 1e-6)

        self.assertTrue((df[df.x == 1].mean_lo.values[0] -
                         (lo_true + 1)) < 1e-6)
        self.assertTrue((df[df.x == 1].mean_up.values[0] -
                         (up_true + 1)) < 1e-6)
Beispiel #10
0
 def test_kurt(self):
     df_truth = pd.DataFrame({"m": [2.605643942300021]})
     df_res = (
         data.df_shewhart
         >> gr.tf_summarize(m=gr.kurt(X.tensile_strength))
     )
     self.assertTrue(df_truth.equals(df_res))
Beispiel #11
0
 def test_skew(self):
     df_truth = pd.DataFrame({"m": [0.09984760044443139]})
     df_res = (
         data.df_shewhart
         >> gr.tf_summarize(m=gr.skew(X.tensile_strength))
     )
     self.assertTrue(df_truth.equals(df_res))
Beispiel #12
0
    def test_prediction_intervals(self):
        ## Correct indexes
        # Example 5.11, Hahn and Meeker
        idx = gr.pint_up_index(100, 59, 30, 0.05)
        self.assertTrue(idx == 64)
        # Example 5.12, Hahn and Meeker
        idx = gr.pint_lo_index(100, 59, 30, 0.05)
        self.assertTrue(idx == 37)

        ## Test functionality
        df_res = (data.df_shewhart >> gr.tf_summarize(
            pi_lo=gr.pint_lo(X.tensile_strength, alpha=0.10 / 2),
            pi_up=gr.pint_up(X.tensile_strength, alpha=0.10 / 2),
        ))
        # Raises assertion
        with self.assertRaises(ValueError):
            df_res = (data.df_shewhart >> gr.tf_summarize(
                pi_lo=gr.pint_lo(X.tensile_strength),
                pi_up=gr.pint_up(X.tensile_strength),
            ))
Beispiel #13
0
 def test_max(self):
     df = data.df_diamonds >> gr.tf_select(X.cut, X.x) >> gr.tf_head(5)
     # straight summarize
     t = df >> gr.tf_summarize(m=gr.max(X.x))
     df_truth = pd.DataFrame({"m": [4.34]})
     self.assertTrue(t.equals(df_truth))
     # grouped summarize
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(m=gr.max(X.x))
     df_truth = pd.DataFrame(
         {"cut": ["Good", "Ideal", "Premium"], "m": [4.34, 3.95, 4.20]}
     )
     self.assertTrue(t.equals(df_truth))
     # straight mutate
     t = df >> gr.tf_mutate(m=gr.max(X.x))
     df_truth = df.copy()
     df_truth["m"] = 4.34
     self.assertTrue(t.equals(df_truth))
     # grouped mutate
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_mutate(m=gr.max(X.x))
     df_truth["m"] = pd.Series([3.95, 4.20, 4.34, 4.20, 4.34])
     self.assertTrue(t.sort_index().equals(df_truth))
Beispiel #14
0
 def test_IQR(self):
     df = data.df_diamonds >> gr.tf_select(X.cut, X.x) >> gr.tf_head(5)
     # straight summarize
     t = df >> gr.tf_summarize(i=gr.IQR(X.x))
     df_truth = pd.DataFrame({"i": [0.25]})
     self.assertTrue(t.equals(df_truth))
     # grouped summarize
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_summarize(i=gr.IQR(X.x))
     df_truth = pd.DataFrame(
         {"cut": ["Good", "Ideal", "Premium"], "i": [0.145, 0.000, 0.155]}
     )
     test_vector = abs(t.i - df_truth.i)
     assert all(test_vector < 0.000000001)
     # straight mutate
     t = df >> gr.tf_mutate(i=gr.IQR(X.x))
     df_truth = df.copy()
     df_truth["i"] = 0.25
     self.assertTrue(t.equals(df_truth))
     # grouped mutate
     t = df >> gr.tf_group_by(X.cut) >> gr.tf_mutate(i=gr.IQR(X.x))
     df_truth["i"] = pd.Series([0.000, 0.155, 0.145, 0.155, 0.145])
     test_vector = abs(t.i - df_truth.i)
     self.assertTrue(all(test_vector < 0.000000001))
Beispiel #15
0
    def test_summarize(self):
        p = pd.DataFrame({
            "price_mean": [data.df_diamonds.price.mean()],
            "price_std": [data.df_diamonds.price.std()],
        })
        self.assertTrue(
            p.equals(data.df_diamonds >> gr.tf_summarize(
                price_mean=X.price.mean(), price_std=X.price.std())))

        pcut = pd.DataFrame(
            {"cut": ["Fair", "Good", "Ideal", "Premium", "Very Good"]})
        pcut["price_mean"] = [
            data.df_diamonds[data.df_diamonds.cut == c].price.mean()
            for c in pcut.cut.values
        ]
        pcut["price_std"] = [
            data.df_diamonds[data.df_diamonds.cut == c].price.std()
            for c in pcut.cut.values
        ]
        self.assertTrue(
            pcut.equals(
                data.df_diamonds >> gr.tf_group_by("cut") >> gr.tf_summarize(
                    price_mean=X.price.mean(), price_std=X.price.std())))
Beispiel #16
0
 def test_n_distinct(self):
     df = pd.DataFrame({
         "col_1": ["a", "a", "a", "b", "b", "b", "c", "c"],
         "col_2": [1, 1, 1, 2, 3, 3, 4, 5],
     })
     # straight summarize
     t = df >> gr.tf_summarize(n=gr.n_distinct(X.col_2))
     df_truth = pd.DataFrame({"n": [5]})
     self.assertTrue(t.equals(df_truth))
     # grouped summarize
     t = df >> gr.tf_group_by(
         X.col_1) >> gr.tf_summarize(n=gr.n_distinct(X.col_2))
     df_truth = pd.DataFrame({"col_1": ["a", "b", "c"], "n": [1, 2, 2]})
     self.assertTrue(t.equals(df_truth))
     # straight mutate
     t = df >> gr.tf_mutate(n=gr.n_distinct(X.col_2))
     df_truth = df.copy()
     df_truth["n"] = 5
     self.assertTrue(t.equals(df_truth))
     # grouped mutate
     t = df >> gr.tf_group_by(
         X.col_1) >> gr.tf_mutate(n=gr.n_distinct(X.col_2))
     df_truth["n"] = pd.Series([1, 1, 1, 2, 2, 2, 2, 2])
     self.assertTrue(t.equals(df_truth))
Beispiel #17
0
    def test_desc(self):
        df = data.df_diamonds >> gr.tf_select(X.cut, X.x) >> gr.tf_head(10)
        t = df >> gr.tf_summarize(last=gr.nth(
            X.x, -1, order_by=[gr.desc(X.cut), gr.desc(X.x)]))

        series_num = pd.Series([4, 1, 3, 2])
        series_bool = pd.Series([True, False, True, False])
        series_str = pd.Series(["d", "a", "c", "b"])

        num_truth = series_num.rank(method="min", ascending=False)
        bool_truth = series_bool.rank(method="min", ascending=False)
        str_truth = series_str.rank(method="min", ascending=False)

        self.assertTrue(gr.desc(series_num).equals(num_truth))
        self.assertTrue(gr.desc(series_bool).equals(bool_truth))
        self.assertTrue(gr.desc(series_str).equals(str_truth))
Beispiel #18
0
    def test_tran_reweight(self):
        """Test the functionality of tran_reweight()

        """
        ## Correctness
        # Choose scale based on Owen (2013) Exercise 9.7
        md_new = (self.md >> gr.cp_marginals(
            x=dict(dist="norm", loc=0, scale=sqrt(4 / 5))))

        df_base = (self.md >> gr.ev_sample(n=500, df_det="nom", seed=101))

        df = (df_base >> gr.tf_reweight(md_base=self.md, md_new=md_new) >>
              gr.tf_summarize(
                  mu=gr.mean(DF.y * DF.weight),
                  se=gr.sd(DF.y * DF.weight) / gr.sqrt(gr.n(DF.weight)),
                  se_orig=gr.sd(DF.y) / gr.sqrt(gr.n(DF.weight)),
              ))
        mu = df.mu[0]
        se = df.se[0]
        se_orig = df.se_orig[0]

        self.assertTrue(mu - se * 2 < 0 and 0 < mu + se * 2)

        ## Optimized IS should be more precise than ordinary monte carlo
        # print("se_orig = {0:4.3f}".format(se_orig))
        # print("se      = {0:4.3f}".format(se))
        self.assertTrue(se < se_orig)

        ## Invariants
        # Missing input in data
        with self.assertRaises(ValueError):
            gr.tran_reweight(df_base[["y"]], md_base=self.md, md_new=self.md)
        # Input mismatch
        with self.assertRaises(ValueError):
            gr.tran_reweight(df_base, md_base=self.md, md_new=gr.Model())
        # Weights collision
        with self.assertRaises(ValueError):
            gr.tran_reweight(df_base >> gr.tf_mutate(weight=0),
                             md_base=self.md,
                             md_new=self.md)
Beispiel #19
0
    def test_nls(self):
        ## Ground-truth model
        c_true = 2
        a_true = 1

        md_true = (gr.Model() >> gr.cp_function(
            fun=lambda x: a_true * np.exp(x[0] * c_true) + x[1],
            var=["x", "epsilon"],
            out=["y"],
        ) >> gr.cp_marginals(epsilon={
            "dist": "norm",
            "loc": 0,
            "scale": 0.5
        }) >> gr.cp_copula_independence())
        df_data = md_true >> gr.ev_sample(
            n=5, seed=101, df_det=gr.df_make(x=[0, 1, 2, 3, 4]))

        ## Model to fit
        md_param = (gr.Model() >> gr.cp_function(
            fun=lambda x: x[2] * np.exp(x[0] * x[1]),
            var=["x", "c", "a"],
            out=["y"]) >> gr.cp_bounds(c=[0, 4], a=[0.1, 2.0]))

        ## Fit the model
        md_fit = df_data >> gr.ft_nls(
            md=md_param,
            verbose=False,
            uq_method="linpool",
        )

        ## Unidentifiable model throws warning
        # -------------------------
        md_unidet = (gr.Model() >> gr.cp_function(
            fun=lambda x: x[2] / x[3] * np.exp(x[0] * x[1]),
            var=["x", "c", "a", "z"],
            out=["y"],
        ) >> gr.cp_bounds(c=[0, 4], a=[0.1, 2.0], z=[0, 1]))
        with self.assertWarns(RuntimeWarning):
            gr.fit_nls(
                df_data,
                md=md_unidet,
                uq_method="linpool",
            )

        ## True parameters in wide confidence region
        # -------------------------
        alpha = 1e-3
        self.assertTrue(
            (md_fit.density.marginals["c"].q(alpha / 2) <= c_true)
            and (c_true <= md_fit.density.marginals["c"].q(1 - alpha / 2)))

        self.assertTrue(
            (md_fit.density.marginals["a"].q(alpha / 2) <= a_true)
            and (a_true <= md_fit.density.marginals["a"].q(1 - alpha / 2)))

        ## Model with fixed parameter
        # -------------------------
        md_fixed = (gr.Model() >> gr.cp_function(
            fun=lambda x: x[2] * np.exp(x[0] * x[1]),
            var=["x", "c", "a"],
            out=["y"]) >> gr.cp_bounds(c=[0, 4], a=[1, 1]))
        md_fit_fixed = df_data >> gr.ft_nls(
            md=md_fixed, verbose=False, uq_method="linpool")

        # Test that fixed model can evaluate successfully
        gr.eval_sample(md_fit_fixed, n=1, df_det="nom")

        ## Trajectory model
        # -------------------------
        md_base = models.make_trajectory_linear()
        md_fit = data.df_trajectory_windowed >> gr.ft_nls(
            md=md_base, method="SLSQP", tol=1e-3)
        df_tmp = md_fit >> gr.ev_nominal(df_det="nom")

        ## Select output for fitting
        # -------------------------
        # Split model has inconsistent "true" parameter value
        md_split = (gr.Model("Split") >> gr.cp_vec_function(
            fun=lambda df: gr.df_make(
                f=1 * df.c * df.x,
                g=2 * df.c * df.x,
            ),
            var=["c", "x"],
            out=["f", "g"],
        ) >> gr.cp_bounds(
            x=(-1, +1),
            c=(-1, +1),
        ))

        df_split = (gr.df_make(x=gr.linspace(-1, +1, 100)) >> gr.tf_mutate(
            f=X.x, g=X.x))

        # Fitting both outputs: cannot achieve mse ~= 0
        df_both = (df_split >> gr.ft_nls(md_split, out=["f", "g"]) >>
                   gr.ev_df(df_split >> gr.tf_rename(f_t=X.f, g_t=X.g)) >>
                   gr.tf_summarize(
                       mse_f=gr.mse(X.f, X.f_t),
                       mse_g=gr.mse(X.g, X.g_t),
                   ))
        self.assertTrue(df_both.mse_f[0] > 0)
        self.assertTrue(df_both.mse_g[0] > 0)

        # Fitting "f" only
        df_f = (df_split >> gr.ft_nls(md_split, out=["f"]) >>
                gr.ev_df(df_split >> gr.tf_rename(f_t=X.f, g_t=X.g)) >>
                gr.tf_summarize(
                    mse_f=gr.mse(X.f, X.f_t),
                    mse_g=gr.mse(X.g, X.g_t),
                ))
        self.assertTrue(df_f.mse_f[0] < 1e-16)
        self.assertTrue(df_f.mse_g[0] > 0)

        # Fitting "g" only
        df_g = (df_split >> gr.ft_nls(md_split, out=["g"]) >>
                gr.ev_df(df_split >> gr.tf_rename(f_t=X.f, g_t=X.g)) >>
                gr.tf_summarize(
                    mse_f=gr.mse(X.f, X.f_t),
                    mse_g=gr.mse(X.g, X.g_t),
                ))
        self.assertTrue(df_g.mse_f[0] > 0)
        self.assertTrue(df_g.mse_g[0] < 1e-16)