当前位置: 首页>>代码示例>>C#>>正文


C# ICollection.Intersect方法代码示例

本文整理汇总了C#中ICollection.Intersect方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Intersect方法的具体用法?C# ICollection.Intersect怎么用?C# ICollection.Intersect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICollection的用法示例。


在下文中一共展示了ICollection.Intersect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compute

        /// <summary>Compute the area under the ROC curve (AUC) of a list of ranked items</summary>
        /// <remarks>
        /// See http://recsyswiki.com/wiki/Area_Under_the_ROC_Curve
        /// </remarks>
        /// <param name="ranked_items">a list of ranked item IDs, the highest-ranking item first</param>
        /// <param name="relevant_items">a collection of positive/correct item IDs</param>
        /// <param name="ignore_items">a collection of item IDs which should be ignored for the evaluation</param>
        /// <returns>the AUC for the given data</returns>
        public static double Compute(IList<int> ranked_items, ICollection<int> relevant_items, ICollection<int> ignore_items = null)
        {
            if (ignore_items == null)
                ignore_items = new HashSet<int>();

            // TODO check again! -- think about good names
            var relevant_items_in_list = relevant_items.Intersect(ranked_items);
            int num_relevant_items = relevant_items_in_list.Count() - ignore_items.Intersect(relevant_items_in_list).Count();
            int num_eval_items     = ranked_items.Count - ignore_items.Intersect(ranked_items).Count();
            int num_eval_pairs     = (num_eval_items - num_relevant_items) * num_relevant_items;
            if (num_eval_pairs < 0)
                throw new ArgumentException("correct_items cannot be larger than ranked_items");

            if (num_eval_pairs == 0)
                return 0.5;

            int num_correct_pairs = 0;
            int hit_count         = 0;
            foreach (int item_id in ranked_items)
            {
                if (ignore_items.Contains(item_id))
                    continue;

                if (!relevant_items.Contains(item_id))
                    num_correct_pairs += hit_count;
                else
                    hit_count++;
            }

            return (double) num_correct_pairs / num_eval_pairs;
        }
开发者ID:tarunanand,项目名称:MyMediaLite,代码行数:39,代码来源:AUC.cs

示例2: Compute

        /// <summary>Compute the area under the ROC curve (AUC) of a list of ranked items</summary>
        /// <remarks>
        /// See http://recsyswiki.com/wiki/Area_Under_the_ROC_Curve
        /// </remarks>
        /// <param name="ranked_items">a list of ranked item IDs, the highest-ranking item first</param>
        /// <param name="relevant_items">a collection of positive/correct item IDs</param>
        /// <param name="num_dropped_items">the number of relevant items that were not ranked (considered to be ranked below all ranked_items)</param>
        /// <returns>the AUC for the given data</returns>
        public static double Compute(IList<int> ranked_items, ICollection<int> relevant_items, int num_dropped_items)
        {
            var relevant_items_in_list = relevant_items.Intersect(ranked_items);
            int num_relevant_items = relevant_items_in_list.Count();
            int num_eval_items     = ranked_items.Count + num_dropped_items;
            int num_eval_pairs     = (num_eval_items - num_relevant_items) * num_relevant_items;
            if (num_eval_pairs < 0)
                throw new Exception("num_eval_pairs cannot be less than 0");

            if (num_eval_pairs == 0)
                return 0.5;

            int num_correct_pairs = 0;
            int hit_count         = 0;
            foreach (int item_id in ranked_items)
                if (!relevant_items.Contains(item_id))
                    num_correct_pairs += hit_count;
                else
                    hit_count++;

            int missing_relevant_items = relevant_items.Except(ranked_items).Count();
            num_correct_pairs += hit_count * (num_dropped_items - missing_relevant_items);

            return (double) num_correct_pairs / num_eval_pairs;
        }
开发者ID:Ambier,项目名称:MyMediaLite,代码行数:33,代码来源:AUC.cs

