コード例 #1
0
    def setUp(self):
        self.basic = ddm.Model(dx=.005,
                               dt=.01,
                               T_dur=2,
                               drift=ddm.DriftConstant(drift=.4),
                               noise=ddm.NoiseConstant(noise=1),
                               bound=ddm.BoundConstant(B=1))

        class NoiseCond(ddm.Noise):
            name = "Noise with a condition"
            required_conditions = ['cond']
            required_parameters = []

            def get_noise(self, conditions, **kwargs):
                return conditions["cond"]

        self.withcond = ddm.Model(noise=NoiseCond())

        class FancyBounds(ddm.Bound):
            name = "Increasing/decreasing bounds"
            required_conditions = []
            required_parameters = []

            def get_bound(self, conditions, t, **kwargs):
                if t <= 1:
                    return 1 + t
                if t > 1:
                    return 2 / t

        self.bound = ddm.Model(bound=FancyBounds())
コード例 #2
0
 def test_ICPoint_collapsing_bounds(self):
     m = ddm.Model(name='ICPoint_BCollapsingLin_test',
                   drift=ddm.DriftConstant(drift=2),
                   noise=ddm.NoiseConstant(noise=1.5),
                   bound=ddm.BoundCollapsingLinear(B=1, t=0.5),
                   IC=ddm.ICPoint(x0=-.25))
     _modeltest_numerical_vs_analytical(m,
                                        method="implicit",
                                        max_diff=.3,
                                        mean_diff=.2,
                                        prob_diff=.05)
コード例 #3
0
 def test_ICPoint(self):
     """Arbitrary pointwise initial condition"""
     m = ddm.Model(name='ICPoint_test',
                   drift=ddm.DriftConstant(drift=2),
                   noise=ddm.NoiseConstant(noise=1.5),
                   bound=ddm.BoundConstant(B=1),
                   IC=ddm.ICPoint(x0=-.25))
     _modeltest_numerical_vs_analytical(m,
                                        method="implicit",
                                        max_diff=.3,
                                        mean_diff=.2,
                                        prob_diff=.05)
コード例 #4
0
    def setUp(self):
        self.basic = ddm.Model(dx=.005,
                               dt=.01,
                               T_dur=2,
                               drift=ddm.DriftConstant(drift=.4),
                               noise=ddm.NoiseConstant(noise=1),
                               bound=ddm.BoundConstant(B=1))

        class NoiseCond(ddm.Noise):
            name = "Noise with a condition"
            required_conditions = ['cond']
            required_parameters = []

            def get_noise(self, conditions, **kwargs):
                return conditions["cond"]

        self.withcond = ddm.Model(noise=NoiseCond())
 def __init__(self, ndt='gaussian'):
     overlay = (ddm.OverlayNonDecisionUniform(nondectime=ddm.Fittable(minval=0, maxval=0.5),
                                             halfwidth=ddm.Fittable(minval=0.001, maxval=0.3)) 
                 if ndt=='uniform' else 
                self.OverlayNonDecisionGaussian(nondectime=ddm.Fittable(minval=0, maxval=0.6),
                                                ndsigma=ddm.Fittable(minval=0.001, maxval=0.3)))
                                             
     self.model = ddm.Model(name='5 TTA- and d-dependent drift and bounds and uniformly distributed nondecision time',
                              drift=self.DriftTtaDistance(alpha=ddm.Fittable(minval=0.1, maxval=3),
                                                          beta=ddm.Fittable(minval=0, maxval=1),
                                                          theta=ddm.Fittable(minval=4, maxval=40)),
                              noise=ddm.NoiseConstant(noise=1),
                              bound=self.BoundCollapsingTta(b_0=ddm.Fittable(minval=0.5, maxval=5), 
                                                            k=ddm.Fittable(minval=0.1, maxval=2),
                                                            tta_crit=ddm.Fittable(minval=3, maxval=6)),
                              overlay=overlay,
                              T_dur=self.T_dur)
コード例 #6
0
    def test_double_fit(self):
        """Fit different parameters in the same (or a different) model using a single Fittable object"""
        class NoiseDouble(ddm.Noise):
            name = "time-varying noise"
            required_parameters = ["noise1", "noise2"]

            def get_noise(self, **kwargs):
                if np.random.rand() > .5:
                    return self.noise1
                else:
                    return self.noise2

        class NoiseConstantButNot(ddm.Noise
                                  ):  # To avoid the numerical simulations
            name = "almost noise constant"
            required_parameters = ["noise"]

            def get_noise(self, **kwargs):
                return self.noise

        # Generate data
        m = ddm.Model(name="DDM",
                      drift=ddm.DriftConstant(drift=1),
                      noise=ddm.NoiseConstant(noise=1.7))
        s = m.solve_numerical(
        )  # Solving analytical and then fitting numerical may give a bias
        sample = s.resample(10000)
        mone = ddm.fit_model(
            sample,
            drift=ddm.DriftConstant(drift=1),
            noise=NoiseConstantButNot(noise=ddm.Fittable(minval=.5, maxval=3)))
        sigs = ddm.Fittable(minval=.5, maxval=3)
        msam = ddm.fit_model(sample,
                             drift=ddm.DriftConstant(drift=1),
                             noise=NoiseDouble(noise1=sigs, noise2=sigs))
        assert msam._noisedep.noise1 == msam._noisedep.noise2, "Fitting to be the same failed"
        assert abs(msam._noisedep.noise1 -
                   mone._noisedep.noise) < 0.1 * mone._noisedep.noise