Exemplo n.º 1
0
        // Gets the list of token transfers by given account id, token id, and page,
        // 7zfr7JY5jyZuHZaTbWGBLdv1WVqHKz3nHgfZcTAjLVBY
        public object AccountTokenTransfers(string account, string token, int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;
            }

            using (var client = CreateApi())
            {
                // Get the list of transactions from the API
                var offset    = limit * (page - 1);
                var transfers = client.TokenWalletTransfersGet(Base58Encoding.Decode(token),
                                                               Base58Encoding.Decode(account), offset, limit);
                var lastPage = ConvUtils.GetNumPages(transfers.Count, limit);
                var count    = transfers.Transfers.Count;

                // Prepare the result
                return(new
                {
                    Page = page,
                    Transfers = transfers.Transfers.Select((t, i) => new TokenTransfer(t)).ToList(),
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = count > 0 ? $"{offset + 1} - {offset + count} of {offset + count}" : "-"
                });
            }
        }
Exemplo n.º 2
0
        // Gets the list of holders by given token id, and page,
        public object TokenHolders(string id, int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;
            }

            using (var client = CreateApi())
            {
                // Get the list of holders from the API
                var offset   = limit * (page - 1);
                var holders  = client.TokenHoldersGet(Base58Encoding.Decode(id), offset, limit);
                var lastPage = ConvUtils.GetNumPages(holders.Count, limit);
                var count    = holders.Holders.Count;

                // Prepare the result
                return(new
                {
                    Page = page,
                    Holders = holders.Holders.Select((t, i) => new TokenHolder(t)).ToList(),
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = count > 0 ? $"{offset + 1} - {offset + count} of {offset + count}" : "-"
                });
            }
        }
Exemplo n.º 3
0
        // Returns the list of blocks on given page, from cache
        public BlocksData Blocks(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            var lastBlock = _indexService.GetIndexData(Net).LastBlockData.LastBlock;
            var lastPage  = ConvUtils.GetNumPages(IndexService.SizeOutAll, limit);

            // Get the list of cached blocks, from given page (we cache last 100K blocks)
            var blocks = _indexService.GetPools(Net, (page - 1) * limit, limit);

            // Prepare all data for page and return
            var result = new BlocksData
            {
                Page         = page,
                Blocks       = blocks,
                HaveNextPage = page < lastPage,
                LastPage     = lastPage,
                NumStr       = blocks.Any() ? $"{blocks.Last().Number} - {blocks.First().Number} of total {lastBlock}" : "-",
                LastBlock    = lastBlock
            };

            return(result);
        }
Exemplo n.º 4
0
        // Returns the list of Tokens on given page (id), from API
        public object Tokens2(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            var offset = (page - 1) * limit;

            using (var client = CreateApi())
            {
                var tokensListResult = client.TokensListGet(offset, limit);
                var tokens           = tokensListResult.Tokens.Select((t, i) => new TokenInfo2(t)).ToList();
                var lastPage         = ConvUtils.GetNumPages(tokensListResult.Count, limit);

                // Prepare all data for page and return
                return(new
                {
                    Tokens = tokens,
                    Page = page,
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = tokens.Count > 0 ? $"{(page - 1) * limit + 1} - {(page - 1) * limit + tokens.Count} of {tokensListResult.Count}" : "-"
                });
            }
        }
Exemplo n.º 5
0
        // Returns the list of Tokens on given page (id), from db
        public object Tokens(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            using (var db = CsmonDbContext.Create())
            {
                var tokensCount = db.Tokens.Count();
                var lastPage    = ConvUtils.GetNumPages(tokensCount, limit);

                var tokens = db.Tokens.Skip((page - 1) * limit).Take(limit).ToList();
                // Prepare all data for page and return
                var result = new
                {
                    Tokens       = tokens,
                    Page         = page,
                    HaveNextPage = page < lastPage,
                    LastPage     = lastPage,
                    NumStr       = tokensCount > 0 ? $"{(page - 1) * limit + 1} - {(page - 1) * limit + tokens.Count} of {tokensCount}" : "-"
                };

                for (var i = 1; i <= result.Tokens.Count; i++)
                {
                    result.Tokens[i - 1].Index = i + (page - 1) * limit;
                }

                return(result);
            }
        }
Exemplo n.º 6
0
        // Returns the list of Accounts on given page, from cache
        public object Accounts(int page, int limit, int sort)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            using (var client = CreateApi())
            {
                // Get the list accounts
                var accounts = client.WalletsGet(0, long.MaxValue, (sbyte)(sort / 2), sort % 2 > 0);

                var lastPage = ConvUtils.GetNumPages(accounts.Wallets.Count, limit);

                var accountsLimited = accounts.Wallets.Skip((page - 1) * limit).Take(limit)
                                      .Select(w => new AccountData(w)).ToList();

                // Prepare all data for page and return
                return(new
                {
                    Accounts = accountsLimited,
                    Page = page,
                    HaveNextPage = page < lastPage,
                    LastPage = lastPage,
                    NumStr = accounts.Wallets.Any() ? $"{(page - 1) * limit + 1} - {(page-1)*limit + accountsLimited.Count} of total {accounts.Wallets.Count}" : "-"
                });
            }
        }
Exemplo n.º 7
0
        // Returns the list of blocks starting from given hash
        public BlocksData BlocksStable(string hash)
        {
            const int limit = 100;

            if (string.IsNullOrEmpty(hash))
            {
                hash = _indexService.GetIndexData(Net).LastBlocks[0].Hash;
            }

            var lastBlock = _indexService.GetIndexData(Net).LastBlockData.LastBlock;
            var lastPage  = ConvUtils.GetNumPages(lastBlock, limit);

            using (var client = CreateApi())
            {
                var blocks        = client.PoolListGetStable(ConvUtils.ConvertHashBack(hash), limit + 1).Pools.Select(p => new BlockInfo(p)).ToList();
                var blocksLimited = blocks.Take(limit).ToList();

                var result = new BlocksData
                {
                    Blocks       = blocksLimited,
                    HaveNextPage = blocks.Count > limit,
                    LastPage     = lastPage,
                    NumStr       = blocksLimited.Any() ? $"{blocksLimited.Last().Number} - {blocksLimited.First().Number} of total {lastBlock}" : "-",
                    LastBlock    = lastBlock
                };
                return(result);
            }
        }
Exemplo n.º 8
0
        public TransactionsData PoolTransactions(string hash, int page, int txcount)
        {
            const int numPerPage = 50;

            if (page <= 0)
            {
                page = 1;
            }
            using (var client = CreateApi())
            {
                var lastPage = ConvUtils.GetNumPages(txcount, numPerPage);
                if (page > lastPage)
                {
                    page = lastPage;
                }
                var result = new TransactionsData
                {
                    Page         = page,
                    LastPage     = lastPage,
                    HaveNextPage = page < lastPage
                };
                var offset = numPerPage * (page - 1);
                var poolTr = client.PoolTransactionsGet(ConvUtils.ConvertHashBack(hash), offset, numPerPage);
                var i      = offset + 1;
                foreach (var t in poolTr.Transactions)
                {
                    var tInfo = new TransactionInfo(i, t.Id, t.Trxn);
                    result.Transactions.Add(tInfo);
                    i++;
                }
                result.NumStr = poolTr.Transactions.Any() ? $"{offset + 1} - {offset + poolTr.Transactions.Count} of {txcount}" : "0";
                return(result);
            }
        }
Exemplo n.º 9
0
        // Returns the list of txs on given page, from cache
        public TransactionsData Txs(int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;            // Page
            }
            // Get the list of cached blocks, from given page (we cache last 100K blocks)
            var txs = _indexService.GetTxs(Net, (page - 1) * limit, limit);

            // Prepare all data for page and return
            var offset   = limit * (page - 1);
            var stats    = _indexService.GetStatData(Net);
            var lastPage = ConvUtils.GetNumPages(IndexService.SizeOutAll, limit);

            var result = new TransactionsData
            {
                Page         = page,
                Transactions = txs,
                HaveNextPage = page < lastPage,
                LastPage     = lastPage,
                NumStr       = txs.Any() ? $"{offset + 1} - {offset + txs.Count} of {stats.Total.AllTransactions.Value}" : "-",
                TxCount      = stats.Total.AllTransactions.Value
            };

            return(result);
        }
Exemplo n.º 10
0
        public TransactionsData ScHistory(int page, string from, string to)
        {
            using (var client = CreateApi())
            {
                var data  = new TransactionsData();
                var pools = client.PoolListGet(0, 100);
                foreach (var poolsPool in pools.Pools)
                {
                    if (poolsPool.TransactionsCount == 0)
                    {
                        continue;
                    }
                    var poolHash = ConvUtils.ConvertHashAscii(poolsPool.Hash);
                    var trs      = client.PoolTransactionsGet(poolsPool.Hash, 0, 0, long.MaxValue);
                    var i        = 1;
                    foreach (var trsTransaction in trs.Transactions)
                    {
                        if (string.IsNullOrEmpty(trsTransaction.SmartContract?.SourceCode))
                        {
                            continue;
                        }
                        data.Transactions.Add(new TransactionInfo(i, $"{poolHash}.{i}", trsTransaction));
                        i++;
                    }
                }

                data.Page         = page;
                data.HaveNextPage = false;
                return(data);
            }
        }
