linear_ramp_pwc
signals.linear_ramp_pwc(duration, segment_count, end_value, start_value=None, start_time=0, end_time=None, segmentation=SegmentationType.UNIFORM, *, name=None)
Create a Pwc representing a linear ramp.
Parameters
- duration (float) – The duration of the signal, T.
- segment_count (int) – The number of segments in the PWC.
- end_value (float or complex or Tensor) – The value of the ramp at t=tend, aend. It must either be a scalar or contain a single element.
- start_value (float or complex or Tensor or None , optional) – The value of the ramp at t=tstart, astart. If passed, it must either be a scalar or contain a single element. Defaults to −aend.
- start_time (float , optional) – The time at which the linear ramp starts, tstart. Defaults to 0.
- end_time (float or None , optional) – The time at which the linear ramp ends, tend. Defaults to the given duration T.
- segmentation (
SegmentationType
) – The type of segmentation for the signal. With a “MINIMAL” segmentation, most of the segments are placed in the non-constant parts of the signal. Defaults to “UNIFORM”, in which case the segments are uniformly distributed along the signal’s duration. - name (str or None , optional) – The name of the node.
Returns
The sampled linear ramp.
Return type
SEE ALSO
boulderopal.signals.linear_ramp
: Create a Signal object representing a linear ramp.
Graph.signals.linear_ramp_stf
: Corresponding operation with Stf output.
Graph.signals.tanh_ramp_pwc
: Create a Pwc representing a hyperbolic tangent ramp.
Notes
The linear ramp is defined as
Linear(t)=⎩⎨⎧astartastart+(aend−astart)tend−tstartt−tstartaendift<tstartiftstart≤t≤tendift>tend.Examples
Define a linear PWC ramp.
>>> graph.signals.linear_ramp_pwc(
... duration=2.0, segment_count=5, end_value=1.5, start_value=0.5, name="linear_ramp"
... )
<Pwc: name="linear_ramp", operation_name="pwc_signal", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="linear_ramp")
>>> result["output"]["linear_ramp"]
{
'durations': array([0.4, 0.4, 0.4, 0.4, 0.4]),
'values': array([0.6, 0.8, 1. , 1.2, 1.4]),
'time_dimension': 0
}
Define a linear ramp with start and end times.
>>> graph.signals.linear_ramp_pwc(
... duration=4,
... segment_count=8,
... end_value=2,
... start_time=1,
... end_time=3,
... name="linear",
... )
<Pwc: name="linear", operation_name="pwc_signal", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="linear")
>>> result["output"]["linear"]
{
'durations': array([0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5]),
'values': array([-2. , -2. , -1.5, -0.5, 0.5, 1.5, 2. , 2. ]),
'time_dimension': 0
}
Define a linear ramp with minimal segmentation.
>>> graph.signals.linear_ramp_pwc(
... duration=4,
... segment_count=6,
... end_value=2,
... start_time=1,
... end_time=3,
... segmentation="MINIMAL",
... name="linear",
... )
<Pwc: name="linear", operation_name="time_concatenate_pwc", value_shape=(), batch_shape=()>
>>> result = bo.execute_graph(graph=graph, output_node_names="linear")
>>> result["output"]["linear"]
{
'durations': array([1. , 0.5, 0.5, 0.5, 0.5, 1. ]),
'values': array([-2. , -1.5, -0.5, 0.5, 1.5, 2. ]),
'time_dimension': 0
}
Define a linear ramp with an optimizable slope around 0.
>>> duration = 4.0
>>> slope = graph.optimizable_scalar(
... lower_bound=-30, upper_bound=30, name="slope"
... )
>>> end_value = slope * duration / 2
>>> graph.signals.linear_ramp_pwc(
... duration=duration, segment_count=64, end_value=end_value, name="linear_ramp"
... )
<Pwc: name="linear_ramp", operation_name="pwc_signal", value_shape=(), batch_shape=()>