Beispiel #1
0
        public List<Recommendation_Meta_Item> GetListR1R4_ForNewUsers(Predict_DAO_MCol dao, Dictionary<string, double> UCA)
        {
            double M = 1;
            if (UCA.ContainsKey("MEANS_VALUE"))
                M = UCA["MEANS_VALUE"];

            List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
            //Content is cleared by M.C. Nguyen 19.9.2015
            return list;
        }
Beispiel #2
0
        public List<ADDGAP> GetListOfNewGAP(Predict_DAO_MCol a)
        {
            List<ADDGAP> lst = new List<ADDGAP>();
            try
            {
                lst = a.GetListOfNewGAP();
            }
            catch (Exception)
            {
                throw;
            }

            return lst;
        }
Beispiel #3
0
        public List<ClusterInfo> GetListCluster()
        {
            Predict_DAO_MCol a = new Predict_DAO_MCol();
            List<ClusterInfo> list = new List<ClusterInfo>();

            try
            {
                a.beginTransaction();
                list = a.GetListCluster();
                a.commitTransaction();
                return list;
            }
            catch (Exception ex)
            {
                a.rollbackTransaction();
                throw ex;
            }
        }
Beispiel #4
0
 public void R1(Predict_DAO_MCol dao, RecommdationSchedule schedule)
 {
     List<Recommendation_Meta_Item> traditionalUsers1 = this.getListRecommendation_R1_TraditionalUsers(dao);
     List<Recommendation_Meta_Item> traditionalUsers2 = this.GetQuantityTraditionalUsers(dao, traditionalUsers1);
     this.Normaliser(traditionalUsers2);
     dao.InsertList(traditionalUsers2, schedule);
 }
Beispiel #5
0
 public void R1(Predict_DAO_MCol dao, RecommdationSchedule schedule, int nbR1, Dictionary<string, double> UCA, List<QTY_GAP> list)
 {
     //Get recommendations for traditional users
     List<Recommendation_Meta_Item> lrc_ForUserTra = getListRecommendation_R1_TraditionalUsers(dao, nbR1);
     lrc_ForUserTra = GetQuantityTraditionalUsers(dao, lrc_ForUserTra, UCA);
     Normaliser(lrc_ForUserTra);
     AddGAPtoListRecommends(list, lrc_ForUserTra);
     dao.InsertList(lrc_ForUserTra, schedule);
 }
Beispiel #6
0
        //THis function get a price of MetaItemID that correspondance with the quantity
        //----------------------------------------------------------------------------------
        public double GetPrice(string MetaItemID, int QTY)
        {
            double Price = 0;
            Predict_DAO_MCol a = new Predict_DAO_MCol();
            try
            {
                Price = a.GetPrice(MetaItemID, QTY);
            }
            catch (Exception)
            {

                throw;
            }

            return Price;
        }
