public void Initialize()
        {
            if (NumAttributeAxes > GPUConstants.MaxAttributeAxes || NumCategoricalAxes > GPUConstants.MaxCategoricalAxes)
            {
                throw new InvalidOperationException("Too attribute axes");
            }
            ContextBuffer   = new CudaArray <GPUDecisionLearnerContext>(1);
            DataPointBuffer = DataPointsToGpu(DataPoints);
            DataPointIds    = new CudaArray <int>(DataPoints.Count);
            Nodes           = new CudaArray <GPUNode>(GPUConstants.MaxTotalNodes);
            OpenNodeIds     = new CudaArray <int>(GPUConstants.MaxNodesAtSingleLevel);
            NextOpenNodeIds = new CudaArray <int>(GPUConstants.MaxNodesAtSingleLevel);

            Kernels = new KernelManager(CudaManager)
            {
                BlockSize       = GPUConstants.NumThreadsPerBlock,
                PrefixArguments = new[] { ContextBuffer },
            };

            Kernels["dlInitContext"].Arguments(
                DataPointBuffer,
                DataPoints.Count,
                TotalWeight,
                NumAttributeAxes,
                NumCategoricalAxes,
                DataPointIds,
                Nodes,
                OpenNodeIds,
                NextOpenNodeIds,
                (int)OpenNodeIds.Size).ExecuteTask();
        }
Пример #2
0
 static void Main(string[] args)
 {
     KernelManager.Initialize();
     KernelManager.GPUMode = true;
     //var superResolution = new GAN();//new ReversibleAutoencoder(); //new ConvSuperResolution();
     new ConvSuperResolution().Train();
     //new GradientChecking().Check();
 }
Пример #3
0
            public void ReturnsTheKernel()
            {
                IKernel kernel = KernelManager.GetKernel();

                Assert.IsNotNull(kernel);

                Assert.AreEqual(@"Ninject.StandardKernel", kernel.GetType().FullName);
            }
Пример #4
0
            public void OverridesHowKernelIsCreated()
            {
                Func <IKernel> creator = () => {
                    return(new FakeKernel());
                };

                KernelManager.SetKernelResolver(creator);
                IKernel kernel = KernelManager.GetKernel();

                Assert.AreEqual(@"fainting.goat.tests.FakeKernel", kernel.GetType().FullName);
            }
Пример #5
0
        static void RunKernel(string name, string[] code)
        {
            Console.WriteLine("{0} Kernel", name);
            using (var kernelManager = new KernelManager(name, new ConsoleLogger()))
            {
                kernelManager.StartKernel();
                using (var client = kernelManager.CreateClient())
                {
                    foreach (var block in code)
                    {
                        client.Execute(block);
                    }

                    while (client.HasPendingExecute() && client.IsAlive)
                    {
                        Pause();
                    }

                    // Now echo out everything we did
                    var executeLog = client.ExecuteLog.Values.OrderBy(x => x.ExecutionIndex);
                    foreach (var entry in executeLog)
                    {
                        Console.WriteLine("Item {0} ------------------------------------------", entry.ExecutionIndex);
                        Console.WriteLine(entry.Request.Content.code);
                        Console.WriteLine();

                        if (entry.Abandoned)
                        {
                            Console.WriteLine("  !! This code had to be abandoned !!");
                        }
                        else
                        {
                            var dataResponse = entry.Response.FirstOrDefault(
                                x => x.Header.MessageType.Equals(MessageType.DisplayData) ||
                                x.Header.MessageType.Equals(MessageType.Stream) ||
                                x.Header.MessageType.Equals(MessageType.ExecuteResult));
                            if (dataResponse == null)
                            {
                                Console.WriteLine("  ( No data returned for this code block )");
                            }
                            else
                            {
                                Console.WriteLine(dataResponse.Content);
                            }
                        }

                        Console.WriteLine("--------------------------------------------------\r\n");
                    }
                }
            }
            Console.WriteLine();
        }
