ComparewConstant ComparewConstant Icon

Compare.ComparewConstant

ComparewConstant()

Checks whether a real-valued input signal (u) is approximately equal to a specified threshold value.

Variables

  • u: Real input signal
  • y: Real output (1.0 if |u - threshold| < tolerance, 0.0 otherwise)
  • threshold: Threshold value to compare against
  • tolerance: Acceptable deviation range around the threshold (default: 1e-5)

Description

This component extends the partialThresholdComparison component and adds a real-valued parameter (tolerance) to define an acceptable deviation range around the threshold.

Examples

threshold = 5.0, tolerance = 1e-5
u = 5.0       → y = 1.0  (exact match)
u = 5.000001  → y = 1.0  (within tolerance)
u = 4.99999   → y = 1.0  (within tolerance)
u = 5.1       → y = 0.0  (outside tolerance)
u = 4.8       → y = 0.0  (outside tolerance)

This component extends from partialThresholdComparison

Usage

PrimitiveComponents.Compare.ComparewConstant(threshold, tolerance=1e-5)

Parameters:

NameDescriptionUnitsDefault value
threshold
tolerance0.00001

Connectors

  • y - This connector represents a real signal as an output from a component (RealOutput)
  • u - This connector represents a real signal as an input to a component (RealInput)

Behavior

\[ \begin{align} y\left( t \right) &= ifelse\left( \left| - \mathtt{threshold} + u\left( t \right)\right| < \mathtt{tolerance}, 1, 0 \right) \end{align} \]

Source

"""
    ComparewConstant()

Checks whether a real-valued input signal (u) is approximately equal to a specified threshold value.

# Variables
- `u`: Real input signal
- `y`: Real output (1.0 if |u - threshold| < tolerance, 0.0 otherwise)
- `threshold`: Threshold value to compare against
- `tolerance`: Acceptable deviation range around the threshold (default: 1e-5)

# Description
This component extends the `partialThresholdComparison` component and adds a real-valued
parameter (tolerance) to define an acceptable deviation range around the threshold.

# Examples

threshold = 5.0, tolerance = 1e-5 u = 5.0 → y = 1.0 (exact match) u = 5.000001 → y = 1.0 (within tolerance) u = 4.99999 → y = 1.0 (within tolerance) u = 5.1 → y = 0.0 (outside tolerance) u = 4.8 → y = 0.0 (outside tolerance)

"""</span>
<span class="hljs-keyword">component</span> ComparewConstant
&nbsp;&nbsp;<span class="hljs-keyword">extends</span> <span class="hljs-link"><a href="../../types/partialThresholdComparison.html">partialThresholdComparison</a></span>
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">tolerance</span>::<span>Real</span> = 1e-5
<span class="hljs-keyword">relations</span>
&nbsp;&nbsp;y = ifelse((abs(u - threshold) < tolerance), float_sym(1.0), float_sym(0.0))
<span class="hljs-keyword">metadata</span> {
&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;"labels": [
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"label": " $(threshold)", "x": 500, "y": -150, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;],
&nbsp;&nbsp;&nbsp;&nbsp;"icons": {"default": "dyad://PrimitiveComponents/EqualThreshold.svg"}
&nbsp;&nbsp;}
}
<span class="hljs-keyword">end</span></code></pre>
Flattened Source
"""
    ComparewConstant()

Checks whether a real-valued input signal (u) is approximately equal to a specified threshold value.

# Variables
- `u`: Real input signal
- `y`: Real output (1.0 if |u - threshold| < tolerance, 0.0 otherwise)
- `threshold`: Threshold value to compare against
- `tolerance`: Acceptable deviation range around the threshold (default: 1e-5)

# Description
This component extends the `partialThresholdComparison` component and adds a real-valued
parameter (tolerance) to define an acceptable deviation range around the threshold.

# Examples

threshold = 5.0, tolerance = 1e-5 u = 5.0 → y = 1.0 (exact match) u = 5.000001 → y = 1.0 (within tolerance) u = 4.99999 → y = 1.0 (within tolerance) u = 5.1 → y = 0.0 (outside tolerance) u = 4.8 → y = 0.0 (outside tolerance)

"""</span>
<span class="hljs-keyword">component</span> ComparewConstant
&nbsp;&nbsp;# Real output(either 1.0 or 0.0)
&nbsp;&nbsp;<span class="hljs-symbol">y</span> = <span>Dyad.RealOutput</span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"icon": {"x1": 1000, "x2": 1040, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;# Real input
&nbsp;&nbsp;<span class="hljs-symbol">u</span> = <span>Dyad.RealInput</span>() {
&nbsp;&nbsp;&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"placement": {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"diagram": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"icon": {"x1": -40, "x2": 0, "y1": 480, "y2": 520, "sh": 1, "sw": 1, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;}
&nbsp;&nbsp;# threshold to compare against
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">threshold</span>::<span>Real</span>()
&nbsp;&nbsp;<span class="hljs-keyword">parameter</span> <span class="hljs-symbol">tolerance</span>::<span>Real</span> = 1e-5
<span class="hljs-keyword">relations</span>
&nbsp;&nbsp;y = ifelse((abs(u - threshold) < tolerance), float_sym(1.0), float_sym(0.0))
<span class="hljs-keyword">metadata</span> {
&nbsp;&nbsp;"Dyad": {
&nbsp;&nbsp;&nbsp;&nbsp;"labels": [
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0},
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{"label": " $(threshold)", "x": 500, "y": -150, "rot": 0}
&nbsp;&nbsp;&nbsp;&nbsp;],
&nbsp;&nbsp;&nbsp;&nbsp;"icons": {"default": "dyad://PrimitiveComponents/EqualThreshold.svg"}
&nbsp;&nbsp;}
}
<span class="hljs-keyword">end</span></code></pre>


Test Cases

No test cases defined.

  • Examples
  • Experiments
  • Analyses