Class TAC

Target Achievement Control (TAC) test block.

JSON configuration

Use these block entries inside a pipeline configuration. Input names must match other blocks in that pipeline; device addresses and file paths must match your setup.

JSON configuration:

{
  "TAC": {
    "Type": "TAC",
    "Inputs": [ "Stimulus", "Predictor" ],
    "Params": [ "Stimulus", 2.0, 0.15 ]
  }
}

Params:

IndexDescription
0StimulusBlockName (string) — name of the Stimulus block to bind to.
1DwellTime (double, default 2.0) — required continuous hold duration in seconds.
2SuccessThreshold (double, default 0.2) — maximum L2 distance to count as "in target".

How Type, Inputs and Params work · Block catalogue and parameter reference

Namespace: MOSAIC.Models.Tests
Assembly: MOSAIC.dll
Syntax
public sealed class TAC : BaseBlock, INotifyPropertyChanged, INotifyPropertyChanging, ISubscriber, IPublisher, IBaseBlockProps, IJsonExportable, IDisposable, IAsyncDisposable
Remarks

Reference: Simon et al. 2011 — https://pmc.ncbi.nlm.nih.gov/articles/PMC4232230/.

Overview: Evaluates a user's ability to reach target postures by computing L2 distance between prediction and target on each tick. A DwellDetector tracks whether the distance stays below threshold for the required dwell time. Trial-level and aggregate metrics are managed by TACResults.

Inputs: Requires exactly two upstream connections:

  • A Stimulus block — provides target vectors and FSM state via (string, Vector<double>) tuples.
  • A prediction source (e.g. IncrementalPredictor) — provides Vector<double> predictions.

Results: Trial-level and aggregate metrics are managed by the companion TACResults class, accessible via Results. Use ExportCsv() for full trial-level export.

Stimulus binding: The pipeline builder must call BindStimulus(Stimulus) after all blocks are constructed. Auto-binding is attempted if the sender is a Stimulus instance.

Constructors

TAC(string, double, string, double, double)

Initializes a new TAC block.

Declaration
public TAC(string name, double desiredRate, string stimulusBlockName, double dwellTime = 2, double successThreshold = 0.2)
Parameters
Type Name Description
string name

Display name.

double desiredRate

Processing rate in Hz (typically inherited).

string stimulusBlockName

Name of the Stimulus block to bind to.

double dwellTime

Required continuous hold duration in seconds.

double successThreshold

Maximum L2 distance for target achievement.

Fields

_clock

High-resolution stopwatch for trial timing.

Declaration
private readonly Stopwatch _clock
Field Value
Type Description
Stopwatch

_currentOvershootCount

Overshoot count for the current trial.

Declaration
[ObservableProperty]
private int _currentOvershootCount
Field Value
Type Description
int

_currentTaskName

Name of the current task (from the Stimulus).

Declaration
[ObservableProperty]
private string _currentTaskName
Field Value
Type Description
string

_currentTrialTaskName

Task name of the current trial.

Declaration
private string _currentTrialTaskName
Field Value
Type Description
string

_distanceToTarget

Current L2 distance between prediction and target.

Declaration
[ObservableProperty]
private double _distanceToTarget
Field Value
Type Description
double

_dwell

Dwell-time state machine tracking hold duration and overshoots.

Declaration
private readonly DwellDetector _dwell
Field Value
Type Description
DwellDetector

_evaluateCount

Total number of Evaluate() calls (for diagnostic throttling).

Declaration
private int _evaluateCount
Field Value
Type Description
int

_holdProgress

Hold progress towards dwell time [0, 1].

Declaration
[ObservableProperty]
private double _holdProgress
Field Value
Type Description
double

_isTrying

Whether the user is actively attempting to reach the target.

Declaration
[ObservableProperty]
private bool _isTrying
Field Value
Type Description
bool

_lastReceivedState

Last FSM state received from the data stream.

Declaration
private string _lastReceivedState
Field Value
Type Description
string

_lastStimulusState

Previous Stimulus FSM state (for transition detection).

Declaration
private string _lastStimulusState
Field Value
Type Description
string

_prediction

Current prediction vector from the upstream predictor.

Declaration
private Vector<double>? _prediction
Field Value
Type Description
Vector<double>

