import * as tf from '@tensorflow/tfjs-node' ; import { ValueError } from './errors' ; export class SigmoidRange extends tf . layers . Layer { high : number ; low : number ; constructor ( config ) { super ( config ) ; if ( this . low > this . high ) { throw new ValueError ( `SigmoidRange max can not be smaller or equal to min` ) ; } this . high = config . high ; this . low = config . low ; } call ( inputs , kwargs ) { const x = tf . sigmoid ( getExactlyOneTensor ( inputs ) ) . mul ( this . high - this . low ) . add ( this . low ) ; return x ; } getConfig ( ) { const config = { high : this . high , low : this . low } ; const baseConfig = super . getConfig ( ) ; Object . assign ( config , baseConfig ) ; return config ; } static get className ( ) { return 'SigmoidRange' ; } } tf . serialization . registerClass ( SigmoidRange ) ; function getExactlyOneTensor ( xs ) { let x ; if ( Array . isArray ( xs ) ) { if ( xs . length !== 1 ) { } x = xs [ 0 ] ; } else { x = xs ; } return x ; }