コード例 #1
0
 public void trainloop(MDouble m, double oSetMin, double oSetMax, bool output = true)
 {
     ts = DateTime.Now;
     while (!Train(m, oSetMin, oSetMax, output))
     {
     }
 }
コード例 #2
0
 private void Finished(MDouble m)
 {
     Console.Write("Finished in " + (DateTime.Now - ts) + $" Final Vaule:{m.Variable}, FInal Longs:");
     for (var i = 0; i < m.length; i++)
     {
         Console.Write($"doubs[{i}]: {m.Doubles[i]}, ");
     }
     Console.WriteLine("      ");
 }
コード例 #3
0
        public void ReplaceValue(int x, int y, double value)
        {
            var matrix = new MyMatrix <MDouble>(
                new[, ]
            {
                { new MDouble().SetValue(3.0), new MDouble().SetValue(15.0), new MDouble().SetValue(14.0) },
                { new MDouble().SetValue(2.1), new MDouble().SetValue(2.2), new MDouble().SetValue(2.3), },
                { new MDouble().SetValue(4.1), new MDouble().SetValue(2.4), new MDouble().SetValue(1.6), }
            });
            var matrixCopy = new MyMatrix <MDouble>(matrix);
            var oldValue   = matrixCopy[x, y];

            matrixCopy[x, y] = new MDouble(value);
            Assert.AreNotEqual(matrix, matrixCopy);
            matrixCopy[x, y] = oldValue;
            Assert.AreEqual(matrix, matrixCopy);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: xuri02/Global
        public void SlotAutomatAlgo(MDouble m, bool ausgabe)
        {
            double bank = 10000;
            double cash = 100;
            var    i    = 0;

            while (cash <= 0 && bank > 0)
            {
                var g = r.Next(0, 100);

                cash -= 2;
                bank += 2;

                if (g > 99)
                {
                    bank -= _lo[0];
                    cash += _lo[0];
                }
                else if (g > 90)
                {
                    bank -= _lo[1];
                    cash += _lo[1];
                }
                else if (g > 80)
                {
                    bank -= _lo[2];
                    cash += _lo[2];
                }
                else if (g > 70)
                {
                    bank -= _lo[3];
                    cash += _lo[3];
                }

                i += 1;
            }
            if (ausgabe)
            {
                Console.WriteLine($"[{i}]: cach:{cash}, bank:{bank}");
            }
            m.Variable = i;
        }
コード例 #5
0
        public void VerifyRandomNormalizedRows([Random(5)] int rand)
        {
            var randomNormalized = KeyedMatrix <int, int, MDouble> .GetRandomNormalized(
                Enumerable.Range(0, 3).ToList(),
                Enumerable.Range(0, 5).ToList(),
                NormalizedMethod.NormalizeRow,
                rand);

            Value <MDouble> sum      = new MDouble();
            Value <MDouble> expected = new MDouble().SetValue(1);

            foreach (int i in randomNormalized.RowsKeys)
            {
                foreach (int j in randomNormalized.ColumnsKeys)
                {
                    sum += randomNormalized[i, j];
                }

                Assert.IsTrue(sum == expected);
                sum = new MDouble();
            }
        }
コード例 #6
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (MInt != 0)
            {
                hash ^= MInt.GetHashCode();
            }
            if (MFloat != 0F)
            {
                hash ^= MFloat.GetHashCode();
            }
            if (MDouble != 0D)
            {
                hash ^= MDouble.GetHashCode();
            }
            if (MBool != false)
            {
                hash ^= MBool.GetHashCode();
            }
            if (MByte != 0)
            {
                hash ^= MByte.GetHashCode();
            }
            if (MShort != 0)
            {
                hash ^= MShort.GetHashCode();
            }
            if (MLong != 0L)
            {
                hash ^= MLong.GetHashCode();
            }
            if (MStr.Length != 0)
            {
                hash ^= MStr.GetHashCode();
            }
            return(hash);
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: xuri02/Global
        private void _Ai()
        {
            const int    loops      = 100;
            const bool   showOutput = false;
            const double vMin       = 0.01D;
            const double vMax       = 0.02D;

            Console.WindowWidth = 153;

            Console.WriteLine("-----------------SETUP----------------");
            var t = DateTime.Now;

            SetAlgorythmos(22, 13, 5, 3);
            _m  = new MDouble(1000, 0, _lo, SlotAutomatAlgo, 90);
            _ai = new AiMasterDouble(new[] { _m });
            Console.WriteLine(_m.GetId);
            Console.WriteLine("done in " + (DateTime.Now - t));
            Console.WriteLine("Press any Key to enter TrainLoop({0})...", loops);
            Console.ReadKey();
            Console.Clear();
            for (var i = 0; i < loops; i++)
            {
                Console.SetCursorPosition(0, 0);
                Console.WriteLine("---------------TRAINING---------------");
                t = DateTime.Now;
                _ai.Trainloop(_m, vMin, vMax, showOutput);
                SetAlgorythmos(_m.Doubles[0], _m.Doubles[1], _m.Doubles[2], _m.Doubles[3]);
                _m = new MDouble(1000, 0, _lo, SlotAutomatAlgo, 90);
                Console.WriteLine("\ndone in " + (DateTime.Now - t));
                Console.WriteLine("---------------FINISHED---------------" + $"                                                                                                          [{ i}/{ loops}]");
                var v = Console.WindowWidth - 3;
                Console.Write("[");
                Console.SetCursorPosition(v + 1, Console.CursorTop);
                Console.Write("]");
                Console.SetCursorPosition(1, Console.CursorTop);
                for (var j = 0; j < (i / (double)100) * v; j++)
                {
                    Console.Write("=");
                }
                Console.Write(">");
                for (var j = i; j < (v - (i / (double)100) * v) - 1; j++)
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine("\n\n-------------RUNNING TESTS------------");
            Console.WriteLine("Press any Key...");
            Console.ReadKey();
            t = DateTime.Now;
            SetAlgorythmos(_m.Doubles[0], _m.Doubles[1], _m.Doubles[2], _m.Doubles[3]);
            _m = new MDouble(10000, 0, _lo, SlotAutomatAlgo, 1000);
            double max = 0;

            for (var i = 0; i < 100; i++)
            {
                SlotAutomatAlgo(_m, true);
                max = _m.Variable > max ? _m.Variable : max;
            }
            Console.WriteLine($"\ndone in {DateTime.Now - t}       Max:{max}");
            Console.WriteLine("---------------FINISHED---------------");
        }
コード例 #8
0
 public virtual void OnMainDouble(MDouble m, bool ausgabe = false)
 {
 }
コード例 #9
0
        public bool Train(MDouble m, double oSetMin, double oSetMax, bool output = true)
        {
            if (m.doubs)
            {
                if (m.w == 0)
                {
                    if (m.addition)
                    {
                        m.w = oSetMin;
                    }
                    else
                    {
                        m.w = -oSetMin;
                    }
                }

                var prev = m.Variable;

                m.Doubles[m.currentIndex] += m.w;
                m.algo(m, output);

                if (m.Variable > m.Ziehl && m.Variable < prev)
                {
                    m.addition = false;
                }
                else if ((m.Variable < m.Ziehl && m.Variable < prev) || (m.Variable > m.Ziehl && m.Variable > prev))
                {
                    m.addition = !m.addition;
                }
                else if (m.Variable < m.Ziehl && m.Variable > prev)
                {
                    m.addition = true;
                }
                m.w = 0;

                if (m.Variable < m.Ziehl + m.tolleranz && m.Variable > m.Ziehl - m.tolleranz)
                {
                    Finished(m);
                    return(true);
                }
                if (prev == m.Variable)
                {
                    m.w += m.addition ? oSetMax : -oSetMin;
                }
                if (output)
                {
                    Console.WriteLine($"ONext:{m.w}, prew:{prev}, post:{m.Variable}, tolleranz:{m.tolleranz}");
                }
                m.round += 1;
            }
            if (m.round == 10)
            {
                m.currentIndex += 1;
                if (m.currentIndex >= m.Doubles.Length)
                {
                    m.currentIndex = 0;
                }
            }
            if (m.round > 20)
            {
                m.round = 0;
            }

            return(false);
        }
コード例 #10
0
 private static MDouble init(MDouble m)
 {
     m.init = true;
     return(m);
 }
コード例 #11
0
 public void AbsoluteTest(MDouble a, MDouble b)
 {
     Assert.True(a.Absolute() == b);
     Assert.True(a != b.Absolute());
 }
コード例 #12
0
 public void EqualityTest(MDouble a, MDouble b)
 {
     Assert.True(a == b);
 }
コード例 #13
0
 public void ComparisonTest(MDouble a, MDouble b)
 {
     Assert.True(a < b);
 }
コード例 #14
0
 public void AddTest(MDouble a, MDouble b, MDouble c)
 {
     Assert.True(c == a + b);
 }