_prevPrediction

Previous prediction vector (for path length computation).

Declaration
private Vector<double>? _prevPrediction
Field Value
Type Description
Vector<double>

_stimulus

Bound Stimulus block reference (set via BindStimulus(Stimulus)).

Declaration
private Stimulus? _stimulus
Field Value
Type Description
Stimulus

_stimulusBlockName

Name of the Stimulus block to bind to.

Declaration
private readonly string _stimulusBlockName
Field Value
Type Description
string

_stimulusState

Current Stimulus FSM state.

Declaration
[ObservableProperty]
private string _stimulusState
Field Value
Type Description
string

_target

Current target vector from the Stimulus.

Declaration
private Vector<double>? _target
Field Value
Type Description
Vector<double>

_timeInTarget

Continuous time spent within the success threshold.

Declaration
[ObservableProperty]
private double _timeInTarget
Field Value
Type Description
double

_trialActive

Whether a trial is currently active.

Declaration
private bool _trialActive
Field Value
Type Description
bool

_trialElapsed

Elapsed time since the current trial started.

Declaration
[ObservableProperty]
private double _trialElapsed
Field Value
Type Description
double

_trialInitialDistance

Initial L2 distance at trial start.

Declaration
private double _trialInitialDistance
Field Value
Type Description
double

_trialPathLength

Cumulative path length for the current trial.

Declaration
private double _trialPathLength
Field Value
Type Description
double

_trialStartTime

Timestamp when the current trial started.

Declaration
private double _trialStartTime
Field Value
Type Description
double

_viz

Visualization bundle. Set by the ViewModel.

Declaration
private BlockVisualization? _viz
Field Value
Type Description
BlockVisualization

Properties

CurrentOvershootCount

Overshoot count for the current trial.

Declaration
[ExcludeFromCodeCoverage]
public int CurrentOvershootCount { get; set; }
Property Value
Type Description
int

CurrentTaskName

Name of the current task (from the Stimulus).

Declaration
[ExcludeFromCodeCoverage]
public string CurrentTaskName { get; set; }
Property Value
Type Description
string

DistanceToTarget

Current L2 distance between prediction and target.

Declaration
[ExcludeFromCodeCoverage]
public double DistanceToTarget { get; set; }
Property Value
Type Description
double

DwellTime

Required continuous hold duration in seconds.

Declaration
public double DwellTime { get; }
Property Value
Type Description
double

HoldProgress

Hold progress towards dwell time [0, 1].

Declaration
[ExcludeFromCodeCoverage]
public double HoldProgress { get; set; }
Property Value
Type Description
double

IsTrying

Whether the user is actively attempting to reach the target.

Declaration
[ExcludeFromCodeCoverage]
public bool IsTrying { get; set; }
Property Value
Type Description
bool

JsonTypeName

Block type identifier for JSON serialization. Override for a custom name.

Declaration
protected override string JsonTypeName { get; }
Property Value
Type Description
string
Overrides
BaseBlock.JsonTypeName

MaxInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MaxInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MaxInputs

MinInputs

Needs exactly two inputs (e.g. a data stream + a Trigger/TriggerBuffer).

Declaration
public override int MinInputs { get; }
Property Value
Type Description
int
Overrides
BaseBlock.MinInputs

Results

Trial-level and aggregate metrics. Bind in the ViewModel for UI display and use ExportCsv() for export.

Declaration
public TACResults Results { get; }
Property Value
Type Description
TACResults

StimulusBlockName

Name of the Stimulus block to bind to (for pipeline builder).

Declaration
public string StimulusBlockName { get; }
Property Value
Type Description
string

StimulusState

Current Stimulus FSM state.

Declaration
[ExcludeFromCodeCoverage]
public string StimulusState { get; set; }
Property Value
Type Description
string

SuccessThreshold

Maximum L2 distance to count as "in target".

Declaration
public double SuccessThreshold { get; }
Property Value
Type Description
double

TimeInTarget

Continuous time spent within the success threshold.

Declaration
[ExcludeFromCodeCoverage]
public double TimeInTarget { get; set; }
Property Value
Type Description
double

TrialElapsed

Elapsed time since the current trial started.

