Skip to content

Commit

Permalink
generalize sigmoid transformation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Sep 26, 2024
1 parent 0a23d1e commit 6abe193
Showing 1 changed file with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,24 @@ public class SigmoidTransformation extends AbstractTensorPixelTransformation
public SigmoidTransformation()
{
super(name);
super.setFloatUnitaryOperator( v -> ( float ) ( 1. / ( 1. + Math.exp( -v ) ) ) );
super.setDoubleUnitaryOperator(v -> ( double ) ( 1. / ( 1. + Math.exp( -v ) ) ));
super.setByteUnitaryOperator(v -> ( byte ) ( 1. / ( 1. + Math.exp( -v ) ) ));
super.setUByteUnitaryOperator(v -> ( int ) ( 1. / ( 1. + Math.exp( -v ) ) ));
super.setShortUnitaryOperator(v -> ( short ) ( 1. / ( 1. + Math.exp( -v ) ) ));
super.setUShortUnitaryOperator(v -> ( int ) ( 1. / ( 1. + Math.exp( -v ) ) ));
super.setIntUnitaryOperator(v -> ( int ) ( 1. / ( 1. + Math.exp( -v ) ) ));
super.setUIntUnitaryOperator(v -> ( long ) ( 1. / ( 1. + Math.exp( -v ) ) ));
super.setLongUnitaryOperator(v -> ( long ) ( 1. / ( 1. + Math.exp( -v ) ) ));
}

public < R extends RealType< R > & NativeType< R > > Tensor< FloatType > apply( final Tensor< R > input )
{
super.setFloatUnitaryOperator( v -> ( float ) ( 1. / ( 1. + Math.exp( -v ) ) ) );
return super.apply(input);
}

public void applyInPlace( final Tensor< FloatType > input )
public < R extends RealType< R > & NativeType< R > > void applyInPlace( final Tensor< R > input )
{
super.setFloatUnitaryOperator( v -> ( float ) ( 1. / ( 1. + Math.exp( -v ) ) ) );
super.apply(input);
super.applyInPlace(input);
}
}

0 comments on commit 6abe193

Please sign in to comment.