Search in sources :

Example 51 with org.haiku.haikudepotserver.dataobjects.auto._User

use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.

the class MultiThreadedNetworkAnalyzer method sampleUsers4ColdStart4Edges.

// reserve edges for link prediction, group users based on document size
// d1 and d2 are thresholds for splitting users into light, medium and heavy users
public void sampleUsers4ColdStart4Edges(String dir, int d1, int d2, int sampleSize) {
    Random rand = new Random();
    ArrayList<String> light = new ArrayList<>();
    ArrayList<String> medium = new ArrayList<>();
    ArrayList<String> heavy = new ArrayList<>();
    // step 1: collect all the user ids in different groups
    for (_User user : m_users) {
        if (user.getReviews() == null)
            continue;
        String userId = user.getUserID();
        int rvwSize = user.getReviews().size();
        if (rvwSize > d2) {
            heavy.add(userId);
        } else if (rvwSize > d1) {
            medium.add(userId);
        } else
            light.add(userId);
    }
    // step 2: sample specified number of users from each group
    HashSet<String> sampledLight = sample(light, sampleSize);
    HashSet<String> sampledMedium = sample(medium, sampleSize);
    HashSet<String> sampledHeavy = sample(heavy, sampleSize);
    // step 3: since edges are symmetric, remove the associated edges
    removeSymmetricEdges(sampledLight);
    removeSymmetricEdges(sampledMedium);
    removeSymmetricEdges(sampledHeavy);
    // step 4: save the sampled users and their interactions
    writeCVIndex4Edges(dir + "_interactions.txt", sampledLight, sampledMedium, sampledHeavy);
    // step 5: sample non-interactions for different groups of users
    for (int time : new int[] { 2, 3, 4, 5, 6, 7, 8 }) {
        String filename = String.format("%s_noninteractions_time_%d_light.txt", dir, time);
        sampleNonInteractions4OneGroup(filename, sampledLight, time);
        filename = String.format("%s_noninteractions_time_%d_medium.txt", dir, time);
        sampleNonInteractions4OneGroup(filename, sampledMedium, time);
        filename = String.format("%s_noninteractions_time_%d_heavy.txt", dir, time);
        sampleNonInteractions4OneGroup(filename, sampledHeavy, time);
    }
}
Also used : structures._User(structures._User)

Example 52 with org.haiku.haikudepotserver.dataobjects.auto._User

use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.

the class CLRWithMMB method loadUsers.

@Override
public void loadUsers(ArrayList<_User> userList) {
    m_userList = new ArrayList<_AdaptStruct>();
    for (_User user : userList) m_userList.add(new _MMBAdaptStruct(user));
    m_pWeights = new double[m_gWeights.length];
    m_indicator = new _HDPThetaStar[m_userList.size()][m_userList.size()];
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._User(structures._User)

Example 53 with org.haiku.haikudepotserver.dataobjects.auto._User

use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.

the class CLinAdaptWithKmeans method loadUsers.

// Initialize the weights of the transformation matrix.
@Override
public void loadUsers(ArrayList<_User> userList) {
    int totalUserSize = userList.size();
    // 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 _CLinAdaptStruct(user, m_dim, i, totalUserSize, m_clusterSize));
    }
    m_pWeights = new double[m_gWeights.length];
    // step1: init the shared A: individual + cluster + global
    _CLinAdaptStruct.sharedA = new double[getVSize()];
    for (int i = 0; i < m_userList.size() + m_clusterSize; i++) {
        for (int j = 0; j < m_dim; j++) {
            _CLinAdaptStruct.sharedA[i * m_dim * 2 + j] = 1;
        }
    }
}
Also used : Classifier.supervised.modelAdaptation._AdaptStruct(Classifier.supervised.modelAdaptation._AdaptStruct) structures._User(structures._User)

Example 54 with org.haiku.haikudepotserver.dataobjects.auto._User

use of org.haiku.haikudepotserver.dataobjects.auto._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 55 with org.haiku.haikudepotserver.dataobjects.auto._User

use of org.haiku.haikudepotserver.dataobjects.auto._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)56 Classifier.supervised.modelAdaptation._AdaptStruct (Classifier.supervised.modelAdaptation._AdaptStruct)15 File (java.io.File)10 IOException (java.io.IOException)10 structures._Review (structures._Review)10 ArrayList (java.util.ArrayList)6 PrintWriter (java.io.PrintWriter)5 BufferedReader (java.io.BufferedReader)4 FileInputStream (java.io.FileInputStream)4 InputStreamReader (java.io.InputStreamReader)4 HashMap (java.util.HashMap)3 ObjectContext (org.apache.cayenne.ObjectContext)3 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)3 User (org.haiku.haikudepotserver.dataobjects.User)3 org.haiku.haikudepotserver.dataobjects.auto._User (org.haiku.haikudepotserver.dataobjects.auto._User)3 AccessDeniedException (org.springframework.security.access.AccessDeniedException)3 InvalidFormatException (opennlp.tools.util.InvalidFormatException)2 structures._SparseFeature (structures._SparseFeature)2 FileNotFoundException (java.io.FileNotFoundException)1 HashSet (java.util.HashSet)1