Declaration
[ExcludeFromCodeCoverage]
public double TrialElapsed { get; set; }
Property Value
Type Description
double

Visualization

This block's visualization, or null when it has none.

Declaration
protected override BlockVisualization? Visualization { get; }
Property Value
Type Description
BlockVisualization
Overrides
BaseBlock.Visualization
Remarks

Blocks own their scope as a public Viz property rather than inheriting one, so the base class has no way to reach it. Overriding this is what lets the rate below be wired up automatically. With correct publication metadata, the bundle derives the time axis for one vector per publication or fixed-size contiguous sample packets from the feed shape.

When a plot needs a rate that publication frequency and feed shape cannot express (for example, variable-sized packets or overlapping windows), declare it with Viz.UpdateSignalRate. An explicit declaration wins over the derived rate. A block with several bundles must configure each one; this hook exposes only one bundle.

Viz

Live plot for this block. Assigned by the ViewModel, which owns the scope.

Declaration
public BlockVisualization? Viz { get; set; }
Property Value
Type Description
BlockVisualization
Remarks

Setting this re-pushes the publish rate: the rate is normally pushed when it changes, which for these blocks happens during construction — before the ViewModel has handed over the scope — so without this the scope would never learn its time base.

Methods

BindStimulus(Stimulus)

Binds the TAC to a Stimulus block. Must be called by the pipeline builder after all blocks are constructed. Without this, trial detection will not work.

Declaration
public void BindStimulus(Stimulus stimulus)
Parameters
Type Name Description
Stimulus stimulus

The Stimulus block instance.

Exceptions
Type Condition
ArgumentNullException

Thrown if stimulus is null.

CompleteTrialFailure()

Records a failed trial when the Stimulus leaves "capture" before dwell completion.

Declaration
private void CompleteTrialFailure()

CompleteTrialSuccess(double)

Records a successful trial, plays a beep, and advances the Stimulus FSM to "fall".

Declaration
private void CompleteTrialSuccess(double completionTime)
Parameters
Type Name Description
double completionTime

ConfigureInput(IServiceProvider, JsonModel)

Creates a TAC from a JSON pipeline definition.

Declaration
public static TAC ConfigureInput(IServiceProvider sp, JsonModel m)
Parameters
Type Name Description
IServiceProvider sp

Service provider for dependency injection.

JsonModel m

JSON model. See the class-level example for Params layout.

Returns
Type Description
TAC

A configured TAC instance.

Exceptions
Type Condition
ArgumentException

Thrown if required parameters are missing.

Dispose()

Unbinds the Stimulus, disposes visualization, and releases base class resources.

Declaration
public override void Dispose()
Overrides
BaseBlock.Dispose()

Evaluate()

Computes L2 distance, delegates dwell tracking to DwellDetector, and detects trial boundaries from Stimulus FSM state transitions.

Declaration
private void Evaluate()

GetJsonParams()

Block-specific parameters for JSON. Override to provide custom parameters.

Declaration
protected override IReadOnlyList<object>? GetJsonParams()
Returns
Type Description
IReadOnlyList<object>

The values for Params, in the order this block's ConfigureInput reads them, or null when the block takes no parameters.

Overrides
BaseBlock.GetJsonParams()

HandleStateTransition(string, double)

Routes state transitions to StartTrial(double) or CompleteTrialFailure().

Declaration
private void HandleStateTransition(string newState, double now)
Parameters
Type Name Description
string newState
double now

OnCurrentOvershootCountChanged(int)

Executes the logic for when CurrentOvershootCount just changed.

Declaration
private void OnCurrentOvershootCountChanged(int value)
Parameters
Type Name Description
int value

The new property value that was set.

Remarks

This method is invoked right after the value of CurrentOvershootCount is changed.

OnCurrentOvershootCountChanged(int, int)

Executes the logic for when CurrentOvershootCount just changed.

