Skip to content

The downsampling algorithm #1617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

eggrobin
Copy link
Member

No description provided.

const_iterator cbegin() const;
const_iterator cend() const;

size_type size() const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment that this is O(N).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is O(N), but it can be Θ(1), so this would be misleading.

// (*itᵢ₋₁, *itᵢ) fits |samples| within |tolerance|, but the interpolation
// of (*itᵢ₋₁, *(it + 1)ᵢ) does not, i.e., the iterators delimit "maximal"
// fitting polynomials.
// Note that it follows from the above that itᵣ < samples.end() - 1, so that at
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't really parse.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

namespace internal_fit_hermite_spline {

// Given |samples| for which the arguments, values, and derivatives can be
// obtained via the given functors, returns a sequence of iterators
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to document the functors better, they are totally mysterious in the template declarations below.

In fact it would be much more readable to do something like, e.g.:

  typename Argument,
  typename Value,

  std::function<Argument(typename Samples::iterator)> const& get_argument,
  ... // Same for get_value.
  std::function<Derivative<Value>(typename Sample::iterator)> const& get_derivative,

As written, all the contract is hidden in the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return {};
}

auto interpolation_error = [get_argument, get_value, get_derivative](
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alphabetize the captures.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// Invariant: The Hermite interpolant on [samples.begin(), lower] is below
// the tolerance, the Hermite interpolant on [samples.begin(), upper] is
// above.
auto lower = samples.begin() + 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be implemented using std::binary_search?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::lower_bound and std::binary_search require (25.4.3.1:1, 25.4.3.4:1)

The elements e of [first,last) shall be partitioned with respect to the expression e < value or comp(e, value).

and std::upper_bound requires (25.4.3.2:1)

The elements e of [first,last) shall be partitioned with respect to the expression !(value < e) or !comp(value, e).

partitioned with respect to an expression is defined as (25.4:6)

A sequence [start,finish) is partitioned with respect to an expression f(e) if there exists an integer n such that for all 0 <= i < distance(start, finish), f(*(start + i)) is true if and only if i < n.

Another option, std::partition_point, requires (25.3.13:16)

[first,last) shall be partitioned by pred, i.e. all elements that satisfy pred shall appear before those that do not.

This is not satisfied by the range [samples.begin()+1, samples.end()[, which may have several alternations of the predicate (but has at least one, and an odd number), as described in the comment.

All citations from the working draft N4296 of JTC 1/SC 22/WG 21.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a proof of termination.


TEST_F(FitHermiteSplineTest, Sinusoid) {
AngularFrequency const ω = 1 * Radian / Second;
auto const f = [ω, this](Instant const t) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instant const& at several places.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

auto const df = [ω, this](Instant const t) {
return -ω * Sin(ω *(t - t0_)) * Metre / Radian;
};
auto t = DoublePrecision<Instant>(t0_);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this immediately before the loops.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and scoped.

// Also note that |Pointee| doesn't work with iterators, so
// |Pointee(Field(&Sample::t, _))| is not an option.
std::function<Instant(std::vector<Sample>::const_iterator)> const get_time =
[](auto it) { return it->t; };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto const

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@eggrobin eggrobin force-pushed the actual-downsampling-algorithm branch from ff0d73f to 8e10071 Compare October 31, 2017 23:09
@pleroy pleroy added the LGTM label Nov 1, 2017
@eggrobin eggrobin merged commit 1cc3736 into mockingbirdnest:master Nov 1, 2017
@eggrobin
Copy link
Member Author

eggrobin commented Nov 6, 2017

This is part of the work on #228.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants