Пример #1
0
    def _mean_regress(self, r, x, y, ox, oy, index, fit, fod, apply_filter):

        if r is None or not isinstance(r, MeanRegressor):
            r = MeanRegressor()

        r.trait_set(xs=x, ys=y, fit=fit)
        if apply_filter:
            r = self._apply_outlier_filter(r, ox, oy, index, fod)
        return r
Пример #2
0
    def _mean_regress(self, r, x, y, ox, oy, index,
                      fit, fod, apply_filter):

        if r is None or not isinstance(r, MeanRegressor):
            r = MeanRegressor()

        r.trait_set(xs=x, ys=y, fit=fit)
        if apply_filter:
            r = self._apply_outlier_filter(r, ox, oy, index, fod)
        return r
Пример #3
0
    def _mean_regressor_factory(self):
        from pychron.core.regression.mean_regressor import MeanRegressor

        xs = self.offset_xs
        reg = MeanRegressor(xs=xs, ys=self.ys,
                            filter_outliers_dict=self.filter_outliers_dict,
                            error_calc_type=self.error_type or 'SEM')
        return reg
Пример #4
0
    def _mean_regress(self, scatter, r, fit):
        if hasattr(scatter, 'yerror'):
            if r is None or not isinstance(r, WeightedMeanRegressor):
                r = WeightedMeanRegressor()
        else:
            if r is None or not isinstance(r, MeanRegressor):
                r = MeanRegressor()

        self._set_regressor(scatter, r)
        r.trait_set(fit=fit, trait_change_notify=False)
        r.calculate()

        self._set_excluded(scatter, r)
        return r
Пример #5
0
    def _mean_regress(self, scatter, r, fit):
        from pychron.core.regression.mean_regressor import MeanRegressor, WeightedMeanRegressor
        if hasattr(scatter, 'yerror') and fit == 'weighted mean':
            if r is None or not isinstance(r, WeightedMeanRegressor):
                r = WeightedMeanRegressor()
        else:
            if r is None or not isinstance(r, MeanRegressor):
                r = MeanRegressor()

        self._set_regressor(scatter, r)
        # r.trait_setq(fit=fit)
        r.calculate()

        self._set_excluded(scatter, r)
        return r
Пример #6
0
 def setUp(self):
     self.reg = MeanRegressor()
Пример #7
0
class TruncateRegressionTest(TestCase):
    def setUp(self):
        self.reg = MeanRegressor()

    def test_pre_truncate(self):
        xs, ys, sol = pre_truncated_data()
        self.reg.trait_set(xs=xs, ys=ys)
        self.solution = sol
        self.reg.trait_set(xs=xs, ys=ys)
        self.reg.set_truncate('x<5')

        self.assertEqual(self.reg.mean, self.solution['pre_mean'])

    def test_post_truncate(self):
        xs, ys, sol = pre_truncated_data()
        self.reg.trait_set(xs=xs, ys=ys)
        self.solution = sol
        self.reg.trait_set(xs=xs, ys=ys)
        self.reg.set_truncate('x>=5')

        self.assertEqual(self.reg.mean, self.solution['post_mean'])