Beispiel #7
0
        public void LoadRecommendation(string LoginID)
        {
            Predict_DAO_MCol dao = null;

            RecommdationSchedule schedule = new RecommdationSchedule();
            schedule.Log = "Recommendation";
            schedule.LoginID = LoginID;
            Predict_MC predictMC = new Predict_MC();
            try
            {
                dao = new Predict_DAO_MCol();
                dao.beginTransaction();
                RecommdationSchedule currentSchedule = dao.addRecommdationSchedule(schedule);
                //Settings st = getSettings();
                Settings r = predictMC.GetRecommendationSeting(dao);
                Dictionary<string, double> UCA = predictMC.getUCA(dao);

                //Data service
                IntergrationManager manager = new IntergrationManager();
                manager.execute();

                //Clustering service
                new ClusterUsers().startClusteringAuto();

                /*
                 *
                 *
                 * this paragraph need to rewrite
                 *
                 * */
                //calculate confident matrix - c4
                ComputeConfident(dao);
                // calculate dist matrix - C5
                ComputeDIST(dao);

                //=====================================================================================

                dao.CLEAN_RECOMMENDATION();

                // R1
                DateTime startC6 = DateTime.Now;
                // predictMC.R1(dao, currentSchedule, r.nbR1, UCA, lstGAP);
                predictMC.R1(dao, currentSchedule);
                DateTime endC6 = DateTime.Now;
                int time_Seconds_CLC6 = Convert.ToInt32((endC6 - startC6).TotalSeconds);

                //////R2
                //DateTime startC7 = DateTime.Now;
                //setRCPurchasedItems(dao, currentSchedule, r.nbR2, lstGAP);
                //DateTime endC7 = DateTime.Now;
                //int time_Seconds_CLC7 = Convert.ToInt32((endC7 - startC7).TotalSeconds);

                //// R3
                DateTime startC8 = DateTime.Now;
                // predictMC.R3(dao, currentSchedule, r.nbR3, UCA, lstGAP);
                predictMC.R3(dao, currentSchedule);
                DateTime endC8 = DateTime.Now;
                int time_Seconds_CLC8 = Convert.ToInt32((endC8 - startC8).TotalSeconds);

                //// R4
                DateTime startC9 = DateTime.Now;
                // predictMC.R4(dao, currentSchedule, r.paramR4, UCA, lstGAP);
                predictMC.R4(dao, currentSchedule);
                DateTime endC9 = DateTime.Now;
                int time_Seconds_CLC9 = Convert.ToInt32((endC9 - startC9).TotalSeconds);

                ////Get R1R4 for new users
                DateTime startR1R4NewUsers = DateTime.Now;
                predictMC.R1R4_FOR_NEW_USERS(dao, currentSchedule, UCA);
                DateTime endR1R4NewUsers = DateTime.Now;
                int time_second_R1R4NewUsers = Convert.ToInt32((endR1R4NewUsers - startR1R4NewUsers).TotalSeconds);

                //GetPrice
                //dao.GetPrice();

                Console.WriteLine("FINISH");

                // build statistic log
                List<string[]> lstStatic = dao.getStaticsData();
                foreach (string[] statics in lstStatic)
                {
                    schedule.Log += statics[0] + statics[1] + ". ";
                }

                schedule.Log += "Time to find LRS01 : " + time_Seconds_CLC6.ToString() + ". ";
                //schedule.Log += "Time to find LRS02 : " + time_Seconds_CLC7.ToString() + ". ";
                schedule.Log += "Time to find LRS03 : " + time_Seconds_CLC8.ToString() + ". ";
                schedule.Log += "Time to find LRS04 : " + time_Seconds_CLC9.ToString() + ". ";
                schedule.Log += "Time to find recommendations for new clients : " + time_second_R1R4NewUsers.ToString() + ". ";
                schedule.Log += "System successfully stopped at " + DateTime.Now.ToString();

                dao.updateRecommdationSchedule(schedule);
                dao.commitTransaction();

            }
            catch (Exception ex)
            {
                dao.rollbackTransaction();
                throw ex;
            }
        }
Beispiel #8
0
 //public List<Recommendation_Meta_Item> GetListRecommendC6_ForTraditionalUser()
 //{
 //    Predict_DAO_MC a = new Predict_DAO_MC();
 //    List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
 //    List<Recommendation_Meta_Item> RC = new List<Recommendation_Meta_Item>();
 //    try
 //    {
 //        a.beginTransaction();
 //        List<User> list_users_tra = a.getTraditionalUser_UnBlocked();
 //        foreach (User u in list_users_tra)
 //        {
 //            RC = a.GetRecommendC6_ForTraditionalUser(u, 1);
 //            list.AddRange(RC);
 //        }
 //        a.commitTransaction();
 //        return list;
 //    }
 //    catch (Exception ex)
 //    {
 //        a.rollbackTransaction();
 //        throw ex;
 //    }
 //}
 //----------------------------------------------------------------------------------------------
 //This function calls GetRecommendC6_ForTraditionalUser from Predict_DAO_MC to give R1
 //Created by MC. NGUYEN
 //Corrected by MC. NGUYEN, 22.10.2014
 //Changed: 24.10.2014: the formule to calculate SCORE for each Meta Produit (based on Count(*)).
 //----------------------------------------------------------------------------------------------
 public List<Recommendation_Meta_Item> getListRecommendation_R1_TraditionalUsers(Predict_DAO_MCol a)
 {
     List<Recommendation_Meta_Item> list1 = new List<Recommendation_Meta_Item>();
     List<Recommendation_Meta_Item> list2 = new List<Recommendation_Meta_Item>();
     List<string> list3 = new List<string>();
     List<string> list4 = new List<string>();
     foreach (string cluster in a.GetListClusterID())
     {
         foreach (string u in a.GetListUser_OfCluster(cluster))
         {
             List<Recommendation_Meta_Item> forTraditionalUser = a.GetRecommendC6_ForTraditionalUser(u, 2);
             list1.AddRange((IEnumerable<Recommendation_Meta_Item>)forTraditionalUser);
         }
     }
     return list1;
 }