Пример #6
0
        public MvcApplication()
        {
            if (MvcApplication.Kernel == null)
            {
                lock (KernelLock) {
                    if (MvcApplication.Kernel == null)
                    {
                        MvcApplication.Kernel = this.RegisterNinject();

                        KernelManager.SetKernelResolver(() => { return(MvcApplication.Kernel); });
                    }
                }
            }
        }
Пример #7
0
        /// <summary>
        /// Load GPU kernels for planet rendering
        /// </summary>
        private void LoadKernels()
        {
            try
            {
                bool useSoftware = (_renderingType == RenderingType.OpenCLSoftware);

                _gpuClear = new GpuClear();

                _clProxy = new OpenCLProxy(useSoftware);

                if (Directory.Exists("Kernels"))
                {
                    KernelManager.GenerateKernels("Kernels");
                }
                else
                {
                    KernelManager.GenerateKernels("../../Kernels");
                }

                _clProxy.CreateIntArgument("resX", RenderUtils.ScreenWidth);
                _clProxy.CreateIntArgument("resY", RenderUtils.ScreenHeight);

                _clProxy.CreateDoubleArgument("cameraLeft", 0);
                _clProxy.CreateDoubleArgument("cameraTop", 0);

                _clProxy.CreateDoubleArgument("cameraWidth", 0);
                _clProxy.CreateDoubleArgument("cameraHeight", 0);

                _clProxy.CreateDoubleArgument("sunNormalX", 0);
                _clProxy.CreateDoubleArgument("sunNormalY", 0);

                _clProxy.CreateDoubleArgument("rotation", 0);

                _clProxy.CreateIntBuffer("image", new int[RenderUtils.ScreenArea], ComputeMemoryFlags.UseHostPointer);

                _gpuClear.Load(_clProxy);

                foreach (IGpuRenderable renderable in _massiveBodies)
                {
                    renderable.Load(_clProxy);
                }
            }
            catch (Exception)
            {
                _renderingType = RenderingType.GDIPlus;
            }
        }
Пример #8
0
        /// <summary>
        /// Load GPU kernels for planet rendering
        /// </summary>
        private void LoadKernels()
        {
            try
            {
                bool useSoftware = _renderingType == RenderingType.OpenCLSoftware;

                _gpuClear = new GpuClear();

                _clProxy = new OpenCLProxy(useSoftware);

                KernelManager.GenerateKernels(Directory.Exists("Kernels") ? "Kernels" : "../../Kernels");

                _clProxy.CreateIntArgument("resX", RenderUtils.ScreenWidth);
                _clProxy.CreateIntArgument("resY", RenderUtils.ScreenHeight);

                _clProxy.CreateDoubleArgument("cX", 0);
                _clProxy.CreateDoubleArgument("cY", 0);

                _clProxy.CreateDoubleArgument("cWidth", 0);
                _clProxy.CreateDoubleArgument("cHeight", 0);

                _clProxy.CreateDoubleArgument("cRot", 0);

                _clProxy.CreateDoubleArgument("sunNormalX", 0);
                _clProxy.CreateDoubleArgument("sunNormalY", 0);

                _clProxy.CreateDoubleArgument("bodyX", 0);
                _clProxy.CreateDoubleArgument("bodyY", 0);
                _clProxy.CreateDoubleArgument("bodyRot", 0);

                _clProxy.CreateIntBuffer("image", new int[RenderUtils.ScreenArea], ComputeMemoryFlags.UseHostPointer);

                _gpuClear.Load(_clProxy);

                foreach (IGpuRenderable renderable in _massiveBodies)
                {
                    renderable.Load(_clProxy);
                }
            }
            catch (Exception)
            {
                _renderingType = RenderingType.GDIPlus;
            }

            UpdateLoadingPercentage(100);
        }
Пример #9
0
 /// <summary>
 /// 构造
 /// </summary>
 public KernelManager()
 {
     if (m_Instance == null)
     {
         m_Instance = this;
         GameObject go = GameObject.Find("Kernel");
         if (go == null)
         {
             go = new GameObject("Kernel");
             m_Instance.m_Kernel = go;
             Object.DontDestroyOnLoad(go);
         }
     }
     else
     {
         Debug.LogError("KernelManager is created repeatly!");
     }
 }
