unobtanium_graph_algorithms/pagerank_configuration.rs
1// SPDX-FileCopyrightText: 2025 Slatian 2025
2//
3// SPDX-License-Identifier: LGPL-3.0-only
4
5/// Parameters for the pagerank algorithm
6#[derive(Debug, Clone)]
7pub struct PageRankConfiguration {
8 /// Works as in "Bringing Order into Texts", the TextRank paper.
9 ///
10 /// ```notest
11 /// score = (1 - damping) + damping * {pagerank calculation}
12 /// ```
13 pub damping: f32,
14
15 /// The convergence threshold.
16 ///
17 /// If no single value changes more than this from one iteration to another
18 /// the weights are considered successfully converged.
19 pub tolerance: f32,
20}
21
22impl Default for PageRankConfiguration {
23 fn default() -> Self {
24 Self {
25 damping: Self::DEFAULT_TEXTRANK_DAMPING,
26 tolerance: Self::DEFAULT_TEXTRANK_TOLERANCE,
27 }
28 }
29}
30
31impl PageRankConfiguration {
32 /// The default damping factor used for textrank
33 pub const DEFAULT_TEXTRANK_DAMPING: f32 = 0.85;
34
35 /// The convergence threshold used in the textrank paper.
36 pub const DEFAULT_TEXTRANK_TOLERANCE: f32 = 0.0001;
37}