You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/k-min-path-error.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -31,14 +31,14 @@ This class implements a more general version, as follows:
31
31
32
32
1. The paths can start/end not only in source/sink nodes, but also in given sets of start/end nodes (set parameters `additional_starts` and `additional_ends`). See also [Additional start/end nodes](additional-start-end-nodes.md).
33
33
2. This class supports adding subpath constraints, that is, lists of edges that must appear in some solution path. See [Subpath constraints](subpath-constraints.md) for details.
34
-
3. The above constraint can happen only over a given subset $E' \subseteq E$ of the edges (set parameter `edges_to_ignore` to be $E \setminus E'$),
35
-
4. The error (i.e. the above absolute of the difference) of every edge can contribute differently to the objective function, according to a scale factor $\in [0,1]$. Set these via a dictionary that you pass to `edge_error_scaling`, which stores the scale factor $\lambda_{(u,v)} \in [0,1]$ of each edge $(u,v)$ in the dictionary. Setting $\lambda_{(u,v)} = 0$ will add the edge $(u,v)$ to `edges_to_ignore`, because the constraint for $(u,v)$ becomes always true.
34
+
3. The above constraint can happen only over a given subset $E' \subseteq E$ of the edges (set parameter `edges_to_ignore` to be $E \setminus E'$). See also [ignoring edges documentation](ignoring-edges.md).
35
+
4. The error (i.e. the above absolute of the difference) of every edge can contribute differently to the objective function, according to a scale factor $\in [0,1]$. Set these via a dictionary that you pass to `edge_error_scaling`, which stores the scale factor $\lambda_{(u,v)} \in [0,1]$ of each edge $(u,v)$ in the dictionary. Setting $\lambda_{(u,v)} = 0$ will add the edge $(u,v)$ to `edges_to_ignore`, because the constraint for $(u,v)$ becomes always true. See also [ignoring edges documentation](ignoring-edges.md).
36
36
5. Another way to relax the constraint is to allow also some looseness in the slack value, based on the length of the solution path. Intuitively, suppose that longer paths have even higher variance in their weight across the edges of the path, while shorter paths less. Formally, suppose that we have a function $\alpha : \mathbb{N} \rightarrow \mathbb{R}^+$ that for every solution path length $\ell$, it returns a multiplicative factor $\alpha(\ell)$. Then, we can multiply each path slack $\rho_i$ by $\alpha(|P_i|)$ in the constraint of the problem (where $|P_i|$ denotes the length of solution path $P_i$). In the above example, we could set $\alpha(\ell) > 1$ for "large" lengths $\ell$. Note that in this model we keep the same objective function (i.e. sum of slacks), and thus this multiplier has no effect on the objective value. You can pass the function $\alpha$ to the class as a piecewise encoding, via parameters `path_length_ranges` and `path_length_factors`, see [kMinPathError()](k-min-path-error.md#flowpaths.kminpatherror.kMinPathError).
37
37
38
38
!!! info "Generalized constraint"
39
39
Formally, the constraint generalized as in 3., 4. and 5. above is:
Copy file name to clipboardExpand all lines: docs/minimum-error-flow.md
+7-6Lines changed: 7 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
# Minimum Correction of Weights to a Flow
2
2
3
-
Often, the edge weights of a graph are not a flow (i.e. do not satisfy flow conservation for non- source/sink nodes). While the models [k-Minimum Path Error](k-min-path-error.md) or [k-Least Absolute Errors](k-least-absolute-errors.md) can decompose such graphs, as a less principled approach, one can first minimally correct the graph weights to become a flow, and then optimally decompose the resulting flow flow using the [Minimum Flow Decomposition](minimum-flow-decomposition.md) model.
3
+
Often, the edge weights of a graph are not a flow (i.e. do not satisfy flow conservation for non- source/sink nodes). While the models [k-Minimum Path Error](k-min-path-error.md) or [k-Least Absolute Errors](k-least-absolute-errors.md) can decompose such graphs, as a less principled approach, one can first minimally correct the graph weights to become a flow, and then optimally decompose the resulting flow using the [Minimum Flow Decomposition](minimum-flow-decomposition.md) model.
4
4
5
-
This is faster in practice, because the Minimum Flow Decomposition solver is faster than the ones decomposing graphs without flow conservation. In some sense, we are delegating error correction to a pre-processing step, and then remove the error-resolution when decomposing the resulting graph.
5
+
This is faster in practice, because the Minimum Flow Decomposition solver is faster than the ones decomposing graphs without flow conservation. We are thus delegating error correction to a pre-processing step, and then avoiding the error-handling difficulty when decomposing the resulting graph.
6
6
7
7
## 1. Definition
8
8
@@ -134,13 +134,14 @@ flowchart LR
134
134
This class implements a more general version, as follows:
135
135
136
136
1. The corrected flow can start/end not only in source/sink nodes, but also in given sets of start/end nodes (set parameters `additional_starts` and `additional_ends`). See also [Additional start/end nodes](additional-start-end-nodes.md).
137
-
2. The error can count only for a given subset $E' \subseteq E$ of the edges (set parameter `edges_to_ignore` to be $E \setminus E'$),
138
-
3. One can also ensure some "sparsity" in the solution, meaning the total corrected flow exiting the source node is counts also in the minimization function, with a given multiplier $\lambda$ (see ref. [2]). If $\lambda = 0$, this has no effect.
137
+
2. The error can count only for a given subset $E' \subseteq E$ of the edges (set parameter `edges_to_ignore` to be $E \setminus E'$). See also [ignoring edges documentation](ignoring-edges.md).
138
+
3. The error (i.e. the above absolute of the difference) of every edge can contribute differently to the objective function, according to a scale factor $\in [0,1]$. Set these via a dictionary that you pass to `edge_error_scaling`, which stores the scale factor $\lambda_{(u,v)} \in [0,1]$ of each edge $(u,v)$ in the dictionary. Setting $\lambda_{(u,v)} = 0$ will add the edge $(u,v)$ to `edges_to_ignore`, because the constraint for $(u,v)$ becomes always true. See also [ignoring edges documentation](ignoring-edges.md).
139
+
4. One can also ensure some "sparsity" in the solution, meaning the total corrected flow exiting the source node is counts also in the minimization function, with a given multiplier $\lambda$ (see ref. [2]). If $\lambda = 0$, this has no effect.
139
140
140
141
!!! info "Generalized objective function"
141
-
Formally, the objective function generalized as in 2.and 3. above is:
142
+
Formally, the objective function generalized as in 2., 3. and 4. above is:
Copy file name to clipboardExpand all lines: flowpaths/kminpatherror.py
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,7 @@ def __init__(
90
90
91
91
Dictionary `edge: factor` storing the error scale factor (in [0,1]) of every edge, which scale the allowed difference between edge weight and path weights.
92
92
Default is an empty dict. If an edge has a missing error scale factor, it is assumed to be 1. The factors are used to scale the
93
-
difference between the flow value of the edge and the sum of the weights of the paths going through the edge.
93
+
difference between the flow value of the edge and the sum of the weights of the paths going through the edge. See [ignoring edges documentation](ignoring-edges.md)
94
94
95
95
- `path_length_ranges: list`, optional
96
96
@@ -114,19 +114,19 @@ def __init__(
114
114
115
115
- `additional_starts: list`, optional
116
116
117
-
List of additional start nodes of the paths. Default is an empty list.
117
+
List of additional start nodes of the paths. Default is an empty list. See [additional start/end nodes documentation](additional-start-end-nodes.md).
118
118
119
119
- `additional_ends: list`, optional
120
120
121
-
List of additional end nodes of the paths. Default is an empty list.
121
+
List of additional end nodes of the paths. Default is an empty list. See [additional start/end nodes documentation](additional-start-end-nodes.md).
122
122
123
123
- `optimization_options: dict`, optional
124
124
125
125
Dictionary with the optimization options. Default is `None`. See [optimization options documentation](solver-options-optimizations.md).
126
126
127
127
- `solver_options: dict`, optional
128
128
129
-
Dictionary with the solver options. Default is `None`. See [solver options documentation](solver-options-optimizations.md).
129
+
Dictionary with the solver options. Default is `{}`. See [solver options documentation](solver-options-optimizations.md).
Copy file name to clipboardExpand all lines: flowpaths/minerrorflow.py
+28-12Lines changed: 28 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -12,6 +12,7 @@ def __init__(
12
12
weight_type: type=float,
13
13
sparsity_lambda: float=0,
14
14
edges_to_ignore: list= [],
15
+
edge_error_scaling: dict= {},
15
16
additional_starts: list= [],
16
17
additional_ends: list= [],
17
18
solver_options: dict= {},
@@ -33,31 +34,37 @@ def __init__(
33
34
34
35
The name of the attribute in the edges of the graph that contains the weight of the edge.
35
36
36
-
- `weight_type: type`
37
+
- `weight_type: type`, optional
37
38
38
39
The type of the weights of the edges. It can be either `int` or `float`. Default is `float`.
39
40
40
-
- `sparsity_lambda: float`
41
+
- `sparsity_lambda: float`, optional
41
42
42
43
The sparsity parameter. It is used to control the trade-off between the sparsity of the solution and the closeness to the original weights. Default is `0`.
43
44
If `sparsity_lambda` is set to `0`, then the solution will be as close as possible to the original weights. If `sparsity_lambda` is set to a positive value, then the solution will be sparser, i.e. it will have less flow going out of the source.
44
45
The higher the value of `sparsity_lambda`, the sparser the solution will be.
45
46
46
-
- `edges_to_ignore: list`
47
+
- `edges_to_ignore: list`, optional
47
48
48
-
A list of edges to ignore. The weights of these edges will still be corrected, but their error will not count in the objective function that is being minimized. Default is `[]`.
49
+
A list of edges to ignore. The weights of these edges will still be corrected, but their error will not count in the objective function that is being minimized. Default is `[]`. See [ignoring edges documentation](ignoring-edges.md)
49
50
50
-
- `additional_starts: list`
51
+
- `edge_error_scaling: dict`, optional
52
+
53
+
Dictionary `edge: factor` storing the error scale factor (in [0,1]) of every edge, which scale the allowed difference between edge weight and path weights.
54
+
Default is an empty dict. If an edge has a missing error scale factor, it is assumed to be 1. The factors are used to scale the
55
+
difference between the flow value of the edge and the sum of the weights of the paths going through the edge. See [ignoring edges documentation](ignoring-edges.md)
56
+
57
+
- `additional_starts: list`, optional
51
58
52
-
A list of nodes to be added as additional sources. Flow is allowed to start start at these nodes, meaning that their out going flow can be greater than their incoming flow. Default is `[]`.
59
+
A list of nodes to be added as additional sources. Flow is allowed to start start at these nodes, meaning that their out going flow can be greater than their incoming flow. Default is `[]`. See also [additional start/end nodes documentation](additional-start-end-nodes.md).
53
60
54
-
- `additional_ends: list`
61
+
- `additional_ends: list`, optional
55
62
56
-
A list of nodes to be added as additional sinks. Flow is allowed to end at these nodes, meaning that their incoming flow can be greater than their outgoing flow. Default is `[]`.
63
+
A list of nodes to be added as additional sinks. Flow is allowed to end at these nodes, meaning that their incoming flow can be greater than their outgoing flow. Default is `[]`. See also [additional start/end nodes documentation](additional-start-end-nodes.md).
57
64
58
-
- `solver_options: dict`
65
+
- `solver_options: dict`, optional
59
66
60
-
A dictionary containing the options for the solver. The options are passed to the solver wrapper. Default is `{}`.
67
+
A dictionary containing the options for the solver. The options are passed to the solver wrapper. Default is `{}`. See [solver options documentation](solver-options-optimizations.md).
61
68
"""
62
69
63
70
self.original_graph_copy=deepcopy(G)
@@ -66,9 +73,18 @@ def __init__(
66
73
ifweight_typenotin [int, float]:
67
74
raiseValueError(f"weight_type must be either int or float, not {weight_type}")
0 commit comments