Beispiel #9
0
 public List<Recommendation_Meta_Item> GetQuantityTraditionalUsers(Predict_DAO_MCol a, List<Recommendation_Meta_Item> list)
 {
     for (int index = 0; index < list.Count; ++index)
     {
         double qualtityTraditionalUser = a.GetQualtityTraditionalUser(list[index]);
         list[index].Quantity = qualtityTraditionalUser == 0.0 ? 1.0 : (double)(int)qualtityTraditionalUser;
     }
     return list;
 }
Beispiel #10
0
 public void R3(Predict_DAO_MCol dao, RecommdationSchedule schedule, int nbR3, Dictionary<string, double> UCA, List<QTY_GAP> lst)
 {
     List<Recommendation_Meta_Item> list = GetRecommendationR3(dao, nbR3);
     list = GetQuantityTraditionalUsersR3(dao, list, UCA);
     dao.RemoveDuplicateR3R1();
     Normaliser(list);
     AddGAPtoListRecommends(lst, list);
     dao.InsertList(list, schedule);
 }
Beispiel #11
0
 //----------------------------------------------------------------------------------------------
 //This function gives R3 AND QUANTITY (with a number of recommendations for each user as input)
 //----------------------------------------------------------------------------------------------
 public List<Recommendation_Meta_Item> GetRecommendationR3(Predict_DAO_MCol a, int nbR3)
 {
     List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
     //Content is cleared by M.C. Nguyen 19.9.2015
     return list;
 }
Beispiel #12
0
 //have formular here
 public List<Recommendation_Meta_Item> GetRecommendationR3(Predict_DAO_MCol a)
 {
     List<Recommendation_Meta_Item> list1 = new List<Recommendation_Meta_Item>();
     Recommendation_Meta_Item recommendationMetaItem1 = new Recommendation_Meta_Item();
     List<CONF> list2 = new List<CONF>();
     List<DIST> list3 = new List<DIST>();
     List<string> list4 = new List<string>();
     List<string> list5 = new List<string>();
     List<string> list6 = new List<string>();
     List<U_I_Q> list7 = new List<U_I_Q>();
     foreach (string cluster in a.GetListClusterID())
     {
         List<CONF> confOfCluster = a.GetCONF_OfCluster(cluster);
         List<DIST> distOfCluster = a.GetDIST_OfCluster(cluster);
         List<string> listUserOfCluster = a.GetListUser_OfCluster(cluster);
         List<U_I_Q> traditionalUsersMore = a.GetQuantityTraditionalUsers_More(cluster);
         foreach (string user in listUserOfCluster)
         {
             List<string> notPurchasedOfUser = a.GetListMetaItemNotPurchased_OfUser(user, cluster);
             List<string> listMetaItemOfUser = a.GetListMetaItem_OfUser(user);
             string str = "";
             double num1 = 0.0;
             for (int index1 = 0; index1 < notPurchasedOfUser.Count; ++index1)
             {
                 double num2 = 0.0;
                 double num3 = 0.0;
                 double num4 = 1.0;
                 for (int index2 = 0; index2 < listMetaItemOfUser.Count; ++index2)
                 {
                     for (int index3 = 0; index3 < confOfCluster.Count; ++index3)
                     {
                         if (confOfCluster[index3].MetaItemSource.Equals(listMetaItemOfUser[index2]) && confOfCluster[index3].MetaItemDestination.Equals(notPurchasedOfUser[index1]))
                         {
                             num3 = confOfCluster[index3].Confident;
                             break;
                         }
                     }
                     for (int index3 = 0; index3 < distOfCluster.Count; ++index3)
                     {
                         if (distOfCluster[index3].MetaItemDestination.Equals(listMetaItemOfUser[index2]) && distOfCluster[index3].MetaItemDestination.Equals(notPurchasedOfUser[index1]))
                         {
                             num4 = distOfCluster[index3].Distance;
                             break;
                         }
                     }
                     if (num4 != 0.0)
                         num2 += num3 / num4;
                 }
                 if (num1 < num2 / (double)listMetaItemOfUser.Count)
                 {
                     num1 = num2;
                     str = notPurchasedOfUser[index1];
                 }
             }
             if (num1 != 0.0)
             {
                 Recommendation_Meta_Item recommendationMetaItem2 = new Recommendation_Meta_Item();
                 recommendationMetaItem2.UserID = user;
                 recommendationMetaItem2.MetaItemID = str;
                 recommendationMetaItem2.RecommendType = ConstantValues.RC_TYPE_LRS03;
                 recommendationMetaItem2.Quantity = 0.0;
                 for (int index = 0; index < traditionalUsersMore.Count; ++index)
                 {
                     if (traditionalUsersMore[index].MetaItemID.Equals(str))
                     {
                         recommendationMetaItem2.Quantity = traditionalUsersMore[index].QTY;
                         break;
                     }
                 }
                 recommendationMetaItem2.Score = num1;
                 list1.Add(recommendationMetaItem2);
             }
         }
     }
     return list1;
 }
