Skip to main content
Ctrl+K

pypillometry

  • Getting started
  • User guide
  • Tutorials
  • API reference
  • Experimental features
  • Development
  • GitHub
  • PyPI
  • Getting started
  • User guide
  • Tutorials
  • API reference
  • Experimental features
  • Development
  • GitHub
  • PyPI

Section Navigation

  • Data classes
    • EyeData
    • EyeDataDict
    • MaskPolicy
    • HeadMountedEyeData
    • SceneNamespace
    • keephistory
    • QualityReport
    • QualityReports
    • QualityMetric
    • Table
    • RecordDict
  • Pupil methods (d.pupil)
    • PupilNamespace
  • Gaze methods (d.gaze)
    • GazeNamespace
  • Pipelines
    • crop
    • downsample
    • scale
    • unscale
    • merge_eyes
    • reset_time
    • mask_intervals
    • mask_signal
    • mask_islands
    • interpolate_intervals
    • exclude_intervals
    • keep_intervals
    • remove_intervals
    • merge_masks
    • clear_layer
    • set_blinks
    • set_events
    • add_events
    • set_experimental_setup
    • drop_data
    • rename_variable
    • copy_variable
    • rename_eye
    • copy_eye
    • drop_original
    • fill_time_discontinuities
    • Step
    • Pipeline
  • Events and intervals
    • Events
    • Epochs
    • Intervals
    • ClockSync
    • concat_intervals
    • sync_clocks
  • Segmented data
    • SegmentedEyeData
    • concat_segments
    • group_segments
    • SegmentedPupilNamespace
    • SegmentedGazeNamespace
  • Plotting (d.plot)
  • Reading and writing data
    • read_eyelink
    • read_tobii_prolab
    • read_gazepoint
    • read_file
    • write_file
    • download
    • fetch_url
    • local_copy
    • get_osf_project_files
    • osf_authenticate
    • get_figshare_files
    • fetch_figshare_file
    • figshare_session
    • list_datasets
    • get
    • default_cache_dir
    • make_manifest
    • read_manifest
    • Dataset
    • PreprocessedDataset
    • Exclude
    • RobisonBrewer2022
    • RLMW
    • get_available_datasets
    • get_example_data
    • get_rlmw_002
    • get_rlmw_002_short
    • get_rlmw_010_edf
    • get_nback_001
    • get_robison_pxb
    • get_robison_pvt
    • get_robison_cd
  • Signal processing
    • butter_lowpass
    • butter_lowpass_filter
    • lowpass_filter_iterative
    • smooth_window
    • downsample
    • zscale
    • bspline
    • baseline_envelope
    • baseline_envelope_iter_bspline
    • baseline_pupil_model
    • velocity_savgol
    • detect_blinks
    • detect_partial_blinks
    • detect_transients
    • detect_transients_excess
    • excess_flank
    • find_islands
    • detect_comb
    • local_level
    • flank_run
    • blink_onsets_mahot
    • interpolate_blinks_mahot
    • interpolate_blinks_kalman
    • blink_stretches
    • transplant_blinks
    • transplant_error
    • blink_cores
    • blink_donors
    • extract_blink_artifacts
    • blink_artifact_profile
    • shrink_blink_artifacts
    • clean_stretches
    • place_blink_artifacts
    • insert_blink_artifacts
    • BlinkTransplant
    • tune_blinks_mahot
    • transplant_error_mahot
    • tune_blinks_kalman
    • transplant_error_kalman
    • tune_post_margins
    • BlinkTuneResult
    • PostMarginResult
    • pupil_kernel
    • pupil_kernel_t
    • pupil_get_max_duration
    • plot_prf
    • pupil_build_design_matrix
    • pupil_response
    • pupil_response_coverage
    • pupilresponse_nnls
    • pupil_signal_quality
    • pupil_eye_offset
  • Geometry and gaze
    • ExperimentalSetup
    • SpatialCalibration
    • ForeshorteningCalibration
    • ROI
    • CircularROI
    • RectangularROI
  • Timescale model (experimental)
    • TimescaleModel
    • TimescaleGroup
    • TimescalePlots
    • TimescaleGroupPlots
    • block_mean
    • coarsen
    • semivariogram
    • plot_variogram
    • spectrum
    • plot_spectrum
    • Variogram
    • Spectrum
    • TimescaleBank
    • GaussianPrior
    • BankFit
    • GroupFit
    • VariogramCheck
    • GaussMarkovModel
    • Matern
    • OU
    • Constant
    • LGSSM
    • fit_bank
    • general_prior
    • reference_prior
    • fit_group
    • blocked_cv
    • variogram_check
    • kalman_filter
    • kalman_loglik
    • rts_smoother
    • forecast_errors
    • simulate
  • Simulated data: pp.sim
    • Simulation
    • SimEyeData
    • SimPlotNamespace
    • Task
    • parse_dist
    • pvt
    • sart
    • ftrsgt
    • nback
    • TimescalePupil
    • Fixations
    • Foreshortening
    • Units
    • Blinks
    • WhiteNoise
    • TrackerLoss
    • Comb
    • blink_occlusion
    • parse_rate
  • Units
    • Quantity
    • Unit
    • parse_time
    • parse_distance
    • parse_angle
  • Viewer, settings and logging
    • view
    • tweak
    • tweak_blink_interpolation
    • set_default_inplace
    • get_default_inplace
    • logging_set_level
    • logging_get_level
    • logging_disable
    • logging_enable
    • loglevel
    • nologging
    • initialize_logging
  • API reference
  • Signal processing
  • tune_blinks_mahot

