Skip to content

Commit

Permalink
Merge pull request #1 from antvis/feat/init
Browse files Browse the repository at this point in the history
feat: init engine
  • Loading branch information
xdddst committed Nov 18, 2020
2 parents 8d0419a + 07f869d commit f8bf4a9
Show file tree
Hide file tree
Showing 17 changed files with 611 additions and 2 deletions.
16 changes: 16 additions & 0 deletions .editorconfig
@@ -0,0 +1,16 @@
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[Makefile]
indent_style = tab
6 changes: 6 additions & 0 deletions .eslintignore
@@ -0,0 +1,6 @@
test/fixtures
dist
es
lib
config/wrapper.js
.docz
41 changes: 41 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,41 @@
module.exports = {
extends: [require.resolve('@umijs/fabric/dist/eslint')],
globals: {
$: true,
_: true,
},
rules: {
'no-bitwise': 0,
'import/order': 0,
'no-plusplus': 0,
'no-console': ['error', { allow: ['warn', 'error'] }],
'operator-assignment': 0,
'consistent-return': 0,
'lines-between-class-members': 0,
'class-methods-use-this': 0,
'lines-between-class-members': 0,
'no-multi-assign': 0,
'no-continue': 0,
'no-underscore-dangle': 0,
'no-useless-constructor': 0,
'prefer-destructuring': 0,
'guard-for-in': 0,
'no-restricted-globals': 0,
'max-classes-per-file': 0,
'no-restricted-syntax': 0,
'prefer-spread': 0,
'@typescript-eslint/camelcase': 0,
'no-loop-func': 0,
'@typescript-eslint/no-loop-func': 0,
'@typescript-eslint/no-redeclare': 0,
'@typescript-eslint/no-shadow': 0,
'@typescript-eslint/no-unused-vars': 0,
'no-param-reassign': 0,
'import/no-extraneous-dependencies': 0,
'no-unused-expressions': 0,
'dot-notation': 0,
'array-callback-return': 0,
'one-var': 0,
'no-lonely-if': 0
},
};
5 changes: 5 additions & 0 deletions .fatherrc.js
@@ -0,0 +1,5 @@
export default {
entry: './src/index.ts',
esm: 'rollup',
cjs: 'rollup'
};
17 changes: 17 additions & 0 deletions .github/workflows/gitleaks.yml
@@ -0,0 +1,17 @@
name: gitleaks

on: [push,pull_request]

jobs:
gitleaks:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: '1'
- name: wget
uses: wei/wget@v1
with:
args: -O .gitleaks.toml https://raw.githubusercontent.com/ycjcl868/gitleaks/master/.gitleaks.toml
- name: gitleaks-action
uses: zricethezav/gitleaks-action@master
83 changes: 83 additions & 0 deletions .gitignore
@@ -0,0 +1,83 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
yarn.lock
lib
es

# lock
package-lock.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

build
dist
temp
.DS_Store
.idea
demos
lib

*.sw*
*.un~

# cache
*.cache
public

esm

es
6 changes: 6 additions & 0 deletions .prettierrc.js
@@ -0,0 +1,6 @@
module.exports = {
semi: true,
trailingComma: 'all',
singleQuote: true,
printWidth: 120,
};
56 changes: 54 additions & 2 deletions README.md
@@ -1,2 +1,54 @@
# vis-predict-engine
可视化预测引擎,目前只用于预测图可视化布局,支持 force 和 radial 两种布局,后续会支持 dagre 和 Concentric 布局。
# @antv/vis-predict-engine 可视化预测引擎

## 图布局预测
目前布局预测的模型由本引擎内置,支持force/radial的二布局分类,后续会支持dagre、concentric等布局。

### 使用方法
```
import { GraphLayoutPredict } from '@antv/vis-predict-engine';
const { predictLayout, confidence } = await GraphLayoutPredict.predict(data, expectLayout, showLog);
# 入参:①data: 图数据(格式见使用示例),必传; ②expectLayout: 期望布局(枚举,目前支持force、radial); ③
showLog: 是否需要打印日志(布尔,默认false)
# 返回:①predictLayout: 预测布局; ②confidence: 置信度。
```

### 使用示例
```
import { GraphLayoutPredict } from '@antv/vis-predict-engine';
const data = {
nodes: [
{
id: '001',
label: '电影awa'
},
{
id: '002',
label: '演员s'
},
{
id: '003',
label: '电影公司a'
},
{
id: '004',
label: '杭州'
},
],
edges: [
{
id: '100000',
label: '主演',
source: '002',
target: '001',
},
{
id: '100001',
label: '出品',
source: '003',
target: '001',
}
]
}
const { predictLayout, confidence } = await GraphLayoutPredict.predict(data, 'force');
```

48 changes: 48 additions & 0 deletions package.json
@@ -0,0 +1,48 @@
{
"name": "@antv/vis-predict-engine",
"version": "0.0.0",
"description": "visualization predict engine",
"repository": {
"type": "git",
"url": "https://github.com/antvis/vis-predict-engine"
},
"license": "MIT",
"author": "https://github.com/orgs/antvis/people",
"main": "src/index.ts",
"files": [
"package.json",
"dist",
"LICENSE",
"README.md"
],
"scripts": {
"start": "father build --watch",
"build": "npm run clean && father build",
"clean": "rimraf es esm lib dist",
"lint": "eslint --ext .js,.jsx,.ts,.tsx --format=pretty \"./\"",
"prettier": "prettier -c --write \"**/*\""
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"prettier --write",
"eslint --ext .js,.jsx,.ts,.tsx",
"git add"
]
},
"devDependencies": {
"eslint": "^7.13.0",
"father": "^2.29.11",
"lint-staged": "^10.5.1",
"pre-commit": "^1.2.2",
"prettier": "^2.1.2",
"rimraf": "^3.0.2"
},
"dependencies": {
"@tensorflow/tfjs": "^2.7.0"
}
}
3 changes: 3 additions & 0 deletions src/graph-predict/index.ts
@@ -0,0 +1,3 @@
import GraphLayoutPredict from './layout';

export { GraphLayoutPredict };
41 changes: 41 additions & 0 deletions src/graph-predict/layout/index.ts
@@ -0,0 +1,41 @@
import * as tf from '@tensorflow/tfjs';
import './layer/graph-conv-layer';
import './layer/pooling-layer';
import { transGraphData, featureProcess, predictLog } from './utils';
import { Layout, GraphData, PredictGraphData } from '../types';

let model: any = null;

const load = tf
.loadLayersModel(
'https://gw.alipayobjects.com/os/bmw-prod/0dbe89ff-b325-458f-85dd-5025866a4870.json',
)
.then(loadedModel => {
model = loadedModel;
return model;
});

const getModel = async () => {
const loadedModel = await load;
return loadedModel;
};

const predictRes = async (data: PredictGraphData) => {
const graphData = featureProcess(data.nodes, data.edges, 16);
const res = await model.predict(graphData).data();
return res;
};

export default {
async predict(data: GraphData, expectLayout: Layout, showLog: boolean = false) {
const graphData = transGraphData(data);
await getModel();
const res = await predictRes(graphData);
const predictLayout = res[0] > res[1] ? Layout.force : Layout.radial;
const confidence = `${(Math.max(res[0], res[1]) * 100).toFixed(2)}%`;
if (showLog) {
predictLog(expectLayout, predictLayout, confidence);
}
return { predictLayout, confidence };
},
};

0 comments on commit f8bf4a9

Please sign in to comment.