Exemple #1
0
 static RubyFileOps()
 {
     ALT_SEPARATOR  = MutableString.CreateAscii(AltDirectorySeparatorChar.ToString()).Freeze();
     SEPARATOR      = MutableString.CreateAscii(DirectorySeparatorChar.ToString()).Freeze();
     Separator      = SEPARATOR;
     PATH_SEPARATOR = MutableString.CreateAscii(PathSeparatorChar.ToString()).Freeze();
 }
Exemple #2
0
 private Regex CreatePathRegex(string pattern)
 {
     pattern = Regex.Escape(pattern)
               .Replace(@"\*\*", ".*")
               .Replace(@"\*", @"[^" + Regex.Escape(DirectorySeparatorChar.ToString()) + "]*");
     return(MatchWholeString(pattern));
 }
Exemple #3
0
        public static string AddTrailingDirectorySeparator(string path, bool addAlternateSeparator)
        {
            return(null == path
            ? null

            : (addAlternateSeparator ? (!path.EndsWith(AltDirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal) ? path + AltDirectorySeparatorChar : path)

               : (!path.EndsWith(DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), StringComparison.Ordinal) ? path + DirectorySeparatorChar : path)));
        }
        public static string AddTrailingDirectorySeparator(string path, bool addAlternateSeparator)
        {
            return(path == null
            ? null
            : (addAlternateSeparator
               ? ((!path.EndsWith(AltDirectorySeparatorChar.ToString(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase))
                  ? path + AltDirectorySeparatorChar
                  : path)

               : ((!path.EndsWith(DirectorySeparatorChar.ToString(CultureInfo.CurrentCulture), StringComparison.OrdinalIgnoreCase))
                  ? path + DirectorySeparatorChar
                  : path)));
        }
Exemple #5
0
        static void Main(string[] args)
        {
            var separator = DirectorySeparatorChar.ToString();
            var mnistPath = $".{separator}mnist-fashion{separator}";
            var mnist     = new Mnist(mnistPath);
            var xor       = new XorDataSet();

            //var imagePath = $"{mnistPath}png{separator}";
            //mnist.OutputImages(imagePath);

            //Trainer.DefaultOptimizer = new AdaDelta();
            //Trainer.DefaultOptimizer = new RMSProp();
            //Trainer.DefaultOptimizer = new NAG();
            Trainer.DefaultOptimizer = new Adam();

            Network.Factory.New();
            Network.Factory.AddLayer(xor.InputDataSize, Identity);
            Network.Factory.AddLayer(100, ReLU);
            Network.Factory.AddConnection(He);
            Network.Factory.AddLayer(xor.OutputDataSize, Identity, false);
            Network.Factory.AddConnection(He);
            Network.Factory.SetErrorFunction(MeanSquared);
            Network.Factory.Create(out var network);

            Trainer.Training(network, xor, limitError: 1e-10f, printLog: true);
            Trainer.RegressionTest(network, xor);

            Network.Factory.New();
            Network.Factory.AddLayer(mnist.InputDataSize, Identity);
            Network.Factory.AddLayer(400, ReLU);
            Network.Factory.AddConnection(He);
            Network.Factory.AddLayer(100, ReLU);
            Network.Factory.AddConnection(He);
            Network.Factory.AddLayer(50, ReLU);
            Network.Factory.AddConnection(He);
            Network.Factory.AddLayer(10, ReLU);
            Network.Factory.AddConnection(He);
            Network.Factory.AddLayer(mnist.OutputDataSize, Softmax, false);
            Network.Factory.AddConnection(He);
            Network.Factory.SetErrorFunction(CrossEntropy);
            Network.Factory.Create(out network);

            //Trainer.PreTraining(network, mnist, epoch: 4, batchSize: 30, printLog: true);
            Trainer.Training(network, mnist, epoch: 5, batchSize: 50, printLog: true);
            Trainer.ClusteringTest(network, mnist);
        }
Exemple #6
0
        public override string GetFullPath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path), Properties.Resources.VALUE_CANNOT_BE_NULL);
            }

            if (path.Length == 0)
            {
                throw new ArgumentException(Properties.Resources.THE_PATH_IS_NOT_OF_A_LEGAL_FORM, nameof(path));
            }

            path = path.Replace(AltDirectorySeparatorChar, DirectorySeparatorChar);

            bool isUnc =
                path.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase) ||
                path.StartsWith(@"//", StringComparison.OrdinalIgnoreCase);

            string root = GetPathRoot(path);

            bool hasTrailingSlash = path.Length > 1 && path[path.Length - 1] == DirectorySeparatorChar;

            string[] pathSegments;

            if (root.Length == 0)
            {
                // relative path on the current drive or volume
                path         = _mockFileDataAccessor.Directory.GetCurrentDirectory() + DirectorySeparatorChar + path;
                pathSegments = GetSegments(path);
            }
            else if (isUnc)
            {
                // unc path
                pathSegments = GetSegments(path);
                if (pathSegments.Length < 2)
                {
                    throw new ArgumentException(@"The UNC path should be of the form \\server\share.", nameof(path));
                }
            }
            else if (@"\".Equals(root, StringComparison.OrdinalIgnoreCase) || @"/".Equals(root, StringComparison.OrdinalIgnoreCase))
            {
                // absolute path on the current drive or volume
                pathSegments = GetSegments(GetPathRoot(_mockFileDataAccessor.Directory.GetCurrentDirectory()), path);
            }
            else
            {
                pathSegments = GetSegments(path);
            }

            // unc paths need at least two segments, the others need one segment
            bool isUnixRooted =
                _mockFileDataAccessor.Directory.GetCurrentDirectory()
                .StartsWith(DirectorySeparatorChar.ToString(), StringComparison.OrdinalIgnoreCase);

            int minPathSegments = isUnc
                ? 2
                : isUnixRooted ? 0 : 1;

            Stack <string> stack = new Stack <string>();

            foreach (string segment in pathSegments)
            {
                if ("..".Equals(segment, StringComparison.OrdinalIgnoreCase))
                {
                    // only pop, if afterwards are at least the minimal amount of path segments
                    if (stack.Count > minPathSegments)
                    {
                        stack.Pop();
                    }
                }
                else if (".".Equals(segment, StringComparison.OrdinalIgnoreCase))
                {
                    // ignore .
                }
                else
                {
                    stack.Push(segment);
                }
            }

            string fullPath = string.Join(DirectorySeparatorChar.ToString(), stack.Reverse().ToArray());

            if (hasTrailingSlash)
            {
                fullPath += DirectorySeparatorChar;
            }

            if (isUnixRooted && !isUnc)
            {
                fullPath = DirectorySeparatorChar + fullPath;
            }
            else if (isUnixRooted)
            {
                fullPath = @"//" + fullPath;
            }
            else if (isUnc)
            {
                fullPath = @"\\" + fullPath;
            }

            return(fullPath);
        }
        public override string GetFullPath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path", "Value cannot be null.");
            }

            if (path.Length == 0)
            {
                throw new ArgumentException("The path is not of a legal form.", "path");
            }

            path = path.Replace(AltDirectorySeparatorChar, DirectorySeparatorChar);

            bool isUnc =
                path.StartsWith(@"\\", StringComparison.OrdinalIgnoreCase) ||
                path.StartsWith(@"//", StringComparison.OrdinalIgnoreCase);

            string root = GetPathRoot(path);

            bool hasTrailingSlash = path.Length > 1 && path[path.Length - 1] == DirectorySeparatorChar;

            string[] pathSegments;

            if (root.Length == 0)
            {
                // relative path on the current drive or volume
                path         = mockFileDataAccessor.Directory.GetCurrentDirectory() + DirectorySeparatorChar + path;
                pathSegments = GetSegments(path);
            }
            else if (isUnc)
            {
                // unc path
                pathSegments = GetSegments(path);
                if (pathSegments.Length < 2)
                {
                    throw new ArgumentException(@"The UNC path should be of the form \\server\share.", "path");
                }
            }
            else if (@"\".Equals(root, StringComparison.OrdinalIgnoreCase) || @"/".Equals(root, StringComparison.OrdinalIgnoreCase))
            {
                // absolute path on the current drive or volume
                pathSegments = GetSegments(GetPathRoot(mockFileDataAccessor.Directory.GetCurrentDirectory()), path);
            }
            else
            {
                pathSegments = GetSegments(path);
            }

            // unc paths need at least two segments, the others need one segment
            bool isUnixRooted =
                mockFileDataAccessor.Directory.GetCurrentDirectory()
                .StartsWith(DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture));

            var minPathSegments = isUnc
                ? 2
                : isUnixRooted ? 0 : 1;

            var stack = new Stack <string>();

            foreach (var segment in pathSegments)
            {
                if ("..".Equals(segment, StringComparison.OrdinalIgnoreCase))
                {
                    // only pop, if afterwards are at least the minimal amount of path segments
                    if (stack.Count > minPathSegments)
                    {
                        stack.Pop();
                    }
                }
                else if (".".Equals(segment, StringComparison.OrdinalIgnoreCase))
                {
                    // ignore .
                }
                else
                {
                    stack.Push(segment);
                }
            }

            var fullPath = string.Join(DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), stack.Reverse().ToArray());

            if (hasTrailingSlash)
            {
                fullPath += DirectorySeparatorChar;
            }

            if (isUnixRooted && !isUnc)
            {
                fullPath = DirectorySeparatorChar + fullPath;
            }
            else if (isUnixRooted && isUnc)
            {
                fullPath = @"//" + fullPath;
            }
            else if (!isUnixRooted && isUnc)
            {
                fullPath = @"\\" + fullPath;
            }

            return(fullPath);
        }