tune_blinks_mahot#

pypillometry.signal.tune_blinks_mahot(train, test=None, refine=None, start=None, bounds=None, fixed=None, n_init=None, n_grid=9, sweeps=3, tol=0.01, max_duration=None, seed=None)[source]#

Tune the parameters of the Mahot interpolation on transplanted blinks.

Searches for the parameters of interpolate_blinks_mahot() with the smallest error on transplanted blinks (see transplant_error_mahot()). The error is not a smooth function of the parameters, so they are searched without derivatives: from the starting parameters, each parameter is tried at n_grid values around its current value, and the one change that reduces the error most is made. This is repeated until no change reduces the error by more than tol, in sweeps rounds with finer and finer grids (the first one covers the whole search range). Different parameters can give nearly the same error (e.g., a lower threshold or a larger margin); with tol, the search stays close to the starting parameters then. Without starting parameters (or with n_init), the search starts from the best of n_init parameter sets that cover the search range evenly (a Sobol sequence).

The search needs many evaluations, so it can be run on a few blinks (train, e.g. 10 different blinks, each transplanted a few times). With few blinks, the result depends on which blinks they are, so the search can be run several times on different blinks (train as a list of such sets). The results (and the starting parameters) are compared on further transplanted blinks (refine, or else on all sets of train), and the best one is refined on its own blinks and refine with one more round on the finest grid.

With many parameters and few blinks, the tuned parameters can fit the blinks they were tuned on better than other blinks. If transplanted blinks that were not used for tuning are given (test), the tuned parameters are only used if they are better on those than the starting parameters.

Parameters:
  • train (BlinkTransplant, list of BlinkTransplant, or list of lists) – signal(s) with transplanted blinks to search the parameters on (see transplant_blinks()); a list of lists (or of lists and BlinkTransplant) is several sets, with one search on each

  • test (BlinkTransplant or list of BlinkTransplant, optional) – signal(s) with other transplanted blinks, to check the tuned parameters (e.g., using other blinks of the same recording, see cores of transplant_blinks())

  • refine (BlinkTransplant or list of BlinkTransplant, optional) – signal(s) with further transplanted blinks, to choose the best of the searches and refine it on (together with its train set)

  • start (dict, optional) – starting parameters: smooth_winsize, rate_onset, rate_offset, margin and blinkwindow (in samples, and units per sample)

  • bounds (dict, optional) – search range (lower, upper) for "smooth_winsize", "rate_onset", "rate_offset" (absolute values), "margin_before", "margin_after" or "blinkwindow". Default: from the data. The windows of the transplanted blinks (before, after) limit the margins (up to the window), the smoothing window (3 samples to half of before) and blinkwindow (up to the whole window); the rates are between a tenth of the noise of the clean signal (the robust standard deviation of its sample-to-sample changes) and the fastest changes in the artifacts.

  • fixed (dict, optional) – parameters that are not tuned, with their values (e.g., {"blinkwindow": 250}); margin as (before, after)

  • n_init (int, optional) – number of parameter sets (rounded up to a power of 2) to choose the start of the search from, in addition to start; default: 0 with starting parameters, otherwise 64

  • n_grid (int) – number of values per parameter and round

  • sweeps (int) – number of rounds of the search

  • tol (float) – minimum relative reduction of the error for changing a parameter

  • max_duration (int, optional) – max_duration of the interpolation (samples; not tuned)

  • seed (int or np.random.Generator, optional) – seed of the random numbers (only used with n_init)

Return type:

BlinkTuneResult

Returns:

the tuned parameters (result.params can be passed to interpolate_blinks_mahot()), their errors and all evaluated parameters

Examples

>>> from pypillometry.signal import transplant_blinks, interpolate_blinks_mahot
>>> rng = np.random.default_rng(1)
>>> y = 1000 + np.cumsum(rng.normal(0, 1, 20000))
>>> for s in range(1000, 20000, 2000):       # blinks
...     y[s-20:s] -= np.linspace(0, 500, 20)
...     y[s+50:s+90] -= np.linspace(500, 0, 40)
...     y[s:s+50] = np.nan
>>> tr = transplant_blinks(y, window=(100, 150), pad=50, seed=1)
>>> res = tune_blinks_mahot(tr, n_init=16, sweeps=1, seed=1)
>>> filled, interpolated, _ = interpolate_blinks_mahot(tr.signal, tr.blinks, **res.params)

previous

BlinkTransplant

next

transplant_error_mahot

On this page
  • tune_blinks_mahot()
Edit on GitHub
Show Source

© Copyright 2020-2026, Matthias Mittner.

Created using Sphinx 9.2.0.

Built with the PyData Sphinx Theme 0.24.0.