当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.EPSILON属性代码示例

本文整理汇总了Java中org.apache.commons.math.util.MathUtils.EPSILON属性的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.EPSILON属性的具体用法?Java MathUtils.EPSILON怎么用?Java MathUtils.EPSILON使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.apache.commons.math.util.MathUtils的用法示例。


在下文中一共展示了MathUtils.EPSILON属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: mstep

@Override
	protected void mstep(EMGMM gmm, GaussianMixtureModelEM learner, Matrix X, Matrix responsibilities,
			Matrix weightedXsum,
			double[] norm)
{
		// Eq. 12 from K. Murphy,
		// "Fitting a Conditional Linear Gaussian Distribution"
		final int nfeatures = X.getColumnDimension();
		for (int c = 0; c < learner.nComponents; c++) {
			final Matrix post = responsibilities.getMatrix(0, X.getRowDimension() - 1, c, c).transpose();

			final double factor = 1.0 / (ArrayUtils.sumValues(post.getArray()) + 10 * MathUtils.EPSILON);

			final Matrix pXt = X.transpose();
			for (int i = 0; i < pXt.getRowDimension(); i++)
				for (int j = 0; j < pXt.getColumnDimension(); j++)
					pXt.set(i, j, pXt.get(i, j) * post.get(0, j));

			final Matrix argcv = pXt.times(X).times(factor);
			final Matrix mu = ((FullMultivariateGaussian) gmm.gaussians[c]).mean;

			((FullMultivariateGaussian) gmm.gaussians[c]).covar = argcv.minusEquals(mu.transpose().times(mu))
					.plusEquals(Matrix.identity(nfeatures, nfeatures).times(learner.minCovar));
		}
	}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:25,代码来源:GaussianMixtureModelEM.java

示例2: isSymmetric

/**
 * Check if a matrix is symmetric.
 * @param matrix matrix to check
 * @return true if matrix is symmetric
 */
