예제 #1
0
        public void WhereShouldWorkWithIndexAndReturnObjectsThatMeetPredicateCriteria()
        {
            var numbers         = new Int32[] { 0, 30, 20, 15, 90, 85, 40, 75 };
            var expectedResults = new Int32[] { 0, 20, 15, 40 };
            var query           = numbers.Where((number, index) => number <= index * 10);
            var enumerator      = query.GetEnumerator();

            Assert.AreEqual(expectedResults.Count(), query.Count());
            for (Int32 i = 0; i < expectedResults.Count(); i++)
            {
                enumerator.MoveNext();
                Assert.AreEqual(expectedResults[i], enumerator.Current);
            }
        }
예제 #2
0
        private void Button2_Click(object sender, RoutedEventArgs e)
        {
            Int32[] nbres = new Int32[1000];
            Random  rnd   = new Random();

            for (Int32 i = 0; i < nbres.Length; i++)
            {
                nbres[i] = rnd.Next(0, 100);
            }
            int n4 = nbres.Count((x) => x > 50);
            int n5 = nbres.Count((y) => (y % 2) == 0);

            MessageBox.Show("Il y a " + n4.ToString() + " chiffres supérieur à 50");
            MessageBox.Show("Il y a " + n5.ToString() + " chiffres paires");
        }
        private void AlgorithmFinal(AbstractNetworkContainer containerToChange)
        {
            Int32[] final = new Int32[containerToChange.Size];
            for (int i = 0; i < final.Length; ++i)
            {
                final[i] = containerToChange.GetActiveStatus(i) ? 1 : 0;
            }

            for (int i = 0; i < containerToChange.GetActiveStatuses().Count; ++i)
            {
                if (!containerToChange.GetActiveStatus(i))
                {
                    continue;
                }
                if (Rand.NextDouble() < lambda)
                {
                    Int32 index = RandomNeighbourToActivate(containerToChange, true, i);
                    if (index != -1)
                    {
                        ++final[index];
                    }
                }
                if (Rand.NextDouble() < mu)
                {
                    --final[i];
                }
            }

            for (int i = 0; i < final.Count(); ++i)
            {
                // TODO get k as parameter
                containerToChange.SetActiveStatus(i, final[i] > 0);
            }
        }
예제 #4
0
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            Int32[] nbres = new Int32[1000];
            Random  rnd   = new Random();

            for (Int32 i = 0; i < nbres.Length; i++)
            {
                nbres[i] = rnd.Next(0, 100);
            }
            int n = nbres.Count((x) => x > 50);

            MessageBox.Show(n.ToString());
            int n2 = nbres.Count((x) => (x % 2) == 0);

            MessageBox.Show(n2.ToString());
        }
예제 #5
0
        /// <summary>
        /// Метод Train реализует обучения по методу градиентного спуска
        /// </summary>
        /// <param name="trainData">Выборка данных для обучения модели</param>
        /// <param name="maxEpochs">Максимальная ошибка</param>
        /// <param name="alpha">Скорость обучения</param>
        /// <returns></returns>
        public Double[] Train(Double[][] trainData, Int32 maxEpochs, Double alpha)
        {
            // скорость обучения
            Int32 epoch = 0;

            // случайнный порядок
            Int32[] sequence = new Int32[trainData.Count()];
            for (Int32 i = 0; i < sequence.Count(); ++i)
            {
                sequence[i] = i;
            }
            while (epoch < maxEpochs)
            {
                ++epoch;
                if (epoch % 100 == 0 && epoch != maxEpochs)
                {
                    Double mse = Error(trainData, weights);
                }
                Shuffle(sequence); // обработка данных в случайном порядке
                // Стохастический или поэтапный подход
                for (Int32 ti = 0; ti < trainData.Count(); ++ti)
                {
                    Int32  i           = sequence[ti];
                    Double computed    = ComputeOutput(trainData[i], weights);
                    Int32  targetIndex = trainData[i].Count() - 1;
                    Double target      = trainData[i][targetIndex];
                    // вес b0 имеет фиктивный 1 вход
                    weights[0] += alpha * (target - computed) * 1;
                    for (Int32 j = 1; j < weights.Count(); ++j)
                    {
                        weights[j] += alpha * (target - computed) * trainData[i][j - 1];
                    }
                }
                // один счет для каждого веса
                Double[] accumulatedGradients = new Double[weights.Length];
                for (Int32 i = 0; i < trainData.Count(); ++i)  // накопление
                {
                    // Нет необходимости, чтобы перетасовать данные
                    double computed    = ComputeOutput(trainData[i], weights);
                    Int32  targetIndex = trainData[i].Length - 1;
                    Double target      = trainData[i][targetIndex];
                    accumulatedGradients[0] += (target - computed) * 1;
                    for (Int32 j = 1; j < weights.Count(); ++j)
                    {
                        accumulatedGradients[j] += (target - computed) * trainData[i][j - 1];
                    }
                }
                for (Int32 j = 0; j < weights.Count(); ++j)
                {
                    weights[j] += alpha * accumulatedGradients[j];
                }
            }
            return(weights);
        }
