Search in sources :

Example 1 with CoLinAdapt._LinAdaptStruct

use of Classifier.supervised.modelAdaptation.CoLinAdapt._LinAdaptStruct in project IR_Base by Linda-sunshine.

the class CLinAdaptWithKmeans method train.

@Override
public double train() {
    int[] iflag = { 0 }, iprint = { -1, 3 };
    double fValue = 0, oldFValue = Double.MAX_VALUE, totalFvalue = 0;
    int displayCount = 0;
    _LinAdaptStruct user;
    init();
    initLBFGS();
    try {
        do {
            fValue = 0;
            initPerIter();
            // accumulate function values and gradients from each user
            for (int i = 0; i < m_userList.size(); i++) {
                user = (_LinAdaptStruct) m_userList.get(i);
                fValue += calculateFuncValue(user);
                calculateGradients(user);
            }
            fValue += calculateRcRg();
            gradientByRcRg();
            if (m_displayLv == 2) {
                gradientTest();
                System.out.println("Fvalue is " + fValue);
            } else if (m_displayLv == 1) {
                if (fValue < oldFValue)
                    System.out.print("o");
                else
                    System.out.print("x");
                if (++displayCount % 100 == 0)
                    System.out.println();
            }
            // In the training process, A is updated.
            LBFGS.lbfgs(m_g.length, 6, _CLinAdaptStruct.sharedA, fValue, m_g, false, m_diag, iprint, 1e-3, 1e-16, iflag);
        } while (iflag[0] != 0);
    } catch (ExceptionWithIflag e) {
        System.out.println("LBFGS fails!!!!");
        e.printStackTrace();
    }
    setPersonalizedModel();
    return totalFvalue;
}
Also used : CoLinAdapt._LinAdaptStruct(Classifier.supervised.modelAdaptation.CoLinAdapt._LinAdaptStruct) ExceptionWithIflag(LBFGS.LBFGS.ExceptionWithIflag)

Example 2 with CoLinAdapt._LinAdaptStruct

use of Classifier.supervised.modelAdaptation.CoLinAdapt._LinAdaptStruct in project IR_Base by Linda-sunshine.

the class CLinAdaptWithKmeans method gradientByR1.

// Calculate the gradients for the use in LBFGS.
@Override
protected void gradientByR1(_AdaptStruct u) {
    _LinAdaptStruct user = (_LinAdaptStruct) u;
    // general enough to accommodate both LinAdapt and CoLinAdapt
    int offset = 2 * m_dim * user.getId();
    // R1 regularization part
    for (int k = 0; k < m_dim; k++) {
        // add 2*eta1*(a_k-1)
        m_g[offset + k] += 2 * m_eta1 * (user.getScaling(k) - 1);
        // add 2*eta2*b_k
        m_g[offset + k + m_dim] += 2 * m_eta2 * user.getShifting(k);
    }
}
Also used : CoLinAdapt._LinAdaptStruct(Classifier.supervised.modelAdaptation.CoLinAdapt._LinAdaptStruct)

Aggregations

CoLinAdapt._LinAdaptStruct (Classifier.supervised.modelAdaptation.CoLinAdapt._LinAdaptStruct)2 ExceptionWithIflag (LBFGS.LBFGS.ExceptionWithIflag)1