Ejemplo n.º 1
0
        public ParallelBackpropagation(NeuralNetwork neuralNetwork, List <DataItem> dataItems,
                                       double learningRate, double momentum, double errorThreshold, int numberOfThreads)
        {
            this.neuralNetwork  = neuralNetwork;
            this.dataItems      = dataItems;
            this.learningRate   = learningRate;
            this.momentum       = momentum;
            this.errorThreshold = errorThreshold;

            CurrentError          = double.MaxValue;
            CurrentEpoch          = 0;
            ValidatePeriod        = 20;
            RemainEpochToValidate = ValidatePeriod;

            randomLearningOrder = new RandomOrder(dataItems, DataItem.DataTypes.Learning);
            randomValidateOrder = new RandomOrder(dataItems, DataItem.DataTypes.Validate);
            randomCurrentOrder  = randomLearningOrder;

            this.numberOfThreads = numberOfThreads;
            barrier      = new Barrier(numberOfThreads);
            semaphore    = new SemaphoreSlim(0);
            threads      = new Task[numberOfThreads];
            threadEvents = new ManualResetEvent[numberOfThreads];

            stopThreads = false;

            for (int i = 0; i < numberOfThreads; i++)
            {
                int threadId = i;
                threads[i] = new Task(() => { backpropagateThread(threadId); });
                threads[i].Start();

                threadEvents[i] = new ManualResetEvent(false);
            }
        }
Ejemplo n.º 2
0
    // Use this for initialization
    void Start()
    {
        instance = this;
        order    = GameObject.FindGameObjectWithTag("RandomOrder").GetComponent <RandomOrder> ();

        foreach (DishType dish in dishTypes)
        {
            dish.button.onClick.AddListener(dish.setDone);
        }
    }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建装有随机订单的 Service(测试用)
        /// </summary>
        static OrderService ServiceWithRand()
        {
            OrderService service = new OrderService();
            int          cnt     = 10;

            for (int i = 1; i <= cnt; i++)
            {
                service.AddOrder(RandomOrder.RandOrder());
            }
            return(service);
        }