Beispiel #13
0
        public List<Recommendation_Meta_Item> GetQuantityTraditionalUsersR3(Predict_DAO_MCol a, List<Recommendation_Meta_Item> list, Dictionary<string, double> UCA)
        {
            double QTY;
            double M = 1;
            if (UCA.ContainsKey("MEANS_VALUE"))
                M = UCA["MEANS_VALUE"];

            for (int i = 0; i < list.Count; i++)
            {
                QTY = a.GetQualtityTraditionalUser(list[i]);
                if (QTY != 0)
                    list[i].Quantity = (int)(list[i].Quantity + QTY) / 2;
                //----------------------------------------
                if (UCA.ContainsKey(list[i].UserID))
                {
                    list[i].Quantity = (int)list[i].Quantity * (UCA[list[i].UserID] / M);
                }
            }

            //--------------------
            //a.commitTransaction();
            return list;
            //}
            //catch (Exception ex)
            //{
            //    a.rollbackTransaction();
            //    throw ex;
            //}
        }
Beispiel #14
0
 public List<Recommendation_Meta_Item> GetQuantityTraditionalUsersR3(Predict_DAO_MCol a, List<Recommendation_Meta_Item> list)
 {
     for (int index = 0; index < list.Count; ++index)
     {
         double qualtityTraditionalUser = a.GetQualtityTraditionalUser(list[index]);
         if (qualtityTraditionalUser != 0.0)
             list[index].Quantity = (double)((int)(list[index].Quantity + qualtityTraditionalUser) / 2);
     }
     return list;
 }
Beispiel #15
0
        //---------------------------------------------------------------------------------------------
        //This function call GetQualtityTraditionalUser to compute the quantity for each recommendations in the list
        //---------------------------------------------------------------------------------------------
        public List<Recommendation_Meta_Item> GetQuantityTraditionalUsers(Predict_DAO_MCol a, List<Recommendation_Meta_Item> list, Dictionary<string, double> UCA)
        {
            Int32 QTY;
            double M = 1;
            if (UCA.ContainsKey("MEANS_VALUE"))
                M = UCA["MEANS_VALUE"];

            for (int i = 0; i < list.Count; i++)
            {
                QTY = a.GetQualtityTraditionalUser(list[i]);
                if (QTY > 0)
                    list[i].Quantity = QTY;
                else
                    list[i].Quantity = 1;

                if (UCA.ContainsKey(list[i].UserID))
                {
                    list[i].Quantity = (int)list[i].Quantity * (UCA[list[i].UserID] / M);
                }
            }

            return list;
        }