Exemplo n.º 11
0
        public void ConvUtils_ToShort()
        {
            Assert.AreEqual((short)55, ConvUtils.ToInt16Ex("55"), "Result differs");
            Assert.AreEqual((short)-55, ConvUtils.ToInt16Ex("-55"), "Result differs");
            Assert.AreEqual((short)0x55, ConvUtils.ToInt16Ex("0x55"), "Result differs");
            Assert.AreEqual((short)0x55, ConvUtils.ToInt16Ex("0X55"), "Result differs");
            Assert.AreEqual((short)3, ConvUtils.ToInt16Ex("0b11"), "Result differs");
            Assert.AreEqual((short)5, ConvUtils.ToInt16Ex("0B101"), "Result differs");
            Assert.AreEqual((short)0x7EDC, ConvUtils.ToInt16Ex("0x7EDC"), "Result differs");
            Assert.AreEqual((short)-0x7EDC, ConvUtils.ToInt16Ex("-0x7EDC"), "Result differs");

            short?nres;

            nres = ConvUtils.ToNullableInt16Ex(null);
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableInt16Ex(String.Empty);
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableInt16Ex("");
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableInt16Ex("0xAA");
            Assert.AreEqual((short)0xAA, nres, "Result differs");

            Assert.Throws <OverflowException>(() => ConvUtils.ToInt16Ex("0xFFFF"));
            Assert.Throws <OverflowException>(() => ConvUtils.ToInt16Ex("-0xFFFF"));
        }