Ejemplo n.º 4
0
        public Backpropagation(NeuralNetwork neuralNetwork, List <DataItem> dataItems,
                               double learningRate, double momentum, double errorThreshold)
        {
            this.neuralNetwork  = neuralNetwork;
            this.dataItems      = dataItems;
            this.learningRate   = learningRate;
            this.momentum       = momentum;
            this.errorThreshold = errorThreshold;

            CurrentError          = double.MaxValue;
            CurrentEpoch          = 0;
            ValidatePeriod        = 50;
            RemainEpochToValidate = ValidatePeriod;

            randomLearningOrder = new RandomOrder(dataItems, DataItem.DataTypes.Learning);
            randomValidateOrder = new RandomOrder(dataItems, DataItem.DataTypes.Validate);
            randomCurrentOrder  = randomLearningOrder;
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            // 测试 int 类型的.
            RandomOrder <int> intRandom = new RandomOrder <int>();

            List <int> intList = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            List <int> intRandomList = intRandom.DoRandomOrder(intList);

            Console.WriteLine("Int 数据列表随机排序.");
            for (int i = 0; i < intRandomList.Count; i++)
            {
                Console.Write("{0}  ", intRandomList[i]);
            }
            Console.WriteLine();



            // 测试 string 类型的.
            RandomOrder <string> stringRandom = new RandomOrder <string>();

            List <string> stringList = new List <string>()
            {
                "A", "B", "C", "D", "E", "F", "G",
            };

            List <string> stringRandomList = stringRandom.DoRandomOrder(stringList);

            Console.WriteLine("string 数据列表随机排序.");
            for (int i = 0; i < stringRandomList.Count; i++)
            {
                Console.Write("{0}  ", stringRandomList[i]);
            }
            Console.WriteLine();



            Console.ReadLine();
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            // 测试 int 类型的.
            RandomOrder<int> intRandom = new RandomOrder<int>();

            List<int> intList = new List<int>()
            {
                1,2,3,4,5,6,7,8,9,10
            };

            List<int> intRandomList = intRandom.DoRandomOrder(intList);
            Console.WriteLine("Int 数据列表随机排序.");
            for (int i = 0; i < intRandomList.Count; i++)
            {
                Console.Write("{0}  ", intRandomList[i]);
            }
            Console.WriteLine();



            // 测试 string 类型的.
            RandomOrder<string> stringRandom = new RandomOrder<string>();

            List<string> stringList = new List<string>()
            {
                "A", "B", "C", "D", "E", "F", "G",
            };

            List<string> stringRandomList = stringRandom.DoRandomOrder(stringList);
            Console.WriteLine("string 数据列表随机排序.");
            for (int i = 0; i < stringRandomList.Count; i++)
            {
                Console.Write("{0}  ", stringRandomList[i]);
            }
            Console.WriteLine();



            Console.ReadLine();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 测试 泛型的类. (类与方法都是泛型)
        /// </summary>
        static void TestGenericClass()
        {
            Console.WriteLine("测试 泛型的类. (类与方法都是泛型)");

            // 测试 int 类型的.
            RandomOrder <int> intRandom = new RandomOrder <int>();

            List <int> intList = new List <int>()
            {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10
            };

            List <int> intRandomList = intRandom.DoRandomOrder(intList);

            Console.WriteLine("Int 数据列表随机排序.");
            for (int i = 0; i < intRandomList.Count; i++)
            {
                Console.Write("{0}  ", intRandomList[i]);
            }
            Console.WriteLine();



            // 测试 string 类型的.
            RandomOrder <string> stringRandom = new RandomOrder <string>();

            List <string> stringList = new List <string>()
            {
                "A", "B", "C", "D", "E", "F", "G",
            };

            List <string> stringRandomList = stringRandom.DoRandomOrder(stringList);

            Console.WriteLine("string 数据列表随机排序.");
            for (int i = 0; i < stringRandomList.Count; i++)
            {
                Console.Write("{0}  ", stringRandomList[i]);
            }
            Console.WriteLine();
        }
Ejemplo n.º 8
0
        public bool Train()
        {
            if (CurrentError > errorThreshold)
            {
                if (RemainEpochToValidate == 0)
                {
                    RemainEpochToValidate = ValidatePeriod;
                    randomCurrentOrder    = randomValidateOrder;
                }
                else
                {
                    randomCurrentOrder = randomLearningOrder;
                }

                CurrentEpoch++;
                RemainEpochToValidate--;

                List <int> indexOrder = randomCurrentOrder.GetShuffledOrder();
                CurrentError = backpropagate(indexOrder);
            }

            return(CurrentError < errorThreshold);
        }
Ejemplo n.º 9
0
        public bool Save(ModuleController moduleController, int moduleId)
        {
            try
            {
                if (moduleController == null || moduleId < 0)
                {
                    return(false);
                }

                moduleController.UpdateModuleSetting(moduleId, ForumsSettingsKey, Forums);
                moduleController.UpdateModuleSetting(moduleId, RowsSettingsKey, Rows.ToString());
                moduleController.UpdateModuleSetting(moduleId, FormatSettingsKey, Format);
                moduleController.UpdateModuleSetting(moduleId, HeaderSettingsKey, Header);
                moduleController.UpdateModuleSetting(moduleId, FooterSettingsKey, Footer);
                moduleController.UpdateModuleSetting(moduleId, RSSEnabledSettingsKey, RSSEnabled.ToString());
                moduleController.UpdateModuleSetting(moduleId, TopicsOnlySettingsKey, TopicsOnly.ToString());
                moduleController.UpdateModuleSetting(moduleId, RandomOrderSettingsKey, RandomOrder.ToString());
                moduleController.UpdateModuleSetting(moduleId, TagsSettingsKey, Tags);
                moduleController.UpdateModuleSetting(moduleId, RSSIgnoreSecuritySettingsKey, RSSIgnoreSecurity.ToString());
                moduleController.UpdateModuleSetting(moduleId, RSSIncludeBodySettingsKey, RSSIncludeBody.ToString());
                moduleController.UpdateModuleSetting(moduleId, RSSCacheTimeoutSettingsKey, RSSCacheTimeout.ToString());

                // Clear the cache
                DataCache.CacheClear("aftp_" + moduleId);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }