-
Notifications
You must be signed in to change notification settings - Fork 153
Conversation
…etected. Removed -dim option accordingly. Also changed some initial parameter values and minutiae in ChangeFinderUDFTest, and fixed a typo in MathUtils.
Implemented multiple passes for multidimensional covariances to ensure they are full-rank. Changed internals of solving the system of equations from Cholesky Decomposition to LU Decomposition (However, after the multiple changes introduced in this commit, Cholesky Decomposition may be viable again.)
- Pretty comments describing the computation process in more detail. - Using the initial values of the data to break in data structures instead of rand. (Random generation tends to unpredictably reduce detection accuracy in the beginning.) - Added a moving average for change-point scores to improve detection accuracy. - Refactored tests
The Java 7 Double class doesn't have a isFinite(double) method. Using isNaN(double) instead.
…ivemall into L3Sota-feature/cf_sdar_focused
feature/changefinder1d
* Implementation refers to MATLAB's `arburg()` function * Test cases come from outputs of Octave's `arburg()` function
* Replace `-A` with `A` in SDAR1D * Update corresponding test cases
Implement `arburg()` and some minor fixes on MatrixUtils
Support Hellinger-distance-based scoring both on SDAR 1D and 2D
*/ | ||
RealMatrix[][] rhs = MatrixUtils.toeplitz(C, k); | ||
RealMatrix[] lhs = Arrays.copyOfRange(C, 1, k + 1); | ||
RealMatrix R = MatrixUtils.flatten(rhs); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@L3Sota Are you expecting each C_i
as a submatrix and flatting a matrix of matrix to a matrix?
R
will not become a Toeplitz Matrix then and it's hard to solve A
by LUDecomposition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@myui Yes, that's expected. I didn't know non-Toeplitz makes LU decomp so difficult at the time of writing, though :(
Small points: the comments from L116-129 seem to be a little off regarding style, not too important:
- In the Yule-Walker equations, i and j are 1..k, but in the visualisation of the equation the C and A vector-of-matrices' run from 1..n
- The A vector-of-matrices should be horizontal
- Both C'_i and C_i' are used
Is this expected behavior for @Test
public void testFlatten2d() {
RealMatrix[] m1 = new RealMatrix[] { new Array2DRowRealMatrix(new double[] {1, 1.1}), new Array2DRowRealMatrix(new double[] {2, 2.2}), new Array2DRowRealMatrix(new double[] {3, 3.3})};
// {1.0,1.1}
// {2.0,2.2}
// {3.0,3.3}
RealMatrix[][] toeplitz1 = MatrixUtils.toeplitz(m1, 3);
// {1.0,1.1} {2.0,2.2}' {3.0,3.3}'
// {2.0,2.2} {1.0,1.1} {2.0,2.2}'
// {3.0,3.3} {2.0,2.2} {1.0,1.1}
RealMatrix flatten1 = MatrixUtils.flatten(toeplitz1, 2);
// 1.0 0.0 2.0 2.2 3.0 3.3
// 1.1 0.0 0.0 0.0 0.0 0.0
// 2.0 0.0 1.0 0.0 2.0 2.2
// 2.2 0.0 1.1 0.0 0.0 0.0
// 3.0 0.0 2.0 0.0 1.0 0.0
// 3.3 0.0 2.2 0.0 1.1 0.0
} LUDecomposition assume a squared matrix. |
>>> from scipy import linalg
>>> import numpy as np
>>> x = np.array([[1.0,1.1],[2.0,2.2],[3.0,3.3]])
>>> x
array([[ 1. , 1.1],
[ 2. , 2.2],
[ 3. , 3.3]])
>>> linalg.toeplitz(x)
array([[ 1. , 1.1, 2. , 2.2, 3. , 3.3],
[ 1.1, 1. , 1.1, 2. , 2.2, 3. ],
[ 2. , 1.1, 1. , 1.1, 2. , 2.2],
[ 2.2, 2. , 1.1, 1. , 1.1, 2. ],
[ 3. , 2.2, 2. , 1.1, 1. , 1.1],
[ 3.3, 3. , 2.2, 2. , 1.1, 1. ]])
>>> x = np.matrix([[1.0,1.1],[2.0,2.2],[3.0,3.3]])
>>> x
matrix([[ 1. , 1.1],
[ 2. , 2.2],
[ 3. , 3.3]])
>>> linalg.toeplitz(x)
array([[ 1. , 1.1, 2. , 2.2, 3. , 3.3],
[ 1.1, 1. , 1.1, 2. , 2.2, 3. ],
[ 2. , 1.1, 1. , 1.1, 2. , 2.2],
[ 2.2, 2. , 1.1, 1. , 1.1, 2. ],
[ 3. , 2.2, 2. , 1.1, 1. , 1.1],
[ 3.3, 3. , 2.2, 2. , 1.1, 1. ]])
>>> x = np.array([np.array([[1.0,1.1],[2.0,2.2]]),np.array([[3.0,3.3],[4.0,4.4]])])
>>> x
array([[[ 1. , 1.1],
[ 2. , 2.2]],
[[ 3. , 3.3],
[ 4. , 4.4]]])
>>> linalg.toeplitz(x)
array([[ 1. , 1.1, 2. , 2.2, 3. , 3.3, 4. , 4.4],
[ 1.1, 1. , 1.1, 2. , 2.2, 3. , 3.3, 4. ],
[ 2. , 1.1, 1. , 1.1, 2. , 2.2, 3. , 3.3],
[ 2.2, 2. , 1.1, 1. , 1.1, 2. , 2.2, 3. ],
[ 3. , 2.2, 2. , 1.1, 1. , 1.1, 2. , 2.2],
[ 3.3, 3. , 2.2, 2. , 1.1, 1. , 1.1, 2. ],
[ 4. , 3.3, 3. , 2.2, 2. , 1.1, 1. , 1.1],
[ 4.4, 4. , 3.3, 3. , 2.2, 2. , 1.1, 1. ]])
>>> y = x.flatten()
>>> y
array([ 1. , 1.1, 2. , 2.2, 3. , 3.3, 4. , 4.4])
>>> y.shape
(8,) Fix transpose scheme of Before:
if (row < col) {
toeplitz[row][col] = c[col - row];
} else if (row > col) {
toeplitz[row][col] = c[row - col].transpose();
}
After:
if (row < col) {
toeplitz[row][col] = c[col - row].transpose();
} else if (row > col) {
toeplitz[row][col] = c[row - col];
} |
*/ | ||
@Nonnull | ||
public static RealMatrix[][] toeplitz(@Nonnull final RealMatrix[] c, final int dim) { | ||
Preconditions.checkArgument(dim >= 1, "Invliad dimension: " + dim); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invliad
-> Invalid
@L3Sota Thanks. Fixed typos. |
I think it should be flattened as follows to be solved by LU decomposition:
|
5 dimenasional input of @L3Sota 's test Hyperparameters used: set ytics nomirror
set y2tics
set y2r[-5:60]
set style fill transparent solid 0.3 noborder
plot \
for [i=7:11:1] \
"sota5d.dat" using 1:(sum [col=i:11] column(col)) \
title columnheader(i) with filledcurves y1=0 axes x1y1, \
"sota5d.dat" using 1:12 with lines title "outlier" axes x1y2, \
"sota5d.dat" using 1:13 with lines title "change" axes x1y2 |
Changes Unknown when pulling 622a793 on feature/changefinder1d into * on master*. |
Revising the PR of #305 by @L3Sota