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


C# IList.Shuffle方法代码示例

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


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

示例1: Train

        public void Train(IList<InputOutput> trainingSet, INeuralNetwork nn)
        {
            Validate();

            if (nn == null)
                throw new ArgumentNullException(nameof(nn));

            var rand = RandomProvider.GetRandom(Seed);

            if (ShouldInitializeWeights)
                InitializeWeights(nn, rand);

            var validationSetFraction = GetValidationSetFraction();

            IList<InputOutput> trainingSubSet;
            IList<InputOutput> validationSubSet = null;

            if (validationSetFraction > 0)
            {
                var split = trainingSet.Shuffle(rand).Split(validationSetFraction);
                validationSubSet = split.First;
                trainingSubSet = split.Second;
            }
            else
            {
                trainingSubSet = trainingSet;
            }

            Train(trainingSubSet, validationSubSet, rand, nn);
        }
开发者ID:ikhramts,项目名称:NNX,代码行数:30,代码来源:BaseTrainer.cs

示例2: GetMatches

        /// <summary>
        /// Returns a list of matches where each team from list1 plays against a team from teams2.
        /// All teams from both lists play one match. Whether a team plays home or away is determined randomly.
        /// The total number of teams for both lists must be an even number and both lists must contain an equal number of teams.
        /// </summary>
        public List<Match> GetMatches(IList<Team> teams1, IList<Team> teams2)
        {
            // Total number of teams must be even and both lists same number of teams.
             bool isValid = (teams1.Count + teams2.Count) % 2 == 0
                        && teams1.Count == teams2.Count;
             if (!isValid)
             {
            throw new Exception("Even number of teams expected and both lists same number of teams");
             }

             teams1.Shuffle();
             teams2.Shuffle();

             var matches = new List<Match>();
             for (int i = 0; i < teams1.Count; i++)
             {
            // Optionally swith home/away
            var homeTeam = teams1[i];
            var awayTeam = teams2[i];
            bool switchHomeAndAway = _randomizer.GetRandomBoolean();
            if (switchHomeAndAway)
            {
               homeTeam = teams2[i];
               awayTeam = teams1[i];
            }

            var match = MatchFactory.CreateMatch(homeTeam, awayTeam);

            matches.Add(match);
             }

             return matches;
        }
开发者ID:bouwe77,项目名称:fmg,代码行数:38,代码来源:SingleRoundTournamentManager.cs

示例3: EvaluateOnline

        /// <summary>Online evaluation for rankings of items</summary>
        /// <remarks>
        /// The evaluation protocol works as follows:
        /// For every test user, evaluate on the test items, and then add the those test items to the training set and perform an incremental update.
        /// The sequence of users is random.
        /// </remarks>
        /// <param name="recommender">the item recommender to be evaluated</param>
        /// <param name="test">test cases</param>
        /// <param name="training">training data (must be connected to the recommender's training data)</param>
        /// <param name="test_users">a list of all test user IDs</param>
        /// <param name="candidate_items">a list of all candidate item IDs</param>
        /// <param name="candidate_item_mode">the mode used to determine the candidate items</param>
        /// <returns>a dictionary containing the evaluation results (averaged by user)</returns>
        public static ItemRecommendationEvaluationResults EvaluateOnline(
			this IRecommender recommender,
			IPosOnlyFeedback test, IPosOnlyFeedback training,
			IList<int> test_users, IList<int> candidate_items,
			CandidateItems candidate_item_mode)
        {
            var incremental_recommender = recommender as IIncrementalItemRecommender;
            if (incremental_recommender == null)
                throw new ArgumentException("recommender must be of type IIncrementalItemRecommender");

            // prepare candidate items once to avoid recreating them
            switch (candidate_item_mode)
            {
                case CandidateItems.TRAINING: candidate_items = training.AllItems; break;
                case CandidateItems.TEST:     candidate_items = test.AllItems; break;
                case CandidateItems.OVERLAP:  candidate_items = new List<int>(test.AllItems.Intersect(training.AllItems)); break;
                case CandidateItems.UNION:    candidate_items = new List<int>(test.AllItems.Union(training.AllItems)); break;
            }

            test_users.Shuffle();
            var results_by_user = new Dictionary<int, ItemRecommendationEvaluationResults>();
            foreach (int user_id in test_users)
            {
                if (candidate_items.Intersect(test.ByUser[user_id]).Count() == 0)
                    continue;

                // prepare data
                var current_test_data = new PosOnlyFeedback<SparseBooleanMatrix>();
                foreach (int index in test.ByUser[user_id])
                    current_test_data.Add(user_id, test.Items[index]);
                // evaluate user
                var current_result = Items.Evaluate(recommender, current_test_data, training, current_test_data.AllUsers, candidate_items, CandidateItems.EXPLICIT);
                results_by_user[user_id] = current_result;

                // update recommender
                var tuples = new List<Tuple<int, int>>();
                foreach (int index in test.ByUser[user_id])
                    tuples.Add(Tuple.Create(user_id, test.Items[index]));
                incremental_recommender.AddFeedback(tuples);
            }

            var results = new ItemRecommendationEvaluationResults();

            foreach (int u in results_by_user.Keys)
                foreach (string measure in Items.Measures)
                    results[measure] += results_by_user[u][measure];

            foreach (string measure in Items.Measures)
                results[measure] /= results_by_user.Count;

            results["num_users"] = results_by_user.Count;
            results["num_items"] = candidate_items.Count;
            results["num_lists"] = results_by_user.Count;

            return results;
        }