Beispiel #16
0
 public void R1R4_FOR_NEW_USERS(Predict_DAO_MCol dao, RecommdationSchedule schedule, Dictionary<string, double> UCA)
 {
     List<Recommendation_Meta_Item> lrc_ForNewUsers = GetListR1R4_ForNewUsers(dao, UCA);
     // lrc_ForNewUsers = GetQuantityNewUsers(dao, lrc_ForNewUsers);
     Normaliser(lrc_ForNewUsers);
     dao.InsertListNewUser(lrc_ForNewUsers, schedule);
 }
Beispiel #17
0
 public void R4(Predict_DAO_MCol dao, RecommdationSchedule schedule)
 {
     List<Recommendation_Meta_Item> recommendationR4 = this.GetRecommendationR4(dao, 2.0);
     this.Normaliser(recommendationR4);
     dao.InsertList(recommendationR4, schedule);
 }
Beispiel #18
0
 public void R3(Predict_DAO_MCol dao, RecommdationSchedule schedule)
 {
     List<Recommendation_Meta_Item> recommendationR3 = this.GetRecommendationR3(dao);
     List<Recommendation_Meta_Item> traditionalUsersR3 = this.GetQuantityTraditionalUsersR3(dao, recommendationR3);
     this.Normaliser(traditionalUsersR3);
     dao.InsertList(traditionalUsersR3, schedule);
 }
Beispiel #19
0
        public void RemoveDuplicateR3R1()
        {
            Predict_DAO_MCol a = new Predict_DAO_MCol();
            try
            {
                a.RemoveDuplicateR3R1();
            }
            catch (Exception)
            {

                throw;
            }
        }
Beispiel #20
0
 public List<Recommendation_Meta_Item> GetRecommendationR4(Predict_DAO_MCol a, double param)
 {
     List<Recommendation_Meta_Item> list1 = new List<Recommendation_Meta_Item>();
     List<string> list2 = new List<string>();
     List<string> list3 = new List<string>();
     List<string> list4 = new List<string>();
     Dictionary<string, double> dictionary1 = new Dictionary<string, double>();
     Dictionary<string, double> dictionary2 = new Dictionary<string, double>();
     Dictionary<string, double> dictionary3 = new Dictionary<string, double>();
     Dictionary<string, double> dictionary4 = new Dictionary<string, double>();
     Dictionary<string, string> dictionary5 = new Dictionary<string, string>();
     List<string> listClusterId = a.GetListClusterID();
     Dictionary<string, string> listNewItem = a.GetListNewItem();
     foreach (string cluster in listClusterId)
     {
         try
         {
             Dictionary<string, double> listRateU = a.GetListRateU(cluster);
             Dictionary<string, double> listRateF = a.GetListRateF(cluster);
             foreach (KeyValuePair<string, double> keyValuePair1 in listRateU)
             {
                 Dictionary<string, double> listRateUf = a.GetListRateUF(keyValuePair1.Key);
                 double num1 = 0.0;
                 string FamillyCode = "Not found";
                 List<string> list5 = new List<string>();
                 List<double> list6 = new List<double>();
                 foreach (KeyValuePair<string, double> keyValuePair2 in listRateF)
                 {
                     double num2;
                     if (listRateUf.ContainsKey(keyValuePair2.Key))
                     {
                         double num3 = keyValuePair2.Value;
                         double num4 = keyValuePair1.Value;
                         double num5 = keyValuePair2.Value;
                         num2 = param * num5 * (1.0 / num4 - 1.0 / num3);
                     }
                     else
                         num2 = 0.0;
                     if (num2 > num1)
                     {
                         num1 = num2;
                         FamillyCode = keyValuePair2.Key;
                     }
                 }
                 if (num1 != 0.0)
                 {
                     double num2 = (double)a.getQTYR4(keyValuePair1.Key, FamillyCode, 1);
                     foreach (KeyValuePair<string, string> keyValuePair2 in listNewItem)
                     {
                         if (keyValuePair2.Value.Equals(FamillyCode))
                             list1.Add(new Recommendation_Meta_Item()
                             {
                                 UserID = keyValuePair1.Key,
                                 RecommendType = ConstantValues.RC_TYPE_LRS04,
                                 MetaItemID = keyValuePair2.Key,
                                 Quantity = num2,
                                 Score = num1
                             });
                     }
                 }
             }
         }
         catch (Exception ex)
         {
         }
     }
     return list1;
 }
