UNPKG

@obliczeniowo/elementary

Version:
139 lines (134 loc) 4.81 kB
import * as i0 from '@angular/core'; import { EventEmitter, ElementRef, SimpleChanges } from '@angular/core'; import { LinePattern } from '@obliczeniowo/elementary/drawing'; import * as i3 from '@obliczeniowo/elementary/linear-diagram'; import { PointType } from '@obliczeniowo/elementary/linear-diagram'; import { Point2D } from '@obliczeniowo/elementary/classes'; import * as i2 from '@angular/common'; import * as i4 from '@obliczeniowo/elementary/array-to-table'; declare class PerceptronComponent { LinePattern: typeof LinePattern; PointType: typeof PointType; /** * Perceptron inputs table all of the same size must be * * this.x[k].length === this.inputs */ x: number[][]; /** * Perceptron y outputs */ y: number[]; /** * Numbers of rounds */ epoch: number; /** * x to predict y after learning session * * this.xWithoutY[k].length === this.inputs */ xWithoutY: number[][]; /** * Expected input parameters, determine size of x second index table * * this.x[k].length === this.inputs */ inputs: number; /** * Value determine speed of learning. Range: > 0 to 1 */ eta: number; /** */ display: { description?: boolean; diagram?: boolean; }; /** */ set weights(weights: number[]); /** */ get weights(): number[]; /** * Emit predicted value */ predicted: EventEmitter<number[]>; readonly svg: ElementRef<SVGSVGElement>; yPred: number[]; points: Point2D[][]; xMinMax: { min: number; max: number; }; yMinMax: { min: number; max: number; }; private readonly perceptron; ngOnChanges(changes: SimpleChanges): void; getError(): number; getErrors(): number[]; getWeights(): number[]; getWeightsHeaders(): string[]; getXHeaders(): string[]; protected predict(): void; protected recalc(): void; static ɵfac: i0.ɵɵFactoryDeclaration<PerceptronComponent, never>; static ɵcmp: i0.ɵɵComponentDeclaration<PerceptronComponent, "obl-perceptron", never, { "x": { "alias": "x"; "required": false; }; "y": { "alias": "y"; "required": false; }; "epoch": { "alias": "epoch"; "required": false; }; "xWithoutY": { "alias": "xWithoutY"; "required": false; }; "inputs": { "alias": "inputs"; "required": false; }; "eta": { "alias": "eta"; "required": false; }; "display": { "alias": "display"; "required": false; }; "weights": { "alias": "weights"; "required": false; }; }, { "predicted": "predicted"; }, never, never, false, never>; } declare class PerceptronModule { static ɵfac: i0.ɵɵFactoryDeclaration<PerceptronModule, never>; static ɵmod: i0.ɵɵNgModuleDeclaration<PerceptronModule, [typeof PerceptronComponent], [typeof i2.CommonModule, typeof i3.LinearDiagramModule, typeof i4.ArrayToTableModule], [typeof PerceptronComponent]>; static ɵinj: i0.ɵɵInjectorDeclaration<PerceptronModule>; } /** * Single perceptron model */ declare class Perceptron { protected paramsLength: number; protected eta: number; protected weights: number[]; protected error: number; protected errors: number[]; constructor(paramsLength: number, eta: number); protected getFactor(parameters: number[]): number; getError(): number; getErrors(): number[]; setParamsLength(paramsLength: number): void; setEta(eta: number): void; /** * Output perceptron response * @param parameters input parameters * @returns -1 / 1 value */ y(parameters: number[]): 1 | -1; /** * Add training data single record * @param parameters array of this.parameters length * @param y expected value -1 or 1 */ train(parameters: number[], y: number): void; /** * Trening perceptron over the epoch times clear previously created table * @param x input parameters training table (size must be equal parameter field of this class) * @param y output expected value * @param epoch how many time repeat training session */ fit(x: number[][], y: number[], epoch: number): void; /** */ getWeights(): number[]; /** */ setWeights(weights: number[]): void; /** * Calc linear function factors for m dimension that is equal to number of input parameters * and weights inside perceptron * * @param n - determine index for f(xn) function of m dimension, n is integer from range 0 * to m - 1 * @returns table of factors for f(xn) function, to calculate xn of m dimension you need to * calc: * * xn = suma od k = 0 do k < n { f[k] * x[k] } + f[n] */ fXnFactors(n: number): number[]; } export { Perceptron, PerceptronComponent, PerceptronModule };