示例3: AUC

        /// <summary>Compute the area under the ROC curve (AUC) of a list of ranked items</summary>
        /// <param name="ranked_items">a list of ranked item IDs, the highest-ranking item first</param>
        /// <param name="correct_items">a collection of positive/correct item IDs</param>
        /// <param name="ignore_items">a collection of item IDs which should be ignored for the evaluation</param>
        /// <returns>the AUC for the given data</returns>
        public static double AUC(int[] ranked_items, ICollection<int> correct_items, ICollection<int> ignore_items)
        {
            int num_eval_items = ranked_items.Length - ignore_items.Intersect(ranked_items).Count();
                int num_eval_pairs = (num_eval_items - correct_items.Count) * correct_items.Count;

                int num_correct_pairs = 0;
                int hit_count         = 0;

                foreach (int item_id in ranked_items)
                {
                    if (ignore_items.Contains(item_id))
                        continue;

                    if (!correct_items.Contains(item_id))
                        num_correct_pairs += hit_count;
                    else
                        hit_count++;
                }

                return ((double) num_correct_pairs) / num_eval_pairs;
        }
开发者ID:zenogantner,项目名称:MML-KDD,代码行数:26,代码来源:Items.cs

示例4: SaveWs

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Save the new list of writing systems to the database
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected void SaveWs(CheckedListBox lstBox, IList<IWritingSystem> currList, ICollection<IWritingSystem> allSet)
		{
			if (allSet.Count != lstBox.Items.Count || allSet.Intersect(lstBox.Items.Cast<IWritingSystem>()).Count() != allSet.Count)
			{
				var newWsIds = new List<string>();
				foreach (IWritingSystem ws in lstBox.Items)
				{
					string id = ws.IcuLocale;
					if (allSet.FirstOrDefault(existing => existing.IcuLocale == id) == null)
						newWsIds.Add(id);
				}
				allSet.Clear();
				foreach (IWritingSystem ws in lstBox.Items)
				{
					if (ws.Handle == 0)
						m_cache.ServiceLocator.WritingSystemManager.Replace(ws);
					allSet.Add(ws);
				}
				m_fWsChanged = true;
				foreach (var newWs in newWsIds)
				{
					// IcuLocale uses _ to separate, RFC5646 uses -.  We need the latter (see FWNX-1165).
					ProgressDialogWithTask.ImportTranslatedListsForWs(this, m_cache, newWs.Replace("_","-"));
				}
			}

			if (!currList.SequenceEqual(lstBox.CheckedItems.Cast<IWritingSystem>()))
			{
				currList.Clear();
				foreach (IWritingSystem ws in lstBox.CheckedItems)
					currList.Add(ws);
				m_fWsChanged = true;
			}
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:39,代码来源:FwProjPropertiesDlg.cs

示例5: WsListChanged

		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Save the new list of writing systems to the database
		/// </summary>
		/// ------------------------------------------------------------------------------------
		protected bool WsListChanged(CheckedListBox lstBox, IList<IWritingSystem> currList, ICollection<IWritingSystem> allSet)
		{
			if (allSet.Count != lstBox.Items.Count || allSet.Intersect(lstBox.Items.Cast<IWritingSystem>()).Count() != allSet.Count)
			{
				return true;
			}

			if (!currList.SequenceEqual(lstBox.CheckedItems.Cast<IWritingSystem>()))
			{
				return true;
			}
			return false;
		}
开发者ID:bbriggs,项目名称:FieldWorks,代码行数:18,代码来源:FwProjPropertiesDlg.cs

示例6: CreateEntityType

        private void CreateEntityType(
            LoadMethodSessionState session, 
            IList<TableDetailsRow> columns, 
            ICollection<string> primaryKeys,
            DbObjectType objectType,
            List<EdmSchemaError> errors)
        {
            Debug.Assert(columns.Count != 0, "Trying to create an EntityType with 0 properties");
            Debug.Assert(primaryKeys != null, "primaryKeys != null");

            DbObjectKey tableKey = columns[0].CreateDbObjectKey(objectType);
            if (errors == null)
            {
                errors = new List<EdmSchemaError>();
            }

            //
            // Handle Tables without explicit declaration of keys
            //
            EntityCreationStatus status = EntityCreationStatus.Normal;
            if (primaryKeys.Count == 0)
            {
                List<string> pKeys = new List<string>(columns.Count);
                session.AddTableWithoutKey(tableKey);
                if (InferKeyColumns(session, columns, pKeys, tableKey, ref primaryKeys))
                {
                    errors.Add(new EdmSchemaError(
                        Strings.NoPrimaryKeyDefined(tableKey),
                                    (int)ModelBuilderErrorCode.NoPrimaryKeyDefined,
                                     EdmSchemaErrorSeverity.Warning));
                    status = EntityCreationStatus.ReadOnly;
                }
                else
                {
                    errors.Add(new EdmSchemaError(
                        Strings.CannotCreateEntityWithNoPrimaryKeyDefined(tableKey),
                                        (int)ModelBuilderErrorCode.CannotCreateEntityWithoutPrimaryKey,
                                        EdmSchemaErrorSeverity.Warning));
                    status = EntityCreationStatus.Invalid;
                }
            }

            Debug.Assert(primaryKeys == null || primaryKeys.Count > 0,"There must be at least one key columns at this point in time");

            IList<string> excludedColumns;
            var properties = CreateEdmProperties(session, columns, tableKey, errors, out excludedColumns);

            var excludedKeyColumns = (primaryKeys != null ? primaryKeys.Intersect(excludedColumns) : new string[0]).ToArray();

            if (primaryKeys != null && excludedKeyColumns.Length == 0)
            {
                foreach (EdmMember pkColumn in properties.Where(p => primaryKeys.Contains(p.Name)))
                {
                    if (!MetadataUtil.IsValidKeyType(_targetEntityFrameworkVersion, pkColumn.TypeUsage.EdmType))
                    {
                        // make it a read-only table by calling this method recursively with no keys
                        errors = new List<EdmSchemaError>();
                        var tableColumn = columns.Where(c => c.ColumnName == pkColumn.Name).Single();
                        errors.Add(new EdmSchemaError(Strings.InvalidTypeForPrimaryKey(tableColumn.GetMostQualifiedTableName(),
                            tableColumn.ColumnName,
                            tableColumn.DataType),
                            (int)ModelBuilderErrorCode.InvalidKeyTypeFound,
                            EdmSchemaErrorSeverity.Warning));

                        string[] keyColumns = new string[0];
                        CreateEntityType(session, columns, keyColumns, objectType, errors);
                        return;
                    }
                }
            }

            if (excludedKeyColumns.Length > 0)
            {
                // see if we have any keys left
                if (primaryKeys != null && excludedKeyColumns.Length < primaryKeys.Count)
                {
                    primaryKeys = primaryKeys.Except(excludedKeyColumns).ToList();
                    status = EntityCreationStatus.ReadOnly;
                }
                else
                {
                    primaryKeys = null;
                    status = EntityCreationStatus.Invalid;
                }

                foreach (string columnName in excludedKeyColumns)
                {
                    if (status == EntityCreationStatus.ReadOnly)
                    {
                        errors.Add(new EdmSchemaError(
                            Strings.ExcludedColumnWasAKeyColumnEntityIsReadOnly(columnName, columns[0].GetMostQualifiedTableName()),
                            (int)ModelBuilderErrorCode.ExcludedColumnWasAKeyColumn,
                            EdmSchemaErrorSeverity.Warning));
                    }
                    else
                    {
                        Debug.Assert(status == EntityCreationStatus.Invalid, "Did we change some code above to make it possible to be something different?");
                        errors.Add(new EdmSchemaError(
                            Strings.ExcludedColumnWasAKeyColumnEntityIsInvalid(columnName, columns[0].GetMostQualifiedTableName()),
                            (int)ModelBuilderErrorCode.ExcludedColumnWasAKeyColumn,
//.........这里部分代码省略.........
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:101,代码来源:EntityStoreSchemaGenerator.cs


注:本文中的ICollection.Intersect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。