Declaration
private void OnCurrentOvershootCountChanged(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that was replaced.

int newValue

The new property value that was set.

Remarks

This method is invoked right after the value of CurrentOvershootCount is changed.

OnCurrentOvershootCountChanging(int)

Executes the logic for when CurrentOvershootCount is changing.

Declaration
private void OnCurrentOvershootCountChanging(int value)
Parameters
Type Name Description
int value

The new property value being set.

Remarks

This method is invoked right before the value of CurrentOvershootCount is changed.

OnCurrentOvershootCountChanging(int, int)

Executes the logic for when CurrentOvershootCount is changing.

Declaration
private void OnCurrentOvershootCountChanging(int oldValue, int newValue)
Parameters
Type Name Description
int oldValue

The previous property value that is being replaced.

int newValue

The new property value being set.

Remarks

This method is invoked right before the value of CurrentOvershootCount is changed.

OnCurrentTaskNameChanged(string)

Executes the logic for when CurrentTaskName just changed.

Declaration
private void OnCurrentTaskNameChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of CurrentTaskName is changed.

OnCurrentTaskNameChanged(string?, string)

Executes the logic for when CurrentTaskName just changed.

Declaration
private void OnCurrentTaskNameChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of CurrentTaskName is changed.

OnCurrentTaskNameChanging(string)

Executes the logic for when CurrentTaskName is changing.

Declaration
private void OnCurrentTaskNameChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of CurrentTaskName is changed.

OnCurrentTaskNameChanging(string?, string)

Executes the logic for when CurrentTaskName is changing.

Declaration
private void OnCurrentTaskNameChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of CurrentTaskName is changed.

OnDistanceToTargetChanged(double)

Executes the logic for when DistanceToTarget just changed.

Declaration
private void OnDistanceToTargetChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of DistanceToTarget is changed.

OnDistanceToTargetChanged(double, double)

Executes the logic for when DistanceToTarget just changed.

Declaration
private void OnDistanceToTargetChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of DistanceToTarget is changed.

OnDistanceToTargetChanging(double)

Executes the logic for when DistanceToTarget is changing.

Declaration
private void OnDistanceToTargetChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of DistanceToTarget is changed.

OnDistanceToTargetChanging(double, double)

Executes the logic for when DistanceToTarget is changing.

Declaration
private void OnDistanceToTargetChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of DistanceToTarget is changed.

OnHoldProgressChanged(double)

Executes the logic for when HoldProgress just changed.

Declaration
private void OnHoldProgressChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of HoldProgress is changed.

OnHoldProgressChanged(double, double)

Executes the logic for when HoldProgress just changed.

Declaration
private void OnHoldProgressChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of HoldProgress is changed.

OnHoldProgressChanging(double)

Executes the logic for when HoldProgress is changing.

Declaration
private void OnHoldProgressChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of HoldProgress is changed.

OnHoldProgressChanging(double, double)

Executes the logic for when HoldProgress is changing.

Declaration
private void OnHoldProgressChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of HoldProgress is changed.

OnIsTryingChanged(bool)

Executes the logic for when IsTrying just changed.

Declaration
private void OnIsTryingChanged(bool value)
Parameters
Type Name Description
bool value

The new property value that was set.

Remarks

This method is invoked right after the value of IsTrying is changed.

OnIsTryingChanged(bool, bool)

Executes the logic for when IsTrying just changed.

Declaration
private void OnIsTryingChanged(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that was replaced.

bool newValue

The new property value that was set.

Remarks

This method is invoked right after the value of IsTrying is changed.

OnIsTryingChanging(bool)

Executes the logic for when IsTrying is changing.

Declaration
private void OnIsTryingChanging(bool value)
Parameters
Type Name Description
bool value

The new property value being set.

Remarks

This method is invoked right before the value of IsTrying is changed.

OnIsTryingChanging(bool, bool)

Executes the logic for when IsTrying is changing.

Declaration
private void OnIsTryingChanging(bool oldValue, bool newValue)
Parameters
Type Name Description
bool oldValue

The previous property value that is being replaced.

bool newValue

The new property value being set.

Remarks

This method is invoked right before the value of IsTrying is changed.

OnReceive(object, object)

Dispatches incoming data: Stimulus inputs provide targets, other inputs provide predictions. Evaluation runs whenever both target and prediction are available.

Declaration
protected override void OnReceive(object sender, object data)
Parameters
Type Name Description
object sender

The upstream block.

object data

A (string, Vector<double>) tuple from a Stimulus, or a MathNet.Numerics.LinearAlgebra.Vector<T> prediction from a predictor.

Overrides
BaseBlock.OnReceive(object, object)

OnStimulusCompleted()

Logs summary when the Stimulus finishes all tasks.

Declaration
private void OnStimulusCompleted()

OnStimulusStateChanged(string)

Executes the logic for when StimulusState just changed.

Declaration
private void OnStimulusStateChanged(string value)
Parameters
Type Name Description
string value

The new property value that was set.

Remarks

This method is invoked right after the value of StimulusState is changed.

OnStimulusStateChanged(string?, string)

Executes the logic for when StimulusState just changed.

Declaration
private void OnStimulusStateChanged(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that was replaced.

string newValue

The new property value that was set.

Remarks

This method is invoked right after the value of StimulusState is changed.

OnStimulusStateChanging(string)

Executes the logic for when StimulusState is changing.

Declaration
private void OnStimulusStateChanging(string value)
Parameters
Type Name Description
string value

The new property value being set.

Remarks

This method is invoked right before the value of StimulusState is changed.

OnStimulusStateChanging(string?, string)

Executes the logic for when StimulusState is changing.

Declaration
private void OnStimulusStateChanging(string? oldValue, string newValue)
Parameters
Type Name Description
string oldValue

The previous property value that is being replaced.

string newValue

The new property value being set.

Remarks

This method is invoked right before the value of StimulusState is changed.

OnTimeInTargetChanged(double)

Executes the logic for when TimeInTarget just changed.

Declaration
private void OnTimeInTargetChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of TimeInTarget is changed.

OnTimeInTargetChanged(double, double)

Executes the logic for when TimeInTarget just changed.

Declaration
private void OnTimeInTargetChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of TimeInTarget is changed.

OnTimeInTargetChanging(double)

Executes the logic for when TimeInTarget is changing.

Declaration
private void OnTimeInTargetChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of TimeInTarget is changed.

OnTimeInTargetChanging(double, double)

Executes the logic for when TimeInTarget is changing.

Declaration
private void OnTimeInTargetChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of TimeInTarget is changed.

OnTrialElapsedChanged(double)

Executes the logic for when TrialElapsed just changed.

Declaration
private void OnTrialElapsedChanged(double value)
Parameters
Type Name Description
double value

The new property value that was set.

Remarks

This method is invoked right after the value of TrialElapsed is changed.

OnTrialElapsedChanged(double, double)

Executes the logic for when TrialElapsed just changed.

Declaration
private void OnTrialElapsedChanged(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that was replaced.

double newValue

The new property value that was set.

Remarks

This method is invoked right after the value of TrialElapsed is changed.

OnTrialElapsedChanging(double)

Executes the logic for when TrialElapsed is changing.

Declaration
private void OnTrialElapsedChanging(double value)
Parameters
Type Name Description
double value

The new property value being set.

Remarks

This method is invoked right before the value of TrialElapsed is changed.

OnTrialElapsedChanging(double, double)

Executes the logic for when TrialElapsed is changing.

Declaration
private void OnTrialElapsedChanging(double oldValue, double newValue)
Parameters
Type Name Description
double oldValue

The previous property value that is being replaced.

double newValue

The new property value being set.

Remarks

This method is invoked right before the value of TrialElapsed is changed.

ResetTrialUI()

Resets observable UI properties between trials.

Declaration
private void ResetTrialUI()

StartTrial(double)

Initialises per-trial state when the Stimulus enters "capture".

Declaration
private void StartTrial(double now)
Parameters
Type Name Description
double now

Events

OnEvaluation

Fired on each evaluation tick (distance, timeInTarget, inTarget).

Declaration
public event Action<double, double, bool>? OnEvaluation
Event Type
Type Description
Action<double, double, bool>

OnTrialCompleted

Fired when a trial completes (success, completionTime, efficiency, overshoots).

Declaration
public event Action<bool, double, double, int>? OnTrialCompleted
Event Type
Type Description
Action<bool, double, double, int>

Implements

INotifyPropertyChanged
INotifyPropertyChanging
ISubscriber
IPublisher
IBaseBlockProps
IJsonExportable
IDisposable
IAsyncDisposable

Search documentation

Start typing to search the documentation.