Beispiel #21
0
        public List<Recommendation_Meta_Item> GetQuantityNewUsers(Predict_DAO_MCol a, List<Recommendation_Meta_Item> list)
        {
            //Predict_DAO_MC a = new Predict_DAO_MC();
            //List<U_I_Q> Cate_Item_QTY = new List<U_I_Q>();
            //try
            //{
            //    a.beginTransaction();
            list = a.GetAllQuantity(list);
            //    a.commitTransaction();

            return list;
            //}
            //catch (Exception ex)
            //{
            //    a.rollbackTransaction();
            //    throw ex;
            //}
        }
Beispiel #22
0
 public void R4(Predict_DAO_MCol dao, RecommdationSchedule schedule, double paramR4, Dictionary<string, double> UCA, List<QTY_GAP> lst)
 {
     List<Recommendation_Meta_Item> list = GetRecommendationR4(dao, paramR4, UCA);
     Normaliser(list);
     AddGAPtoListRecommends(lst, list);
     dao.InsertList(list, schedule);
 }
Beispiel #23
0
 public List<Recommendation_Meta_Item> GetRecommendations(string sql)
 {
     Predict_DAO_MCol a = new Predict_DAO_MCol();
     try
     {
         a.beginTransaction();
         List<Recommendation_Meta_Item> list = a.GetRecommendations(sql);
         a.commitTransaction();
         return list;
     }
     catch (Exception ex)
     {
         a.rollbackTransaction();
         throw ex;
     }
 }
Beispiel #24
0
        public List<QTY_GAP> UpdateQTYGap(Predict_DAO_MCol a, List<ADDGAP> list)
        {
            List<QTY_GAP> lst = new List<QTY_GAP>();
            try
            {

                a.UpdateGAP(list);
                lst = a.GetGAP();
            }
            catch (Exception)
            {

                throw;
            }
            return lst;
        }
Beispiel #25
0
        public Settings GetRecommendationSeting(Predict_DAO_MCol a)
        {
            Settings st = new Settings();

            try
            {
                List<Recommendation_Setting> listCs = a.GetRecommendationSetting();

                if (null != listCs && listCs.Count > 0)
                    foreach (var item in listCs)
                    {
                        if (item.Key.Equals(ConstantValues.nb_R1))
                        {
                            foreach (var cs_detail in item.Values)
                                if (cs_detail.isDedault.Equals(true))
                                {
                                    st.nbR1 = Convert.ToInt32(cs_detail.Value.Trim());
                                    break;
                                }
                        }
                        else
                            if (item.Key.Equals(ConstantValues.nb_R2))
                            {
                                foreach (var cs_detail in item.Values)
                                    if (cs_detail.isDedault.Equals(true))
                                    {
                                        st.nbR2 = Convert.ToInt32(cs_detail.Value.Trim());
                                        break;
                                    }
                            }
                            else if (item.Key.Equals(ConstantValues.nb_R3))
                            {
                                foreach (var cs_detail in item.Values)
                                    if (cs_detail.isDedault.Equals(true))
                                    {
                                        st.nbR3 = Convert.ToInt32(cs_detail.Value.Trim());
                                        break;
                                    }
                            }
                            else if (item.Key.Equals(ConstantValues.param_R4))
                            {
                                foreach (var cs_detail in item.Values)
                                    if (cs_detail.isDedault.Equals(true))
                                    {
                                        st.paramR4 = Convert.ToDouble(cs_detail.Value.Trim(), CultureInfo.CreateSpecificCulture("en-GB"));
                                        break;
                                    }
                            }
                    }

            }
            catch (Exception ex)
            {
                a.rollbackTransaction();
                throw ex;
            }
            return st;
        }
