You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

mindspore.dataset.GraphData.rst 12 kB

4 years ago
4 years ago
4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. mindspore.dataset.GraphData
  2. ===========================
  3. .. py:class:: mindspore.dataset.GraphData(dataset_file, num_parallel_workers=None, working_mode='local', hostname='127.0.0.1', port=50051, num_client=1, auto_shutdown=True)
  4. 从共享文件或数据库中读取用于GNN训练的图数据集。
  5. **参数:**
  6. - **dataset_file** (str) - 数据集文件路径。
  7. - **num_parallel_workers** (int, 可选) - 读取数据的工作线程数,默认值:None,使用mindspore.dataset.config中配置的线程数。
  8. - **working_mode** (str, 可选) - 设置工作模式,目前支持'local'/'client'/'server',默认值:'local'。
  9. - **local**:用于非分布式训练场景。
  10. - **client**:用于分布式训练场景。客户端不加载数据,而是从服务器获取数据。
  11. - **server**:用于分布式训练场景。服务器加载数据并可供客户端使用。
  12. - **hostname** (str, 可选) - 图数据集服务器的主机名。该参数仅在工作模式设置为 'client' 或 'server' 时有效,默认值:'127.0.0.1'。
  13. - **port** (int, 可选) - 图数据服务器的端口,取值范围为1024-65535。此参数仅当工作模式设置为 'client' 或 'server' 时有效,默认值:50051。
  14. - **num_client** (int, 可选) - 期望连接到服务器的最大客户端数。服务器将根据该参数分配资源。该参数仅在工作模式设置为 'server' 时有效,默认值:1。
  15. - **auto_shutdown** (bool, 可选) - 当工作模式设置为 'server' 时有效。当连接的客户端数量达到 `num_client` ,且没有客户端正在连接时,服务器将自动退出,默认值:True。
  16. **异常:**
  17. - **ValueError** - `dataset_file` 路径下数据文件不存在或无效。
  18. - **ValueError** - `num_parallel_workers` 参数超过系统最大线程数。
  19. - **ValueError** - `working_mode` 参数取值不为'local', 'client' 或 'server'。
  20. - **TypeError** - `hostname` 参数类型错误。
  21. - **ValueError** - `port` 参数不在范围[1024, 65535]内。
  22. - **ValueError** - `num_client` 参数不在范围[1, 255]内。
  23. .. py:method:: get_all_edges(edge_type)
  24. 获取图的所有边。
  25. **参数:**
  26. - **edge_type** (int) - 指定边的类型,在数据集转换为MindRecord格式时,需要指定 `edge_type` 的值,并在此API中对应使用。详见 `加载图数据集 <https://www.mindspore.cn/docs/programming_guide/zh-CN/master/load_dataset_gnn.html>`_ 。
  27. **返回:**
  28. numpy.ndarray,包含边的数组。
  29. **异常:**
  30. **TypeError**:参数 `edge_type` 的类型不为整型。
  31. .. py:method:: get_all_neighbors(node_list, neighbor_type, output_format=OutputFormat.NORMAL)
  32. 获取 `node_list` 所有节点的相邻节点,以 `neighbor_type` 类型返回。格式的定义参见以下示例:1表示两个节点之间连接,0表示不连接。
  33. .. list-table:: 邻接矩阵
  34. :widths: 20 20 20 20 20
  35. :header-rows: 1
  36. * -
  37. - 0
  38. - 1
  39. - 2
  40. - 3
  41. * - 0
  42. - 0
  43. - 1
  44. - 0
  45. - 0
  46. * - 1
  47. - 0
  48. - 0
  49. - 1
  50. - 0
  51. * - 2
  52. - 1
  53. - 0
  54. - 0
  55. - 1
  56. * - 3
  57. - 1
  58. - 0
  59. - 0
  60. - 0
  61. .. list-table:: 普通格式
  62. :widths: 20 20 20 20 20
  63. :header-rows: 1
  64. * - src
  65. - 0
  66. - 1
  67. - 2
  68. - 3
  69. * - dst_0
  70. - 1
  71. - 2
  72. - 0
  73. - 1
  74. * - dst_1
  75. - -1
  76. - -1
  77. - 3
  78. - -1
  79. .. list-table:: COO格式
  80. :widths: 20 20 20 20 20 20
  81. :header-rows: 1
  82. * - src
  83. - 0
  84. - 1
  85. - 2
  86. - 2
  87. - 3
  88. * - dst
  89. - 1
  90. - 2
  91. - 0
  92. - 3
  93. - 1
  94. .. list-table:: CSR格式
  95. :widths: 40 20 20 20 20 20
  96. :header-rows: 1
  97. * - offsetTable
  98. - 0
  99. - 1
  100. - 2
  101. - 4
  102. -
  103. * - dstTable
  104. - 1
  105. - 2
  106. - 0
  107. - 3
  108. - 1
  109. **参数:**
  110. - **node_list** (Union[list, numpy.ndarray]) - 给定的节点列表。
  111. - **neighbor_type** (int) - 指定相邻节点的类型。
  112. - **output_format** (OutputFormat, 可选) - 输出存储格式,默认值:mindspore.dataset.OutputFormat.NORMAL,取值范围:[OutputFormat.NORMAL, OutputFormat.COO, OutputFormat.CSR]。
  113. **返回:**
  114. 对于普通格式或COO格式,将返回numpy.ndarray类型的数组表示相邻节点。如果指定了CSR格式,将返回两个numpy.ndarray数组,第一个表示偏移表,第二个表示相邻节点。
  115. **异常:**
  116. - **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
  117. - **TypeError** - 参数 `neighbor_type` 的类型不为整型。
  118. .. py:method:: get_all_nodes(node_type)
  119. 获取图中的所有节点。
  120. **参数:**
  121. - **node_type** (int) - 指定节点的类型。在数据集转换为MindRecord格式时,需要指定 `node_type` 的值,并在此API中对应使用。详见 `加载图数据集 <https://www.mindspore.cn/docs/programming_guide/zh-CN/master/load_dataset_gnn.html>`_ 。
  122. **返回:**
  123. numpy.ndarray,包含节点的数组。
  124. **异常:**
  125. **TypeError**:参数 `node_type` 的类型不为整型。
  126. .. py:method:: get_edge_feature(edge_list, feature_types)
  127. 获取 `edge_list` 列表中边的特征,以 `feature_types` 类型返回。
  128. **参数:**
  129. - **edge_list** (Union[list, numpy.ndarray]) - 包含边的列表。
  130. - **feature_types** (Union[list, numpy.ndarray]) - 包含给定特征类型的列表。
  131. **返回:**
  132. numpy.ndarray,包含特征的数组。
  133. **异常:**
  134. - **TypeError** - 参数 `edge_list` 的类型不为列表或numpy.ndarray。
  135. - **TypeError** - 参数 `feature_types` 的类型不为列表或numpy.ndarray。
  136. .. py:method:: get_edges_from_nodes(node_list)
  137. 从节点获取边。
  138. **参数:**
  139. - **node_list** (Union[list[tuple], numpy.ndarray]) - 含一个或多个图节点ID对的列表。
  140. **返回:**
  141. numpy.ndarray,含一个或多个边ID的数组。
  142. **异常:**
  143. **TypeError**:参数 `edge_list` 的类型不为列表或numpy.ndarray。
  144. .. py:method:: get_neg_sampled_neighbors(node_list, neg_neighbor_num, neg_neighbor_type)
  145. 获取 `node_list` 列表中节所有点的负样本相邻节点,以 `neg_neighbor_type` 类型返回。
  146. **参数:**
  147. - **node_list** (Union[list, numpy.ndarray]) - 包含节点的列表。
  148. - **neg_neighbor_num** (int) - 采样的相邻节点数量。
  149. - **neg_neighbor_type** (int) - 指定负样本相邻节点的类型。
  150. **返回:**
  151. numpy.ndarray,包含相邻节点的数组。
  152. **异常:**
  153. - **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
  154. - **TypeError** - 参数 `neg_neighbor_num` 的类型不为整型。
  155. - **TypeError** - 参数 `neg_neighbor_type` 的类型不为整型。
  156. .. py:method:: get_node_feature(node_list, feature_types)
  157. 获取 `node_list` 中节点的特征,以 `feature_types` 类型返回。
  158. **参数:**
  159. - **node_list** (Union[list, numpy.ndarray]) - 包含节点的列表。
  160. - **feature_types** (Union[list, numpy.ndarray]) - 指定特征的类型。
  161. **返回:**
  162. numpy.ndarray,包含特征的数组。
  163. **异常:**
  164. - **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
  165. - **TypeError** - 参数 `feature_types` 的类型不为列表或numpy.ndarray。
  166. .. py:method:: get_nodes_from_edges(edge_list)
  167. 从图中的边获取节点。
  168. **参数:**
  169. - **edge_list** (Union[list, numpy.ndarray]) - 包含边的列表。
  170. **返回:**
  171. numpy.ndarray,包含节点的数组。
  172. **异常:**
  173. **TypeError** 参数 `edge_list` 不为列表或ndarray。
  174. .. py:method:: get_sampled_neighbors(node_list, neighbor_nums, neighbor_types, strategy=SamplingStrategy.RANDOM)
  175. 获取已采样相邻节点信息。此API支持多跳相邻节点采样。即将上一次采样结果作为下一跳采样的输入,最多允许6跳。采样结果平铺成列表,格式为[input node, 1-hop sampling result, 2-hop samling result ...]
  176. **参数:**
  177. - **node_list** (Union[list, numpy.ndarray]) - 包含节点的列表。
  178. - **neighbor_nums** (Union[list, numpy.ndarray]) - 每跳采样的相邻节点数。
  179. - **neighbor_types** (Union[list, numpy.ndarray]) - 每跳采样的相邻节点类型。
  180. - **strategy** (SamplingStrategy, 可选) - 采样策略,默认值:mindspore.dataset.SamplingStrategy.RANDOM。取值范围:[SamplingStrategy.RANDOM, SamplingStrategy.EDGE_WEIGHT]。
  181. - **SamplingStrategy.RANDOM**:随机抽样,带放回采样。
  182. - **SamplingStrategy.EDGE_WEIGHT**:以边缘权重为概率进行采样。
  183. **返回:**
  184. numpy.ndarray,包含相邻节点的数组。
  185. **异常:**
  186. - **TypeError** - 参数 `node_list` 的类型不为列表或numpy.ndarray。
  187. - **TypeError** - 参数 `neighbor_nums` 的类型不为列表或numpy.ndarray。
  188. - **TypeError** - 参数 `neighbor_types` 的类型不为列表或numpy.ndarray。
  189. .. py:method:: graph_info()
  190. 获取图的元信息,包括节点数、节点类型、节点特征信息、边数、边类型、边特征信息。
  191. **返回:**
  192. dict,图的元信息。键为 `node_num` 、 `node_type` 、 `node_feature_type` 、 `edge_num` 、 `edge_type` 和 `edge_feature_type` 。
  193. .. py:method:: random_walk(target_nodes, meta_path, step_home_param=1.0, step_away_param=1.0, default_node=-1)
  194. 在节点中的随机游走。
  195. **参数:**
  196. - **target_nodes** (list[int]) - 随机游走中的起始节点列表。
  197. - **meta_path** (list[int]) - 每个步长的节点类型。
  198. - **step_home_param** (float, 可选) - 返回 `node2vec算法 <https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf>`_ 中的超参,默认值:1.0。
  199. - **step_away_param** (float, 可选) - `node2vec算法 <https://www.kdd.org/kdd2016/papers/files/rfp0218-groverA.pdf>`_ 中的in和out超参,默认值:1.0。
  200. - **default_node** (int, 可选) - 如果找不到更多相邻节点,则为默认节点,默认值:-1,表示不给定节点。
  201. **返回:**
  202. numpy.ndarray,包含节点的数组。
  203. **异常:**
  204. - **TypeError** - 参数 `target_nodes` 的类型不为列表或numpy.ndarray。
  205. - **TypeError** - 参数 `meta_path` 的类型不为列表或numpy.ndarray。