开发者ID:wendelad,项目名称:RecSys,代码行数:69,代码来源:ItemsOnline.cs

示例4: InfectionDeck

 public InfectionDeck(IList<InfectionCard> infectionCards)
 {
     infectionCards.Shuffle();
     foreach (InfectionCard card in infectionCards)
     {
         card.Discarded += CardDiscarded;
     }
     cardPile = new Stack<InfectionCard>(infectionCards);
     discardPile = new Stack<InfectionCard>();
 }
开发者ID:BrandonFitzgibbon,项目名称:Pandemic,代码行数:10,代码来源:InfectionDeck.cs

示例5: FetchTopicMetadata

        /// <summary>
        /// Used by the producer to send a metadata request since it has access to the ProducerConfig
        /// </summary>
        /// <param name="topics">The topics for which the metadata needs to be fetched</param>
        /// <param name="brokers">The brokers in the cluster as configured on the client</param>
        /// <param name="producerConfig">The producer's config</param>
        /// <param name="correlationId">topic metadata response</param>
        /// <returns></returns>
        public static TopicMetadataResponse FetchTopicMetadata(
            ISet<string> topics, IList<Broker> brokers, ProducerConfig producerConfig, int correlationId)
        {
            var fetchMetaDataSucceeded = false;
            var i = 0;
            var topicMetadataRequest = new TopicMetadataRequest(
                TopicMetadataRequest.CurrentVersion, correlationId, producerConfig.ClientId, topics.ToList());

            TopicMetadataResponse topicMetadataResponse = null;
            Exception t = null;

            // shuffle the list of brokers before sending metadata requests so that most requests don't get routed to the same broker
            var shuffledBrokers = brokers.Shuffle();
            while (i < shuffledBrokers.Count() && !fetchMetaDataSucceeded)
            {
                var producer = ProducerPool.CreateSyncProducer(producerConfig, shuffledBrokers[i]);
                Logger.InfoFormat("Fetching metadata from broker {0} with correlation id {1} for {2} topic(s) {3}", shuffledBrokers[i], correlationId, topics.Count, string.Join(",", topics));
                try
                {
                    topicMetadataResponse = producer.Send(topicMetadataRequest);
                    fetchMetaDataSucceeded = true;
                }
                catch (Exception e)
                {
                    Logger.Warn(string.Format("Fetching topic metadata with correlation id {0} for topic [{1}] from broker [{2}] failed", correlationId, topics, shuffledBrokers[i]), e);
                    t = e;
                }
                finally
                {
                    i++;
                    producer.Dispose();
                }
            }

            if (!fetchMetaDataSucceeded)
            {
                throw new KafkaException(
                    string.Format(
                        "fetching topic metadata for topics [{0}] from broker [{1}] failed", string.Join(",", topics), string.Join(", ", shuffledBrokers)),
                    t);
            }

            Logger.DebugFormat("Successfully fetched metadata for {0} topic(s) {1}", topics.Count(), string.Join(",",  topics));
            return topicMetadataResponse;
        }
开发者ID:CMTelecom,项目名称:kafka-net,代码行数:53,代码来源:ClientUtils.cs

