Skip to content

Commit 21a0f97

Browse files
authored
Improve DiscreteMeasureData tutorial (#266)
1 parent 01b4d15 commit 21a0f97

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

docs/src/develop/extensions.md

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -312,22 +312,21 @@ evaluation methods, users may want to embed the new evaluation method under the
312312
### Creating a DiscreteMeasureData Object
313313
The basic way to do that is to write a function that creates
314314
[`DiscreteMeasureData`](@ref) object and pass the object to [`measure`](@ref).
315-
For instance, let's consider defining a function that enables the definition of a
316-
uniform grid for a univariate or multivariate infinite parameter in
317-
[`IntervalDomain`](@ref). The function, denoted `uniform_grid`, generates uniform
318-
grid points as supports for univariate parameter and each component of
319-
independent multivariate parameter. The univariate version of this function
320-
can be defined as follows:
321-
315+
This considers a measure approximation of the form:
316+
```math
317+
\sum_{i \in I} \alpha_i f(\tau_i) w(\tau_i)
318+
```
319+
where ``\alpha_i`` are coefficients, ``f(\cdot)`` is the expression being measured,
320+
``w(\cdot)`` is a weighting function, and ``i \in I`` indexes the support points.
321+
Let's consider defining a function that enables the definition of a
322+
uniform grid for a univariate infinite parameter in [`IntervalDomain`](@ref).
323+
This example approximation uses a uniformly spaced supports ``\tau_i`` with
324+
``\alpha_i = \frac{ub - lb}{|I|}``:
322325
```jldoctest measure_eval; output = false, setup = :(using InfiniteOpt)
323-
function uniform_grid(
324-
param::GeneralVariableRef,
325-
lb::Real,
326-
ub::Real,
327-
num_supports::Int
328-
)::DiscreteMeasureData
329-
increment = (ub - lb) / (num_supports - 1)
330-
supps = [lb + (i - 1) * increment for i in 1:num_supports]
326+
function uniform_grid(param, num_supports)
327+
lb = lower_bound(param)
328+
ub = upper_bound(param)
329+
supps = collect(LinRange(lb, ub, num_supports))
331330
coeffs = ones(num_supports) / num_supports * (ub - lb)
332331
return DiscreteMeasureData(param, coeffs, supps, lower_bound = lb, upper_bound = ub)
333332
end
@@ -352,7 +351,7 @@ Now we can use `uniform_grid` to construct a [`DiscreteMeasureData`](@ref) and
352351
create a measure using the measure data, as shown below:
353352

354353
```jldoctest measure_eval
355-
julia> tdata = uniform_grid(t, 0, 5, 6);
354+
julia> tdata = uniform_grid(t, 6);
356355
357356
julia> y_meas = measure(y, tdata)
358357
measure{t ∈ [0, 5]}[y(t)]

0 commit comments

Comments
 (0)