Package org.apache.mahout.cf.taste.impl.model

Examples of org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray$PreferenceArrayIterator


  @Test
  public void lessItemsThanBatchSize() throws Exception {

    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
    userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
        new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
    userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
        new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));

    DataModel dataModel = new GenericDataModel(userData);
    ItemBasedRecommender recommender =
        new GenericItemBasedRecommender(dataModel, new TanimotoCoefficientSimilarity(dataModel));
View Full Code Here


  @Test
  public void higherDegreeOfParallelismThanBatches() throws Exception {

    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
    userData.put(1, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(1, 1, 1),
        new GenericPreference(1, 2, 1), new GenericPreference(1, 3, 1))));
    userData.put(2, new GenericUserPreferenceArray(Arrays.asList(new GenericPreference(2, 1, 1),
        new GenericPreference(2, 2, 1), new GenericPreference(2, 4, 1))));

    DataModel dataModel = new GenericDataModel(userData);
    ItemBasedRecommender recommender =
        new GenericItemBasedRecommender(dataModel, new TanimotoCoefficientSimilarity(dataModel));
View Full Code Here

    List<Preference> prefsOfUser789 = Lists.newArrayList();
    prefsOfUser789.add(new GenericPreference(789L, 1L, 0.5f));
    prefsOfUser789.add(new GenericPreference(789L, 3L, 1.0f));

    PreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray(prefsOfUser123);

    FastByIDMap<PreferenceArray> userData = new FastByIDMap<PreferenceArray>();
    userData.put(123L, prefArrayOfUser123);
    userData.put(456L, new GenericUserPreferenceArray(prefsOfUser456));
    userData.put(789L, new GenericUserPreferenceArray(prefsOfUser789));

    DataModel dataModel = new GenericDataModel(userData);

    CandidateItemsStrategy strategy =
        new SamplingCandidateItemsStrategy(1, 1, 1, dataModel.getNumUsers(), dataModel.getNumItems());
View Full Code Here

   
    DataModel dataModel = EasyMock.createMock(DataModel.class);
    EasyMock.expect(dataModel.getNumItems()).andReturn(3);
    EasyMock.expect(dataModel.getItemIDs()).andReturn(allItemIDs.iterator());

    PreferenceArray prefArrayOfUser123 = new GenericUserPreferenceArray(Collections.singletonList(
        new GenericPreference(123L, 2L, 1.0f)));

    CandidateItemsStrategy strategy = new AllUnknownItemsCandidateItemsStrategy();

    EasyMock.replay(dataModel);
View Full Code Here

        pusers = new OpenIntObjectHashMap<PreferenceArray>(
                dataModel.getNumUsers());
        IntArrayList list = (IntArrayList) dataModel.getUserIDs();
        for (int i = 0; i < list.size(); i++) {
            int key = list.get(i);
            PreferenceArray value = new GenericUserPreferenceArray(key,
                    parameter_k);
            pusers.put(key, value);
        }

        // get item ids and initialize qi;
View Full Code Here

        puTemp = new OpenIntObjectHashMap<PreferenceArray>(
                dataModel.getNumUsers());
        IntArrayList list = (IntArrayList) dataModel.getUserIDs();
        for (int i = 0; i < list.size(); i++) {
            int key = list.get(i);
            PreferenceArray value = new GenericUserPreferenceArray(key,
                    parameter_k);
            pusers.put(key, value);

            value = new GenericUserPreferenceArray(key, parameter_k);
            puTemp.put(key, value);
        }

        // get item ids and initialize qi;
        qitems = new OpenIntObjectHashMap<PreferenceArray>(
View Full Code Here

            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++;

                    // update bias values
                    double tmp = busers.get(userid) + gamma1
                            * (eui - lamda6 * busers.get(userid));
                    busers.put(userid, tmp);
                    tmp = bitems.get(itemid) + gamma1
                            * (eui - lamda6 * bitems.get(itemid));
                    bitems.put(itemid, tmp);

                    // update user factor and movie factor vectors

                    PreferenceArray ItemFactor = qitems.get(itemid);
                    UserFactor = pusers.get(userid);
                    PreferenceArray puTempFactor = puTemp.get(userid);

                    for (int k = 0; k < parameter_k; k++) {

                        // user factor
                        float preval = UserFactor.getValue(k);
                        float temp = ItemFactor.getValue(k);
                        preval = (float) (preval + gamma2
                                * (eui * temp - lamda7 * preval));
                        UserFactor.setValue(k, preval);

                        // item factor
                        preval = ItemFactor.getValue(k);
                        temp = puTempFactor.getValue(k);
                        preval = (float) (preval + gamma2
                                * (eui * temp - lamda7 * preval));
                        ItemFactor.setValue(k, preval);

                        // Accumulate information for gradient steps on y_i
                        preval = sumQE.getValue(k);
                        preval += eui * ItemFactor.getValue(k);
                        sumQE.setValue(k, preval);

                        // // implicit factor test;
                        // PreferenceArray yFactor = y.get(itemid);
                        // preval = yFactor.getValue(k);
                        // preval += gamma2
                        // * (eui*ItemFactor.getValue(k)/Math.sqrt(nu) - lamda7
                        // * preval);
                        // yFactor.setValue(k, preval);
                    }
                }

                // implicit factor
                itor = tmpitems.iterateNonZero();
                while (itor.hasNext()) {
                    Element e = itor.next();
                    int itemid = e.index();
                    PreferenceArray yFactor = y.get(itemid);
                    for (int k = 0; k < parameter_k; k++) {
                        float preval = yFactor.getValue(k);
                        preval = (float) (preval + gamma2
                                * (sumQE.getValue(k) / Math.sqrt(nu) - lamda7
                                * preval));
                        yFactor.setValue(k, preval);
                    }
                }
            }
View Full Code Here

TOP

Related Classes of org.apache.mahout.cf.taste.impl.model.GenericUserPreferenceArray$PreferenceArrayIterator

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.