예제 #6
0
        public SongLevel(BinaryReader br, int version)
        {
            Difficulty  = br.ReadInt32();
            AnchorCount = br.ReadInt32();
            Anchors     = new Anchor[AnchorCount];
            for (int i = 0; i < AnchorCount; ++i)
            {
                Anchors[i] = new Anchor(br);
            }

            SlideCount = br.ReadInt32();
            Slides     = new Slide[SlideCount];
            for (int i = 0; i < SlideCount; ++i)
            {
                Slides[i] = new Slide(br);
            }

            HandShapeCount = br.ReadInt32();
            HandShapes     = new HandShape[HandShapeCount];
            for (int i = 0; i < HandShapeCount; ++i)
            {
                HandShapes[i] = new HandShape(br);
            }

            NoteCount = br.ReadInt32();
            Notes     = new Note[NoteCount];
            for (int i = 0; i < NoteCount; ++i)
            {
                Notes[i] = new Note(br, version);
            }

            PhraseCount           = br.ReadInt32();
            AverageNotesPerPhrase = new float[PhraseCount];
            for (int i = 0; i < PhraseCount; ++i)
            {
                AverageNotesPerPhrase[i] = br.ReadSingle();
            }

            PhraseIterationCount = br.ReadInt32();
            NotesPerIteration1   = new Int32[PhraseIterationCount];
            for (int i = 0; i < NotesPerIteration1.Count(); ++i)
            {
                NotesPerIteration1[i] = br.ReadInt32();
            }

            PhraseIterationCount = br.ReadInt32();
            NotesPerIteration2   = new Int32[PhraseIterationCount];
            for (int i = 0; i < NotesPerIteration2.Count(); ++i)
            {
                NotesPerIteration2[i] = br.ReadInt32();
            }
        }
예제 #7
0
        /// <summary>
        /// Метод IntputArray позволяет ввести элементы массива с клавиатуры
        /// </summary>
        /// <param name="intArray">Ссылка на экземпляр массива</param>
        /// <returns></returns>
        public static Int32[] IntputArray(this Int32[] intArray)
        {
            Console.Write("Укажите размер массива: ");
            Int32 n = Convert.ToInt32(Console.ReadLine());

            intArray = new Int32[n];
            for (int i = 0; i < intArray.Count(); i++)
            {
                Console.Write($"IntArray [{i}]: ");
                intArray[i] = Convert.ToInt32(Console.ReadLine());
            }
            return(intArray);
        }
예제 #8
0
        public void LoadQAMChart(ComplexSingle[] riData, ComplexSingle[] dmrsData, double rmsEVM = 0)
        {
            Int32 div = 0;
            Int32 mod = 0;

            Int32[] mods = new Int32[999];

            for (int j = 0; j < mods.Count(); j++)
            {
                //mods[j] = Convert.ToInt32(Math.Pow(2, j + 1));
                mods[j] = j + 1;

                Math.DivRem(riData.Count(), mods[j], out mod);

                //get highest mod
                if (mod == 0)
                {
                    double ratio = ((Convert.ToDouble(riData.LongCount()) / Convert.ToDouble(mods[j])) / Convert.ToDouble(riData.LongCount())) * 100;
                    if (ratio > 5)
                    {
                        div = mods[j];
                        Console.WriteLine("Divisor = " + div.ToString());
                    }
                    else
                    {
                        Console.WriteLine("Divisor = " + mods[j].ToString() + " ---NOT USED---Ratio = " + ratio.ToString() + " %");
                    }
                }
            }

            Console.WriteLine("Drawing DMRS");
            Single[] iData = new Single[Convert.ToInt32(dmrsData.LongCount())];
            Single[] qData = new Single[Convert.ToInt32(dmrsData.LongCount())];

            ComplexSingle.DecomposeArray(dmrsData, out iData, out qData);

            for (int x = 0; x < iData.LongCount(); x++)
            {
                this.chrtConstellation.Series["DMRS"].Points.AddXY(iData[x], qData[x]);
            }

            ComplexSingle[] newRIData = null;
            Single[]        relData   = null;
            Single[]        imgData   = null;

            if (div == 0)
            {
                newRIData = riData;
                relData   = new Single[Convert.ToInt32(riData.LongCount())];
                imgData   = new Single[Convert.ToInt32(riData.LongCount())];
            }
            else
            {
                newRIData = new ComplexSingle[Convert.ToInt32(riData.LongCount() / div)];
                for (int k = 0; k < Convert.ToInt32(riData.LongCount() / div); k++)
                {
                    newRIData[k] = riData[k * div];
                }
                relData = new Single[Convert.ToInt32(riData.LongCount() / div)];
                imgData = new Single[Convert.ToInt32(riData.LongCount() / div)];
            }

            ComplexSingle.DecomposeArray(newRIData, out relData, out imgData);
            Console.WriteLine("Charting..." + newRIData.LongCount().ToString() + " points!");
            Console.WriteLine("Drawing DATA Constellation");
            for (int x = 0; x < relData.LongCount(); x++)
            {
                this.chrtConstellation.Series["DATA"].Points.AddXY(relData[x], imgData[x]);
                //System.Windows.Forms.DataVisualization.Charting.DataPoint dataPoint1 = new System.Windows.Forms.DataVisualization.Charting.DataPoint(0D, 0D);
                //series1.ChartArea = "ChartArea1";
                //series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
                //series1.Legend = "Legend1";
                //series1.Name = "DATA";
                //series1.Points.Add(dataPoint1);

                //this.chrtConstellation.Series.Add(series1);
            }

            this.lblRMSMean.Text = "RMS Mean = " + rmsEVM.ToString("#0.##0");
        }