Search in sources :

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

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

the class MultiThreadedLMAnalyzer method findtrainFriends.

public void findtrainFriends(String filename) {
    _User ui, uj;
    // Detect all co-purchase.
    for (int i = 0; i < m_users.size(); i++) {
        ui = m_users.get(i);
        for (int j = i + 1; j < m_users.size(); j++) {
            uj = m_users.get(j);
            if (hasCoPurchase(ui, uj)) {
                ui.addAmazonFriend(uj.getUserID());
                uj.addAmazonFriend(ui.getUserID());
            }
        }
    }
    try {
        double avg = 0, count = 0;
        PrintWriter writer = new PrintWriter(new File(filename));
        for (_User u : m_users) {
            if (u.getAmazonFriends().size() == 0)
                continue;
            m_validUserMap.put(u.getUserID(), m_validUserMap.size());
            count++;
            avg += u.getAmazonFriends().size();
            writer.write(u.getUserID() + "\t");
            for (String frd : u.getAmazonFriends()) writer.write(frd + "\t");
            writer.write("\n");
        }
        System.out.format("[Info]%.1f users have friends and avg friend size: %.2f\n", count, avg / count);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : structures._User(structures._User) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

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

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

the class MultiThreadedLMAnalyzer method findTestFriends.

public void findTestFriends(String filename) {
    _User ui, uj;
    // Detect all co-purchase.
    for (int i = 0; i < m_users.size(); i++) {
        ui = m_users.get(i);
        if (!m_validUserMap.containsKey(ui.getUserID()))
            continue;
        for (int j = i + 1; j < m_users.size(); j++) {
            uj = m_users.get(j);
            if (!m_validUserMap.containsKey(uj.getUserID()))
                continue;
            if (hasCoPurchaseInTest(ui, uj)) {
                ui.addAmazonTestFriend(uj.getUserID());
                uj.addAmazonTestFriend(ui.getUserID());
            }
        }
    }
    try {
        double avg = 0, count = 0;
        PrintWriter writer = new PrintWriter(new File(filename));
        for (_User u : m_users) {
            if (u.getAmazonTestFriends().size() == 0)
                continue;
            count++;
            avg += u.getAmazonFriends().size();
            writer.write(u.getUserID() + "\t");
            for (String frd : u.getAmazonFriends()) writer.write(frd + "\t");
            writer.write("\n");
        }
        System.out.format("[Info]%.1f users have friends in test set and avg test friend size: %.2f\n", count, avg / count);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : structures._User(structures._User) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 8 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 calcEdgeStat4LightMediumHeavy.

public void calcEdgeStat4LightMediumHeavy(int k1, int k2) {
    int light = 0, medium = 0, heavy = 0, max = 0;
    for (_User user : m_users) {
        if (user.getFriends() == null)
            continue;
        int frdSize = user.getFriends().length;
        max = Math.max(frdSize, max);
        if (frdSize > k2) {
            heavy++;
        } else if (frdSize > k1) {
            medium++;
        } else
            light++;
    }
    System.out.format("[Stat]Edges-Light: %d, Medium: %d, Heavy: %d, max: %d.\n", light, medium, heavy, max);
}
Also used : structures._User(structures._User)

Example 9 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 saveCVIndex4TADW.

// shuffle the document index based on each user
public void saveCVIndex4TADW(String filename) {
    int[] stat = new int[5];
    try {
        PrintWriter writer = new PrintWriter(new File(filename));
        for (_User u : m_users) {
            for (_Review r : u.getReviews()) {
                writer.write(String.format("%s,%s,%d\n", r.getUserID(), r.getItemID(), r.getMask4CV()));
                stat[r.getMask4CV()]++;
            }
        }
        writer.close();
        System.out.println("[Info]Finish writing cv index for TADW! Stat as follow:");
        for (int s : stat) System.out.print(s + "\t");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : structures._Review(structures._Review) structures._User(structures._User)

Example 10 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 sampleNonInteractions4OneGroup.

public void sampleNonInteractions4OneGroup(String filename, HashSet<String> uids, int time) {
    ArrayList<Integer> interactions = new ArrayList<Integer>();
    ArrayList<Integer> nonInteractions = new ArrayList<Integer>();
    HashMap<String, HashSet<Integer>> userNonInteractionMap = new HashMap<>();
    for (String uid : uids) {
        int i = m_userIDIndex.get(uid);
        _User ui = m_users.get(i);
        interactions.clear();
        nonInteractions.clear();
        for (String frd : ui.getFriends()) {
            interactions.add(m_userIDIndex.get(frd));
        }
        for (int j = 0; j < m_users.size(); j++) {
            if (i == j)
                continue;
            if (interactions.contains(j))
                continue;
            nonInteractions.add(j);
        }
        int number = time * interactions.size();
        userNonInteractionMap.put(uid, sampleNonInteractions(nonInteractions, number));
    }
    try {
        PrintWriter writer = new PrintWriter(new File(filename));
        for (String uid : userNonInteractionMap.keySet()) {
            writer.write(uid + "\t");
            for (int nonIdx : userNonInteractionMap.get(uid)) {
                String nonId = m_users.get(nonIdx).getUserID();
                writer.write(nonId + "\t");
            }
            writer.write("\n");
        }
        writer.close();
        System.out.format("[Stat]%d users' non-interactions are written in %s.\n", uids.size(), filename);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : 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