Пример #10
0
            public void SettingToNullGoesBackToDefault()
            {
                Func <IKernel> creator = () => {
                    return(new FakeKernel());
                };

                KernelManager.SetKernelResolver(creator);
                IKernel kernel = KernelManager.GetKernel();

                Assert.AreEqual(@"fainting.goat.tests.FakeKernel", kernel.GetType().FullName);

                // set to null to get default behavior
                KernelManager.SetKernelResolver(null);

                kernel = KernelManager.GetKernel();
                Assert.IsNotNull(kernel);

                Assert.AreEqual(@"Ninject.StandardKernel", kernel.GetType().FullName);
            }
        public void TestSum()
        {
            int[] numbers = Enumerable.Range(999, 10000).ToArray();
            using (CudaManager cudaManager = Provider.CudaManagerPool.GetCudaManagerForThread(Provider.Logger))
                using (CudaArray <int> numbersBuffer = numbers)
                    using (CudaArray <int> outputBuffer = new[] { 0 }) {
                        KernelManager kernels = new KernelManager(cudaManager);

                        for (int nBlocks = 1; nBlocks <= 1024; nBlocks *= 2)
                        {
                            for (int threadsPerBlock = 1; threadsPerBlock <= 1024; threadsPerBlock *= 2)
                            {
                                kernels["setIntKernel"].Arguments(outputBuffer, 0).ExecuteTask();
                                Assert.AreEqual(0, outputBuffer.Read()[0]);
                                kernels["sumToOutputKernel"].Arguments(numbersBuffer, numbers.Length, outputBuffer, SharedBuffer.Ints(threadsPerBlock)).Execute(nBlocks * threadsPerBlock, threadsPerBlock);
                                Assert.AreEqual(numbers.Sum(), outputBuffer.Read()[0]);
                            }
                        }
                    }
        }
Пример #12
0
        /// <summary>
        /// Main entry point in application
        /// </summary>
        /// <param name="args">{0} SharePoint site for which code review tasks should be inserted - not required</param>
        static void Main(string[] args)
        {
            // line below causes output to console - it's not needed
            //log4net.Config.BasicConfigurator.Configure();

            // Ninject configuration
            KernelManager kernelManager = new KernelManager();
            var           helper        = kernelManager.TfsHelper;

            // 1. Parse input - if first arg is filled then assume that SharePoint tasks list should be performed
            InputParser    inputParser         = new InputParser(args);
            InputArguments inputParseArguments = inputParser.Parse();

            // TODO - if statement can be changed to factory pattern
            if (inputParseArguments.IsSharePointListInsert) // handling for sharepoint list
            {
                throw new NotImplementedException("To be implemented");
            }
            else // no sharepoint list
            {
                // 1. Prompt for tfs address until valid address is provided
                string tfsAddress;

                do
                {
                    Console.WriteLine("Please provide TFS address");

                    // Expected format is e.g. http://server_name:8080/tfs
                    tfsAddress = Console.ReadLine();
                }while(URLHelper.IsValidAddress(tfsAddress) == false);

                // 2. Prompt for command - TODO

                // 2. a. For now all projects in collection are listed
                // Get TFSHelper class created using ninject module
                helper.TFSAddress = tfsAddress;
                helper.ListAllCollections();


                //TFSHelper tfs = null; // new TFSHelper(tfsAddress);
                //tfs.ListAllCollections();

                //var projects = tfs.GetAllTeamProjects();
                //tfs.ListAllProjectsNames(projects);

                //tfs.QueryAllWorkItems(projects[0]);
                //Console.WriteLine("Closed tasks");
                //tfs.QueryClosedTodayWorkItems(projects[0]);
            }

            // TODO - further implementation

            // 2. Read closed tasks, resolved bugs and issues for day of application run

            // 3. If 1 is applied then insert code review task into SharePoint tasks list
            // #TaskId, #ProjectName, #TFS server address

            // 4. Get reports foreach defined project
            // 4a. Save to csv list of all tasks for specified project


            Console.WriteLine("End of program");
            Console.ReadLine();
        }
