예제 #1
0
파일: simple.py 프로젝트: ntardiff/PyDDM
# Create a simple model with constant drift, noise, and bounds.
from ddm import Model
from ddm.models import DriftConstant, NoiseConstant, BoundConstant, OverlayNonDecision, ICPointSourceCenter
from ddm.functions import fit_adjust_model, display_model

model = Model(name='Simple model',
              drift=DriftConstant(drift=2.2),
              noise=NoiseConstant(noise=1.5),
              bound=BoundConstant(B=1.1),
              overlay=OverlayNonDecision(nondectime=.1),
              dx=.001, dt=.01, T_dur=2)

# Solve the model, i.e. simulate the differential equations to
# generate a probability distribution solution.
display_model(model)
sol = model.solve()

# Now, sample from the model solution to create a new generated
# sample.
samp = sol.resample(1000)

# Fit a model identical to the one described above on the newly
# generated data so show that parameters can be recovered.
from ddm import Fittable, Fitted
from ddm.models import LossRobustBIC
from ddm.functions import fit_adjust_model
model_fit = Model(name='Simple model (fitted)',
                  drift=DriftConstant(drift=Fittable(minval=0, maxval=4)),
                  noise=NoiseConstant(noise=Fittable(minval=.5, maxval=4)),
                  bound=BoundConstant(B=1.1),
예제 #2
0
    # resulting distribution of response times by
    # `nondectime` seconds.
    overlay=OverlayChain(overlays=[
        OverlayNonDecision(nondectime=Fittable(minval=0, maxval=.4)),
        OverlayPoissonMixture(pmixturecoef=.02, rate=1)
    ]),
    dx=.001,
    dt=.01,
    T_dur=2)

# Fitting this will also be fast because PyDDM can automatically
# determine that DriftCoherence will allow an analytical solution.
fit_model_rs = fit_adjust_model(sample=roitman_sample,
                                model=model_rs,
                                verbose=False)
display_model(fit_model_rs)
fit_model_rs.parameters()

# Plot the model fit to the PDFs and save the file.
import ddm.plot
import matplotlib.pyplot as plt

ddm.plot.plot_fit_diagnostics(model=fit_model_rs, sample=roitman_sample)
plt.savefig("roitman-fit.png")
plt.show()

# To get an intuition for how parameters affect the fit, play with the
# parameters and task conditions in a GUI.
ddm.plot.model_gui(model=fit_model_rs, sample=roitman_sample)

# Let's try to improve the model fit.
예제 #3
0
### Fit the model to the dataset to find parameters

# Use the "differential_evolution" fitting method (default, recommanded fitting method)
fit_model_foodc = fit_adjust_model(sample=foodc_sample,
                                   model=model_foodc,
                                   method='differential_evolution')

# Use the "simple" fitting method (much faster)
# fit_model_foodc = fit_adjust_model(sample = foodc_sample, model = model_foodc, method = 'simple')

# To note, In documentation the key word "method" is documented as "fitting_method",
# which is actually invalid now.

# Display the fitting outcome (parameters)
display_model(fit_model_foodc)

### Plot
import ddm.plot
# import matplotlib.pyplot as plt
ddm.plot.plot_fit_diagnostics(model=fit_model_foodc,
                              sample=foodc_sample,
                              data_dt=.01)
plt.savefig("./foodc_PyDDM1.png")
# plt.savefig("./foodc_PyDDM1.png", bbox_inches='tight')
plt.show()

# At the moment the plot is incorrect

# The warning information from execution:
# /opt/anaconda3/lib/python3.7/site-packages/ddm/plot.py:232: