UNPKG

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

Version:

Data analysis model package without any dependencies

150 lines (149 loc) 4.45 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 | number)[] | string | number} [inputs] Input node names or const value for the added layer */ add(layer: Layer | PlainLayerObject, name?: string, inputs?: (string | number)[] | string | number): 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 | number | (string | number)[]; name?: string; }; /** * @ignore * @typedef {import("./layer/index").PlainLayerObject} PlainLayerObject */ /** * @typedef {PlainLayerObject & {input?: string | number | (string | number)[], name?: string}} LayerObject */ declare class Node { /** * @param {string} name Name of this node * @param {PlainLayerObject} layer Layer * @param {(string | number)[]} 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 | number)[], parent: { index: number; subscript: number | null; }[], graph: ComputationalGraph); name: string; layer: import("./layer/index.js").PlainLayerObject; input: (string | number)[]; _graph: ComputationalGraph; _parent: { index: number; subscript: number | null; }[]; get parents(): { index: number; subscript: number | null; }[]; /** * @param {Matrix | Matrix[]} value Output value of this node to next layer */ set outputValue(value: Matrix | Matrix[]); /** * Output value of this node to next layer * @type {Matrix | Matrix[]} */ get outputValue(): Matrix | Matrix[]; _outputValue: Matrix<number> | Matrix<number>[]; /** * @param {Matrix[]} value Gradient value of this node from next layer */ set gradientValue(value: Matrix[]); /** * Gradient value of this node from next layer * @type {Matrix[]} */ get gradientValue(): Matrix[]; _gradientValue: Matrix<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 {};