dgld.utils.common
- class dgld.utils.common.ExpRecord(filepath='result.csv')[source]
Bases:
object
create a read a existed csv file to record the experiments
- Parameters
filepath (str, filepath) – description, by default ‘result.csv’
Examples
>>> exprecord = ExpRecord() >>> argsdict = vars(args) >>> argsdict['auc'] = 1.0 >>> argsdict['info'] = "test" >>> exprecord.add_record(argsdict)
- class dgld.utils.common.Multidict2dict[source]
Bases:
object
convert multilayer Dict to a single layer Dict
- Parameters
inputs (Dict) –
Dict (input) – {“a”:{“as”:”value”}}
like{ (Maybe multilayer) – {“a”:{“as”:”value”}}
} –
- Returns
Dict
- Return type
a single layer Dict
Examples
>>> tool = Multidict2dict() >>> inputs = { >>> "1layer":{ >>> "2layer_one":{ >>> "3layers1":4, >>> "3layers2":2, >>> }, >>> "2layer_two":2 >>> } >>> } >>> result = tool.solve(inputs) >>> print(result) >>> {'3layers1': 4, '3layers2': 2, '2layer_two': 2}
- class dgld.utils.common.ParameterShower[source]
Bases:
object
show Parameter using texttable
Examples
>>> inputs = { >>> "1layer":{ >>> "2layer_one":{ >>> "3layers1":4, >>> "3layers2":2, >>> }, >>> "2layer_two":2 >>> } >>> } >>> >>> tool = ParameterShower() >>> tool.show_multilayer(inputs) +------------+-------+ | Name | Value | +============+=======+ | 3layers1 | 4 | +------------+-------+ | 3layers2 | 2 | +------------+-------+ | 2layer_two | 2 | +------------+-------+
- dgld.utils.common.allclose(a, b, rtol=0.0001, atol=0.0001)[source]
This function checks if a and b satisfy the condition: |a - b| <= atol + rtol * |b|
- Parameters
input (Tensor) – first tensor to compare
other (Tensor) – second tensor to compare
atol (float, optional) – absolute tolerance. Default: 1e-08
rtol (float, optional) – relative tolerance. Default: 1e-05
- Returns
res – True for close, False for not
- Return type
bool
- dgld.utils.common.is_bidirected(g)[source]
Return whether the graph is a bidirected graph. A graph is bidirected if for any edge \((u, v)\) in \(G\) with weight \(w\), there exists an edge \((v, u)\) in \(G\) with the same weight.
- Parameters
g (DGL.graph) –
- Returns
res – True for bidirected, False for not
- Return type
bool
- dgld.utils.common.load_ACM(raw_dir='D:\\git repo\\DGLD\\src\\dgld/data/')[source]
load ACM dgl graph
- Parameters
raw_dir (str) – Data path. Supports user customization.
- Returns
graph
- Return type
DGL.graph
Examples
>>> graph=load_ACM()[0]
- dgld.utils.common.load_BlogCatalog(raw_dir='D:\\git repo\\DGLD\\src\\dgld/data/')[source]
load BlogCatalog dgl graph
- Parameters
raw_dir (str) – Data path. Supports user customization.
- Returns
graph
- Return type
DGL.graph
Examples
>>> graph=load_BlogCatalog()[0]
- dgld.utils.common.load_Flickr(raw_dir='D:\\git repo\\DGLD\\src\\dgld/data/')[source]
load Flickr dgl graph
- Parameters
raw_dir (str) – Data path. Supports user customization.
- Returns
graph
- Return type
DGL.graph
Examples
>>> graph=load_Flickr()[0]
- dgld.utils.common.load_mat_data2dgl(data_path, verbose=True)[source]
load data from .mat file
- Parameters
data_path (str) – the file to read in
verbose (bool, optional) – print info, by default True
- Returns
graph – the graph read from data_path
- Return type
DGL.graph
- dgld.utils.common.load_ogbn_arxiv(raw_dir='D:\\git repo\\DGLD\\src\\dgld/data/')[source]
Read ogbn-arxiv from dgl.
- Parameters
raw_dir (str) – Data path. Supports user customization.
- Returns
graph – the graph of ogbn-arxiv
- Return type
dgl.graph
- dgld.utils.common.loadargs_from_json(filename, indent=4)[source]
load args from a format json file
- Parameters
filename (file name) – json filename
indent (int, optional) – description, by default 4
- Returns
Dict – args parameters
- Return type
json
- dgld.utils.common.move_start_node_fisrt(pace, start_node)[source]
return a new pace in which the start node is in the first place.
- Parameters
pace (list) – the subgraph of start node
start_node (int) – target node
- Returns
pace – subgraph whose first value is start_node
- Return type
list
- dgld.utils.common.preprocess_features(features)[source]
Functions that process features, here norm in row
- Parameters
features (torch.Tensor) – features to be processed
- Return type
None
- dgld.utils.common.print_format_dict(dict_input)[source]
print dict with json for a decent show
- Parameters
dict_input (Dict) – dict to print
- dgld.utils.common.ranknorm(input_arr)[source]
return the 1-norm of rankdata of input_arr
- Parameters
input_arr (list) – the data to be ranked
- Returns
rank – the 1-norm of rankdata
- Return type
numpy.ndarray