Пример #8
0
    def _test_fired(self):
        import numpy as np

        self.db.connect()
        xbase = np.linspace(430, 580, 150)
        #        ybase = np.zeros(150)
        #        cddybase = np.zeros(150)
        ybase = np.random.random(150)
        cddybase = np.random.random(150) * 0.001

        base = [
            zip(xbase, ybase),
            zip(xbase, ybase),
            zip(xbase, ybase),
            zip(xbase, ybase),
            zip(xbase, cddybase),
        ]

        xsig = np.linspace(20, 420, 410)
        #        y40 = np.ones(410) * 680
        #        y39 = np.ones(410) * 107
        #        y38 = np.zeros(410) * 1.36
        #        y37 = np.zeros(410) * 0.5
        #        y36 = np.ones(410) * 0.001

        y40 = 680 - 0.1 * xsig
        y39 = 107 - 0.1 * xsig
        y38 = np.zeros(410) * 1.36
        y37 = np.zeros(410) * 0.5
        y36 = 1 + 0.1 * xsig

        sig = [
            zip(xsig, y40),
            zip(xsig, y39),
            zip(xsig, y38),
            zip(xsig, y37),
            zip(xsig, y36),
        ]

        regbs = MeanRegressor(xs=xbase, ys=ybase)
        cddregbs = MeanRegressor(xs=xbase, ys=cddybase)
        reg = PolynomialRegressor(xs=xsig, ys=y40, fit='linear')

        reg1 = PolynomialRegressor(xs=xsig, ys=y39, fit='linear')
        reg2 = PolynomialRegressor(xs=xsig, ys=y38, fit='linear')
        reg3 = PolynomialRegressor(xs=xsig, ys=y37, fit='linear')
        reg4 = PolynomialRegressor(xs=xsig, ys=y36, fit='linear')

        keys = [
            ('H1', 'Ar40'),
            ('AX', 'Ar39'),
            ('L1', 'Ar38'),
            ('L2', 'Ar37'),
            ('CDD', 'Ar36'),
        ]

        regresults = (dict(
            Ar40=ufloat(reg.predict(0), reg.predict_error(0)),
            Ar39=ufloat(reg1.predict(0), reg1.predict_error(0)),
            Ar38=ufloat(reg2.predict(0), reg2.predict_error(0)),
            Ar37=ufloat(reg3.predict(0), reg3.predict_error(0)),
            Ar36=ufloat(reg4.predict(0), reg4.predict_error(0)),
        ),
                      dict(Ar40=ufloat(regbs.predict(0),
                                       regbs.predict_error(0)),
                           Ar39=ufloat(regbs.predict(0),
                                       regbs.predict_error(0)),
                           Ar38=ufloat(regbs.predict(0),
                                       regbs.predict_error(0)),
                           Ar37=ufloat(regbs.predict(0),
                                       regbs.predict_error(0)),
                           Ar36=ufloat(cddregbs.predict(0),
                                       cddregbs.predict_error(0))))
        blanks = [
            ufloat(0, 0.1),
            ufloat(0.1, 0.001),
            ufloat(0.01, 0.001),
            ufloat(0.01, 0.001),
            ufloat(0.00001, 0.0001),
        ]
        fits = (dict(
            zip(['Ar40', 'Ar39', 'Ar38', 'Ar37', 'Ar36'],
                ['Linear', 'Linear', 'Linear', 'Linear', 'Linear'])),
                dict(
                    zip(['Ar40', 'Ar39', 'Ar38', 'Ar37', 'Ar36'], [
                        'Average Y', 'Average Y', 'Average Y', 'Average Y',
                        'Average Y'
                    ])))
        mass_spectrometer = 'obama'
        extract_device = 'Laser Furnace'
        extract_value = 10
        position = 1
        duration = 10
        first_stage_delay = 0
        second_stage_delay = 30
        tray = '100-hole'
        runscript_name = 'Foo'
        runscript_text = 'this is a test script'

        self.add_analysis(
            '4318',
            '500',
            '',
            '4318',
            base,
            sig,
            blanks,
            keys,
            regresults,
            fits,
            mass_spectrometer,
            extract_device,
            tray,
            position,
            extract_value,  # power requested
            extract_value,  # power achieved
            duration,  # total extraction
            duration,  # time at extract_value
            first_stage_delay,
            second_stage_delay,
            runscript_name,
            runscript_text,
        )