Пример #13
0
        public static void Convolve(Matrix input, bool rotInput, int inputOff, int inputSz, int paddingSz, int dilation, float strideLen, Matrix filter, bool rotFilter, int filterOff, int filterSz, Matrix output, bool rotOutput, int outputOff, int outputSz, bool zero, Matrix bias = null, int bias_off = 0)
        {
            if (KernelManager.GPUMode)
            {
                if (!input.GPU_uptodate)
                {
                    input.UpdateGPU();
                }
                if (!filter.GPU_uptodate)
                {
                    filter.UpdateGPU();
                }
                if (!output.GPU_uptodate)
                {
                    output.UpdateGPU();
                }

                KernelManager.Convolve(input, inputOff, inputSz, filter, filterOff, filterSz, rotFilter, paddingSz, strideLen, output, outputOff, outputSz, rotOutput, zero, bias, bias_off);

                output.CPU_uptodate = false;
                output.GPU_uptodate = true;

                return;
            }

            if (zero)
            {
                output.Clear();
            }

            unsafe
            {
                fixed(float *filter_m = &filter.Memory[filterOff])
                fixed(float *input_m  = &input.Memory[inputOff])
                fixed(float *output_m = &output.Memory[outputOff])
                {
                    if (filterSz < outputSz)
                    {
                        int f_sz = filterSz * filterSz - 1;
                        for (int c = 0; c < filterSz * filterSz; ++c)
                        {
                            int   x0         = c % filterSz;
                            int   y0         = c / filterSz;
                            float filter_val = filter_m[(rotFilter ? c : f_sz - c)];

                            for (int y = 0; y < outputSz; y++)
                            {
                                int i_y = (int)(y * strideLen + y0 * dilation - paddingSz);
                                if (rotInput)
                                {
                                    i_y = inputSz - 1 - i_y;
                                }

                                if (bias != null)
                                {
                                    float b_val = bias.Memory[bias_off];
                                    for (int x = 0; x < outputSz; x++)
                                    {
                                        if (rotOutput)
                                        {
                                            output_m[(outputSz - 1 - y) * outputSz + (outputSz - 1 - x)] += b_val;
                                        }
                                        else
                                        {
                                            output_m[y * outputSz + x] += b_val;
                                        }
                                    }
                                }

                                if (i_y >= 0 && i_y < inputSz)
                                {
                                    for (int x = 0; x < outputSz; x++)
                                    {
                                        int i_x = (int)(x * strideLen + x0 * dilation - paddingSz);
                                        if (rotInput)
                                        {
                                            i_x = inputSz - 1 - i_x;
                                        }

                                        if (i_x >= 0 && i_x < inputSz)
                                        {
                                            float output_val = filter_val * input_m[i_y * inputSz + i_x];

                                            if (rotOutput)
                                            {
                                                output_m[(outputSz - 1 - y) * outputSz + (outputSz - 1 - x)] += output_val;
                                            }
                                            else
                                            {
                                                output_m[y * outputSz + x] += output_val;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        int o_sz = outputSz * outputSz - 1;
                        for (int c = 0; c < outputSz * outputSz; ++c)
                        {
                            int   x          = c % outputSz;
                            int   y          = c / outputSz;
                            float output_val = 0;

                            if (bias != null)
                            {
                                output_val += bias.Memory[bias_off];
                            }

                            for (int y0 = 0; y0 < filterSz; y0++)
                            {
                                int i_y = (int)(y * strideLen + y0 * dilation - paddingSz);
                                if (rotInput)
                                {
                                    i_y = inputSz - 1 - i_y;
                                }

                                if (i_y >= 0 && i_y < inputSz)
                                {
                                    for (int x0 = 0; x0 < filterSz; x0++)
                                    {
                                        int i_x = (int)(x * strideLen + x0 * dilation - paddingSz);
                                        if (rotInput)
                                        {
                                            i_x = inputSz - 1 - i_x;
                                        }

                                        float filter_val = filter_m[(filterSz - 1 - y0) * filterSz + (filterSz - 1 - x0)];
                                        if (rotFilter)
                                        {
                                            filter_val = filter_m[y0 * filterSz + x0];
                                        }

                                        if (i_x >= 0 && i_x < inputSz)
                                        {
                                            output_val += filter_val * input_m[i_y * inputSz + i_x];
                                        }
                                    }
                                }
                            }

                            output_m[(rotOutput ? o_sz - c : c)] += output_val;
                        }
                    }
                }
            }
        }
Пример #14
0
        public void Loss(Matrix output, Matrix expectedOutput, Matrix result, float regularizationParam)
        {
#if GPU
            KernelManager.Loss(expectedOutput, output, result, func);
#elif CPU
            switch (func)
            {
            case "quadratic_loss":
            {
                Parallel.For(0, result.Rows, (i) => result.Memory[i] += (0.5f * (float)Math.Pow(output.Memory[i] - expectedOutput.Memory[i], 2)) / result.Rows + regularizationParam);
            }
            break;

            case "binary_cross_entropy":
            {
                //- (z * log(y + eps) + (1-z) * log(1 - y + eps))
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        result.Memory[i] += (-(float)(expectedOutput.Memory[i] * Math.Log(output.Memory[i] + float.Epsilon) + (1 - expectedOutput.Memory[i]) * Math.Log(1 - output.Memory[i] + float.Epsilon)) / result.Rows + regularizationParam);
                    });
            }
            break;

            case "gan_disc_fake":
            {
                //- (z / (y + eps) - (1 - z) / (1 - y + eps));
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        float r_0         = (float)Math.Log(1.0f - expectedOutput.Memory[i] - output.Memory[i]);
                        result.Memory[i] += r_0 + regularizationParam;
                        //result.memory[i] += -(float)((expectedOutput.memory[i] / (output.memory[i] + float.Epsilon) - (1 - expectedOutput.memory[i]) / (1 - output.memory[i] + float.Epsilon))/result.Rows);
                    });
            }
            break;

            case "gan_disc_real":
            {
                //- (z / (y + eps) - (1 - z) / (1 - y + eps));
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        float r_0         = -(float)Math.Log((1 - expectedOutput.Memory[i]) + output.Memory[i]);
                        result.Memory[i] += r_0 + regularizationParam;
                        //result.memory[i] += -(float)((expectedOutput.memory[i] / (output.memory[i] + float.Epsilon) - (1 - expectedOutput.memory[i]) / (1 - output.memory[i] + float.Epsilon))/result.Rows);
                    });
            }
            break;

            case "gan_gen":
            {
                //- (z / (y + eps) - (1 - z) / (1 - y + eps));
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        float r_0         = -(float)Math.Log(output.Memory[i]);
                        result.Memory[i] += r_0 + regularizationParam;
                        //result.memory[i] += -(float)((expectedOutput.memory[i] / (output.memory[i] + float.Epsilon) - (1 - expectedOutput.memory[i]) / (1 - output.memory[i] + float.Epsilon))/result.Rows);
                    });
            }
            break;
            }