示例6: GetNightActivity

        /// <summary>
        /// SIDE EFFECT: Sets the Victim property if needed
        /// </summary>
        /// <param name="zoo"></param>
        /// <param name="killer"></param>
        /// <returns>the night activity text</returns>
        public IList<string> GetNightActivity(IList<string> zoo, string killer)
        {
            if (!zoo.Contains(killer))
            {
                return new List<string>();
            }

            zoo.Shuffle();
            Victim = GetVictim(zoo, killer);

            IList<string> nightCopy = new List<string>(GameResources.TwoPersonNightActivities);
            nightCopy.Shuffle();

            IList<string> activities = new List<string>();
            for (int i = 0; i < zoo.Count - 1; i++)
            {
                activities.Add(String.Format(nightCopy[i], zoo[i], zoo[i + 1]));
            }
            activities.Add(String.Format(nightCopy[zoo.Count], zoo[zoo.Count - 1], zoo[0]));
            activities.Shuffle();

            return activities;
        }
开发者ID:mprofGamesDev-Dreams,项目名称:zooDoneIt,代码行数:29,代码来源:ClueManager.cs

示例7: FoldIn

        ///
        protected override float[] FoldIn(IList<Tuple<int, float>> rated_items)
        {
            SetupLoss();

            // initialize user parameters
            float user_bias = 0;
            var factors = new float[NumFactors];
            factors.InitNormal(InitMean, InitStdDev);

            float reg_weight = FrequencyRegularization ? (float) (RegU / Math.Sqrt(rated_items.Count)) : RegU;

            // perform training
            rated_items.Shuffle();
            for (uint it = 0; it < NumIter; it++)
                for (int index = 0; index < rated_items.Count; index++)
                {
                    int item_id = rated_items[index].Item1;

                    // compute rating and error
                    double score = global_bias + user_bias + item_bias[item_id] + DataType.MatrixExtensions.RowScalarProduct(item_factors, item_id, factors);
                    double sig_score = 1 / (1 + Math.Exp(-score));
                    double prediction = min_rating + sig_score * rating_range_size;
                    double err = rated_items[index].Item2 - prediction;

                    float gradient_common = compute_gradient_common(sig_score, err);

                    // adjust bias
                    user_bias += BiasLearnRate * LearnRate * (gradient_common - BiasReg * reg_weight * user_bias);

                    // adjust factors
                    for (int f = 0; f < NumFactors; f++)
                    {
                        float u_f = factors[f];
                        float i_f = item_factors[item_id, f];

                        double delta_u = gradient_common * i_f - reg_weight * u_f;
                        factors[f] += (float) (LearnRate * delta_u);
                    }
                }

            var user_vector = new float[NumFactors + 1];
            user_vector[FOLD_IN_BIAS_INDEX] = user_bias;
            Array.Copy(factors, 0, user_vector, FOLD_IN_FACTORS_START, NumFactors);

            return user_vector;
        }
开发者ID:pipifuyj,项目名称:MyMediaLite,代码行数:47,代码来源:BiasedMatrixFactorization.cs

示例8: FoldIn

        ///
        protected override float[] FoldIn(IList<Tuple<int, float>> rated_items)
        {
            var user_p = new float[NumFactors];
            user_p.InitNormal(InitMean, InitStdDev);
            float user_bias = 0;

            var items = (from pair in rated_items select pair.Item1).ToArray();
            float user_reg_weight = FrequencyRegularization ? (float) (Regularization / Math.Sqrt(items.Length)) : Regularization;

            // compute stuff that will not change
            var y_sum_vector = y.SumOfRows(items);
            double norm_denominator = Math.Sqrt(items.Length);
            for (int f = 0; f < y_sum_vector.Count; f++)
                y_sum_vector[f] = (float) (y_sum_vector[f] / norm_denominator);

            rated_items.Shuffle();
            for (uint it = 0; it < NumIter; it++)
            {
                for (int index = 0; index < rated_items.Count; index++)
                {
                    int item_id = rated_items[index].Item1;

                    double prediction = global_bias + user_bias + item_bias[item_id];
                    prediction += DataType.MatrixExtensions.RowScalarProduct(item_factors, item_id, y_sum_vector);
                    prediction += DataType.MatrixExtensions.RowScalarProduct(item_factors, item_id, user_p);

                    float err = (float) (rated_items[index].Item2 - prediction);

                    // adjust bias
                    user_bias += BiasLearnRate * LearnRate * ((float) err - BiasReg * user_reg_weight * user_bias);

                    // adjust factors
                    for (int f = 0; f < NumFactors; f++)
                    {
                        float u_f = user_p[f];
                        float i_f = item_factors[item_id, f];

                        double delta_u = err * i_f - user_reg_weight * u_f;
                        user_p[f] += (float) (LearnRate * delta_u);
                    }
                }
            }

            // assign final parameter values to return vector
            var user_vector = new float[NumFactors + 1];
            user_vector[0] = user_bias;
            for (int f = 0; f < NumFactors; f++)
                user_vector[f + 1] = (float) y_sum_vector[f] + user_p[f];

            return user_vector;
        }