private boolean isSymmetric(final RealMatrix matrix) {
    final int rows    = matrix.getRowDimension();
    final int columns = matrix.getColumnDimension();
    final double eps  = 10 * rows * columns * MathUtils.EPSILON;
    for (int i = 0; i < rows; ++i) {
        for (int j = i + 1; j < columns; ++j) {
            final double mij = matrix.getEntry(i, j);
            final double mji = matrix.getEntry(j, i);
            if (Math.abs(mij - mji) > (Math.max(Math.abs(mij), Math.abs(mji)) * eps)) {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:20,代码来源:EigenDecompositionImpl.java

示例3: isSymmetric

/**
 * Check if a matrix is symmetric.
 *
 * @param matrix Matrix to check.
 * @param raiseException If {@code true}, the method will throw an
 * exception if {@code matrix} is not symmetric.
 * @return {@code true} if {@code matrix} is symmetric.
 * @throws NonSymmetricMatrixException if the matrix is not symmetric and
 * {@code raiseException} is {@code true}.
 */
private boolean isSymmetric(final RealMatrix matrix,
                            boolean raiseException) {
    final int rows = matrix.getRowDimension();
    final int columns = matrix.getColumnDimension();
    final double eps = 10 * rows * columns * MathUtils.EPSILON;
    for (int i = 0; i < rows; ++i) {
        for (int j = i + 1; j < columns; ++j) {
            final double mij = matrix.getEntry(i, j);
            final double mji = matrix.getEntry(j, i);
            if (FastMath.abs(mij - mji) >
                (FastMath.max(FastMath.abs(mij), FastMath.abs(mji)) * eps)) {
                if (raiseException) {
                    throw new NonSymmetricMatrixException(i, j, eps);
                }
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:EigenDecompositionImpl.java

示例4: isSymmetric

/**
 * Check if a matrix is symmetric.
 * @param matrix
 *            matrix to check
 * @return true if matrix is symmetric
 */
private boolean isSymmetric(final RealMatrix matrix) {
    final int rows = matrix.getRowDimension();
    final int columns = matrix.getColumnDimension();
    final double eps = 10 * rows * columns * MathUtils.EPSILON;
    for (int i = 0; i < rows; ++i) {
        for (int j = i + 1; j < columns; ++j) {
            final double mij = matrix.getEntry(i, j);
            final double mji = matrix.getEntry(j, i);
            if (Math.abs(mij - mji) > (Math.max(Math.abs(mij), Math
                    .abs(mji)) * eps)) {
                return false;
            }
        }
    }
    return true;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:22,代码来源:EigenDecompositionImpl.java

示例5: findEigenvalues

/**
 * Find the realEigenvalues.
 * @exception InvalidMatrixException if a block cannot be diagonalized
 */
private void findEigenvalues()
    throws InvalidMatrixException {

    // compute splitting points
    List<Integer> splitIndices = computeSplits();

    // find realEigenvalues in each block
    realEigenvalues = new double[main.length];
    imagEigenvalues = new double[main.length];
    int begin = 0;
    for (final int end : splitIndices) {
        final int n = end - begin;
        switch (n) {

        case 1:
            // apply dedicated method for dimension 1
            process1RowBlock(begin);
            break;

        case 2:
            // apply dedicated method for dimension 2
            process2RowsBlock(begin);
            break;

        case 3:
            // apply dedicated method for dimension 3
            process3RowsBlock(begin);
            break;

        default:

            // choose an initial shift for LDL<sup>T</sup> decomposition
            final double[] range       = eigenvaluesRange(begin, n);
            final double oneFourth     = 0.25 * (3 * range[0] + range[1]);
            final int oneFourthCount   = countEigenValues(oneFourth, begin, n);
            final double threeFourth   = 0.25 * (range[0] + 3 * range[1]);
            final int threeFourthCount = countEigenValues(threeFourth, begin, n);
            final boolean chooseLeft   = (oneFourthCount - 1) >= (n - threeFourthCount);
            final double lambda        = chooseLeft ? range[0] : range[1];

            tau = (range[1] - range[0]) * MathUtils.EPSILON * n + 2 * minPivot;

            // decompose T-&lambda;I as LDL<sup>T</sup>
            ldlTDecomposition(lambda, begin, n);

            // apply general dqd/dqds method
            processGeneralBlock(n);

            // extract realEigenvalues
            if (chooseLeft) {
                for (int i = 0; i < n; ++i) {
                    realEigenvalues[begin + i] = lambda + work[4 * i];
                }
            } else {
                for (int i = 0; i < n; ++i) {
                    realEigenvalues[begin + i] = lambda - work[4 * i];
                }
            }

        }
        begin = end;
    }

    // sort the realEigenvalues in decreasing order
    Arrays.sort(realEigenvalues);
    int j = realEigenvalues.length - 1;
    for (int i = 0; i < j; ++i) {
        final double tmp = realEigenvalues[i];
        realEigenvalues[i] = realEigenvalues[j];
        realEigenvalues[j] = tmp;
        --j;
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:78,代码来源:EigenDecompositionImpl.java

示例6: include

/**
 * The include method is where the QR decomposition occurs. This statement forms all
 * intermediate data which will be used for all derivative measures.
 * According to the miller paper, note that in the original implementation the x vector
 * is overwritten. In this implementation, the include method is passed a copy of the
 * original data vector so that there is no contamination of the data. Additionally,
 * this method differs slightly from Gentleman's method, in that the assumption is
 * of dense design matrices, there is some advantage in using the original gentleman algorithm
 * on sparse matrices.
 *
 * @param x observations on the regressors
 * @param wi weight of the this observation (-1,1)
 * @param yi observation on the regressand
 */
private void include(final double[] x, final double wi, final double yi) {
    int nextr = 0;
    double w = wi;
    double y = yi;
    double xi;
    double di;
    double wxi;
    double dpi;
    double xk;
    double _w;
    this.rss_set = false;
    sumy = smartAdd(yi, sumy);
    sumsqy = smartAdd(sumsqy, yi * yi);
    for (int i = 0; i < x.length; i++) {
        if (w == 0.0) {
            return;
        }
        xi = x[i];

        if (xi == 0.0) {
            nextr += nvars - i - 1;
            continue;
        }
        di = d[i];
        wxi = w * xi;
        _w = w;
        if (di != 0.0) {
            dpi = smartAdd(di, wxi * xi);
            double tmp = wxi * xi / di;
            if (FastMath.abs(tmp) > MathUtils.EPSILON) {
                w = (di * w) / dpi;
            }
        } else {
            dpi = wxi * xi;
            w = 0.0;
        }
        d[i] = dpi;
        for (int k = i + 1; k < nvars; k++) {
            xk = x[k];
            x[k] = smartAdd(xk, -xi * r[nextr]);
            if (di != 0.0) {
                r[nextr] = smartAdd(di * r[nextr], (_w * xi) * xk) / dpi;
            } else {
                r[nextr] = xk / xi;
            }
            ++nextr;
        }
        xk = y;
        y = smartAdd(xk, -xi * rhs[i]);
        if (di != 0.0) {
            rhs[i] = smartAdd(di * rhs[i], wxi * xk) / dpi;
        } else {
            rhs[i] = xk / xi;
        }
    }
    sserr = smartAdd(sserr, w * y * y);
    return;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:72,代码来源:MillerUpdatingRegression.java

示例7: findEigenvalues

/**
 * Find the realEigenvalues.
 * @exception InvalidMatrixException if a block cannot be diagonalized
 */
private void findEigenvalues()
    throws InvalidMatrixException {

    // compute splitting points
    List<Integer> splitIndices = computeSplits();

    // find realEigenvalues in each block
    realEigenvalues = new double[main.length];
    imagEigenvalues = new double[main.length];
    int begin = 0;
    for (final int end : splitIndices) {
        final int n = end - begin;
        switch (n) {

        case 1:
            // apply dedicated method for dimension 1
            process1RowBlock(begin);
            break;

        case 2:
            // apply dedicated method for dimension 2
            process2RowsBlock(begin);
            break;

        case 3:
            // apply dedicated method for dimension 3
            process3RowsBlock(begin);
            break;

        default:

            // choose an initial shift for LDL<sup>T</sup> decomposition
            final double[] range       = eigenvaluesRange(begin, n);
            final double oneFourth     = 0.25 * (3 * range[0] + range[1]);
            final int oneFourthCount   = countEigenValues(oneFourth, begin, n);
            final double threeFourth   = 0.25 * (range[0] + 3 * range[1]);
            final int threeFourthCount = countEigenValues(threeFourth, begin, n);
            final boolean chooseLeft   = (oneFourthCount - 1) >= (n - threeFourthCount);
            final double lambda        = chooseLeft ? range[0] : range[1];

            tau = (range[1] - range[0]) * MathUtils.EPSILON * n + 2 * minPivot;

            // decompose T&lambda;I as LDL<sup>T</sup>
            ldlTDecomposition(lambda, begin, n);

            // apply general dqd/dqds method
            processGeneralBlock(n);

            // extract realEigenvalues
            if (chooseLeft) {
                for (int i = 0; i < n; ++i) {
                    realEigenvalues[begin + i] = lambda + work[4 * i];
                }
            } else {
                for (int i = 0; i < n; ++i) {
                    realEigenvalues[begin + i] = lambda - work[4 * i];
                }
            }

        }
        begin = end;
    }

    // sort the realEigenvalues in decreasing order
    Arrays.sort(realEigenvalues);
    int j = realEigenvalues.length - 1;
    for (int i = 0; i < j; ++i) {
        final double tmp = realEigenvalues[i];
        realEigenvalues[i] = realEigenvalues[j];
        realEigenvalues[j] = tmp;
        --j;
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:78,代码来源:EigenDecompositionImpl.java

示例8: findEigenvalues

/**
 * Find the realEigenvalues.
 * @exception InvalidMatrixException if a block cannot be diagonalized
 */
private void findEigenvalues()
    throws InvalidMatrixException {

    // compute splitting points
    List<Integer> splitIndices = computeSplits();

    // find realEigenvalues in each block
    realEigenvalues = new double[main.length];
    imagEigenvalues = new double[main.length];
    int begin = 0;
    for (final int end : splitIndices) {
        final int n = end - begin;
        switch (n) {

        case 1:
            // apply dedicated method for dimension 1
            process1RowBlock(begin);
            break;

        case 2:
            // apply dedicated method for dimension 2
            process2RowsBlock(begin);
            break;

        case 3:
            // apply dedicated method for dimension 3
            process3RowsBlock(begin);
            break;

        default:

            // choose an initial shift for LDL<sup>T</sup> decomposition
            final double[] range       = eigenvaluesRange(begin, n);
            final double oneFourth     = 0.25 * (3 * range[0] + range[1]);
            final int oneFourthCount   = countEigenValues(oneFourth, begin, n);
            final double threeFourth   = 0.25 * (range[0] + 3 * range[1]);
            final int threeFourthCount = countEigenValues(threeFourth, begin, n);
            final boolean chooseLeft   = (oneFourthCount - 1) >= (n - threeFourthCount);
            final double lambda        = chooseLeft ? range[0] : range[1];

            tau = (range[1] - range[0]) * MathUtils.EPSILON * n + 2 * minPivot;

            // decompose T&lambda;I as LDL<sup>T</sup>
            ldlTDecomposition(lambda, begin, n);

            // apply general dqd/dqds method
            processGeneralBlock(n);

            // extract realEigenvalues
            if (chooseLeft) {
                for (int i = 0; i < n; ++i) {
                    realEigenvalues[begin + i] = lambda + work[4 * i];
                }
            } else {
                for (int i = 0; i < n; ++i) {
                    realEigenvalues[begin + i] = lambda - work[4 * i];
                }                    
            }

        }
        begin = end;
    }

    // sort the realEigenvalues in decreasing order
    Arrays.sort(realEigenvalues);
    for (int i = 0, j = realEigenvalues.length - 1; i < j; ++i, --j) {
        final double tmp = realEigenvalues[i];
        realEigenvalues[i] = realEigenvalues[j];
        realEigenvalues[j] = tmp;
    }

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:76,代码来源:EigenDecompositionImpl.java

示例9: MillerUpdatingRegression

/**
 * Primary constructor for the MillerUpdatingRegression
 *
 * @param numberOfVariables maximum number of potential regressors
 * @param includeConstant include a constant automatically
 */
public MillerUpdatingRegression(int numberOfVariables, boolean includeConstant) {
    this(numberOfVariables, includeConstant, MathUtils.EPSILON);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:MillerUpdatingRegression.java


注:本文中的org.apache.commons.math.util.MathUtils.EPSILON属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。