Пример #9
0
    def regressor(self):
        fit = self.fit
        if fit is None:
            fit = 'linear'
            self.fit = fit

        lfit = fit.lower()
        is_mean = 'average' in lfit
        is_expo = lfit == 'exponential'
        is_poly = not (is_mean or is_expo)

        reg = self._regressor
        if reg is None:
            if is_mean:
                reg = MeanRegressor()
            elif is_expo:
                reg = ExponentialRegressor()
            else:
                reg = PolynomialRegressor()
        elif is_poly and not isinstance(reg, PolynomialRegressor):
            reg = PolynomialRegressor()
        elif is_mean and not isinstance(reg, MeanRegressor):
            reg = MeanRegressor()
        elif is_expo and not isinstance(reg, ExponentialRegressor):
            reg = ExponentialRegressor()

        if is_poly:
            reg.set_degree(fit_to_degree(fit), refresh=False)

        reg.trait_set(xs=self.offset_xs,
                      ys=self.ys,
                      error_calc_type=self.error_type or 'SEM',
                      filter_outliers_dict=self.filter_outliers_dict,
                      tag=self.name)

        if self.truncate:
            reg.set_truncate(self.truncate)
        reg.calculate()

        self._regressor = reg
        return reg
    def _test_fired(self):
        import numpy as np

        self.db.connect()
        xbase = np.linspace(430, 580, 150)
        #        ybase = np.zeros(150)
        #        cddybase = np.zeros(150)
        ybase = np.random.random(150)
        cddybase = np.random.random(150) * 0.001

        base = [zip(xbase, ybase), zip(xbase, ybase), zip(xbase, ybase), zip(xbase, ybase), zip(xbase, cddybase)]

        xsig = np.linspace(20, 420, 410)
        #        y40 = np.ones(410) * 680
        #        y39 = np.ones(410) * 107
        #        y38 = np.zeros(410) * 1.36
        #        y37 = np.zeros(410) * 0.5
        #        y36 = np.ones(410) * 0.001

        y40 = 680 - 0.1 * xsig
        y39 = 107 - 0.1 * xsig
        y38 = np.zeros(410) * 1.36
        y37 = np.zeros(410) * 0.5
        y36 = 1 + 0.1 * xsig

        sig = [zip(xsig, y40), zip(xsig, y39), zip(xsig, y38), zip(xsig, y37), zip(xsig, y36)]

        regbs = MeanRegressor(xs=xbase, ys=ybase)
        cddregbs = MeanRegressor(xs=xbase, ys=cddybase)
        reg = PolynomialRegressor(xs=xsig, ys=y40, fit="linear")

        reg1 = PolynomialRegressor(xs=xsig, ys=y39, fit="linear")
        reg2 = PolynomialRegressor(xs=xsig, ys=y38, fit="linear")
        reg3 = PolynomialRegressor(xs=xsig, ys=y37, fit="linear")
        reg4 = PolynomialRegressor(xs=xsig, ys=y36, fit="linear")

        keys = [("H1", "Ar40"), ("AX", "Ar39"), ("L1", "Ar38"), ("L2", "Ar37"), ("CDD", "Ar36")]

        regresults = (
            dict(
                Ar40=ufloat(reg.predict(0), reg.predict_error(0)),
                Ar39=ufloat(reg1.predict(0), reg1.predict_error(0)),
                Ar38=ufloat(reg2.predict(0), reg2.predict_error(0)),
                Ar37=ufloat(reg3.predict(0), reg3.predict_error(0)),
                Ar36=ufloat(reg4.predict(0), reg4.predict_error(0)),
            ),
            dict(
                Ar40=ufloat(regbs.predict(0), regbs.predict_error(0)),
                Ar39=ufloat(regbs.predict(0), regbs.predict_error(0)),
                Ar38=ufloat(regbs.predict(0), regbs.predict_error(0)),
                Ar37=ufloat(regbs.predict(0), regbs.predict_error(0)),
                Ar36=ufloat(cddregbs.predict(0), cddregbs.predict_error(0)),
            ),
        )
        blanks = [ufloat(0, 0.1), ufloat(0.1, 0.001), ufloat(0.01, 0.001), ufloat(0.01, 0.001), ufloat(0.00001, 0.0001)]
        fits = (
            dict(zip(["Ar40", "Ar39", "Ar38", "Ar37", "Ar36"], ["Linear", "Linear", "Linear", "Linear", "Linear"])),
            dict(
                zip(
                    ["Ar40", "Ar39", "Ar38", "Ar37", "Ar36"],
                    ["Average Y", "Average Y", "Average Y", "Average Y", "Average Y"],
                )
            ),
        )
        mass_spectrometer = "obama"
        extract_device = "Laser Furnace"
        extract_value = 10
        position = 1
        duration = 10
        first_stage_delay = 0
        second_stage_delay = 30
        tray = "100-hole"
        runscript_name = "Foo"
        runscript_text = "this is a test script"

        self.add_analysis(
            "4318",
            "500",
            "",
            "4318",
            base,
            sig,
            blanks,
            keys,
            regresults,
            fits,
            mass_spectrometer,
            extract_device,
            tray,
            position,
            extract_value,  # power requested
            extract_value,  # power achieved
            duration,  # total extraction
            duration,  # time at extract_value
            first_stage_delay,
            second_stage_delay,
            runscript_name,
            runscript_text,
        )
Пример #11
0
 def _mean_regressor_factory(self):
     reg = MeanRegressor(xs=self.xs, ys=self.ys,
                         filter_outliers_dict=self.filter_outliers_dict,
                         error_type=self.error_type)
     return reg
Пример #12
0
    def regressor(self):
        fit = self.fit
        if fit is None:
            fit = 'linear'
            self.fit = fit

        lfit = fit.lower()
        is_mean = 'average' in lfit
        is_expo = lfit == 'exponential'
        is_poly = not (is_mean or is_expo)

        reg = self._regressor
        if reg is None:
            if is_mean:
                reg = MeanRegressor()
            elif is_expo:
                reg = ExponentialRegressor()
            else:
                reg = PolynomialRegressor()
        elif is_poly and not isinstance(reg, PolynomialRegressor):
            reg = PolynomialRegressor()
        elif is_mean and not isinstance(reg, MeanRegressor):
            reg = MeanRegressor()
        elif is_expo and not isinstance(reg, ExponentialRegressor):
            reg = ExponentialRegressor()

        if is_poly:
            reg.set_degree(fit_to_degree(fit), refresh=False)

        reg.trait_set(xs=self.offset_xs, ys=self.ys,
                      error_calc_type=self.error_type or 'SEM',
                      filter_outliers_dict=self.filter_outliers_dict,
                      tag=self.name)

        if self.truncate:
            reg.set_truncate(self.truncate)
        reg.calculate()

        self._regressor = reg
        return reg
Пример #13
0
 def setUp(self):
     self.reg = MeanRegressor()
Пример #14
0
class TruncateRegressionTest(TestCase):
    def setUp(self):
        self.reg = MeanRegressor()

    def test_pre_truncate(self):
        xs, ys, sol = pre_truncated_data()
        self.reg.trait_set(xs=xs, ys=ys)
        self.solution = sol
        self.reg.trait_set(xs=xs, ys=ys)
        self.reg.set_truncate('x<5')

        self.assertEqual(self.reg.mean, self.solution['pre_mean'])

    def test_post_truncate(self):
        xs, ys, sol = pre_truncated_data()
        self.reg.trait_set(xs=xs, ys=ys)
        self.solution = sol
        self.reg.trait_set(xs=xs, ys=ys)
        self.reg.set_truncate('x>=5')

        self.assertEqual(self.reg.mean, self.solution['post_mean'])