Package resys.impl.datamodel

Examples of resys.impl.datamodel.DataModel


     * initialize the bias bu and bi, the method in the page 2 of koren's
     * TKDD'09 paper
     */
    public void initBias() {

        DataModel datamodel = getDataModel();

        double mean = datamodel.getMean();
        // 1. first item bias
        IntArrayList items = (IntArrayList) datamodel.getItemIDs();
        for (int i = 0; i < items.size(); i++) {
            int itemid = items.get(i);
            Vector tmp = datamodel.getVectorOfUsers(itemid);
            Iterator<Element> iter = tmp.iterateNonZero();
            double rate = 0.0;
            while (iter.hasNext()) {
                rate += (iter.next().get() - mean);
            }
            bitems.put(itemid, rate / (tmp.getNumNondefaultElements() + lamda2));
        }

        // 2. second user bias
        IntArrayList users = (IntArrayList) datamodel.getUserIDs();
        for (int i = 0; i < users.size(); i++) {
            int userid = users.get(i);
            Vector tmp = datamodel.getVectorOfItems(userid);
            Iterator<Element> iter = tmp.iterateNonZero();
            double rate = 0.0;
            while (iter.hasNext()) {
                Element e = iter.next();
                rate += (e.get() - mean - bitems.get(e.index()));
View Full Code Here


     * character(Q) and implicit matrix Y
     */
    public void initPQ() {

        // Initialize user-factor matrix P
        DataModel datamodel = getDataModel();
        IntArrayList users = (IntArrayList) datamodel.getUserIDs();
        for (int i = 0; i < users.size(); i++) {
            int userid = users.get(i);
            PreferenceArray pa = pusers.get(userid);
            for (int j = 0; j < parameter_k; j++) {
                float randvalue = (float) (0.1 * Math.random() / Math
                        .sqrt(parameter_k));
                pa.setValue(j, randvalue);
            }
        }

        // Initialize item-factor matrix q and y
        IntArrayList items = (IntArrayList) datamodel.getItemIDs();
        for (int i = 0; i < items.size(); i++) {
            int itemid = items.get(i);
            PreferenceArray paItem = qitems.get(itemid);
            PreferenceArray paY = y.get(itemid);
            for (int j = 0; j < parameter_k; j++) {
View Full Code Here

     * Main training procedure
     */
    @Override
    public void train() {

        DataModel datamodel = getDataModel();

        initBias();
        initPQ();

        int nu = 0; // the number of items user u rated

        for (int iter = 0; iter < iteration; iter++) {

            double rmse = 0.0;
            int n = 0;
            IntArrayList users = (IntArrayList) datamodel.getUserIDs();

            for (int u = 0; u < users.size(); u++) {
                // initialize sumQE
                // why use it???
                PreferenceArray sumQE = new GenericUserPreferenceArray(
                        parameter_k);

                // get userid
                int userid = users.get(u);

                nu = datamodel.getNumOfItemsRateByUser(userid);
                Vector tmpitems = datamodel.getVectorOfItems(userid);

                // calculate temp_Pu += sigma(yi)/sqrt(Nu);
                PreferenceArray tempUserFactor = puTemp.get(userid);
                PreferenceArray UserFactor = pusers.get(userid);
                for (int k = 0; k < parameter_k; k++) {
                    Iterator<Element> itor = tmpitems.iterateNonZero();
                    double sum = 0.0;
                    while (itor.hasNext()) {
                        Element e = itor.next();
                        int itemid = e.index();
                        sum = sum + y.get(itemid).getValue(k);
                    }
                    float temp = (float) (UserFactor.getValue(k) + sum
                            / Math.sqrt(nu));
                    tempUserFactor.setValue(k, temp);

                    sumQE.setValue(k, 0.0f);
                }

                // iterate to deal with items
                Iterator<Element> itor = tmpitems.iterateNonZero();
                while (itor.hasNext()) {

                    Element e = itor.next();
                    int itemid = e.index();

                    // actual rating and estimated rating
                    double rui = datamodel.getPreferenceValue(userid, itemid);
                    double pui = predictPreference(userid, itemid);
                    double eui = rui - pui;

                    rmse += eui * eui;
                    n++;
View Full Code Here

     * @param itemID
     * @return
     */
    public double predictPreference(int userID, int itemID) {

        DataModel datamodel = getDataModel();

        // number of items which are rated by the userid
        int uRateItemNum = datamodel.getNumOfItemsRateByUser(userID);

        double mean = datamodel.getMean();
        double result;
        if (uRateItemNum >= 1) {
            result = mean + busers.get(userID) + bitems.get(itemID)
                    + dot(puTemp.get(userID), qitems.get(itemID), parameter_k);
        } else {
View Full Code Here

     * initialize the bias bu and bi, the method in the page 2 of koren's
     * TKDD'09 paper
     */
    public void initBias() {

        DataModel datamodel = getDataModel();

        double mean = datamodel.getMean();
        // 1. first item bias
        IntArrayList items = (IntArrayList) datamodel.getItemIDs();
        for (int i = 0; i < items.size(); i++) {
            int itemid = items.get(i);
            Vector tmp = datamodel.getVectorOfUsers(itemid);
            Iterator<Element> iter = tmp.iterateNonZero();
            double rate = 0.0;
            while (iter.hasNext()) {
                rate += (iter.next().get() - mean);
            }
            bitems.put(itemid, rate / (tmp.getNumNondefaultElements() + lamda2));
            // bitems.put(itemid, 0);
        }

        // 2. second user bias
        IntArrayList users = (IntArrayList) datamodel.getUserIDs();
        for (int i = 0; i < users.size(); i++) {
            int userid = users.get(i);
            Vector tmp = datamodel.getVectorOfItems(userid);
            Iterator<Element> iter = tmp.iterateNonZero();
            double rate = 0.0;
            while (iter.hasNext()) {
                Element e = iter.next();
                rate += (e.get() - mean - bitems.get(e.index()));
View Full Code Here

     * character(Q) and implicit matrix Y
     */
    public void initPQ() {

        // Initialize user-factor matrix P
        DataModel datamodel = getDataModel();
        IntArrayList users = (IntArrayList) datamodel.getUserIDs();
        for (int i = 0; i < users.size(); i++) {
            int userid = users.get(i);
            PreferenceArray pa = pusers.get(userid);
            for (int j = 0; j < parameter_k; j++) {
                float randvalue = (float) (0.1 * Math.random() / Math
                        .sqrt(parameter_k));
                pa.setValue(j, randvalue);
            }
        }

        // Initialize item-factor matrix q and y
        IntArrayList items = (IntArrayList) datamodel.getItemIDs();
        for (int i = 0; i < items.size(); i++) {
            int itemid = items.get(i);
            PreferenceArray paItem = qitems.get(itemid);
            for (int j = 0; j < parameter_k; j++) {
                float randvalue = (float) (0.1 * Math.random() / Math
View Full Code Here

     * Main training procedure
     */
    @Override
    public void train() {

        DataModel datamodel = getDataModel();

        initBias();
        initPQ();

        for (int iter = 0; iter < iteration; iter++) {

            double rmse = 0.0;
            int n = 0;
            IntArrayList users = (IntArrayList) datamodel.getUserIDs();

            for (int u = 0; u < users.size(); u++) {
                // get userid
                int userid = users.get(u);

                Vector tmpitems = datamodel.getVectorOfItems(userid);

                PreferenceArray UserFactor = pusers.get(userid);

                // iterate to items
                Iterator<Element> itor = tmpitems.iterateNonZero();
                while (itor.hasNext()) {

                    Element e = itor.next();
                    int itemid = e.index();

                    // actual rating and estimated rating
                    double rui = datamodel.getPreferenceValue(userid, itemid);
                    double pui = predictPreference(userid, itemid);
                    double eui = rui - pui;

                    rmse += eui * eui;
                    n++;
View Full Code Here

     * @param itemID
     * @return
     */
    public double predictPreference(int userID, int itemID) {

        DataModel datamodel = getDataModel();

        // number of items which are rated by the userid
        int uRateItemNum = datamodel.getNumOfItemsRateByUser(userID);

        double mean = datamodel.getMean();
        double result;
        if (uRateItemNum >= 1) {
            result = mean + busers.get(userID) + bitems.get(itemID)
                    + dot(pusers.get(userID), qitems.get(itemID), parameter_k);
        } else {
View Full Code Here

TOP

Related Classes of resys.impl.datamodel.DataModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.