Search in sources :

Example 6 with LinearEquationSystem

use of de.lmu.ifi.dbs.elki.math.linearalgebra.LinearEquationSystem in project elki by elki-project.

the class LevenbergMarquardtMethod method iterate.

/**
 * Perform an iteration of the approximation loop.
 */
public void iterate() {
    // 1+lambda
    for (int i = 0; i < numfit; i++) {
        System.arraycopy(alpha[i], 0, covmat[i], 0, numfit);
        covmat[i][i] *= (1.0 + lambda);
    }
    // System.out.println("Chisq: " + chisq);
    // System.out.println("Lambda: " + lambda);
    // System.out.print("beta: ");
    // for (double d : beta)
    // System.out.print(d + " ");
    // System.out.println();
    // Solve the equation system (Gauss-Jordan)
    LinearEquationSystem ls = new LinearEquationSystem(covmat, beta);
    ls.solveByTotalPivotSearch();
    // update covmat with the inverse
    covmat = ls.getCoefficents();
    // and deltaparams with the solution vector
    deltaparams = ls.getRHS();
    // deltaparams = beta;
    // System.out.print("deltaparams: ");
    // for (double d : deltaparams)
    // System.out.print(d + " ");
    // System.out.println();
    int i2 = 0;
    for (int i = 0; i < numparams; i++) {
        if (dofit[i]) {
            paramstry[i] = params[i] + deltaparams[i2];
            i2++;
        }
    }
    double newchisq = simulateParameters(paramstry);
    // have the results improved?
    if (newchisq < chisq) {
        // TODO: Do we need a larger limit than MIN_NORMAL?
        if (lambda * 0.1 > Double.MIN_NORMAL) {
            lambda = lambda * 0.1;
        }
        chisq = newchisq;
        // and da as new beta
        for (int i = 0; i < numfit; i++) {
            System.arraycopy(covmat[i], 0, alpha[i], 0, numfit);
            beta[i] = deltaparams[i];
        }
        System.arraycopy(paramstry, 0, params, 0, numparams);
    } else {
        // Anyway, this should prevent overflows.
        if (lambda * 10 < Double.MAX_VALUE) {
            lambda = lambda * 10;
        }
    }
}
Also used : LinearEquationSystem(de.lmu.ifi.dbs.elki.math.linearalgebra.LinearEquationSystem)

Aggregations

LinearEquationSystem (de.lmu.ifi.dbs.elki.math.linearalgebra.LinearEquationSystem)6 NonNumericFeaturesException (de.lmu.ifi.dbs.elki.datasource.filter.normalization.NonNumericFeaturesException)2 DependencyDerivator (de.lmu.ifi.dbs.elki.algorithm.DependencyDerivator)1 CASHInterval (de.lmu.ifi.dbs.elki.algorithm.clustering.correlation.cash.CASHInterval)1 ParameterizationFunction (de.lmu.ifi.dbs.elki.algorithm.clustering.correlation.cash.ParameterizationFunction)1 ClusterModel (de.lmu.ifi.dbs.elki.data.model.ClusterModel)1 LinearEquationModel (de.lmu.ifi.dbs.elki.data.model.LinearEquationModel)1 Model (de.lmu.ifi.dbs.elki.data.model.Model)1 Database (de.lmu.ifi.dbs.elki.database.Database)1 ProxyDatabase (de.lmu.ifi.dbs.elki.database.ProxyDatabase)1 ModifiableDBIDs (de.lmu.ifi.dbs.elki.database.ids.ModifiableDBIDs)1 PCAFilteredResult (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCAFilteredResult)1 PCARunner (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.PCARunner)1 SortedEigenPairs (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.SortedEigenPairs)1 StandardCovarianceMatrixBuilder (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.StandardCovarianceMatrixBuilder)1 EigenPairFilter (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.EigenPairFilter)1 FirstNEigenPairFilter (de.lmu.ifi.dbs.elki.math.linearalgebra.pca.filter.FirstNEigenPairFilter)1 ComparableMinHeap (de.lmu.ifi.dbs.elki.utilities.datastructures.heap.ComparableMinHeap)1 IntegerPriorityObject (de.lmu.ifi.dbs.elki.utilities.datastructures.heap.IntegerPriorityObject)1 ObjectHeap (de.lmu.ifi.dbs.elki.utilities.datastructures.heap.ObjectHeap)1