#endif
        }
Пример #15
0
        static void Main(string[] args)
        {
            KernelManager.Initialize();

            var tags = new string[]
            {
                //"emilia_(re:zero)",
                //"katou_megumi",
                //"tokisaki_kurumi",
                //"sawamura_spencer_eriri",
                //"kasumigaoka_utaha",
                //"zero_two_(darling_in_the_franxx)",
                //"nishikino_maki",
                //"souryuu_asuka_langley",
                //"shiba_miyuki",
                //"akemi_homura",
                //"kizuna_ai",
                //"euryale",
                "osakabe-hime_(fate/grand_order)",
                "momo_velia_deviluke",
                "semiramis_(fate)",
                "altera_(fate)",
                "takao_(aoki_hagane_no_arpeggio)",
                "medb_(fate)_(all)",
                "meltlilith",
                "yuzuriha_inori",
                //"redjuice"
            };

            var globalTags = new string[]
            {
                "1girl",
                "solo",
                "-*boy*",
                "-large_breasts",
                "-video",
            };

            BooruDatasetBuilder datasetBuilder = new BooruDatasetBuilder();

            for (int i = 0; i < globalTags.Length; i++)
            {
                datasetBuilder.AddGlobalTag(globalTags[i]);
            }

            for (int i = 0; i < tags.Length; i++)
            {
                datasetBuilder.AddLocalTag(tags[i]);
            }

            datasetBuilder.Download(500, @"I:\Datasets\Gelbooru");
            //var inputDataset = datasetBuilder.GetDataset(@"I:\Datasets\Gelbooru", @"I:\Datasets\Gelbooru_SMALL", Side, 250);

            /*
             * var classifier = new NeuralNetworkBuilder(Side * Side * 3)
             *                  .WeightInitializer(new UniformWeightInitializer(0, 0))
             *                  .LossFunction<Quadratic>()
             *                  .AddConv(3, 3, 1, 0, Side, 3)
             *                  .AddActivation<ReLU>()
             *                  .AddPooling(2, 2, 3)
             *                  .AddConv(3, 10, 1, 0, Side / 2, 3)
             *                  .AddActivation<ReLU>()
             *                  .AddPooling(2, 2, 10)
             *                  .AddFC(4096)
             *                  .AddActivation<LeakyReLU>()
             *                  .AddFC(1024)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(512)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(256)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(64)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(16)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(8)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(8)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(8)
             *                  .AddActivation<ReLU>()
             *                  .AddFC(tags.Length)
             *                  .AddActivation<Sigmoid>()
             *                  .Build();
             *
             * var trainer = new ClassifierTrainer("Anime Classifier", tags, classifier);
             * trainer.SetDataset(inputDataset);
             *
             * LearningManager.Show(trainer);*/
        }