Beispiel #26
0
        //---------------------------------------------------------------------------------------
        //This function computes the DISTANCE matrix and inserts it into the database
        //This is the distance between the two columns of the Rating Matrix
        //---------------------------------------------------------------------------------------
        public void ComputeDIST(Predict_DAO_MCol dao)
        {
            //dao.CLEAN_DIST_Matrix();

            List<string> list_ClusterID = dao.getAllClusterID();
            foreach (var item in list_ClusterID)
            {
                Dictionary<string, int> RM_dic_users = new Dictionary<string, int>();
                Dictionary<string, int> RM_dic_items = new Dictionary<string, int>();
                // Compute ratting matrix
                List<MatrixItem> lstRMI = dao.getRattingMatrixItem_ByClusterID(item);
                double[][] RattingMatrix = Util.toMatrix_MatrixItem(lstRMI, out RM_dic_users, out RM_dic_items);

                if (RattingMatrix.Length > 0 & RM_dic_items.Count > 1)
                {
                    double[][] DIST = new double[RattingMatrix[0].Length][];
                    for (int i = 0; i < RattingMatrix[0].Length; i++)
                        DIST[i] = new double[RattingMatrix[0].Length];

                    // Compute DIST Matrix
                    for (int i1 = 0; i1 < RattingMatrix[0].Length - 1; i1++)
                        for (int i2 = i1 + 1; i2 < RattingMatrix[0].Length; i2++)
                        {
                            double value = 0.0;
                            for (int t = 0; t < RattingMatrix.Length; t++)
                                value += Math.Pow(RattingMatrix[t][i1] - RattingMatrix[t][i2], 2);
                            value = Math.Sqrt(value);
                            DIST[i1][i2] = value;
                            DIST[i2][i1] = value;
                        }

                    if (DIST.Length > 0)
                    {
                        double max = DIST[0][0];
                        // Find Max
                        for (int i = 0; i < DIST.Length; i++)
                        {
                            double localMax = DIST[i].Max();
                            if (localMax > max)
                                max = localMax;
                        }

                        // Standardization
                        if (max != 0)
                        {
                            for (int i = 0; i < DIST.Length; i++)
                                for (int j = 0; j < DIST[0].Length; j++)
                                    DIST[i][j] /= max;
                        }

                        // Save to Database
                        for (int i = 0; i < DIST.Length; i++)
                            for (int j = 0; j < DIST[0].Length; j++)
                                if (DIST[i][j] > 0)
                                {
                                    MatrixItem matrixItem = new MatrixItem();
                                    matrixItem.Row = Util.FindKeyByValue(RM_dic_items, i);
                                    matrixItem.Column = Util.FindKeyByValue(RM_dic_items, j);
                                    matrixItem.Cell = DIST[i][j];
                                    matrixItem.ClusterID = item;
                                    dao.setDIST_Matrix(matrixItem);
                                }
                    }
                }
            }
        }
Beispiel #27
0
        public Dictionary<string, double> getUCA(Predict_DAO_MCol dao)
        {
            Dictionary<string, double> lstUCA = new Dictionary<string, double>();
            try
            {
                lstUCA = dao.getUCA();
            }
            catch (Exception)
            {

                lstUCA = null;
            }
            return lstUCA;
        }
