public void add_User_Centroid(User_Centroid centroid)
        {
            string strSelect = "INSERT INTO  [RS].[USER_CENTROID_TBL] ([ClusterID] ,[MetaItemID] ,[Value]) VALUES (@ClusterID ,@MetaItemID ,@Value) ";
            Dictionary<string, object> parameters = new Dictionary<string, object>();
            parameters.Add("@ClusterID", centroid.ClusterID);
            parameters.Add("@MetaItemID", centroid.MetaItemID);
            parameters.Add("@Value", centroid.Value);

            executeNonQuery(strSelect, parameters);
        }
Example #2
0
        private void LoadUpdateCluster(Clustering_Users_DAO dao,
            Settings st,
            ref bool existTransac,
            List<Partion> listPartion,
            string U_SubCategoryID,
            string categoryName,
            Dictionary<string, int> dic_users,
            Dictionary<string, int> dic_items,
            double[][] x)
        {
            if (x.Length > 0)
            {
                existTransac = true;
                List<string> listClusterID = getListClusterID(listPartion);

                // Get existed V
                double[][] v = new double[listClusterID.Count][];
                Cluster cl = new Cluster();
                cl.addSetting(v.Length, st.maxLoop, x, 0.0001, st.Alpha, st.T, st.U_M);
                Dictionary<int, int> clustered_Data;

                if (listPartion.Count > 0)
                {
                    v = get_V_ByNewItems_ReComputeAll(x, dic_items, dic_users, listPartion, listClusterID);
                    clustered_Data = cl.Clustering_Merge(st.cluster_type, v);
                }
                else
                    clustered_Data = cl.Clustering_Merge(st.cluster_type);

                v = cl.getV();

                // Mapping UserID to clustered Data
                Dictionary<string, int> mapped_Data = map_ID_to_Index(dic_users, clustered_Data);

                #region C1 - Ratting Matrix

                // Add Ratting Matrix
                for (int i = 0; i < x.Length; i++)
                    for (int j = 0; j < x[0].Length; j++)
                        if (x[i][j] > 0)
                        {
                            try
                            {
                                MatrixItem matrixItem = new MatrixItem();
                                matrixItem.ClusterID = categoryName + (mapped_Data[Util.FindKeyByValue(dic_users, i)] + 1);
                                matrixItem.Row = Util.FindKeyByValue(dic_users, i);
                                matrixItem.Column = Util.FindKeyByValue(dic_items, j);
                                matrixItem.Cell = x[i][j];
                                dao.setRattingMatrix(matrixItem);
                            }
                            catch (Exception) { }
                        }

                #endregion

                // Remove old USER_CLUSTER_TBL
                dao.delete_USER_CLUSTER_TBL(categoryName);
                // Add to USER_CLUSTER_TBL
                for (int i = 0; i < v.Length; i++)
                    dao.addCluster(categoryName + (i + 1), U_SubCategoryID);

                // Remove old PARTION_TBL
                dao.delete_PARTION_TBL(categoryName);
                // Add to PARTION_TBL
                foreach (var map in mapped_Data)
                {
                    Partion detail = new Partion();
                    detail.UserID = map.Key;
                    detail.ClusterID = categoryName + (map.Value + 1);
                    dao.addPARTION_TBL(detail);
                }

                // Remove old USER_CENTROID_TBL
                dao.delete_USER_CENTROID_TBL(categoryName);
                // Add to USER_CENTROID_TBL
                for (int i = 0; i < v.Length; i++)
                    for (int j = 0; j < v[0].Length; j++)
                        if (!Double.NaN.Equals(v[i][j]))
                        {
                            try
                            {
                                User_Centroid centroid = new User_Centroid();
                                centroid.Value = v[i][j];
                                centroid.ClusterID = categoryName + (i + 1);
                                centroid.MetaItemID = Util.FindKeyByValue(dic_items, j);
                                dao.add_User_Centroid(centroid);
                            }
                            catch (Exception) { }
                        }

            }
        }