Пример #16
0
    private IEnumerator StartUp()
    {
        KernelManager kernelMgr = KernelManager.Instance();

        if (kernelMgr == null)
        {
            kernelMgr = new KernelManager();
        }
        HotFixUpdate hotFixUpdater = kernelMgr.AddKernel <HotFixUpdate>();

        if (!AppDefineConst.IsAppStartUped)
        {
            kernelMgr.AddKernel <GameManager>();
            kernelMgr.AddKernel <TimeManager>();
            WindowManager.InitWindowManager();

            if (isOpenHotFix)// 判断是否需要拷贝初始资源
            {
                HotFixUpdate.HotfixProgressChangedEvent += HotFixUpdate_HotfixProgressChangedEvent;
                yield return(StartCoroutine(HotFixUpdate.Instance().TryUpdateAssetFromStreamingAssets()));

                HotFixUpdate.HotfixProgressChangedEvent -= HotFixUpdate_HotfixProgressChangedEvent;
                if (m_FirstHandleProgressTips != null)
                {
                    m_FirstHandleProgressTips.gameObject.SetActive(false);
                }
            }
        }
        else
        {
            WindowManager.Instance.CloseAllWindows();
        }

        // 注册资源管理器
        AssetBundleManager assetBundleMgr = AssetBundleManager.Instance;

        while (!assetBundleMgr.IsReady)
        {
            yield return(1);
        }

        if (assetBundleMgr.LaunchFailed)
        {
            Application.Quit();
        }

        UILoading.Show();

        if (isOpenHotFix)
        {
            hotFixUpdater.TryStartUpdateRemoteAssetsToLocal();
            while (hotFixUpdater.IsWorking)
            {
                yield return(1);
            }
            // 更新管理器完成了
            if (hotFixUpdater.UpdaterState == HotFixUpdaterState.Done)
            {
                if (!hotFixUpdater.IsValidatedAssets)
                {
                    Debug.LogError("HotfixUpdate error, the assets was not validated!");
                    Application.Quit();
                    yield break;
                }
                // 有更新资源,需要重新加载资源管理器
                if (hotFixUpdater.IsLoadedNewAsset)
                {
                    WindowManager.Instance.CloseWindow(UILoading.UIAssetName, false);
                    HotFixUpdate_HotfixProgressChangedEvent(null, new HotfixProgressChangedEventArgs(50, "载入新的游戏资源..."));
                    AssetBundleManager.Instance.ReLaunch();
                    while (!AssetBundleManager.Instance.IsReady)
                    {
                        yield return(1);
                    }
                    if (AssetBundleManager.Instance.LaunchFailed)
                    {
                        Application.Quit();
                    }
                    UILoading.Show();
                }
            }
        }

        // 初始化网络管理器
        kernelMgr.AddKernel <Net.ConnectManager>();
        Net.ConnectManager.Instance().CloseAllNetworkClient();
        // 初始化对象池管理器
        LuaAsynFuncMgr.Instance.Init();
        // 初始化Lua管理器
        if (!AppDefineConst.IsAppStartUped)
        {
            LuaManager.Instance.Launch();
        }
        else
        {
            LuaManager.Instance.ReLaunch();
        }

        while (!LuaManager.Instance.IsReady)
        {
            yield return(1);
        }
        if (LuaManager.Instance.LaunchFailed)
        {
            Application.Quit();
        }
        yield return(1);

        LuaManager.Instance.StartUp();

        kernelMgr.DeleteKernel <HotFixUpdate>();
        GameObject.Destroy(this);

        GameObject splashObj = GameObject.Find("SplashUI");

        if (splashObj != null)
        {
            GameObject.Destroy(splashObj);
        }

        AppDefineConst.IsAppStartUped = true;
    }
