|
1 | 1 | 'use strict'; |
2 | 2 |
|
| 3 | +const arrayUtils = require('ml-array-utils'); |
| 4 | + |
3 | 5 | /** |
4 | 6 | * Real matrix |
5 | 7 | * @class Matrix |
@@ -1026,6 +1028,43 @@ class Matrix extends Array { |
1026 | 1028 | return result; |
1027 | 1029 | } |
1028 | 1030 |
|
| 1031 | + /** |
| 1032 | + * Returns a row-by-row scaled matrix |
| 1033 | + * @param [min=0] - Minimum scaled value |
| 1034 | + * @param [max=1] - Maximum scaled value |
| 1035 | + */ |
| 1036 | + scaleRows(min, max) { |
| 1037 | + min = min === undefined ? 0 : min; |
| 1038 | + max = max === undefined ? 1 : max; |
| 1039 | + var newMatrix = Matrix.empty(this.rows, this.columns); |
| 1040 | + for(var i=0; i<this.rows; i++) { |
| 1041 | + var scaled = arrayUtils.scale(this.getRow(i), {min, max}); |
| 1042 | + newMatrix.setRow(i, scaled); |
| 1043 | + } |
| 1044 | + return newMatrix; |
| 1045 | + } |
| 1046 | + |
| 1047 | + /** |
| 1048 | + * Returns a column-by-column scaled matrix |
| 1049 | + * @param [min=0] - Minimum scaled value |
| 1050 | + * @param [max=1] - Maximum scaled value |
| 1051 | + */ |
| 1052 | + scaleColumns(min, max) { |
| 1053 | + min = min === undefined ? 0 : min; |
| 1054 | + max = max === undefined ? 1 : max; |
| 1055 | + var newMatrix = Matrix.empty(this.rows, this.columns); |
| 1056 | + for(var i=0; i<this.columns; i++) { |
| 1057 | + var scaled = arrayUtils.scale(this.getColumn(i), { |
| 1058 | + min: min, |
| 1059 | + max: max |
| 1060 | + }); |
| 1061 | + newMatrix.setColumn(i, scaled); |
| 1062 | + } |
| 1063 | + return newMatrix; |
| 1064 | + } |
| 1065 | + |
| 1066 | + |
| 1067 | + |
1029 | 1068 | /** |
1030 | 1069 | * Returns the Kronecker product (also known as tensor product) between this and other |
1031 | 1070 | * See https://en.wikipedia.org/wiki/Kronecker_product |
|
0 commit comments