Java 类名:com.alibaba.alink.operator.batch.graph.Node2VecWalkBatchOp
Python 类名:Node2VecWalkBatchOp

参数说明

| 名称 | 中文名称 | 描述 | 类型 | 是否必须? | 取值范围 | 默认值 | | —- | —- | —- | —- | —- | —- | —- |

| sourceCol | 起始点列名 | 用来指定起始点列 | String | ✓ | 所选列类型为 [INTEGER, LONG, STRING] | |

| targetCol | 中止点点列名 | 用来指定中止点列 | String | ✓ | 所选列类型为 [INTEGER, LONG, STRING] | |

| walkLength | 游走的长度 | 随机游走完向量的长度 | Integer | ✓ | | |

| walkNum | 路径数目 | 每一个起始点游走出多少条路径 | Integer | ✓ | | |

| delimiter | 分隔符 | 用来分割字符串 | String | | | “ “ |

| isToUndigraph | 是否转无向图 | 选为true时,会将当前图转成无向图,然后再游走 | Boolean | | | false |

| p | 算法参数P | 控制随机游走序列的跳转概率 | Double | | | 1.0 |

| q | 算法参数Q | 控制随机游走序列的跳转概率 | Double | | | 1.0 |

| samplingMethod | 起始点列名 | 用来指定起始点列 | String | | | “ALIAS” |

| weightCol | 权重列名 | 权重列对应的列名 | String | | 所选列类型为 [BIGDECIMAL, BIGINTEGER, BYTE, DOUBLE, FLOAT, INTEGER, LONG, SHORT] | null |

代码示例

Python 代码

  1. from pyalink.alink import *
  2. import pandas as pd
  3. useLocalEnv(1)
  4. df = pd.DataFrame([
  5. [1, 1, 1.0],
  6. [1, 2, 1.0],
  7. [2, 3, 1.0],
  8. [3, 4, 1.0],
  9. [4, 2, 1.0],
  10. [3, 1, 1.0],
  11. [2, 4, 1.0],
  12. [4, 1, 1.0]])
  13. source = BatchOperator.fromDataframe(df, schemaStr="start int, dest int, weight double")
  14. n2vWalkBatchOp = Node2VecWalkBatchOp() \
  15. .setWalkNum(4) \
  16. .setWalkLength(50) \
  17. .setDelimiter(",") \
  18. .setSourceCol("start") \
  19. .setTargetCol("dest") \
  20. .setIsToUndigraph(True) \
  21. .setWeightCol("weight")
  22. n2vWalkBatchOp.linkFrom(source).print()

Java 代码

  1. import org.apache.flink.types.Row;
  2. import com.alibaba.alink.operator.batch.BatchOperator;
  3. import com.alibaba.alink.operator.batch.graph.Node2VecWalkBatchOp;
  4. import com.alibaba.alink.operator.batch.source.MemSourceBatchOp;
  5. import org.junit.Test;
  6. import java.util.Arrays;
  7. import java.util.List;
  8. public class Node2VecWalkBatchOpTest {
  9. @Test
  10. public void testNode2VecWalkBatchOp() throws Exception {
  11. List <Row> df = Arrays.asList(
  12. Row.of(1, 1, 1.0),
  13. Row.of(1, 2, 1.0),
  14. Row.of(2, 3, 1.0),
  15. Row.of(3, 4, 1.0),
  16. Row.of(4, 2, 1.0),
  17. Row.of(3, 1, 1.0),
  18. Row.of(2, 4, 1.0)
  19. );
  20. BatchOperator <?> source = new MemSourceBatchOp(df, "start int, dest int, weight double");
  21. BatchOperator <?> n2vWalkBatchOp = new Node2VecWalkBatchOp()
  22. .setWalkNum(4)
  23. .setWalkLength(50)
  24. .setDelimiter(",")
  25. .setSourceCol("start")
  26. .setTargetCol("dest")
  27. .setIsToUndigraph(true)
  28. .setWeightCol("weight");
  29. n2vWalkBatchOp.linkFrom(source).print();
  30. }
  31. }

运行结果

| path | | —- |

| 3,2,1,1,4,2,3,4,2,1,3,1,1,1,3,1,3,4,1,2,4,3,2,1,1,3,2,4,3,4,1,4,2,1,2,1,4,3,1,2,1,3,4,2,4,3,2,3,4,1 |

| 2,3,2,4,2,1,2,3,2,3,2,4,3,1,2,3,4,2,4,2,3,2,3,2,4,2,1,3,1,4,1,1,4,2,1,2,4,1,3,1,1,3,4,2,4,2,3,4,2,4 |

| 4,2,1,4,1,1,1,2,3,4,2,3,2,3,2,4,1,2,3,2,1,2,4,3,1,1,2,4,3,4,2,4,1,2,4,3,1,4,2,4,2,1,3,4,2,1,2,4,3,4 |

| 4,3,1,1,1,3,4,3,4,1,2,4,2,3,2,1,1,1,2,3,4,1,2,4,3,4,3,1,4,2,3,2,4,1,1,1,3,1,3,2,4,2,4,3,1,1,1,3,2,1 |

| 4,3,1,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