Пример #17
0
        public void LossDeriv(Matrix output, Matrix expectedOutput, Matrix result, float regularizationParam)
        {
#if GPU
            KernelManager.Loss(expectedOutput, output, result, func_deriv);
#elif CPU
            switch (func_deriv)
            {
            case "quadratic_loss_deriv":
            {
                Parallel.For(0, result.Rows, (i) => result.Memory[i] += (output.Memory[i] - expectedOutput.Memory[i]) / result.Rows + regularizationParam);
            }
            break;

            case "binary_cross_entropy_deriv":
            {
                //- (z / (y + eps) - (1 - z) / (1 - y + eps));
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        float r_0         = ((1.0f - expectedOutput.Memory[i]) - output.Memory[i]);
                        float r           = (r_0 == 0) ? 0 : (1.0f / r_0);
                        result.Memory[i] += r + regularizationParam;
                        //result.memory[i] += -(float)((expectedOutput.memory[i] / (output.memory[i] + float.Epsilon) - (1 - expectedOutput.memory[i]) / (1 - output.memory[i] + float.Epsilon))/result.Rows);
                    });
            }
            break;

            case "gan_disc_fake":
            {
                //- (z / (y + eps) - (1 - z) / (1 - y + eps));
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        float r_0         = (1.0f - expectedOutput.Memory[i] - output.Memory[i]);
                        float r           = (r_0 == 0) ? 0 : (1.0f / r_0);
                        result.Memory[i] += r + regularizationParam;
                        //result.memory[i] += -(float)((expectedOutput.memory[i] / (output.memory[i] + float.Epsilon) - (1 - expectedOutput.memory[i]) / (1 - output.memory[i] + float.Epsilon))/result.Rows);
                    });
            }
            break;

            case "gan_disc_real":
            {
                //- (z / (y + eps) - (1 - z) / (1 - y + eps));
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        float r_0         = ((1 - expectedOutput.Memory[i]) + output.Memory[i]);
                        float r           = (r_0 == 0) ? 0 : -(1.0f / r_0);
                        result.Memory[i] += r + regularizationParam;
                        //result.memory[i] += -(float)((expectedOutput.memory[i] / (output.memory[i] + float.Epsilon) - (1 - expectedOutput.memory[i]) / (1 - output.memory[i] + float.Epsilon))/result.Rows);
                    });
            }
            break;

            case "gan_gen":
            {
                //- (z / (y + eps) - (1 - z) / (1 - y + eps));
                //z = expected out
                //y = actual output
                Parallel.For(0, result.Rows, (i) =>
                    {
                        float r_0         = -1.0f / (output.Memory[i]);
                        result.Memory[i] += r_0 + regularizationParam;
                        //result.memory[i] += -(float)((expectedOutput.memory[i] / (output.memory[i] + float.Epsilon) - (1 - expectedOutput.memory[i]) / (1 - output.memory[i] + float.Epsilon))/result.Rows);
                    });
            }
            break;
            }
#endif
        }