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


Java NotConvergedException类代码示例

本文整理汇总了Java中no.uib.cipr.matrix.NotConvergedException的典型用法代码示例。如果您正苦于以下问题:Java NotConvergedException类的具体用法?Java NotConvergedException怎么用?Java NotConvergedException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: convergedI

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
@Override
protected boolean convergedI(double r, Vector x)
        throws IterativeSolverNotConvergedException {
    // Store initial residual
    if (isFirst())
        initR = r;

    // Check for convergence
    if (r < Math.max(rtol * (normA * x.norm(normType) + normb), atol))
        return true;

    // Check for divergence
    if (r > dtol * initR)
        throw new IterativeSolverNotConvergedException(
                NotConvergedException.Reason.Divergence, this);
    if (iter >= maxIter)
        throw new IterativeSolverNotConvergedException(
                NotConvergedException.Reason.Iterations, this);
    if (Double.isNaN(r))
        throw new IterativeSolverNotConvergedException(
                NotConvergedException.Reason.Divergence, this);

    // Neither convergence nor divergence
    return false;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:26,代码来源:MatrixIterationMonitor.java

示例2: convergedI

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
@Override
protected boolean convergedI(double r)
        throws IterativeSolverNotConvergedException {
    // Store initial residual
    if (isFirst())
        initR = r;

    // Check for convergence
    if (r < Math.max(rtol * initR, atol))
        return true;

    // Check for divergence
    if (r > dtol * initR)
        throw new IterativeSolverNotConvergedException(
                NotConvergedException.Reason.Divergence, this);
    if (iter >= maxIter)
        throw new IterativeSolverNotConvergedException(
                NotConvergedException.Reason.Iterations, this);
    if (Double.isNaN(r))
        throw new IterativeSolverNotConvergedException(
                NotConvergedException.Reason.Divergence, this);

    // Neither convergence nor divergence
    return false;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:26,代码来源:DefaultIterationMonitor.java

示例3: boundaryDetection

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
/**
 * Performs boundary detection using trained thresholds.
 * @param parameter Trained thresholds.
 */
public static HashMap<Sequence, ArrayList<int[]>> boundaryDetection(Collection<Sequence> sequence, Parameter parameter, HyperParameter hyperParameter, Config config) throws IOException, UnsupportedAudioFileException, NotConvergedException
{
	HashMap<Sequence, double[]> spectrogramAmplitude=spectrogramAmplitude(sequence, hyperParameter, config);
	HashMap<Sequence, ArrayList<int[]>> noteList=new HashMap<>(sequence.size()*4/3);
	for(Sequence seq: sequence)
	{
		ArrayList<int[]> soundInterval=soundInterval(spectrogramAmplitude.get(seq), parameter.amplitude).stream().collect(Collectors.toCollection(ArrayList::new));
		removeShortGap(soundInterval, parameter.gapLengthLower);
		removeShortNote(soundInterval, parameter.noteLengthLower);
		ArrayList<int[]> note=soundInterval.stream()
				.map(si->new int[]{si[0], si[1]})
				.collect(Collectors.toCollection(ArrayList::new));
		noteList.put(seq, note);
	}
	return noteList;
}
 
开发者ID:cycentum,项目名称:birdsong-recognition,代码行数:21,代码来源:Thresholding.java

示例4: create

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
/**
 * Creates {@link BatchData} by loading wave files and converting them into spectrograms.  
 * 
 * @param numLowerLabel Number of sub-divisions in a single element.
 * @param silentLabelFunc A converter from the number of labels and sub-divisions to the index for the silent label.
 * @param finalInputHeight Input height of the spectrogram, seen from the final output layer.
 * @param waveFileDir Directory of wave files.
 * @param stftParam Parameters for short time Fourier transformation.
 * @param dpssParam Parameter for discrete prolate spheroidal sequences. 
 * @param freqOffset Beginning of the frequency band.
 * @param freqLength Length of the frequency band.
 * @param spectrogramMeanSd Mean and SD of the spectrograms in the training data. Used for input scaling.
 * @param inputHeightUpper Upper value of the combined input spectrogram.
 * @return
 * @throws IOException
 * @throws UnsupportedAudioFileException
 * @throws NotConvergedException
 */
public static BatchData create(List<Sequence> sequence, MersenneTwister random, int numLowerLabel, IntBinaryOperator silentLabelFunc, int finalInputHeight, Path waveFileDir, STFTParam stftParam, int dpssParam, int freqOffset, int freqLength, double[] spectrogramMeanSd, int inputHeightUpper) throws IOException, UnsupportedAudioFileException, NotConvergedException
{
	int marginBegin=finalInputHeight/2;
	int marginEnd=finalInputHeight/2-1;
	HashMap<Sequence, WavePosition> wavePosition=Sequence.wavePositionMap(sequence, waveFileDir);
	for(WavePosition wp: wavePosition.values())
	{
		int waveBegin=wp.getPosition()-marginBegin*stftParam.getShiftLength();
		int waveEnd=wp.getEnd()+marginEnd*stftParam.getShiftLength();
		wp.setPosition(waveBegin);
		wp.setLength(waveEnd-waveBegin);
	}
	HashMap<Sequence, float[]> spectrogram=SoundUtils.spectrogram(wavePosition, stftParam, dpssParam, freqOffset, freqLength);
	SoundUtils.whiteSpectrogram(spectrogram.values(), spectrogramMeanSd[0], spectrogramMeanSd[1]);
	
	ArrayList<float[]> spectrogramList=sequence.stream().map(s->spectrogram.get(s)).collect(Collectors.toCollection(ArrayList::new));
	ArrayList<ArrayList<Integer>> packedSpectrogram=packedSpectrogramIndex(inputHeightUpper, spectrogramList, random, freqLength);
	
	int packedHeight=packedSpectrogram.stream()
			.mapToInt(spec->spec.stream().mapToInt(s->spectrogram.get(sequence.get(s)).length/freqLength).sum())
			.max().getAsInt();
	
	return new BatchData(spectrogramList, packedHeight, packedSpectrogram, sequence, numLowerLabel, silentLabelFunc, marginBegin, marginEnd, finalInputHeight, stftParam);
}
 
开发者ID:cycentum,项目名称:birdsong-recognition,代码行数:43,代码来源:BatchData.java

示例5: factor

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
/**
 * Computes the eigenvalue decomposition of the given matrix
 *
 * @param A Matrix to factorize. Overwritten on return
 * @return The current decomposition
 * @throws NotConvergedException
 */
public NativeEVD factor(DenseMatrix A) throws NotConvergedException {
    if (!A.isSquare())
        throw new IllegalArgumentException("!A.isSquare()");
    else if (A.numRows() != n)
        throw new IllegalArgumentException("A.numRows() != n");

    intW info = new intW(0);
    //NativeBlas.dgeev(jobLeft.netlib(), jobRight.netlib(), n, A.getData(),
    //      LAPACKUtils.ld(n), Wr, Wi, jobLeft == JobEigEnum.All ? Vl.getData() : new double[0],
    //    LAPACKUtils.ld(n), jobRight == JobEigEnum.All ? Vr.getData() : new double[0], LAPACKUtils.ld(n),
    //  work, work.length, info);

    if (info.val > 0)
        throw new NotConvergedException(
                NotConvergedException.Reason.Iterations);
    else if (info.val < 0)
        throw new IllegalArgumentException();

    return this;
}
 
开发者ID:scalalab,项目名称:scalalab,代码行数:28,代码来源:NativeEVD.java

示例6: learnBasisNorm

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
@Override
public void learnBasisNorm(Matrix norm) {
	try {
		final no.uib.cipr.matrix.DenseMatrix mjtA = new no.uib.cipr.matrix.DenseMatrix(norm.getArray());
		final no.uib.cipr.matrix.EconomySVD svd = no.uib.cipr.matrix.EconomySVD.factorize(mjtA);

		final no.uib.cipr.matrix.DenseMatrix output = svd.getVt();

		final int dims = ndims < 0 ? svd.getS().length : ndims;

		basis = new Matrix(output.numColumns(), dims);
		eigenvalues = Arrays.copyOf(svd.getS(), dims);

		final double normEig = 1.0 / (norm.getRowDimension() - 1);
		for (int i = 0; i < eigenvalues.length; i++)
			eigenvalues[i] = eigenvalues[i] * eigenvalues[i] * normEig;

		final double[][] basisData = basis.getArray();
		for (int j = 0; j < output.numColumns(); j++)
			for (int i = 0; i < dims; i++)
				basisData[j][i] = output.get(i, j);

	} catch (final NotConvergedException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:27,代码来源:SvdPrincipalComponentAnalysis.java

示例7: solveHomogeneousSystem

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
/**
 * Solves the system <code>Ax = 0</code>, returning the vector x as an
 * array. Internally computes the least-squares solution using the SVD of
 * <code>A</code>.
 * 
 * @param A
 *            the matrix describing the system
 * @return the solution vector
 */
public static double[] solveHomogeneousSystem(DenseMatrix A) {
	try {
		final SVD svd = SVD.factorize(A);

		final double[] x = new double[svd.getVt().numRows()];
		final int c = svd.getVt().numColumns() - 1;

		for (int i = 0; i < x.length; i++) {
			x[i] = svd.getVt().get(c, i);
		}

		return x;
	} catch (final NotConvergedException e) {
		throw new RuntimeException(e);
	}
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:26,代码来源:MatrixUtils.java

示例8: logGeneralizedDeterminant

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
public static double logGeneralizedDeterminant(SymmTridiagMatrix X) {
	//Set up the eigenvalue solver
	SymmTridiagEVD eigen = new SymmTridiagEVD(X.numRows(), false);
	//Solve for the eigenvalues
	try {
		eigen.factor(X);
	} catch (NotConvergedException e) {
		throw new RuntimeException("Not converged error in generalized determinate calculation.\n" + e.getMessage());
	}

	//Get the eigenvalues
	double[] x = eigen.getEigenvalues();

	double a = 0;
	for (double d : x) {
		if (d > 0.00001)
			a += Math.log(d);
	}

	return a;
}
 
开发者ID:whdc,项目名称:ieo-beast,代码行数:22,代码来源:GMRFSkyrideLikelihood.java

示例9: logGeneralizedDeterminant

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
public static double logGeneralizedDeterminant(SymmTridiagMatrix X) {
    //Set up the eigenvalue solver
    SymmTridiagEVD eigen = new SymmTridiagEVD(X.numRows(), false);
    //Solve for the eigenvalues
    try {
        eigen.factor(X);
    } catch (NotConvergedException e) {
        throw new RuntimeException("Not converged error in generalized determinate calculation.\n" + e.getMessage());
    }

    //Get the eigenvalues
    double[] x = eigen.getEigenvalues();

    double a = 0;
    for (double d : x) {
        if (d > 0.00001)
            a += Math.log(d);
    }

    return a;
}
 
开发者ID:whdc,项目名称:ieo-beast,代码行数:22,代码来源:GaussianProcessSkytrackLikelihood.java

示例10: solve

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    double rho_1 = 1, rho_2 = 1, alpha = 1, beta = 1;

    A.multAdd(-1, x, r.set(b));
    rtilde.set(r);

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        M.apply(r, z);
        M.transApply(rtilde, ztilde);
        rho_1 = z.dot(rtilde);

        if (rho_1 == 0.)
            throw new IterativeSolverNotConvergedException(
                    NotConvergedException.Reason.Breakdown, "rho", iter);

        if (iter.isFirst()) {
            p.set(z);
            ptilde.set(ztilde);
        } else {
            beta = rho_1 / rho_2;
            p.scale(beta).add(z);
            ptilde.scale(beta).add(ztilde);
        }

        A.mult(p, q);
        A.transMult(ptilde, qtilde);

        alpha = rho_1 / ptilde.dot(q);
        x.add(alpha, p);
        r.add(-alpha, q);
        rtilde.add(-alpha, qtilde);

        rho_2 = rho_1;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:41,代码来源:BiCG.java

示例11: main

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
public static void main(String[] args) throws IOException, NotConvergedException {
	final List<Point2dImpl> modelPoints = loadModelPoints();
	final List<List<Point2dImpl>> points = loadImagePoints();

	final List<List<? extends IndependentPair<? extends Point2d, ? extends Point2d>>> pointMatches =
			new ArrayList<List<? extends IndependentPair<? extends Point2d, ? extends Point2d>>>();

	for (int i = 0; i < points.size(); i++) {
		final List<IndependentPair<Point2dImpl, Point2dImpl>> data =
				IndependentPair.pairList(modelPoints, points.get(i));
		pointMatches.add(data);
	}

	final CameraCalibrationZhang calib = new CameraCalibrationZhang(pointMatches, 640, 480);
	// final CameraCalibrationZhang calib = new
	// CameraCalibration(pointMatches);

	System.out.println(calib.getIntrisics());

	System.out.println(calib.calculateError());

	final MBFImage img = new MBFImage(640, 480);
	for (int i = 0; i < pointMatches.get(0).size(); i++) {
		final Point2d model = pointMatches.get(0).get(i).firstObject();
		final Point2d observed = pointMatches.get(0).get(i).secondObject();

		final Point2d proj = calib.getCameras().get(0).project(model);
		img.drawPoint(proj, RGBColour.RED, 1);
		img.drawPoint(observed, RGBColour.GREEN, 1);
	}
	DisplayUtilities.display(img);

	final FImage img1 = ImageUtilities.readF(new URL(
			"http://research.microsoft.com/en-us/um/people/zhang/Calib/Calibration/CalibIm1.gif"));
	DisplayUtilities.display(img1);
	final FImage img2 = calib.getIntrisics().undistort(img1);
	DisplayUtilities.display(img2);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:39,代码来源:TestHarness.java

示例12: estimate_internal

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
private void estimate_internal(Matrix y, Matrix x) {
	try {
		final no.uib.cipr.matrix.DenseMatrix mjtX = new no.uib.cipr.matrix.DenseMatrix(x.getArray());
		no.uib.cipr.matrix.SVD svd;
		svd = no.uib.cipr.matrix.SVD.factorize(mjtX);
		final Matrix u = MatrixUtils.convert(svd.getU(), svd.getU().numRows(), svd.getS().length);
		final Matrix v = MatrixUtils.convert(svd.getVt(), svd.getS().length, svd.getVt().numColumns()).transpose();
		final Matrix d = MatrixUtils.diag(svd.getS());

		weights = v.times(MatrixUtils.pseudoInverse(d)).times(u.transpose()).times(y);
	} catch (final NotConvergedException e) {
		throw new RuntimeException(e.getMessage());
	}

}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:16,代码来源:LinearRegression.java

示例13: pseudoInverse

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
/**
 * Compute the Moore-Penrose Pseudo-Inverse.
 * 
 * @param matrix
 *            The matrix to invert.
 * @return the pseudo-inverse.
 */
public static Matrix pseudoInverse(Matrix matrix) {
	final no.uib.cipr.matrix.DenseMatrix mjtA = new no.uib.cipr.matrix.DenseMatrix(matrix.getArray());
	no.uib.cipr.matrix.SVD svd;

	try {
		svd = no.uib.cipr.matrix.SVD.factorize(mjtA);
	} catch (final NotConvergedException e) {
		throw new RuntimeException(e);
	}

	final Matrix Sinv = new Matrix(matrix.getColumnDimension(), matrix.getRowDimension());

	final double[] Sarr = svd.getS();
	for (int i = 0; i < svd.getS().length; i++) {
		if (Sarr[i] != 0)
			Sinv.set(i, i, 1.0 / Sarr[i]);
	}

	final Matrix Vt = new Matrix(svd.getVt().numRows(), svd.getVt().numColumns());
	for (int r = 0; r < svd.getVt().numRows(); r++) {
		for (int c = 0; c < svd.getVt().numColumns(); c++) {
			Vt.set(r, c, svd.getVt().get(r, c));
		}
	}

	final Matrix U = new Matrix(svd.getU().numRows(), svd.getU().numColumns());
	for (int r = 0; r < svd.getU().numRows(); r++) {
		for (int c = 0; c < svd.getU().numColumns(); c++) {
			U.set(r, c, svd.getU().get(r, c));
		}
	}

	final Matrix pinv = Vt.transpose().times(Sinv).times(U.transpose());

	return pinv;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:44,代码来源:PseudoInverse.java

示例14: reduceRank

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
/**
 * Reduce the rank a matrix by estimating a the best (in a least-squares
 * sense) approximation using the thin SVD.
 * 
 * @param m
 *            the matrix to reduce.
 * @param rank
 *            the desired rank.
 * @return the rank-reduced matrix.
 */
public static Matrix reduceRank(Matrix m, int rank) {
	if (rank > Math.min(m.getColumnDimension(), m.getRowDimension())) {
		return m;
	}

	final no.uib.cipr.matrix.DenseMatrix mjtA = new no.uib.cipr.matrix.DenseMatrix(
			m.getArray());
	no.uib.cipr.matrix.SVD svd;
	try {
		svd = no.uib.cipr.matrix.SVD.factorize(mjtA);
	} catch (final NotConvergedException e) {
		throw new RuntimeException(e);
	}

	final DenseMatrix U = svd.getU();
	final DenseMatrix Vt = svd.getVt();
	final double[] svector = svd.getS();
	final DenseMatrix S = new DenseMatrix(U.numColumns(), Vt.numRows());
	for (int i = 0; i < rank; i++)
		S.set(i, i, svector[i]);

	final DenseMatrix C = new DenseMatrix(U.numRows(), S.numColumns());
	final DenseMatrix out = new DenseMatrix(C.numRows(), Vt.numColumns());
	U.mult(S, C);
	C.mult(Vt, out);

	final Matrix outFinal = convert(out);
	return outFinal;
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:40,代码来源:MatrixUtils.java

示例15: solve

import no.uib.cipr.matrix.NotConvergedException; //导入依赖的package包/类
public Vector solve(Matrix A, Vector b, Vector x)
        throws IterativeSolverNotConvergedException {
    checkSizes(A, b, x);

    double rho_1 = 1, rho_2 = 1, alpha = 1, beta = 1, omega = 1;

    A.multAdd(-1, x, r.set(b));
    rtilde.set(r);

    for (iter.setFirst(); !iter.converged(r, x); iter.next()) {
        rho_1 = rtilde.dot(r);

        if (rho_1 == 0)
            throw new IterativeSolverNotConvergedException(
                    NotConvergedException.Reason.Breakdown, "rho", iter);

        if (omega == 0)
            throw new IterativeSolverNotConvergedException(
                    NotConvergedException.Reason.Breakdown, "omega", iter);

        if (iter.isFirst())
            p.set(r);
        else {
            beta = (rho_1 / rho_2) * (alpha / omega);

            // temp = p - omega * v
            temp.set(-omega, v).add(p);

            // p = r + beta * temp = r + beta * (p - omega * v)
            p.set(r).add(beta, temp);
        }

        M.apply(p, phat);
        A.mult(phat, v);
        alpha = rho_1 / rtilde.dot(v);
        s.set(r).add(-alpha, v);

        x.add(alpha, phat);
        if (iter.converged(s, x))
            return x;

        M.apply(s, shat);
        A.mult(shat, t);
        omega = t.dot(s) / t.dot(t);
        x.add(omega, shat);
        r.set(s).add(-omega, t);

        rho_2 = rho_1;
    }

    return x;
}
 
开发者ID:opprop-benchmarks,项目名称:matrix-toolkits-java,代码行数:53,代码来源:BiCGstab.java


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