Utilities
This module provides the support classes and various constants.
Classes
LabelType: label type. LinkType: link type. ImageExt: image extention.
DataType
Bases: Enum
DataType Enumerator.
Source code in causalflow/basics/constants.py
34 35 36 37 38 |
|
ImageExt
Bases: Enum
ImageExt Enumerator.
Source code in causalflow/basics/constants.py
50 51 52 53 54 55 |
|
LabelType
Bases: Enum
LabelType Enumerator.
Source code in causalflow/basics/constants.py
26 27 28 29 30 31 |
|
LinkType
Bases: Enum
LinkType Enumerator.
Source code in causalflow/basics/constants.py
41 42 43 44 45 46 47 |
|
This module provides the Logger class.
Classes
Logger: class responsible for the log.
Logger
Bases: object
Logger class.
Source code in causalflow/basics/logger.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
__init__(path, clean_console=True)
Class constructor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
str
|
log file path. |
required |
clean_console |
bool
|
clean console flag. Defaults to True. |
True
|
Source code in causalflow/basics/logger.py
15 16 17 18 19 20 21 22 23 24 25 |
|
close()
Close logger.
Source code in causalflow/basics/logger.py
44 45 46 47 |
|
flush()
python3 compatibility.
Source code in causalflow/basics/logger.py
37 38 39 40 41 42 |
|
write(message)
Write message.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
message |
str
|
log msg. |
required |
Source code in causalflow/basics/logger.py
27 28 29 30 31 32 33 34 35 |
|
This module provides methods for computing various metrics.
FNR(gt, cm, alsoOrient=False)
Compute False Negative Rate between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
false negative rate. |
Source code in causalflow/basics/metrics.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
|
FPR(gt, min_lag, max_lag, cm, alsoOrient=False)
Compute False Positve Rate between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
min_lag |
int
|
min time lag. |
required |
max_lag |
int
|
max time lag. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
false positive rate. |
Source code in causalflow/basics/metrics.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
TNR(gt, min_lag, max_lag, cm, alsoOrient=False)
Compute True Negative Rate between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
min_lag |
int
|
min time lag. |
required |
max_lag |
int
|
max time lag. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
true negative rate. |
Source code in causalflow/basics/metrics.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 |
|
TPR(gt, cm, alsoOrient=False)
Compute True Positive Rate between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
true positive rate. |
Source code in causalflow/basics/metrics.py
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
|
f1_score(gt, cm, alsoOrient=False)
Compute F1-score between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
F1-score. |
Source code in causalflow/basics/metrics.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
|
fully_connected_dag(features, min_lag, max_lag, alsoOrient=False)
Build a fully connected DAG.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
features |
list
|
variable list |
required |
min_lag |
int
|
min time lag. |
required |
max_lag |
int
|
max time lag. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
fully connected dag |
Source code in causalflow/basics/metrics.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
get_FN(gt, cm, alsoOrient=False)
Compute false negative number: edge present in the groundtruth but absent in the causal model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
false negative. |
Source code in causalflow/basics/metrics.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
get_FP(gt, cm, alsoOrient=False)
Compute false positive number: edge present in the causal model but absent in the groundtruth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
false positive. |
Source code in causalflow/basics/metrics.py
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
get_TN(gt, min_lag, max_lag, cm, alsoOrient=False)
Compute true negative number: edge absent in the groundtruth and absent in the causal model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
min_lag |
int
|
min time lag. |
required |
max_lag |
int
|
max time lag. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
true negative. |
Source code in causalflow/basics/metrics.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
|
get_TP(gt, cm, alsoOrient=False)
Compute true positive number: edge present in the causal model and present in the groundtruth.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
true positive. |
Source code in causalflow/basics/metrics.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
|
precision(gt, cm, alsoOrient=False)
Compute Precision between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
precision. |
Source code in causalflow/basics/metrics.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
|
recall(gt, cm, alsoOrient=False)
Compute Recall between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
recall. |
Source code in causalflow/basics/metrics.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
|
shd(gt, cm, alsoOrient=False)
Compute Structural Hamming Distance between ground-truth causal graph and the estimated one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gt |
dict
|
ground-truth SCM. |
required |
cm |
dict
|
estimated SCM. |
required |
alsoOrient |
bool
|
Flag to compute the metric considering also the orientation of the link and not only its presence. Default False. |
False
|
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
shd. |
Source code in causalflow/basics/metrics.py
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
This module provides utilities methods.
cls()
Clear terminal.
Source code in causalflow/basics/utils.py
9 10 11 |
|
create_results_folder(resfolder)
Create results folder if doesn't exist.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resfolder |
str
|
result folder's name. |
required |
Source code in causalflow/basics/utils.py
28 29 30 31 32 33 34 35 |
|
get_selectorpath(resfolder)
Return log file path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resfolder |
str
|
result folder. |
required |
Returns:
Type | Description |
---|---|
str
|
log file path. |
Source code in causalflow/basics/utils.py
14 15 16 17 18 19 20 21 22 23 24 25 |
|
remove_from_list(list, item)
Create a copy of a list and remove from it an item.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
list |
list
|
list. |
required |
item |
any
|
item to remove. |
required |
Returns:
Name | Type | Description |
---|---|---|
list |
list()
|
new list without the item. |
Source code in causalflow/basics/utils.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
|