Example #3
0
        private void LoadCluster(Clustering_Users_DAO dao,
            Settings st,
            ref bool existTransac,
            string U_SubCategoryID,
            string categoryName,
            Dictionary<string, int> dic_users,
            Dictionary<string, int> dic_items,
            double[][] x)
        {
            if (x.Length > 0)
            {
                existTransac = true;

                // Clustering Data
                Cluster cluster = new Cluster();
                Dictionary<int, int> clustered_Data = new Dictionary<int, int>();

                cluster.addSetting(st.k, st.maxLoop, x, st.epsilon, st.Alpha, st.T, st.U_M);
                clustered_Data = cluster.Clustering(st.cluster_type);

                //cuong add if
                //if (clustered_Data.Count > 0)
                //{
                    // Mapping UserID to clustered Data
                    Dictionary<string, int> mapped_Data = map_ID_to_Index(dic_users, clustered_Data);

                    // Get Destination V
                    double[][] v = cluster.getV();

                    // Add new data

                    #region C1 - Ratting Matrix

                    // Add Ratting Matrix
                    for (int i = 0; i < x.Length; i++)
                        for (int j = 0; j < x[0].Length; j++)
                            if (x[i][j] > 0)
                            {
                                try
                                {
                                    MatrixItem matrixItem = new MatrixItem();
                                    matrixItem.ClusterID = categoryName + (mapped_Data[Util.FindKeyByValue(dic_users, i)] + 1);
                                    matrixItem.Row = Util.FindKeyByValue(dic_users, i);
                                    matrixItem.Column = Util.FindKeyByValue(dic_items, j);
                                    matrixItem.Cell = x[i][j];
                                    dao.setRattingMatrix(matrixItem);
                                }
                                catch (Exception) { }
                            }

                    #endregion

                    // Add to USER_CLUSTER_TBL
                    for (int i = 0; i < v.Length; i++)
                        dao.addCluster(categoryName + (i + 1), U_SubCategoryID);

                    // Add to PARTION_TBL
                    foreach (var map in mapped_Data)
                    {
                        Partion detail = new Partion();
                        detail.UserID = map.Key;
                        detail.ClusterID = categoryName + (map.Value + 1);
                        dao.addPARTION_TBL(detail);
                    }

                    // Add to USER_CENTROID_TBL
                    for (int i = 0; i < v.Length; i++)
                        for (int j = 0; j < v[0].Length; j++)
                            if (!Double.NaN.Equals(v[i][j]))
                            {
                                try
                                {
                                    User_Centroid centroid = new User_Centroid();
                                    centroid.Value = v[i][j];
                                    centroid.ClusterID = categoryName + (i + 1);
                                    centroid.MetaItemID = Util.FindKeyByValue(dic_items, j);
                                    dao.add_User_Centroid(centroid);
                                }
                                catch (Exception) { }
                            }
                }
            //}//cuong add
        }
 public List<User_Centroid> getUserCentroid(string ClusterID)
 {
     string strSelect = "SELECT [ClusterID] ,[MetaItemID] ,[Value] FROM [RS].[USER_CENTROID_TBL] WHERE [ClusterID]=@ClusterID";
     Dictionary<string, object> parameters = new Dictionary<string, object>();
     parameters.Add("@ClusterID", ClusterID);
     SqlDataReader dr = executeReader(strSelect, parameters);
     List<User_Centroid> list = new List<User_Centroid>();
     while (dr.Read())
     {
         User_Centroid obj = new User_Centroid();
         obj.ClusterID = ClusterID;
         obj.MetaItemID = dr.GetString(dr.GetOrdinal("MetaItemID"));
         obj.Value = dr.GetDouble(dr.GetOrdinal("Value"));
         list.Add(obj);
     }
     dr.Close();
     return list;
 }