ssim.js 4.0.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLA.md +66 -0
- package/CONTRIBUTING.md +119 -0
- package/LICENSE +1 -1
- package/LICENSES/LIVE Images Database +18 -0
- package/LICENSES/Subjective quality assessment - IVC database +5 -0
- package/LICENSES/Wang et al SSIM +24 -0
- package/LICENSES/bezkrovny +49 -0
- package/LICENSES/cell2csv +2 -0
- package/LICENSES/obartra-ssim +21 -0
- package/LICENSES/rhys-e +21 -0
- package/README.md +216 -34
- package/dist/bezkrovnySsim.d.ts +5 -19
- package/dist/bezkrovnySsim.js +113 -72
- package/dist/bezkrovnySsim.js.map +1 -1
- package/dist/browser.d.mts +9 -0
- package/dist/browser.d.ts +9 -0
- package/dist/browser.js +37 -0
- package/dist/browser.js.map +1 -0
- package/dist/browser.mjs +742 -0
- package/dist/browser.mjs.map +7 -0
- package/dist/defaults.d.ts +3 -1
- package/dist/defaults.js +14 -4
- package/dist/defaults.js.map +1 -1
- package/dist/gaussian.d.ts +2 -0
- package/dist/gaussian.js +168 -0
- package/dist/gaussian.js.map +1 -0
- package/dist/gaussianSymmetric.d.ts +3 -0
- package/dist/gaussianSymmetric.js +62 -0
- package/dist/gaussianSymmetric.js.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +8 -19
- package/dist/index.js +19 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +718 -0
- package/dist/index.mjs.map +7 -0
- package/dist/options.d.ts +2 -0
- package/dist/options.js +60 -0
- package/dist/options.js.map +1 -0
- package/dist/originalSsim.d.ts +3 -26
- package/dist/originalSsim.js +5 -57
- package/dist/originalSsim.js.map +1 -1
- package/dist/pixels.d.ts +5 -0
- package/dist/pixels.js +157 -0
- package/dist/pixels.js.map +1 -0
- package/dist/prepare.d.ts +7 -0
- package/dist/prepare.js +48 -0
- package/dist/prepare.js.map +1 -0
- package/dist/referenceSsim.d.ts +4 -0
- package/dist/referenceSsim.js +59 -0
- package/dist/referenceSsim.js.map +1 -0
- package/dist/result.d.ts +2 -0
- package/dist/result.js +20 -0
- package/dist/result.js.map +1 -0
- package/dist/ssim.d.ts +3 -21
- package/dist/ssim.js +4 -126
- package/dist/ssim.js.map +1 -1
- package/dist/ssim.web.js +2 -2
- package/dist/ssim.web.js.map +7 -1
- package/dist/types.d.ts +27 -7
- package/dist/weberSsim.d.ts +19 -0
- package/dist/weberSsim.js +119 -0
- package/dist/weberSsim.js.map +1 -0
- package/package.json +116 -1
- package/src/bezkrovnySsim.ts +133 -67
- package/src/browser.ts +49 -0
- package/src/defaults.ts +16 -6
- package/src/gaussian.ts +228 -0
- package/src/gaussianSymmetric.ts +95 -0
- package/src/index.ts +47 -96
- package/src/options.ts +74 -0
- package/src/originalSsim.ts +9 -79
- package/src/pixels.ts +198 -0
- package/src/prepare.ts +73 -0
- package/src/referenceSsim.ts +71 -0
- package/src/result.ts +23 -0
- package/src/ssim.ts +9 -168
- package/src/types.ts +44 -15
- package/src/weberSsim.ts +132 -0
- package/dist/downsample.d.ts +0 -12
- package/dist/downsample.js +0 -70
- package/dist/downsample.js.map +0 -1
- package/dist/math.d.ts +0 -155
- package/dist/math.js +0 -394
- package/dist/math.js.map +0 -1
- package/dist/matlab/conv2.d.ts +0 -137
- package/dist/matlab/conv2.js +0 -250
- package/dist/matlab/conv2.js.map +0 -1
- package/dist/matlab/filter2.d.ts +0 -18
- package/dist/matlab/filter2.js +0 -53
- package/dist/matlab/filter2.js.map +0 -1
- package/dist/matlab/fspecial.d.ts +0 -39
- package/dist/matlab/fspecial.js +0 -102
- package/dist/matlab/fspecial.js.map +0 -1
- package/dist/matlab/imfilter.d.ts +0 -24
- package/dist/matlab/imfilter.js +0 -84
- package/dist/matlab/imfilter.js.map +0 -1
- package/dist/matlab/index.d.ts +0 -23
- package/dist/matlab/index.js +0 -29
- package/dist/matlab/index.js.map +0 -1
- package/dist/matlab/internal/numbers.d.ts +0 -14
- package/dist/matlab/internal/numbers.js +0 -28
- package/dist/matlab/internal/numbers.js.map +0 -1
- package/dist/matlab/mod.d.ts +0 -21
- package/dist/matlab/mod.js +0 -27
- package/dist/matlab/mod.js.map +0 -1
- package/dist/matlab/normpdf.d.ts +0 -36
- package/dist/matlab/normpdf.js +0 -55
- package/dist/matlab/normpdf.js.map +0 -1
- package/dist/matlab/ones.d.ts +0 -15
- package/dist/matlab/ones.js +0 -22
- package/dist/matlab/ones.js.map +0 -1
- package/dist/matlab/padarray.d.ts +0 -37
- package/dist/matlab/padarray.js +0 -349
- package/dist/matlab/padarray.js.map +0 -1
- package/dist/matlab/rgb2gray.d.ts +0 -15
- package/dist/matlab/rgb2gray.js +0 -58
- package/dist/matlab/rgb2gray.js.map +0 -1
- package/dist/matlab/skip2d.d.ts +0 -34
- package/dist/matlab/skip2d.js +0 -55
- package/dist/matlab/skip2d.js.map +0 -1
- package/dist/matlab/sub.d.ts +0 -17
- package/dist/matlab/sub.js +0 -33
- package/dist/matlab/sub.js.map +0 -1
- package/dist/matlab/transpose.d.ts +0 -18
- package/dist/matlab/transpose.js +0 -34
- package/dist/matlab/transpose.js.map +0 -1
- package/dist/matlab/zeros.d.ts +0 -15
- package/dist/matlab/zeros.js +0 -22
- package/dist/matlab/zeros.js.map +0 -1
- package/dist/version.d.ts +0 -2
- package/dist/version.js +0 -5
- package/dist/version.js.map +0 -1
- package/src/downsample.ts +0 -81
- package/src/math.ts +0 -447
- package/src/matlab/conv2.ts +0 -272
- package/src/matlab/filter2.ts +0 -52
- package/src/matlab/fspecial.ts +0 -107
- package/src/matlab/imfilter.ts +0 -93
- package/src/matlab/index.ts +0 -23
- package/src/matlab/internal/numbers.ts +0 -28
- package/src/matlab/mod.ts +0 -23
- package/src/matlab/normpdf.ts +0 -57
- package/src/matlab/ones.ts +0 -19
- package/src/matlab/padarray.ts +0 -375
- package/src/matlab/rgb2gray.ts +0 -65
- package/src/matlab/skip2d.ts +0 -58
- package/src/matlab/sub.ts +0 -38
- package/src/matlab/transpose.ts +0 -33
- package/src/matlab/zeros.ts +0 -19
- package/src/types/bmp-js.d.ts +0 -1
- package/src/version.ts +0 -2
package/src/matlab/filter2.ts
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { conv2 } from "./conv2";
|
|
2
|
-
import { Matrix, Shape } from "../types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Rotates a matrix 180deg.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* 1 2 3 4 becomes: 8 7 6 5
|
|
9
|
-
* 5 6 7 8 4 3 2 1
|
|
10
|
-
*
|
|
11
|
-
* @method rotate1802d
|
|
12
|
-
* @param {Matrix} mx - The input matrix
|
|
13
|
-
* @returns {Matrix} out - The rotated matrix
|
|
14
|
-
* @private
|
|
15
|
-
* @memberOf matlab
|
|
16
|
-
* @since 0.0.2
|
|
17
|
-
*/
|
|
18
|
-
function rotate1802d({ data: ref, width, height }: Matrix): Matrix {
|
|
19
|
-
const data = new Array(ref.length);
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < height; i++) {
|
|
22
|
-
for (let j = 0; j < width; j++) {
|
|
23
|
-
data[i * width + j] = ref[(height - 1 - i) * width + width - 1 - j];
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
data,
|
|
29
|
-
width,
|
|
30
|
-
height
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Given a matrix X and a two-dimensional FIR filter h, filter2 rotates your filter matrix 180
|
|
36
|
-
* degrees to create a convolution kernel. It then calls conv2, the two-dimensional convolution
|
|
37
|
-
* function, to implement the filtering operation.
|
|
38
|
-
*
|
|
39
|
-
* This method mimics Matlab's `filter2` method
|
|
40
|
-
*
|
|
41
|
-
* @method filter2
|
|
42
|
-
* @param {Matrix} h - The FIR filter
|
|
43
|
-
* @param {Matrix} X - The input matrix
|
|
44
|
-
* @param string [shape='same'] - The convolution shape
|
|
45
|
-
* @returns {Matrix} conv - The 2D convolution of X with h
|
|
46
|
-
* @public
|
|
47
|
-
* @memberOf matlab
|
|
48
|
-
* @since 0.0.2
|
|
49
|
-
*/
|
|
50
|
-
export function filter2(h: Matrix, X: Matrix, shape: Shape = "same"): Matrix {
|
|
51
|
-
return conv2(X, rotate1802d(h), shape);
|
|
52
|
-
}
|
package/src/matlab/fspecial.ts
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { Matrix } from "../types";
|
|
2
|
-
import { sum2d, divide2d } from "../math";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Creates a matrix of lenght `2 * length + 1` with values being the sum of the square of the
|
|
6
|
-
* distance for each component from the center. E.g:
|
|
7
|
-
*
|
|
8
|
-
* For a length of 5 it results in a matrix size of 11. Looking at [0, 0] (distance: [-5, -5] from
|
|
9
|
-
* the center), the value at that position becomes `-5^2 + -5^2 = 50`
|
|
10
|
-
*
|
|
11
|
-
* @method rangeSquare2d
|
|
12
|
-
* @param {Number} length - The maxium distance from the matrix center
|
|
13
|
-
* @returns {Matrix} mx - The generated matrix
|
|
14
|
-
* @private
|
|
15
|
-
* @memberOf matlab
|
|
16
|
-
* @since 0.0.2
|
|
17
|
-
*/
|
|
18
|
-
function rangeSquare2d(length: number): Matrix {
|
|
19
|
-
const size = length * 2 + 1;
|
|
20
|
-
const data = new Array(size ** 2);
|
|
21
|
-
|
|
22
|
-
for (let x = 0; x < size; x++) {
|
|
23
|
-
for (let y = 0; y < size; y++) {
|
|
24
|
-
data[x * size + y] = (x - length) ** 2 + (y - length) ** 2;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
data,
|
|
30
|
-
width: size,
|
|
31
|
-
height: size
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Applies a gaussian filter of sigma to a given matrix
|
|
37
|
-
*
|
|
38
|
-
* @method gaussianFilter2d
|
|
39
|
-
* @param {Matrix} A - The input matrix
|
|
40
|
-
* @param {Number} σ - The sigma value
|
|
41
|
-
* @returns {Matrix} B - The matrix with the gaussian filter applied
|
|
42
|
-
* @private
|
|
43
|
-
* @memberOf matlab
|
|
44
|
-
* @since 0.0.2
|
|
45
|
-
*/
|
|
46
|
-
function gaussianFilter2d(
|
|
47
|
-
{ data: ref, width, height }: Matrix,
|
|
48
|
-
σ: number
|
|
49
|
-
): Matrix {
|
|
50
|
-
const data = new Array(ref.length);
|
|
51
|
-
|
|
52
|
-
for (let x = 0; x < ref.length; x++) {
|
|
53
|
-
data[x] = Math.exp(-ref[x] / (2 * σ ** 2));
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
data,
|
|
58
|
-
width,
|
|
59
|
-
height
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Create predefined 2-D filter
|
|
64
|
-
*
|
|
65
|
-
* `h = fspecial(type, parameters)` accepts the filter specified by type plus additional modifying
|
|
66
|
-
* parameters particular to the type of filter chosen. If you omit these arguments, fspecial uses
|
|
67
|
-
* default values for the parameters.
|
|
68
|
-
*
|
|
69
|
-
* This method mimics Matlab's `fspecial2` method with `type = 'gaussian'`. `hsize` cannot be a
|
|
70
|
-
* vector (unlike Matlab's implementation), only a Number is accepted.
|
|
71
|
-
*
|
|
72
|
-
* `h = fspecial('gaussian', hsize, sigma)` returns a rotationally symmetric Gaussian lowpass filter
|
|
73
|
-
* of size `hsize` with standard deviation sigma (positive). In this implementation `hsize` will
|
|
74
|
-
* always be a scalar, which will result in `h` being a square matrix.
|
|
75
|
-
*
|
|
76
|
-
* The gaussian logic follows: hg(hsize) = e^(-2*hsize^2 / 2σ^2)
|
|
77
|
-
*
|
|
78
|
-
* @example
|
|
79
|
-
* fspecial('gaussian', 3, 1.5) === {
|
|
80
|
-
* data: [
|
|
81
|
-
* 0.094742, 0.118318, 0.094742,
|
|
82
|
-
* 0.118318, 0.147761, 0.118318,
|
|
83
|
-
* 0.094742, 0.118318, 0.094742
|
|
84
|
-
* ],
|
|
85
|
-
* width: 3,
|
|
86
|
-
* height: 3
|
|
87
|
-
* };
|
|
88
|
-
*
|
|
89
|
-
* @method fspecial
|
|
90
|
-
* @param {String} [type='gaussian'] - The type of 2D filter to create (coerced to 'gaussian')
|
|
91
|
-
* @param {Number} [hsize=3] - The length of the filter
|
|
92
|
-
* @param {Number} [σ=1.5] - The filter sigma value
|
|
93
|
-
* @returns {Matrix} c - Returns the central part of the convolution of the same
|
|
94
|
-
* size as `a`.
|
|
95
|
-
* @public
|
|
96
|
-
* @memberOf matlab
|
|
97
|
-
* @since 0.0.2
|
|
98
|
-
*/
|
|
99
|
-
export function fspecial(_type?: "gaussian", hsize = 3, σ = 1.5): Matrix {
|
|
100
|
-
hsize = (hsize - 1) / 2;
|
|
101
|
-
|
|
102
|
-
const pos = rangeSquare2d(hsize);
|
|
103
|
-
const gauss = gaussianFilter2d(pos, σ);
|
|
104
|
-
const total = sum2d(gauss);
|
|
105
|
-
|
|
106
|
-
return divide2d(gauss, total);
|
|
107
|
-
}
|
package/src/matlab/imfilter.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { mod } from "./mod";
|
|
2
|
-
import { padarray, PaddingValue } from "./padarray";
|
|
3
|
-
import { floor } from "../math";
|
|
4
|
-
import { filter2 } from "./filter2";
|
|
5
|
-
import { Matrix, Shape } from "../types";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Adds padding to input matrix A
|
|
9
|
-
*
|
|
10
|
-
* @method padMatrix
|
|
11
|
-
* @param {Matrix} A - The target matrix
|
|
12
|
-
* @param {Number} frows - The number of rows in the filter
|
|
13
|
-
* @param {Number} fcols - The number of columns in the filter
|
|
14
|
-
* @param {String} pad - The type of padding to apply
|
|
15
|
-
* @param {Matrix} B - The padded input matrix
|
|
16
|
-
* @private
|
|
17
|
-
* @memberOf matlab
|
|
18
|
-
*/
|
|
19
|
-
function padMatrix(
|
|
20
|
-
A: Matrix,
|
|
21
|
-
frows: number,
|
|
22
|
-
fcols: number,
|
|
23
|
-
pad: PaddingValue
|
|
24
|
-
): Matrix {
|
|
25
|
-
A = padarray(A, floor([frows / 2, fcols / 2]) as [number, number], pad);
|
|
26
|
-
if (mod(frows, 2) === 0) {
|
|
27
|
-
// remove the last row
|
|
28
|
-
A.data = A.data.slice(0, -A.width);
|
|
29
|
-
A.height--;
|
|
30
|
-
}
|
|
31
|
-
if (mod(fcols, 2) === 0) {
|
|
32
|
-
// remove the last column
|
|
33
|
-
const data = [];
|
|
34
|
-
|
|
35
|
-
for (let x = 0; x < A.data.length; x++) {
|
|
36
|
-
if ((x + 1) % A.width !== 0) {
|
|
37
|
-
data.push(A.data[x]);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
A.data = data;
|
|
41
|
-
A.width--;
|
|
42
|
-
}
|
|
43
|
-
return A;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Gets the `shape` parameter for `conv2` based on the `resSize` parameter for `imfilter`. In most
|
|
48
|
-
* cases they are equivalent except for when `resSize` equals "same" which is converted to "valid".
|
|
49
|
-
*
|
|
50
|
-
* @method getConv2Size
|
|
51
|
-
* @param {String} resSize - The format to use for the `imfilter` call
|
|
52
|
-
* @returns {String} shape - The shape value to use for `conv2`
|
|
53
|
-
* @private
|
|
54
|
-
* @memberOf matlab
|
|
55
|
-
*/
|
|
56
|
-
function getConv2Size(resSize: Shape): Shape {
|
|
57
|
-
if (resSize === "same") {
|
|
58
|
-
resSize = "valid";
|
|
59
|
-
}
|
|
60
|
-
return resSize;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* `B = imfilter(A,f)` filters a 2-dimensional array `A` with the 2-dimensional filter `f`. The
|
|
65
|
-
* result `B` has the same size as `A`.
|
|
66
|
-
*
|
|
67
|
-
* `imfilter` computes each element of the output, `B`. If `A` is an integer, `imfilter` will not
|
|
68
|
-
* truncate the output elements that exceed the range, and it will not round fractional values.
|
|
69
|
-
*
|
|
70
|
-
* This method mimics Matlab's `imfilter` method with `padval = 'symmetric'` without integer
|
|
71
|
-
* rounding. No other options have been implemented and, if set, they will be ignored.
|
|
72
|
-
*
|
|
73
|
-
* @method imfilter
|
|
74
|
-
* @param {Matrix} A - The target matrix
|
|
75
|
-
* @param {Matrix} f - The filter to apply
|
|
76
|
-
* @param {String} [pad="symmetric"] - The type of padding. Only "symmetric" is implemented
|
|
77
|
-
* @param {String} [resSize="same"] - The format to use for the filter size. Valid values are:
|
|
78
|
-
* "same", "valid" and "full"
|
|
79
|
-
* @returns {Matrix} B - The filtered array
|
|
80
|
-
* @public
|
|
81
|
-
* @memberOf matlab
|
|
82
|
-
* @since 0.0.2
|
|
83
|
-
*/
|
|
84
|
-
export function imfilter(
|
|
85
|
-
A: Matrix,
|
|
86
|
-
f: Matrix,
|
|
87
|
-
pad: PaddingValue = "symmetric",
|
|
88
|
-
resSize: Shape = "same"
|
|
89
|
-
) {
|
|
90
|
-
A = padMatrix(A, f.width, f.height, pad);
|
|
91
|
-
resSize = getConv2Size(resSize);
|
|
92
|
-
return filter2(f, A, resSize);
|
|
93
|
-
}
|
package/src/matlab/index.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Implements Matlab functions or functionality.
|
|
3
|
-
*
|
|
4
|
-
* The goal here is not a perfect reproduction of matlab logic but just a minimal implementation
|
|
5
|
-
* needed to correctly reproduce the SSIM matlab script.
|
|
6
|
-
*
|
|
7
|
-
* That means that functionality used will be implemented but additional / unused parameters will
|
|
8
|
-
* not.
|
|
9
|
-
*
|
|
10
|
-
* @namespace matlab
|
|
11
|
-
*/
|
|
12
|
-
export * from "./conv2";
|
|
13
|
-
export * from "./filter2";
|
|
14
|
-
export * from "./fspecial";
|
|
15
|
-
export * from "./imfilter";
|
|
16
|
-
export * from "./normpdf";
|
|
17
|
-
export * from "./ones";
|
|
18
|
-
export * from "./padarray";
|
|
19
|
-
export * from "./rgb2gray";
|
|
20
|
-
export * from "./skip2d";
|
|
21
|
-
export * from "./sub";
|
|
22
|
-
export * from "./transpose";
|
|
23
|
-
export * from "./zeros";
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { Matrix } from "../../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Create a matrix with each cell with the value of `num`
|
|
5
|
-
*
|
|
6
|
-
* @method numbers
|
|
7
|
-
* @param {Number} height - The number of rows
|
|
8
|
-
* @param {Number} width - The number of columns
|
|
9
|
-
* @param {Number} num - The value to set on each cell
|
|
10
|
-
* @returns {Matrix} B - An n-by-m matrix of `num`
|
|
11
|
-
* @private
|
|
12
|
-
* @memberOf matlab
|
|
13
|
-
* @since 0.0.2
|
|
14
|
-
*/
|
|
15
|
-
export function numbers(height: number, width: number, num: number): Matrix {
|
|
16
|
-
const size = width * height;
|
|
17
|
-
const data = new Array(size);
|
|
18
|
-
|
|
19
|
-
for (let x = 0; x < size; x++) {
|
|
20
|
-
data[x] = num;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return {
|
|
24
|
-
data,
|
|
25
|
-
width,
|
|
26
|
-
height
|
|
27
|
-
};
|
|
28
|
-
}
|
package/src/matlab/mod.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `M = mod(X,Y)` returns the remainder `X - Y.*floor(X./Y)` for nonzero `Y`, and returns `X`
|
|
3
|
-
* otherwise. `mod(X,Y)` always differs from `X` by a multiple of `Y`.
|
|
4
|
-
*
|
|
5
|
-
* So long as operands `X` and `Y` are of the same sign, the function `mod(X,Y)` returns the same
|
|
6
|
-
* result as does `rem(X,Y)`. However, for positive `X` and `Y`, `mod(-x,y) = rem(-x,y)+y`.
|
|
7
|
-
*
|
|
8
|
-
* The mod function is useful for congruence relationships: x and y are congruent (mod m) if and
|
|
9
|
-
* only if mod(x,m) == mod(y,m).
|
|
10
|
-
*
|
|
11
|
-
* This method mimics Matlab's `mod` method
|
|
12
|
-
*
|
|
13
|
-
* @method mod
|
|
14
|
-
* @param {Number} x - The dividend
|
|
15
|
-
* @param {Numvwe} y - The divisor
|
|
16
|
-
* @returns {Number} M - Returns the signed remainder after division.
|
|
17
|
-
* @private
|
|
18
|
-
* @memberOf matlab
|
|
19
|
-
* @since 0.0.2
|
|
20
|
-
*/
|
|
21
|
-
export function mod(x: number, y: number): number {
|
|
22
|
-
return x - y * Math.floor(x / y);
|
|
23
|
-
}
|
package/src/matlab/normpdf.ts
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Matrix } from "../types";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* `Y = normpdf(X,μ,σ)` computes the pdf at each of the values in `X` using the normal
|
|
5
|
-
* distribution with mean `μ` and standard deviation `σ`. `X`, `μ`, and `σ` can be vectors,
|
|
6
|
-
* matrices, or multidimensional arrays that all have the same size. A scalar input is expanded to a
|
|
7
|
-
* constant array with the same dimensions as the other inputs. The parameters in `σ` must be
|
|
8
|
-
* positive.
|
|
9
|
-
*
|
|
10
|
-
* The normal pdf is: `y = f(x|μ,σ) = (1 / (σ√(2π))) * e^(-(x-μ)^2/2σ^2)`
|
|
11
|
-
*
|
|
12
|
-
* The likelihood function is the pdf viewed as a function of the parameters. Maximum likelihood
|
|
13
|
-
* estimators (MLEs) are the values of the parameters that maximize the likelihood function for a
|
|
14
|
-
* fixed value of `x`.
|
|
15
|
-
*
|
|
16
|
-
* The standard normal distribution has `µ = 0` and `σ = 1`.
|
|
17
|
-
* If x is standard normal, then `xσ + µ` is also normal with mean `µ` and standard deviation `σ`.
|
|
18
|
-
* Conversely, if `y` is normal with mean `µ` and standard deviation `σ`, then `x = (y – µ) / σ` is
|
|
19
|
-
* standard normal.
|
|
20
|
-
*
|
|
21
|
-
* `Y = normpdf(X)` uses the standard normal distribution (`µ = 0`, `σ = 1`).
|
|
22
|
-
* `Y = normpdf(X,µ)` uses the normal distribution with unit standard deviation (`σ = 1`).
|
|
23
|
-
*
|
|
24
|
-
* @example normpdf({ data: [2, 1, 0, 1, 2], width: 5, height: 1 }, 0, 1.5) =>
|
|
25
|
-
* { data: [ 0.10934, 0.21297, 0.26596, 0.21297, 0.10934], width: 5, height: 1 }
|
|
26
|
-
*
|
|
27
|
-
* @method normpdf
|
|
28
|
-
* @param {Matrix} X - The input matrix
|
|
29
|
-
* @param {Number} [µ=0] - The length of the filter
|
|
30
|
-
* @param {Number} [σ=1] - The filter sigma value
|
|
31
|
-
* @returns {Matrix} Y - Returns the central part of the convolution of the same
|
|
32
|
-
* size as `a`.
|
|
33
|
-
* @public
|
|
34
|
-
* @memberOf matlab
|
|
35
|
-
* @since 0.0.2
|
|
36
|
-
*/
|
|
37
|
-
export function normpdf(
|
|
38
|
-
{ data: ref, width, height }: Matrix,
|
|
39
|
-
µ = 0,
|
|
40
|
-
σ = 1
|
|
41
|
-
): Matrix {
|
|
42
|
-
// data = ((2 * pi)^(-1 / 2)) * exp(-((x - µ) / σ)^2 / 2) / σ;
|
|
43
|
-
const SQ2PI = 2.506628274631000502415765284811;
|
|
44
|
-
const data = new Array(ref.length);
|
|
45
|
-
|
|
46
|
-
for (let i = 0; i < ref.length; i++) {
|
|
47
|
-
const z = (ref[i] - µ) / σ;
|
|
48
|
-
|
|
49
|
-
data[i] = Math.exp(-(z ** 2) / 2) / (σ * SQ2PI);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return {
|
|
53
|
-
data,
|
|
54
|
-
width,
|
|
55
|
-
height
|
|
56
|
-
};
|
|
57
|
-
}
|
package/src/matlab/ones.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Matrix } from "../types";
|
|
2
|
-
import { numbers } from "./internal/numbers";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Create a matrix of all ones
|
|
6
|
-
*
|
|
7
|
-
* This method mimics Matlab's `ones` method
|
|
8
|
-
*
|
|
9
|
-
* @method ones
|
|
10
|
-
* @param {Number} height - The height of the matrix (rows)
|
|
11
|
-
* @param {Number} [width=height] - The width of the matrix (columns)
|
|
12
|
-
* @returns {Matrix} B - An n-by-m matrix of ones
|
|
13
|
-
* @public
|
|
14
|
-
* @memberOf matlab
|
|
15
|
-
* @since 0.0.2
|
|
16
|
-
*/
|
|
17
|
-
export function ones(height: number, width: number = height): Matrix {
|
|
18
|
-
return numbers(height, width, 1);
|
|
19
|
-
}
|