You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
469 B

  1. export class Scaler {
  2. private u = 0
  3. private s = 1
  4. fit(u: number, s: number): void {
  5. this.u = u
  6. this.s = s
  7. }
  8. transform(value: number): number {
  9. return (value - this.u) / this.s
  10. }
  11. inverse(value: number): number {
  12. return value * this.s + this.u
  13. }
  14. }
  15. export const transform = (value: number, u: number, s: number): number => (value - u) / s
  16. export const inverseTransform = (value: number, u: number, s: number): number => value * s + u