开发者ID:Spirit-Dongdong,项目名称:MyMediaLite,代码行数:52,代码来源:SVDPlusPlus.cs

示例9: FoldIn

        ///
        protected override float[] FoldIn(IList<Tuple<int, float>> rated_items)
        {
            SetupLoss();

            float user_bias = 0;

            var items = (from pair in rated_items select pair.Item1).ToArray();
            float user_reg_weight = FrequencyRegularization ? (float) (Regularization / Math.Sqrt(items.Length)) : Regularization;

            // compute stuff that will not change
            var y_sum_vector = y.SumOfRows(items);
            double norm_denominator = Math.Sqrt(items.Length);
            for (int f = 0; f < y_sum_vector.Count; f++)
                y_sum_vector[f] = (float) (y_sum_vector[f] / norm_denominator);

            rated_items.Shuffle();
            for (uint it = 0; it < NumIter; it++)
            {
                for (int index = 0; index < rated_items.Count; index++)
                {
                    int item_id = rated_items[index].Item1;

                    double score = global_bias + user_bias + item_bias[item_id];
                    score += item_factors.RowScalarProduct(item_id, y_sum_vector);
                    double sig_score = 1 / (1 + Math.Exp(-score));
                    double prediction = min_rating + sig_score * rating_range_size;
                    float err = (float) (rated_items[index].Item2 - prediction);
                    float gradient_common = compute_gradient_common(sig_score, err);

                    // adjust bias
                    user_bias += BiasLearnRate * LearnRate * ((float) gradient_common - BiasReg * user_reg_weight * user_bias);
                }
            }

            // assign final parameter values to return vector
            var user_vector = new float[NumFactors + 1];
            user_vector[0] = user_bias;
            for (int f = 0; f < NumFactors; f++)
                user_vector[f + 1] = (float) y_sum_vector[f];

            return user_vector;
        }
开发者ID:Spirit-Dongdong,项目名称:MyMediaLite,代码行数:43,代码来源:SigmoidItemAsymmetricFactorModel.cs

示例10: FoldIn

        /// <summary>Compute parameters (latent factors) for a user represented by ratings</summary>
        /// <returns>a vector of latent factors</returns>
        /// <param name='rated_items'>a list of (item ID, rating value) pairs</param>
        protected virtual float[] FoldIn(IList<Pair<int, float>> rated_items)
        {
            var user_vector = new float[NumFactors];
            user_vector.InitNormal(InitMean, InitStdDev);
            rated_items.Shuffle();
            for (uint it = 0; it < NumIter; it++)
            {
                for (int index = 0; index < rated_items.Count; index++)
                {
                    int item_id = rated_items[index].First;
                    float err = rated_items[index].Second - Predict(user_vector, item_id, false);

                    // adjust factors
                    for (int f = 0; f < NumFactors; f++)
                    {
                        float u_f = user_vector[f];
                        float i_f = item_factors[item_id, f];

                        double delta_u = err * i_f - Regularization * u_f;
                        user_vector[f] += (float) (LearnRate * delta_u);
                    }
                }
            }
            return user_vector;
        }
开发者ID:mvreg,项目名称:MyMediaLite,代码行数:28,代码来源:ThreadSafeMatrixFactorization.cs

示例11: StartRound

		void StartRound() {
			int round = rounds.Count + 1;

			var previousRound = currentRound;
			if (currentRound != null)
				rounds.Add(currentRound);
			currentRound = new List<Attempt>();

			items = previousRound != null 
				? new List<PracticeItem>(from x in previousRound where !x.Correct select x.Item) 
				: Owner.GetAllItems();

			items.Shuffle(rng);

			index = 0;
			score = 0;

			state = items.Count > 0 ? State.Guessing : State.GameOverview;
		}
开发者ID:dbremner,项目名称:szotar,代码行数:19,代码来源:Learn.cs

示例12: BonusGenerateAsync

 public async Task BonusGenerateAsync(int count)
 {
     var connect = new SQLiteAsyncConnection(DataBaseFile);
     _bonuses = await connect.Table<BonusTable>().Take(count).ToListAsync();
     _bonuses.Shuffle();
 }
开发者ID:okrotowa,项目名称:Yorsh,代码行数:6,代码来源:Rep.cs


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