numerical-collection-cpp 0.10.0
A collection of algorithms in numerical analysis implemented in C++
Loading...
Searching...
No Matches
global_length_parameter_calculator.h
Go to the documentation of this file.
1/*
2 * Copyright 2024 MusicScience37 (Kenta Kabashima)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
20#pragma once
21
22#include <cstddef>
23#include <limits>
24#include <vector>
25
29#include "num_collect/constants/zero.h" // IWYU pragma: keep
32
34
41template <concepts::distance_function DistanceFunction>
43public:
45 using distance_function_type = DistanceFunction;
46
48 using variable_type = typename DistanceFunction::variable_type;
49
51 using scalar_type = typename DistanceFunction::value_type;
52
54 static constexpr bool uses_global_length_parameter = true;
55
60
67 void compute(const std::vector<variable_type>& variables,
68 const distance_function_type& distance_function) {
69 const std::size_t num_samples = variables.size();
71 num_samples > 0, "Sample points must be given.");
72
73 auto max_min_distance = constants::zero<scalar_type>;
74 for (std::size_t i = 0; i < num_samples; ++i) {
75 auto min_distance = std::numeric_limits<scalar_type>::max();
76 for (std::size_t j = 0; j < num_samples; ++j) {
77 if (i != j) {
78 const auto distance =
79 distance_function(variables[i], variables[j]);
80 if (distance < min_distance) {
81 min_distance = distance;
82 }
83 }
84 }
85 if (min_distance > max_min_distance) {
86 max_min_distance = min_distance;
87 }
88 }
89
90 length_parameter_ = scale_ * max_min_distance;
91 }
92
99 [[nodiscard]] auto length_parameter_at(index_type i) const -> scalar_type {
100 (void)i;
101 return length_parameter_;
102 }
103
109 [[nodiscard]] auto scale() const noexcept -> scalar_type { return scale_; }
110
116 void scale(scalar_type value) {
118 "Scale of length parameters must be a positive number.");
119 scale_ = value;
120 }
121
122private:
124 static constexpr auto default_scale = static_cast<scalar_type>(10);
125
128
131};
132
133} // namespace num_collect::rbf::length_parameter_calculators
static constexpr auto default_scale
Default value of the scalar of length parameters.
static constexpr bool uses_global_length_parameter
Whether this calculator uses the globally fixed length parameters.
void compute(const std::vector< variable_type > &variables, const distance_function_type &distance_function)
Compute the length parameters.
auto scale() const noexcept -> scalar_type
Get the current scale of length parameters.
auto length_parameter_at(index_type i) const -> scalar_type
Get the length parameter at a point.
Definition of distance_function concept.
Definition of exceptions.
Definition of index_type type.
Definition of macros for logging.
std::ptrdiff_t index_type
Type of indices in this library.
Definition index_type.h:33
constexpr T zero
Value 0.
Definition zero.h:30
Namespace of calculators of length parameters.
Definition of NUM_COLLECT_PRECONDITION macro.
#define NUM_COLLECT_PRECONDITION(CONDITION,...)
Check whether a precondition is satisfied and throw an exception if not.
Definition of zero.