Exemplo n.º 12
0
        public TransactionsData PoolTransactions(string hash, int page)
        {
            if (page <= 0)
            {
                page = 1;
            }
            using (var client = CreateApi())
            {
                var result = new TransactionsData {
                    Page = page
                };
                const int numPerPage = 50;
                var       offset     = numPerPage * (page - 1);
                var       poolTr     = client.PoolTransactionsGet(ConvUtils.ConvertHashBack(hash), offset, numPerPage);
                var       i          = offset + 1;
                foreach (var t in poolTr.Transactions)
                {
                    var tInfo = new TransactionInfo(i, $"{hash}.{i}", t.Trxn);
                    result.Transactions.Add(tInfo);
                    i++;
                }

                return(result);
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Max pool layer.
 /// The max pool layers function is to progressively reduce the spatial size of the representation
 /// to reduce the amount of parameters and computation in the network.
 /// The reduction is only done on the width and height. Depth dimension is preserved.
 /// </summary>
 /// <param name="poolWidth">The width of the pool area (default is 2)</param>
 /// <param name="poolHeight">The height of the pool area (default is 2)</param>
 /// <param name="stride">Controls the distance between each neighbouring pool areas (default is 2)</param>
 /// <param name="borderMode">Border mode of the max pool operation.
 /// This will set the width and height padding automatically based on the selected border mode: Valid, Same or Full (default is Valid).</param>
 public MaxPool2DLayer(int poolWidth, int poolHeight, int stride = 2, BorderMode borderMode = BorderMode.Valid)
     : this(poolWidth, poolHeight, stride,
            ConvUtils.PaddingFromBorderMode(poolWidth, borderMode),
            ConvUtils.PaddingFromBorderMode(poolHeight, borderMode))
 {
     BorderMode = borderMode;
 }
Exemplo n.º 14
0
        public void ConvUtils_ToInt32()
        {
            Assert.AreEqual(0, ConvUtils.ToInt32Ex(""), "Result differs");
            Assert.AreEqual(55, ConvUtils.ToInt32Ex("55"), "Result differs");
            Assert.AreEqual(55, ConvUtils.ToInt32Ex("+55"), "Result differs");
            Assert.AreEqual(-55, ConvUtils.ToInt32Ex("-55"), "Result differs");
            Assert.AreEqual(0x55, ConvUtils.ToInt32Ex("0x55"), "Result differs");
            Assert.AreEqual(0x55, ConvUtils.ToInt32Ex("0X55"), "Result differs");
            Assert.AreEqual(3, ConvUtils.ToInt32Ex("0b11"), "Result differs");
            Assert.AreEqual(5, ConvUtils.ToInt32Ex("0B101"), "Result differs");
            Assert.AreEqual(0xFEDC, ConvUtils.ToInt32Ex("0XFEDC"), "Result differs");
            Assert.AreEqual(-0xFEDC, ConvUtils.ToInt32Ex("-0xFEDC"), "Result differs");

            int?nres;

            nres = ConvUtils.ToNullableInt32Ex(null);
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableInt32Ex(String.Empty);
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableInt32Ex("");
            Assert.IsNull(nres, "Not null result");
            nres = ConvUtils.ToNullableInt32Ex("0xAA");
            Assert.AreEqual(0xAA, nres, "Result differs");

            Assert.Throws <OverflowException>(() => ConvUtils.ToUInt32Ex("0xFFFFFFFFF"));
        }
Exemplo n.º 15
0
 public TransactionInfo TransactionInfo(string id)
 {
     using (var client = CreateApi())
     {
         var ids  = id.Split('.');
         var trId = new TransactionId()
         {
             Index    = int.Parse(ids[1]) - 1,
             PoolHash = ConvUtils.ConvertHashBack(ids[0])
         };
         var tr    = client.TransactionGet(trId);
         var tInfo = new TransactionInfo(0, null, tr.Transaction.Trxn)
         {
             Id = id, Found = tr.Found
         };
         if (!tr.Found)
         {
             return(tInfo);
         }
         if (string.IsNullOrEmpty(tInfo.PoolHash))
         {
             return(tInfo);
         }
         var pool = client.PoolInfoGet(ConvUtils.ConvertHashBack(tInfo.PoolHash), 0);
         tInfo.Time = ConvUtils.UnixTimeStampToDateTime(pool.Pool.Time);
         return(tInfo);
     }
 }
Exemplo n.º 16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="inputWidth"></param>
        /// <param name="inputHeight"></param>
        /// <param name="inputDepth"></param>
        /// <param name="batchSize"></param>
        /// <param name="initializtion"></param>
        /// <param name="random"></param>

        public void Initialize(int inputWidth, int inputHeight, int inputDepth, int batchSize,
                               Initialization initializtion, Random random)
        {
            InputWidth  = inputWidth;
            InputHeight = inputHeight;
            InputDepth  = inputDepth;

            // computed
            this.Depth = this.InputDepth;

            this.Width = ConvUtils.GetFilterGridLength(InputWidth, m_poolWidth,
                                                       m_stride, m_padWidth, BorderMode);

            this.Height = ConvUtils.GetFilterGridLength(InputHeight, m_poolHeight,
                                                        m_stride, m_padHeight, BorderMode);

            // store switches for x,y coordinates for where the max comes from, for each output neuron
            this.Switchx = Enumerable.Range(0, batchSize)
                           .Select(v => new int[this.Width * this.Height * this.Depth]).ToArray();

            this.Switchy = Enumerable.Range(0, batchSize)
                           .Select(v => new int[this.Width * this.Height * this.Depth]).ToArray();

            var fanIn  = InputWidth * InputDepth * InputHeight;
            var fanOut = Depth * Width * Height;

            OutputActivations = Matrix <float> .Build.Dense(batchSize, fanOut);

            m_delta = Matrix <float> .Build.Dense(batchSize, fanIn);
        }
Exemplo n.º 17
0
        // Gets the list of network nodes by network id
        public NodesData GetNodes(string network, int page, int limit)
        {
            if (limit < 10 || limit > 100)
            {
                limit = 25;
            }
            if (page <= 0)
            {
                page = 1;
            }

            var offset = limit * (page - 1);

            var nodes      = _states[network].Nodes;
            var nodesCount = nodes.Count;
            var listNodes  = nodes.Skip(offset).Take(limit).ToList();

            // Prepare the result and return
            var result = new NodesData
            {
                Page         = page,
                Nodes        = listNodes,
                OnlineCount  = nodes.Count(n => n.Active),
                OfflineCount = nodes.Count(n => !n.Active),
                HaveNextPage = nodesCount > offset + limit,
                LastPage     = ConvUtils.GetNumPages(nodesCount, limit),
                NumStr       = nodesCount > 0 ? $"{offset + 1} - {offset + listNodes.Count} of {nodesCount}" : "0"
            };

            return(result);
        }
Exemplo n.º 18
0
        public void ConvUtils_ReshapeConvolutionsToRowMajor()
        {
            var batchSize = 5;

            var filterHeight = 2;
            var filterWidth  = 2;
            var filterDepth  = 2;

            var stride  = 1;
            var padding = 0;

            var inputWidth  = 3;
            var inputHeight = 3;
            var inputDepth  = 3;

            var filterGridWidth  = ConvUtils.GetFilterGridLength(inputWidth, filterWidth, stride, padding, BorderMode.Valid);
            var filterGridHeight = ConvUtils.GetFilterGridLength(inputHeight, filterHeight, stride, padding, BorderMode.Valid);

            var k   = filterDepth;
            var crs = inputDepth * filterWidth * filterHeight;
            var npq = batchSize * filterGridWidth * filterGridHeight;

            var convolutedInput = Matrix <float> .Build.Dense(k, npq, new float[] { -6.260461f, 87.38299f, -7.173417f, 94.47046f, -8.999331f, 108.6454f, -9.912288f, 115.7329f, -6.260461f, 87.38299f, -7.173417f, 94.47046f, -8.999331f, 108.6454f, -9.912288f, 115.7329f, -6.260461f, 87.38299f, -7.173417f, 94.47046f, -8.999331f, 108.6454f, -9.912288f, 115.7329f, -6.260461f, 87.38299f, -7.173417f, 94.47046f, -8.999331f, 108.6454f, -9.912288f, 115.7329f, -6.260461f, 87.38299f, -7.173417f, 94.47046f, -8.999331f, 108.6454f, -9.912288f, 115.7329f });

            var actual = Matrix <float> .Build.Dense(batchSize, k *filterGridWidth *filterGridHeight);

            ConvUtils.ReshapeConvolutionsToRowMajor(convolutedInput, inputDepth, inputHeight, inputWidth, filterHeight, filterWidth,
                                                    padding, padding, stride, stride, BorderMode.Valid, actual);

            var expected = Matrix <float> .Build.Dense(batchSize, k *filterGridWidth *filterGridHeight, new float[] { -6.260461f, -6.260461f, -6.260461f, -6.260461f, -6.260461f, -7.173417f, -7.173417f, -7.173417f, -7.173417f, -7.173417f, -8.999331f, -8.999331f, -8.999331f, -8.999331f, -8.999331f, -9.912288f, -9.912288f, -9.912288f, -9.912288f, -9.912288f, 87.38299f, 87.38299f, 87.38299f, 87.38299f, 87.38299f, 94.47046f, 94.47046f, 94.47046f, 94.47046f, 94.47046f, 108.6454f, 108.6454f, 108.6454f, 108.6454f, 108.6454f, 115.7329f, 115.7329f, 115.7329f, 115.7329f, 115.7329f });

            MatrixAsserts.AreEqual(expected, actual);
        }
Exemplo n.º 19
0
        public void ConvUtils_Batch_Col2Im()
        {
            var batchSize = 5;

            var filterHeight = 2;
            var filterWidth  = 2;

            var stride  = 1;
            var padding = 0;

            var inputWidth  = 3;
            var inputHeight = 3;
            var inputDepth  = 3;

            var filterGridWidth  = ConvUtils.GetFilterGridLength(inputWidth, filterWidth, stride, padding, BorderMode.Valid);
            var filterGridHeight = ConvUtils.GetFilterGridLength(inputHeight, filterHeight, stride, padding, BorderMode.Valid);

            var k     = filterWidth * filterHeight * inputDepth;
            var n     = filterGridWidth * filterGridHeight * batchSize;
            var fanIn = inputWidth * inputHeight * inputDepth;

            var input = Matrix <float> .Build.Random(k, n, 42);

            var actual = Matrix <float> .Build.Dense(batchSize, fanIn);

            ConvUtils.Batch_Col2Im(input, inputDepth, inputHeight, inputWidth,
                                   filterHeight, filterWidth, padding, padding, stride, stride, BorderMode.Valid, actual);

            Trace.WriteLine(actual.ToString());
            Trace.WriteLine(string.Join(",", actual.ToColumnMajorArray()));

            var expected = Matrix <float> .Build.Dense(batchSize, fanIn, new float[] { 0.408388f, -0.3281617f, -0.163763f, -0.7540793f, -0.8690567f, -0.8093507f, 0.2888344f, -1.777985f, -2.136633f, 2.92046f, -2.021355f, -0.4799407f, -0.6079422f, 0.5664175f, 1.640147f, 0.2616988f, -0.4687745f, -0.7903177f, 1.407904f, 0.1495381f, -1.212453f, 0.6085976f, -0.7663184f, -0.05670342f, 1.895431f, -0.6066797f, -0.2541801f, -0.01155096f, 1.438064f, -1.349128f, 1.942754f, 0.5057944f, -1.907569f, -0.5227588f, 0.5727027f, -1.167249f, 0.2078037f, 2.980192f, 0.4892522f, -0.6720377f, 0.9384909f, -0.9973568f, 0.5546624f, 1.710745f, 1.995577f, -0.734176f, -2.817736f, -0.8027026f, -0.7883626f, -1.275902f, -0.5054669f, 0.3228757f, 3.105314f, -0.3089013f, 1.549119f, -0.5383296f, 1.401819f, 1.837471f, 0.1251182f, -0.7002729f, 0.07180786f, -0.9396007f, 0.6037194f, -0.7305622f, 1.063156f, 4.591741f, 0.4193244f, -1.031005f, -3.045349f, 0.4254266f, 0.6900162f, -2.136511f, -1.578628f, 0.7839373f, 1.781849f, 0.1622419f, -0.6845301f, -1.676224f, 1.028266f, 0.9345228f, 0.789884f, 1.158841f, 1.703116f, -0.8997472f, -1.423375f, -0.1056926f, -0.08005979f, 1.399474f, -0.05612089f, -0.722365f, -0.6606446f, 0.08791012f, -1.749763f, 0.685056f, 0.3641174f, 0.2083111f, -0.5394329f, 1.846675f, 0.5931945f, -1.26804f, -1.087396f, 0.5506561f, -1.644088f, -0.8753259f, -1.839462f, 0.5598704f, -2.054844f, 1.20434f, -3.263947f, 1.221963f, -0.5145022f, -1.402665f, 1.101824f, 0.4248552f, -2.63849f, 1.160408f, 2.130142f, 0.3172536f, 1.109406f, 0.9979748f, 0.2864983f, 0.00849107f, -2.00572f, 1.178588f, -0.3127078f, -1.662103f, -1.043834f, 1.065703f, -0.9702578f, -0.1781971f, -1.362978f, 0.4443011f, -1.050083f, 0.6755545f, -1.088875f });

            MatrixAsserts.AreEqual(expected, actual);
        }
Exemplo n.º 20
0
        public void ConvUtils_Batch_Im2Cols()
        {
            var batchSize = 5;

            var filterHeight = 2;
            var filterWidth  = 2;

            var stride  = 1;
            var padding = 0;

            var inputWidth  = 3;
            var inputHeight = 3;
            var inputDepth  = 3;

            var random = new Random(42);
            var input  = Matrix <float> .Build.Random(batchSize, inputWidth *inputHeight *inputDepth, 42);

            var filterGridWidth  = ConvUtils.GetFilterGridLength(inputWidth, filterWidth, stride, padding, BorderMode.Valid);
            var filterGridHeight = ConvUtils.GetFilterGridLength(inputHeight, filterHeight, stride, padding, BorderMode.Valid);

            var k = filterWidth * filterHeight * inputDepth;
            var n = batchSize * filterGridWidth * filterGridHeight;

            var actual = Matrix <float> .Build.Dense(k, n);

            ConvUtils.Batch_Im2Col(input, inputDepth, inputHeight, inputWidth, filterHeight, filterWidth,
                                   padding, padding, stride, stride, BorderMode.Valid, actual);

            Trace.WriteLine(actual.ToString());
            Trace.WriteLine(string.Join(",", actual.ToColumnMajorArray()));

            var expected = Matrix <float> .Build.Dense(k, n, new float[] { 0.408388f, -0.5256838f, -1.416015f, -0.3205518f, 0.8964508f, -0.7706847f, 0.1228476f, 1.401819f, 0.02538049f, 0.4443011f, 0.3597376f, -0.8992839f, -0.5256838f, -0.8472909f, -0.3205518f, 0.168334f, -0.7706847f, -0.2688324f, 1.401819f, 0.5753565f, 0.4443011f, -0.8027026f, -0.8992839f, -0.6576554f, -1.416015f, -0.3205518f, 0.1622419f, -0.8718526f, 0.1228476f, 1.401819f, -0.8105127f, -1.366049f, 0.3597376f, -0.8992839f, -0.09693441f, 0.1117831f, -0.3205518f, 0.168334f, -0.8718526f, 2.464335f, 1.401819f, 0.5753565f, -1.366049f, 0.7328596f, -0.8992839f, -0.6576554f, 0.1117831f, -2.00572f, -0.8723587f, 1.785321f, 0.02021696f, -1.087396f, -0.7902505f, -0.06449615f, -0.4799407f, 0.7755837f, -0.08005979f, -0.163763f, 1.463557f, -0.5891034f, 1.785321f, -0.7747191f, -1.087396f, 1.942754f, -0.06449615f, 0.08791012f, 0.7755837f, 1.559499f, -0.163763f, 1.144407f, -0.5891034f, 1.486937f, 0.02021696f, -1.087396f, 1.386084f, -0.742821f, -0.4799407f, 0.7755837f, -0.93938f, 0.4403726f, 1.463557f, -0.5891034f, 0.2961742f, -1.676224f, -1.087396f, 1.942754f, -0.742821f, 0.3750592f, 0.7755837f, 1.559499f, 0.4403726f, 1.018316f, -0.5891034f, 1.486937f, -1.676224f, 0.5095494f, -1.069885f, 0.1028096f, -0.5383296f, -0.5273784f, -1.362978f, -2.817736f, -0.3506753f, -2.379571f, -0.205604f, -0.8553149f, 1.364009f, 1.960906f, 0.1028096f, 0.06300805f, -0.5273784f, 0.1655738f, -2.817736f, -0.2654593f, -2.379571f, 0.3019102f, -0.8553149f, 0.380102f, 1.960906f, -1.644088f, -0.5383296f, -0.5273784f, 1.407161f, 0.8093351f, -0.3506753f, -2.379571f, -0.1132597f, 0.00849107f, 1.364009f, 1.960906f, -1.907569f, 1.585406f, -0.5273784f, 0.1655738f, 0.8093351f, -0.5961999f, -2.379571f, 0.3019102f, 0.00849107f, -0.9973568f, 1.960906f, -1.644088f, 1.585406f, 0.1513373f, 0.06503697f, -0.6606446f, 1.281655f, 0.2639574f, -0.3281617f, 0.6252633f, -0.9870397f, -0.2739736f, 0.5706424f, -0.6933832f, -0.9226705f, 1.837471f, -0.6606446f, -2.021355f, 0.2639574f, -1.713513f, 0.6252633f, -0.6887951f, -0.2739736f, -0.1102718f, -0.6933832f, -0.2514778f, 1.837471f, 1.012506f, 1.281655f, 0.2639574f, -0.6539868f, -1.332823f, -0.9870397f, -0.2739736f, -0.6845301f, 0.3220822f, -0.9226705f, 1.837471f, 2.257283f, -0.2592173f, 0.2639574f, -1.713513f, -1.332823f, -0.1056926f, -0.2739736f, -0.1102718f, 0.3220822f, 0.02583288f, 1.837471f, 1.012506f, -0.2592173f, 0.5775524f, -0.734176f, 0.5288628f, 0.314957f, 1.331584f, 0.1659867f, -0.0002207408f, -0.3023876f, 0.5506561f, -1.365916f, -0.314546f, -0.6079422f, 0.3696074f, 0.5288628f, -0.7030032f, 1.331584f, 0.7429405f, -0.0002207408f, -2.21279f, 0.5506561f, 0.5057944f, -0.314546f, -1.749763f, 0.3696074f, -0.1464183f, 0.314957f, 1.331584f, 0.2864983f, 0.9384909f, -0.3023876f, 0.5506561f, 1.133461f, 1.134041f, -0.6079422f, 0.3696074f, 0.2236174f, -0.9724815f, 1.331584f, 0.7429405f, 0.9384909f, 1.441582f, 0.5506561f, 0.5057944f, 1.134041f, 0.2430595f, 0.3696074f, -0.1464183f, -0.9724815f, 0.7229092f });

            MatrixAsserts.AreEqual(expected, actual);
        }
Exemplo n.º 21
0
        public TransactionsData AccountTransactions(string id, int page, bool conv = true)
        {
            const int numPerPage = 15;

            if (page <= 0)
            {
                page = 1;
            }
            using (var client = CreateApi())
            {
                var offset = numPerPage * (page - 1);
                var trs    = client.TransactionsGet(conv ? ConvUtils.ConvertHashBackPartial(id) : id, offset, numPerPage + 1);
                var result = new TransactionsData
                {
                    Page         = page,
                    Transactions = new List <TransactionInfo>(),
                    HaveNextPage = trs.Transactions.Count > numPerPage
                };
                var count = Math.Min(numPerPage, trs.Transactions.Count);
                for (var i = 0; i < count; i++)
                {
                    var t     = trs.Transactions[i];
                    var tInfo = new TransactionInfo(i + offset + 1, "_", t);
                    result.Transactions.Add(tInfo);
                }
                result.NumStr = count > 0 ? $"{offset + 1} - {offset + count}" : "-";
                return(result);
            }
        }
Exemplo n.º 22
0
 /// <summary>
 /// 2D Convolutional layer using GEMM implementation
 /// based on: https://petewarden.com/2015/04/20/why-gemm-is-at-the-heart-of-deep-learning/
 /// and: https://arxiv.org/pdf/1410.0759.pdf
 /// </summary>
 /// <param name="filterWidth">The width of the filters</param>
 /// <param name="filterHeight">The height of the filters</param>
 /// <param name="filterCount">The number of filters</param>
 /// <param name="stride">Controls the distance between each neighbouring filter (default is 1)</param>
 /// <param name="borderMode">Border mode of the convolutional operation.
 /// This will set the width and height padding automatically based on the selected border mode: Valid, Same or Full (default is Valid)</param>
 /// <param name="activation">Type of activation function used (default is Relu)</param>
 public Conv2DLayer(int filterWidth, int filterHeight, int filterCount, int stride = 1,
                    BorderMode borderMode = BorderMode.Valid, Activation activation = Activation.Relu)
     : this(filterWidth, filterHeight, filterCount, stride,
            ConvUtils.PaddingFromBorderMode(filterWidth, borderMode),
            ConvUtils.PaddingFromBorderMode(filterHeight, borderMode))
 {
     BorderMode = borderMode;
 }
Exemplo n.º 23
0
 public string Balance(string id)
 {
     using (var client = CreateApi())
     {
         var balance = client.BalanceGet(Base58Encoding.Decode(id), 1);
         return(ConvUtils.FormatAmount(balance.Amount));
     }
 }
Exemplo n.º 24
0
 public string Balance(string id)
 {
     using (var client = CreateApi())
     {
         var balance = client.BalanceGet(id, "cs");
         return(ConvUtils.FormatAmount(balance.Amount));
     }
 }
Exemplo n.º 25
0
 public DateTime GetTransactionTime(string id)
 {
     using (var client = CreateApi())
     {
         var poolHash = id.Split(".")[0];
         var pool     = client.PoolInfoGet(ConvUtils.ConvertHashBack(poolHash), 0);
         return(ConvUtils.UnixTimeStampToDateTime(pool.Pool.Time));
     }
 }
Exemplo n.º 26
0
        /// <summary>
        /// 查询城市对应的行政区
        /// </summary>
        /// <param name="cityID"></param>
        /// <returns></returns>
        public List <Model.Area> QueryAreaList(int cityID)
        {
            List <Area> list    = new List <Area>();
            string      sql     = "SELECT [AreaId],[AreaName] FROM [FxtDataCenter].[dbo].[SYS_Area] where CityId = " + cityID;
            DataTable   dt_area = DBUtils.getData(CenterUrl, sql);

            logger.Debug("QueryAreaList SQL:" + sql);
            list = ConvUtils <Area> .ConvertToList(dt_area);

            return(list);
        }
Exemplo n.º 27
0
        /// <summary>
        ///  查询城市信息
        /// </summary>
        /// <returns></returns>
        public List <City> QueryCityList()
        {
            List <City> list    = new List <City>();
            string      sql     = @"SELECT 
	t1.CityId,t1.CityName,t1.ProvinceId,t2.ProjectTable,t2.CaseTable
FROM [FxtDataCenter].[dbo].[SYS_City] t1
inner join [FxtDataCenter].dbo.SYS_City_Table t2
on t1.CityId = t2.CityId";
            DataTable   dt_city = DBUtils.GetData(CenterUrl, sql);

            list = ConvUtils <City> .ConvertToList(dt_city);

            return(list);
        }
Exemplo n.º 28
0
        /// <summary>
        /// 查询城市所有楼盘名称信息
        /// </summary>
        /// <param name="cityID"></param>
        /// <returns></returns>
        public List <Model.DataProject> QueryDataProjectList(int cityID, int AreaID,
                                                             string tableName)
        {
            List <DataProject> list = new List <DataProject>();
            string             sql  = "SELECT [ProjectId],[ProjectName],[OtherName],[PinYin],[PinYinAll] FROM [FXTProject]." + tableName + @" where CityId = " + cityID;

            logger.DebugFormat("QueryDataProjectList CityID={0}, AreaID={1}, tname={2}, SQL={3}",
                               cityID, AreaID, tableName, sql);
            DataTable data = DBUtils.getData(CaseUrl, sql);

            list = ConvUtils <DataProject> .ConvertToList(data);

            return(list);
        }
Exemplo n.º 29
0
        // Gets transaction time by transaction id
        public DateTime GetTransactionTime(string id)
        {
            using (var client = CreateApi())
            {
                // Extract block hash from transaction id
                var poolHash = id.Split(".")[0];

                // Get block data from API
                var pool = client.PoolInfoGet(ConvUtils.ConvertHashBack(poolHash), 0);

                // Return block time - this is also a transaction time
                return(ConvUtils.UnixTimeStampToDateTime(pool.Pool.Time));
            }
        }
        public void BatchNormalizationLayer_Forward_SpatialInput()
        {
            var batchSize = 2;

            var filterHeight = 2;
            var filterWidth  = 2;
            var filterDepth  = 2;

            var stride  = 1;
            var padding = 0;

            var inputWidth  = 3;
            var inputHeight = 3;
            var inputDepth  = 3;

            var filterGridWidth = ConvUtils.GetFilterGridLength(inputWidth, filterWidth,
                                                                stride, padding, BorderMode.Valid);

            var filterGridHeight = ConvUtils.GetFilterGridLength(inputHeight, filterHeight,
                                                                 stride, padding, BorderMode.Valid);

            var k = filterDepth;

            var input     = new float[] { 111, 121, 112, 122, 113, 123, 114, 124, 211, 221, 212, 222, 213, 223, 214, 224 };
            var convInput = Matrix <float> .Build.Dense(2, 8, input);

            var rowWiseInput = Matrix <float> .Build.Dense(batchSize, k *filterGridWidth *filterGridHeight);

            Trace.WriteLine(convInput);

            ConvUtils.ReshapeConvolutionsToRowMajor(convInput, inputDepth, inputHeight, inputWidth,
                                                    filterHeight, filterWidth, padding, padding, stride, stride,
                                                    BorderMode.Valid, rowWiseInput);

            Trace.WriteLine(rowWiseInput);

            var sut = new BatchNormalizationLayer();

            sut.Initialize(filterGridWidth, filterGridHeight, filterDepth, batchSize,
                           Initialization.GlorotUniform, new Random(232));

            var actual = sut.Forward(rowWiseInput);

            Trace.WriteLine(string.Join(", ", actual.ToColumnMajorArray()));
            Trace.WriteLine(actual);

            var expected = Matrix <float> .Build.Dense(batchSize, k *filterGridWidth *filterGridHeight, new float[] { -1.0297426f, 0.9697576f, -1.00974762f, 0.9897526f, -0.9897526f, 1.00974762f, -0.9697576f, 1.0297426f, -1.0297426f, 0.9697576f, -1.00974762f, 0.9897526f, -0.9897526f, 1.00974762f, -0.9697576f, 1.0297426f });

            MatrixAsserts.AreEqual(expected, actual);
        }