anpcpp 0.4.0
Analytic Network Process computational library
Loading...
Searching...
No Matches
rowsens.hpp
Go to the documentation of this file.
1
6#pragma once
7
8#include <cstddef>
9#include <map>
10#include <optional>
11#include <string>
12#include <vector>
13
15#include "anpcpp/matrix.hpp"
16
17namespace anpcpp {
18
22enum class P0ModeKind {
24 Direct,
26 Smart,
29};
30
34struct P0Mode {
37 double direct = 0.5;
39 std::size_t smart_alt = 0;
40
42 static P0Mode Direct(double p0) {
43 P0Mode m;
44 m.kind = P0ModeKind::Direct;
45 m.direct = p0;
46 return m;
47 }
49 static P0Mode Smart(std::size_t alt_index) {
50 P0Mode m;
51 m.kind = P0ModeKind::Smart;
52 m.smart_alt = alt_index;
53 return m;
54 }
56 static P0Mode Original() {
57 P0Mode m;
59 return m;
60 }
61};
62
67 std::string name;
68 double original = 0.0;
69 double up_score = 0.0;
70 double up_diff = 0.0;
71 double down_score = 0.0;
72 double down_diff = 0.0;
73};
74
79 std::string name;
80 double original = 0.0;
81 double rank_influence = 0.0;
82};
83
88 std::string name;
89 double marginal = 0.0;
90 double smart_p0 = 0.5;
91};
92
97 std::string name;
98 double total_influence = 0.0;
99 double max_alt_change = 0.0;
100};
101
112[[nodiscard]] Matrix row_adjust(const Matrix& mat,
113 std::size_t row,
114 double p,
115 const P0Mode& p0mode = P0Mode::Direct(0.5),
116 const std::vector<std::size_t>& cluster_nodes = {});
117
126[[nodiscard]] double smart_p0(
127 const Matrix& mat,
128 std::size_t row,
129 std::size_t cont_alt,
130 const std::vector<std::size_t>& cluster_nodes = {},
131 const LimitMatrixOptions& options = {});
132
144 const Matrix& mat,
145 std::size_t row,
146 double p,
147 const P0Mode& p0mode = P0Mode::Direct(0.5),
148 const std::vector<std::size_t>& cluster_nodes = {},
149 const LimitMatrixOptions& options = {},
150 bool normalize_to_orig = true);
151
164 const Matrix& mat,
165 std::size_t row,
166 double p0,
167 int left_or_right = 0,
168 double delta = 1e-6,
169 const std::vector<std::size_t>& influence_nodes = {},
170 const std::vector<std::size_t>& cluster_nodes = {},
171 const LimitMatrixOptions& options = {});
172
183[[nodiscard]] std::vector<InfluenceMarginalEntry> influence_marginal_smart(
184 const Matrix& mat,
185 std::size_t row,
186 const std::vector<std::size_t>& influence_nodes,
187 const std::vector<std::string>& names,
188 const std::vector<std::size_t>& cluster_nodes = {},
189 double delta = 1e-6,
190 const LimitMatrixOptions& options = {});
191
204[[nodiscard]] std::vector<InfluenceRawEntry> influence_raw(
205 const Matrix& mat,
206 std::size_t row,
207 const std::vector<std::size_t>& influence_nodes,
208 const std::vector<std::string>& names,
209 double delta_up = 0.1,
210 double delta_down = 0.1,
211 double p0 = 0.5,
212 const std::vector<std::size_t>& cluster_nodes = {},
213 const LimitMatrixOptions& options = {});
214
226[[nodiscard]] std::vector<InfluenceRankEntry> influence_rank(
227 const Matrix& mat,
228 std::size_t row,
229 const std::vector<std::size_t>& influence_nodes,
230 const std::vector<std::string>& names,
231 const std::vector<std::size_t>& cluster_nodes = {},
232 double error = 1e-5,
233 int round_to_decimal = 5,
234 const LimitMatrixOptions& options = {});
235
251 const Matrix& mat,
252 std::size_t row,
253 const std::vector<std::size_t>& influence_nodes,
254 double delta = 0.25,
255 double p0 = 0.5,
256 const std::vector<std::size_t>& cluster_nodes = {},
257 const LimitMatrixOptions& options = {});
258
270[[nodiscard]] std::vector<InfluenceTotalEntry> influence_total(
271 const Matrix& mat,
272 const std::vector<std::size_t>& rows,
273 const std::vector<std::string>& row_names,
274 const std::vector<std::size_t>& influence_nodes,
275 double delta = 0.25,
276 double p0 = 0.5,
277 const std::vector<std::size_t>& cluster_nodes = {},
278 const LimitMatrixOptions& options = {});
279
294[[nodiscard]] Vector perspective(
295 const Matrix& mat,
296 std::size_t row,
297 const P0Mode& p0mode = P0Mode::Direct(0.5),
298 const std::vector<std::size_t>& cluster_nodes = {},
299 const LimitMatrixOptions& options = {},
300 bool normalize_to_orig = true);
301
315 const Matrix& mat,
316 const std::vector<std::size_t>& rows = {},
317 const P0Mode& p0mode = P0Mode::Direct(0.5),
318 const std::vector<std::size_t>& cluster_nodes = {},
319 const LimitMatrixOptions& options = {},
320 bool normalize_to_orig = true);
321
323inline constexpr double kPerspectivePCoarse = 1.0 - 1e-6;
324inline constexpr double kPerspectivePFine = 1.0 - 1e-7;
325inline constexpr double kPerspectivePRefine = 1.0 - 1e-9;
327inline constexpr double kPerspectiveAgreeTol = 1e-6;
328
329} // namespace anpcpp
Dense row-major matrix stored in a flat buffer.
Definition matrix.hpp:136
One-dimensional array of doubles with element-wise arithmetic.
Definition matrix.hpp:34
Limit matrix and priority extraction from supermatrices.
Dense row-major vectors and matrices.
Analytic Network Process computational library.
Definition eigen.hpp:14
std::vector< InfluenceRawEntry > influence_raw(const Matrix &mat, std::size_t row, const std::vector< std::size_t > &influence_nodes, const std::vector< std::string > &names, double delta_up=0.1, double delta_down=0.1, double p0=0.5, const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={})
Raw fixed-distance influence table (original / up / down scores).
Vector influence_marginal(const Matrix &mat, std::size_t row, double p0, int left_or_right=0, double delta=1e-6, const std::vector< std::size_t > &influence_nodes={}, const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={})
Marginal influence (finite difference) at a direct (p_0).
constexpr double kPerspectiveAgreeTol
Max L-inf gap between coarse/fine before refining further.
Definition rowsens.hpp:327
std::vector< InfluenceRankEntry > influence_rank(const Matrix &mat, std::size_t row, const std::vector< std::size_t > &influence_nodes, const std::vector< std::string > &names, const std::vector< std::size_t > &cluster_nodes={}, double error=1e-5, int round_to_decimal=5, const LimitMatrixOptions &options={})
Rank influence score per alternative (max of upper/lower searches).
Matrix perspective_matrix(const Matrix &mat, const std::vector< std::size_t > &rows={}, const P0Mode &p0mode=P0Mode::Direct(0.5), const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={}, bool normalize_to_orig=true)
Perspective matrix: column j is perspective for rows[j].
Vector perspective(const Matrix &mat, std::size_t row, const P0Mode &p0mode=P0Mode::Direct(0.5), const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={}, bool normalize_to_orig=true)
Perspective of one row: limit as p approaches 1 of row sensitivity.
double smart_p0(const Matrix &mat, std::size_t row, std::size_t cont_alt, const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={})
Smart resting (p_0) making score of cont_alt continuous at (p_0).
std::vector< InfluenceTotalEntry > influence_total(const Matrix &mat, const std::vector< std::size_t > &rows, const std::vector< std::string > &row_names, const std::vector< std::size_t > &influence_nodes, double delta=0.25, double p0=0.5, const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={})
Per-row total influence (pyanp multi-row influence_fixed Totals).
constexpr double kPerspectivePCoarse
Near-1 p values for limit-as-p-approaches-1 perspective (never exactly 1).
Definition rowsens.hpp:323
P0ModeKind
How resting parameter (p_0) is chosen for row sensitivity.
Definition rowsens.hpp:22
@ Smart
Smart (p_0) making scores continuous for one alternative index.
@ OriginalWeight
Use each column's original row weight as (p_0).
@ Direct
Fixed (p_0) (typically 0.5).
Matrix row_adjust(const Matrix &mat, std::size_t row, double p, const P0Mode &p0mode=P0Mode::Direct(0.5), const std::vector< std::size_t > &cluster_nodes={})
Adjusts row row of scaled supermatrix mat to parameter p.
Vector priority_after_row_adjust(const Matrix &mat, std::size_t row, double p, const P0Mode &p0mode=P0Mode::Direct(0.5), const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={}, bool normalize_to_orig=true)
Priorities after row adjust (pyanp row_adjust_priority, normalize_to_orig).
std::vector< InfluenceMarginalEntry > influence_marginal_smart(const Matrix &mat, std::size_t row, const std::vector< std::size_t > &influence_nodes, const std::vector< std::string > &names, const std::vector< std::size_t > &cluster_nodes={}, double delta=1e-6, const LimitMatrixOptions &options={})
Per-alternative smart-(p_0) marginal influence (single value each).
InfluenceTotalEntry influence_total_row(const Matrix &mat, std::size_t row, const std::vector< std::size_t > &influence_nodes, double delta=0.25, double p0=0.5, const std::vector< std::size_t > &cluster_nodes={}, const LimitMatrixOptions &options={})
Fixed-distance total influence for one row (L1 and max of abs diffs).
Smart-(p_0) marginal influence for one row or alternative.
Definition rowsens.hpp:87
Rank-influence result for one row (or one alternative under a fixed Wrt).
Definition rowsens.hpp:78
One alternative's raw (fixed-distance) influence result.
Definition rowsens.hpp:66
Fixed-distance total influence for one row (pyanp influence_fixed Total).
Definition rowsens.hpp:96
(p_0) selection for row_adjust.
Definition rowsens.hpp:34
static P0Mode Smart(std::size_t alt_index)
Definition rowsens.hpp:49
double direct
Used when kind is Direct.
Definition rowsens.hpp:37
std::size_t smart_alt
Alternative/node index made continuous when kind is Smart.
Definition rowsens.hpp:39
static P0Mode Original()
Definition rowsens.hpp:56
static P0Mode Direct(double p0)
Definition rowsens.hpp:42