Search in sources :

Example 21 with com.model._User

use of com.model._User in project IR_Base by Linda-sunshine.

the class UserAnalyzer method loadSVDFile.

// Added by Lin: Load the svd file to get the low dim representation of users.
public void loadSVDFile(String filename) {
    try {
        // Construct the <userID, user> map first.
        int count = 0;
        HashMap<String, double[]> IDLowDimMap = new HashMap<String, double[]>();
        int skip = 3;
        File file = new File(filename);
        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
        String line, userID;
        String[] strs;
        double[] lowDims;
        // Skip the first three lines.
        while (skip-- > 0) reader.readLine();
        while ((line = reader.readLine()) != null) {
            strs = line.split("\\s+");
            userID = strs[0];
            lowDims = new double[strs.length - 1];
            for (int i = 1; i < strs.length; i++) lowDims[i - 1] = Double.valueOf(strs[i]);
            IDLowDimMap.put(userID, lowDims);
            count++;
        }
        // Currently, there are missing low dimension representation of users.
        for (_User u : m_users) {
            if (IDLowDimMap.containsKey(u.getUserID()))
                u.setLowDimProfile(IDLowDimMap.get(u.getUserID()));
            else {
                System.out.println("[Warning]" + u.getUserID() + " : low dim profile missing.");
                u.setLowDimProfile(new double[11]);
            }
        }
        reader.close();
        System.out.format("Ther are %d users and %d users' low dimension profile are loaded.\n", m_users.size(), count);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) BufferedReader(java.io.BufferedReader) structures._User(structures._User) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 22 with com.model._User

use of com.model._User in project IR_Base by Linda-sunshine.

the class IndividualSVM method loadSuperUsers.

public void loadSuperUsers(ArrayList<_User> userList) {
    m_supUserList = new ArrayList<_AdaptStruct>();
    for (_User user : userList) m_supUserList.add(new _AdaptStruct(user));
    m_pWeights = new double[m_featureSize + 1];
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._User(structures._User)

Example 23 with com.model._User

use of com.model._User in project IR_Base by Linda-sunshine.

the class CoLinAdaptWithDiffFeatureGroups method constructUserList.

@Override
void constructUserList(ArrayList<_User> userList) {
    int ASize = 2 * m_dimA;
    int BSize = 2 * m_dimB;
    // step 1: create space
    m_userList = new ArrayList<_AdaptStruct>();
    for (int i = 0; i < userList.size(); i++) {
        _User user = userList.get(i);
        m_userList.add(new _CoLinAdaptDiffFvGroupsStruct(user, m_dimA, i, m_topK, m_dimB));
    }
    m_pWeights = new double[m_gWeights.length];
    // huge space consumption
    _CoLinAdaptDiffFvGroupsStruct.sharedA = new double[getASize()];
    _CoLinAdaptDiffFvGroupsStruct.sharedB = new double[getBSize()];
    // step 2: copy each user's A and B to shared A and B in _CoLinAdaptStruct
    _CoLinAdaptDiffFvGroupsStruct user;
    for (int i = 0; i < m_userList.size(); i++) {
        user = (_CoLinAdaptDiffFvGroupsStruct) m_userList.get(i);
        System.arraycopy(user.m_A, 0, _CoLinAdaptDiffFvGroupsStruct.sharedA, ASize * i, ASize);
        System.arraycopy(user.m_B, 0, _CoLinAdaptDiffFvGroupsStruct.sharedB, BSize * i, BSize);
    }
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._User(structures._User)

Example 24 with com.model._User

use of com.model._User in project IR_Base by Linda-sunshine.

the class LinAdapt method loadUsers.

// Initialize the weights of the transformation matrix.
@Override
public void loadUsers(ArrayList<_User> userList) {
    m_userList = new ArrayList<_AdaptStruct>();
    for (_User user : userList) m_userList.add(new _LinAdaptStruct(user, m_dim));
    m_pWeights = new double[m_gWeights.length];
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._User(structures._User)

Example 25 with com.model._User

use of com.model._User in project IR_Base by Linda-sunshine.

the class WeightedAvgAdapt method constructUserList.

@Override
void constructUserList(ArrayList<_User> userList) {
    int vSize = m_dim;
    // step 1: create space
    m_userList = new ArrayList<_AdaptStruct>();
    for (int i = 0; i < userList.size(); i++) {
        _User user = userList.get(i);
        // we will not create transformation matrix for this user
        m_userList.add(new _CoLinAdaptStruct(user, -1, i, m_topK));
        // Initiate user weights with global weights.
        user.setModel(m_gWeights);
    }
    m_pWeights = new double[m_gWeights.length];
    // huge space consumption
    _CoLinAdaptStruct.sharedA = new double[getVSize()];
    // step 2: copy each user's weights to shared A(weights) in _CoLinAdaptStruct
    for (int i = 0; i < m_userList.size(); i++) System.arraycopy(m_gWeights, 0, _CoLinAdaptStruct.sharedA, vSize * i, vSize);
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._User(structures._User)

Aggregations

structures._User (structures._User)24 Classifier.supervised.modelAdaptation._AdaptStruct (Classifier.supervised.modelAdaptation._AdaptStruct)15 File (java.io.File)7 IOException (java.io.IOException)6 BufferedReader (java.io.BufferedReader)4 FileInputStream (java.io.FileInputStream)4 InputStreamReader (java.io.InputStreamReader)4 structures._Review (structures._Review)4 com.model._User (com.model._User)3 ArrayList (java.util.ArrayList)3 PrintWriter (java.io.PrintWriter)2 C (com.C)1 DbFactory (com.DbFactory)1 EventTags (com.EventTags)1 InstanceFactory (com.app.annotation.apt.InstanceFactory)1 CheckLogin (com.app.annotation.aspect.CheckLogin)1 Bus (com.app.annotation.javassist.Bus)1 BusRegister (com.app.annotation.javassist.BusRegister)1 BusUnRegister (com.app.annotation.javassist.BusUnRegister)1 ApiFactory (com.apt.ApiFactory)1