UNPKG

@ai-on-browser/data-analysis-models

Version:

Data analysis model package without any dependencies

155 lines (154 loc) 4.47 kB
/** * Computational graph for Neuralnetwork structure */ export default class ComputationalGraph { /** * Returns Graph. * @param {LayerObject[]} nodes Array of object represented a graph * @returns {ComputationalGraph} Graph */ static fromObject(nodes: LayerObject[]): ComputationalGraph; /** * Load onnx model. * @param {Uint8Array | ArrayBuffer | File} buffer File * @returns {Promise<ComputationalGraph>} Loaded graph */ static fromONNX(buffer: Uint8Array | ArrayBuffer | File): Promise<ComputationalGraph>; _nodes: any[]; _order: any[]; /** * Graph nodes * @type {Node[]} */ get nodes(): Node[]; /** * Input nodes * @type {Node[]} */ get inputNodes(): Node[]; /** * Output nodes * @type {Node[]} */ get outputNodes(): Node[]; /** * Number of nodes * @type {number} */ get size(): number; /** * Returns object representation. * @returns {LayerObject[]} Object represented this graph */ toObject(): LayerObject[]; /** * Returns a string of DOT format. * @returns {string} String of DOT format */ toDot(): string; /** * Returns onnx model * @returns {Uint8Array} onnx model byte array */ toONNX(): Uint8Array; /** * Add a layer. * @param {Layer | PlainLayerObject} layer Added layer * @param {string} [name] Node name * @param {string[] | string} [inputs] Input node names for the added layer */ add(layer: Layer | PlainLayerObject, name?: string, inputs?: string[] | string): void; /** * Bind values to layers * @param {object} values Binding values */ bind(values: object): void; _calcOrder(): void; /** * Returns calculated values. * @param {(string | number)[]} [require] Name or index of nodes at least calculated */ calc(require?: (string | number)[]): void; /** * Returns gradient values. * @param {Matrix} [e] Input of gradient * @returns {Matrix} Output of gradient */ grad(e?: Matrix): Matrix; /** * Returns a specific name node. * @param {string} name Node name * @returns {Node=} Node */ getNode(name: string): Node | undefined; } export type PlainLayerObject = import("./layer/index").PlainLayerObject; export type LayerObject = PlainLayerObject & { input?: string | string[]; name?: string; }; /** * @ignore * @typedef {import("./layer/index").PlainLayerObject} PlainLayerObject */ /** * @typedef {PlainLayerObject & {input?: string | string[], name?: string}} LayerObject */ declare class Node { /** * @param {string} name Name of this node * @param {PlainLayerObject} layer Layer * @param {string[]} input Input node names * @param {{index: number, subscript: number | null}[]} parent Parent node informations * @param {ComputationalGraph} graph graph */ constructor(name: string, layer: PlainLayerObject, input: string[], parent: { index: number; subscript: number | null; }[], graph: ComputationalGraph); name: string; layer: import("./layer/index.js").PlainLayerObject; input: string[]; _graph: ComputationalGraph; _parent: { index: number; subscript: number | null; }[]; get parents(): { index: number; subscript: string | number; }[]; /** * @param {Matrix | Matrix[]} value Output value of this node to next layer */ set outputValue(value: Matrix<number> | Matrix<number>[]); /** * Output value of this node to next layer * @type {Matrix | Matrix[]} */ get outputValue(): Matrix<number> | Matrix<number>[]; _outputValue: Matrix<number> | Matrix<number>[]; /** * @param {Matrix[]} value Gradient value of this node from next layer */ set gradientValue(value: Matrix<number>[]); /** * Gradient value of this node from next layer * @type {Matrix[]} */ get gradientValue(): Matrix<number>[]; _gradientValue: Matrix<number>[]; /** * Output value size * @type {number[]} */ get lastOutputSize(): number[]; /** * Returns object representation. * @returns {LayerObject} Object represented this node */ toObject(): LayerObject; } import Layer from './layer/base.js'; import Matrix from '../../util/matrix.js'; export {};