From 4faf17ea347188ad928dc21dff222e8c22133d2a Mon Sep 17 00:00:00 2001 From: syt123450 <421537891@qq.com> Date: Sat, 24 Nov 2018 23:38:30 -0800 Subject: [PATCH] merge function subtract2d, multiply2d, maximum2d, average2d (#14) --- src/merge/Average.js | 9 +++++++++ src/merge/Maximum.js | 9 +++++++++ src/merge/Multiply.js | 9 +++++++++ src/merge/Subtract.js | 9 +++++++++ src/merge/factory/StrategyFactory.js | 30 +++++++++++++++++++++++++++- src/merge/strategy/Average2d.js | 17 ++++++++++++++++ src/merge/strategy/Maximum2d.js | 17 ++++++++++++++++ src/merge/strategy/Multiply2d.js | 17 ++++++++++++++++ src/merge/strategy/Subtract2d.js | 17 ++++++++++++++++ test/test.html | 2 +- 10 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 src/merge/strategy/Average2d.js create mode 100644 src/merge/strategy/Maximum2d.js create mode 100644 src/merge/strategy/Multiply2d.js create mode 100644 src/merge/strategy/Subtract2d.js diff --git a/src/merge/Average.js b/src/merge/Average.js index 54546a2f..4c9d9ca1 100644 --- a/src/merge/Average.js +++ b/src/merge/Average.js @@ -2,6 +2,7 @@ * @author syt123450 / https://github.com/syt123450 */ +import { MergedLayer2d } from "../layer/abstract/MergedLayer2d"; import { MergedLayer3d } from "../layer/abstract/MergedLayer3d"; function Average( layerList, config ) { @@ -44,6 +45,14 @@ function Average( layerList, config ) { } else if ( layerList[ 0 ].layerDimension === 2 ) { + return new MergedLayer2d( { + + operator: operatorType, + mergedElements: layerList, + userConfig: userConfig + + } ); + } else if ( layerList[ 0 ].layerDimension === 3 ) { return new MergedLayer3d( { diff --git a/src/merge/Maximum.js b/src/merge/Maximum.js index 24cb0078..f64dfd2d 100644 --- a/src/merge/Maximum.js +++ b/src/merge/Maximum.js @@ -2,6 +2,7 @@ * @author syt123450 / https://github.com/syt123450 */ +import { MergedLayer2d } from "../layer/abstract/MergedLayer2d"; import { MergedLayer3d } from "../layer/abstract/MergedLayer3d"; function Maximum( layerList, config ) { @@ -44,6 +45,14 @@ function Maximum( layerList, config ) { } else if ( layerList[ 0 ].layerDimension === 2 ) { + return new MergedLayer2d( { + + operator: operatorType, + mergedElements: layerList, + userConfig: userConfig + + } ); + } else if ( layerList[ 0 ].layerDimension === 3 ) { return new MergedLayer3d( { diff --git a/src/merge/Multiply.js b/src/merge/Multiply.js index 3068eca7..6ec7f1dc 100644 --- a/src/merge/Multiply.js +++ b/src/merge/Multiply.js @@ -2,6 +2,7 @@ * @author syt123450 / https://github.com/syt123450 */ +import { MergedLayer2d } from "../layer/abstract/MergedLayer2d"; import { MergedLayer3d } from "../layer/abstract/MergedLayer3d"; function Multiply( layerList, config ) { @@ -44,6 +45,14 @@ function Multiply( layerList, config ) { } else if ( layerList[ 0 ].layerDimension === 2 ) { + return new MergedLayer2d( { + + operator: operatorType, + mergedElements: layerList, + userConfig: userConfig + + } ); + } else if ( layerList[ 0 ].layerDimension === 3 ) { return new MergedLayer3d( { diff --git a/src/merge/Subtract.js b/src/merge/Subtract.js index 77a22d07..3ab9d1a0 100644 --- a/src/merge/Subtract.js +++ b/src/merge/Subtract.js @@ -2,6 +2,7 @@ * @author syt123450 / https://github.com/syt123450 */ +import { MergedLayer2d } from "../layer/abstract/MergedLayer2d"; import { MergedLayer3d } from "../layer/abstract/MergedLayer3d"; function Subtract( layerList, config ) { @@ -44,6 +45,14 @@ function Subtract( layerList, config ) { } else if ( layerList[ 0 ].layerDimension === 2 ) { + return new MergedLayer2d( { + + operator: operatorType, + mergedElements: layerList, + userConfig: userConfig + + } ); + } else if ( layerList[ 0 ].layerDimension === 3 ) { return new MergedLayer3d( { diff --git a/src/merge/factory/StrategyFactory.js b/src/merge/factory/StrategyFactory.js index b6c44587..aae65e34 100644 --- a/src/merge/factory/StrategyFactory.js +++ b/src/merge/factory/StrategyFactory.js @@ -9,7 +9,11 @@ import { Multiply3d } from "../strategy/Multiply3d"; import { Dot3d } from "../strategy/Dot3d"; import { Maximum3d } from "../strategy/Maximum3d"; import { Average3d } from "../strategy/Average3d"; -import {Add2d} from "../strategy/Add2d"; +import { Add2d } from "../strategy/Add2d"; +import { Subtract2d } from "../strategy/Subtract2d"; +import { Maximum2d } from "../strategy/Maximum2d"; +import { Average2d } from "../strategy/Average2d"; +import { Multiply2d } from "../strategy/Multiply2d"; let StrategyFactory = ( function() { @@ -53,6 +57,30 @@ let StrategyFactory = ( function() { return new Add2d( mergedElements ); + } else if ( operator === "concatenate" ) { + + + + } else if ( operator === "subtract" ) { + + return new Subtract2d( mergedElements ); + + } else if ( operator === "multiply" ) { + + return new Multiply2d( mergedElements ); + + } else if ( operator === "dot" ) { + + + + } else if ( operator === "maximum" ) { + + return new Maximum2d( mergedElements ); + + } else if ( operator === "average" ) { + + return new Average2d( mergedElements ); + } } else if ( dimension === 1 ) { diff --git a/src/merge/strategy/Average2d.js b/src/merge/strategy/Average2d.js new file mode 100644 index 00000000..9b14d213 --- /dev/null +++ b/src/merge/strategy/Average2d.js @@ -0,0 +1,17 @@ +/** + * @author syt123450 / https://github.com/syt123450 + */ + +import { StableMerge2d } from "../abstract/StableMerge2d"; + +function Average2d( mergedElements ) { + + StableMerge2d.call( this, mergedElements ); + + this.strategyType = "Average2d"; + +} + +Average2d.prototype = Object.assign( Object.create( StableMerge2d.prototype ) ); + +export { Average2d }; \ No newline at end of file diff --git a/src/merge/strategy/Maximum2d.js b/src/merge/strategy/Maximum2d.js new file mode 100644 index 00000000..b637c863 --- /dev/null +++ b/src/merge/strategy/Maximum2d.js @@ -0,0 +1,17 @@ +/** + * @author syt123450 / https://github.com/syt123450 + */ + +import { StableMerge2d } from "../abstract/StableMerge2d"; + +function Maximum2d( mergedElements ) { + + StableMerge2d.call( this, mergedElements ); + + this.strategyType = "Maximum2d"; + +} + +Maximum2d.prototype = Object.assign( Object.create( StableMerge2d.prototype ) ); + +export { Maximum2d }; \ No newline at end of file diff --git a/src/merge/strategy/Multiply2d.js b/src/merge/strategy/Multiply2d.js new file mode 100644 index 00000000..26425968 --- /dev/null +++ b/src/merge/strategy/Multiply2d.js @@ -0,0 +1,17 @@ +/** + * @author syt123450 / https://github.com/syt123450 + */ + +import { StableMerge2d } from "../abstract/StableMerge2d"; + +function Multiply2d( mergedElements ) { + + StableMerge2d.call( this, mergedElements ); + + this.strategyType = "Multiply2d"; + +} + +Multiply2d.prototype = Object.assign( Object.create( StableMerge2d.prototype ) ); + +export { Multiply2d }; \ No newline at end of file diff --git a/src/merge/strategy/Subtract2d.js b/src/merge/strategy/Subtract2d.js new file mode 100644 index 00000000..119ce27d --- /dev/null +++ b/src/merge/strategy/Subtract2d.js @@ -0,0 +1,17 @@ +/** + * @author syt123450 / https://github.com/syt123450 + */ + +import { StableMerge2d } from "../abstract/StableMerge2d"; + +function Subtract2d( mergedElements ) { + + StableMerge2d.call( this, mergedElements ); + + this.strategyType = "Subtract2d"; + +} + +Subtract2d.prototype = Object.assign( Object.create( StableMerge2d.prototype ) ); + +export { Subtract2d }; \ No newline at end of file diff --git a/test/test.html b/test/test.html index ab698791..424239cc 100644 --- a/test/test.html +++ b/test/test.html @@ -74,7 +74,7 @@ model.add( conv1d2 ); - let addLayer = TSP.layers.Add( [ conv1d1, conv1d2 ] ); + let addLayer = TSP.layers.Multiply( [ conv1d1, conv1d2 ] ); model.add( addLayer );