Beispiel #28
0
        //---------------------------------------------------------------------------------------
        //This function computes the Confident Matrix and Weight Matrix, forllowing the formulars
        //---------------------------------------------------------------------------------------
        public void ComputeConfident(Predict_DAO_MCol dao)
        {
            dao.CLEAN_CONF_Matrix();
            dao.CLEAN_WEIG_Matrix();

            List<string> list_ClusterID = dao.getAllClusterID();
            foreach (var item in list_ClusterID)
            {
                List<Transac> u_transacs = dao.getTransac_ForMatrix_ByClusterID_V2(item);
                if (u_transacs.Count > 0)
                {
                    // Get QuantityMatrix - MC
                    Dictionary<string, int> QM_dic_users = new Dictionary<string, int>();
                    Dictionary<string, int> QM_dic_items = new Dictionary<string, int>();
                    double[][] QuantityMatrix = Util.getQuantityMatrix_FromTransac_ByMetaItemID(u_transacs, out QM_dic_users, out QM_dic_items);

                    if (QuantityMatrix[0].Length > 1)
                    {
                        // Compute Support One Item Matrix - MC
                        double[] S = new double[QuantityMatrix[0].Length];
                        for (int j = 0; j < QuantityMatrix[0].Length; j++)
                        {
                            double count = 0.0;
                            for (int i = 0; i < QuantityMatrix.Length; i++)
                                if (QuantityMatrix[i][j] > 0)
                                    count++;
                            S[j] = count;
                        }

                        // Compute Support Matrix - MC
                        double[][] SupportMatrix = new double[QuantityMatrix[0].Length][];
                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                            SupportMatrix[i] = new double[QuantityMatrix[0].Length];

                        for (int i = 0; i < QuantityMatrix.Length; i++)
                        {
                            for (int j = 0; j < QuantityMatrix[0].Length; j++)
                                for (int j2 = 0; j2 < QuantityMatrix[0].Length; j2++)
                                    if (QuantityMatrix[i][j] > 0 & QuantityMatrix[i][j2] > 0 & j != j2)
                                        SupportMatrix[j][j2]++;
                        }

                        // Compute CONF Matrix - MC
                        double[][] CONF = new double[QuantityMatrix[0].Length][];
                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                            CONF[i] = new double[QuantityMatrix[0].Length];

                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                        {
                            for (int j = 0; j < QuantityMatrix[0].Length; j++)
                                if (i == j)
                                    CONF[i][j] = 1.0;
                                else if (S[i] > 0)
                                    CONF[i][j] = SupportMatrix[i][j] / S[i];
                        }

                        // Compute WEIG Matrix - MC
                        double[][] WEIG = new double[QuantityMatrix[0].Length][];
                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                            WEIG[i] = new double[QuantityMatrix[0].Length];

                        for (int i = 0; i < QuantityMatrix[0].Length; i++)
                        {
                            for (int j = 0; j < QuantityMatrix[0].Length; j++)
                                if (i != j)
                                    WEIG[i][j] = computeWEIG(i, j, SupportMatrix, QuantityMatrix);
                        }

                        // Save CONF Matrix - MC
                        for (int i = 0; i < CONF.Length; i++)
                            for (int j = 0; j < CONF[0].Length; j++)
                                if (CONF[i][j] > 0)
                                {
                                    MatrixItem matrixItem = new MatrixItem();
                                    matrixItem.Row = Util.FindKeyByValue(QM_dic_items, i);
                                    matrixItem.Column = Util.FindKeyByValue(QM_dic_items, j);
                                    matrixItem.Cell = CONF[i][j];
                                    matrixItem.ClusterID = item;
                                    dao.setCONF_Matrix(matrixItem);
                                }

                        // Save WEIG Matrix
                        for (int i = 0; i < WEIG.Length; i++)
                            for (int j = 0; j < WEIG[0].Length; j++)
                                if (WEIG[i][j] > 0)
                                {
                                    MatrixItem matrixItem = new MatrixItem();
                                    matrixItem.Row = Util.FindKeyByValue(QM_dic_items, i);
                                    matrixItem.Column = Util.FindKeyByValue(QM_dic_items, j);
                                    matrixItem.Cell = WEIG[i][j];
                                    matrixItem.ClusterID = item;
                                    dao.setWEIG_Matrix(matrixItem);
                                }
                    }
                }
            }
        }
Beispiel #29
0
        public List<Recommendation_Meta_Item> getListRecommendation_R1_TraditionalUsers(Predict_DAO_MCol a, int nbR1)
        {
            //Predict_DAO_MC a = new Predict_DAO_MC();
            List<Recommendation_Meta_Item> list = new List<Recommendation_Meta_Item>();
            List<Recommendation_Meta_Item> RC = new List<Recommendation_Meta_Item>();
            List<string> lstCluster = new List<string>();
            List<string> User_OfCluster = new List<string>();
            //Settings r = GetRecommendationSeting(a);
            lstCluster = a.GetListClusterID();
            //Check number of recommendations
            if (nbR1 <= 0) nbR1 = 1;

            //int i = 0;

            foreach (string cluster in lstCluster)
            {

                User_OfCluster = a.GetListUser_OfCluster(cluster);

                foreach (string u in User_OfCluster)
                {

                    RC = a.GetRecommendC6_ForTraditionalUser(u, nbR1);//2
                    list.AddRange(RC);

                }
            }
            return list;
        }