Exemple #1
0
    public void SaveStaticObject(SerializedStaticObject.SendMessageStruct param)
    {
        param.SetComponentResult(className, false);
        var id    = GetComponent <UniqueId>().ID;
        var units = GetComponentsInChildren <SerializedDynamicObject>();

        if (!DictionaryTools <string, object> .TryToAdd(ref param.dictionary, className + "[" + id + "]._numberUnits", _numberUnits, true))
        {
            return;
        }

        var teamPrefix = className + "[" + id + "]";

        int index = 0;

        foreach (var unit in units)
        {
            if (!AddUnitToDictionary(unit, teamPrefix, index++, ref param.dictionary))
            {
                return;
            }
        }

        param.SetComponentResult(className, DictionaryTools <string, object> .TryToAdd(ref param.dictionary, className + "[" + id + "].numActiveUnits", index, true));
    }
Exemple #2
0
    private bool GetUnitFromDictionary(out SerializedDynamicObject unit, string teamPrefix, int index, ref Dictionary <string, object> dictionary)
    {
        unit = null;
        bool isSuccess  = false;
        var  prefix     = teamPrefix + ".object[" + index + "]";
        var  prefabName = (string)DictionaryTools <string, object> .TryToGet(ref dictionary, prefix + ".prefabName", "", out isSuccess, true);

        if (!isSuccess)
        {
            return(false);
        }

        var obj = CreateObject(prefabName);

        if (!obj)
        {
            return(false);
        }
        unit = obj.GetComponent <SerializedDynamicObject>();
        if (!unit)
        {
            return(false);
        }
        return(unit.LoadObject(new KeyValuePair <string, Dictionary <string, object> >(prefix, dictionary)));
    }
Exemple #3
0
    private bool AddUnitToDictionary(SerializedDynamicObject unit, string teamPrefix, int index, ref Dictionary <string, object> dictionary)
    {
        var prefix = teamPrefix + ".object[" + index + "]";

        if (!DictionaryTools <string, object> .TryToAdd(ref dictionary, prefix + ".prefabName", unit.PrefabName, true))
        {
            return(false);
        }
        return(unit.SaveObject(new KeyValuePair <string, Dictionary <string, object> >(prefix, dictionary)));
    }
        public double Learn(double[][] learnData, int[] learnLabel, double[][] testData, int[] testLabel)
        {
            Log.Write(this.GetType(), "Begin Learning");

            int nInputs  = learnData[0].Length;
            int nOutputs = learnLabel.Distinct().Count();

            double[][] labelDoubles = DictionaryTools.IntToDoubles(nOutputs, learnLabel);

            int[] layers =
            {
                nOutputs * 2, nOutputs
            };

            _neuralNetwork = new DeepBeliefNetwork(nInputs, layers);
            new GaussianWeights(_neuralNetwork).Randomize();
            _neuralNetwork.UpdateVisibleWeights();

            BackPropagationLearning learning = new BackPropagationLearning(_neuralNetwork);

            List <double> errorList = new List <double>();
            int           counter   = 1;

            while (true)
            {
                double error    = learning.RunEpoch(learnData, labelDoubles);
                double tmpError = 0;
                if (errorList.Count > 0)
                {
                    tmpError = errorList.Last();
                }
                errorList.Add(error);

                if (counter % 10 == 0)
                {
                    Log.Write(this.GetType(), $"Iteration {counter} | Score {Score(testData, testLabel)} | Error {error}");
                }

                if (Math.Abs(errorList.Last() - tmpError) < 0.01)
                {
                    break;
                }

                counter++;
            }

            double scoreResult = Score(testData, testLabel);

            Log.Write(this.GetType(), $"Final Score {scoreResult}");
            Log.Write(this.GetType(), "End Learning");

            return(scoreResult);
        }
Exemple #5
0
    public void LoadStaticObject(SerializedStaticObject.SendMessageStruct param)
    {
        var isSuccess = false;
        var id        = GetComponent <UniqueId>().ID;

        _numEmited = (int)DictionaryTools <string, object> .TryToGet(ref param.dictionary, className + "[" + id + "]._numEmited", _numEmited, out isSuccess, false);

        if (!isSuccess)
        {
            Clear();
        }
        param.SetComponentResult(className, true);
    }
Exemple #6
0
        public static Dictionary <string, string> ParseQuery(string query)
        {
            Dictionary <string, string> dest = DictionaryTools.CreateIgnoreCase <string>();

            foreach (string qToken in query.Split('&'))
            {
                string[] qPair = qToken.Split('=');

                if (qPair.Length == 2)
                {
                    dest.Add(qPair[0], qPair[1]);
                }
            }
            return(dest);
        }
Exemple #7
0
    public void LoadStaticObject(SerializedStaticObject.SendMessageStruct param)
    {
        param.SetComponentResult(className, false);
        RemoveAllDynamicChild();
        var  id        = GetComponent <UniqueId>().ID;
        bool isSuccess = false;

        _numberUnits = (int)DictionaryTools <string, object> .TryToGet(ref param.dictionary, className + "[" + id + "]._numberUnits", _numberUnits, out isSuccess, true);

        if (!isSuccess)
        {
            return;
        }

        var numActiveUnits = (int)DictionaryTools <string, object> .TryToGet(ref param.dictionary, className + "[" + id + "].numActiveUnits", 0, out isSuccess, true);

        if (!isSuccess)
        {
            return;
        }

        var teamPrefix = className + "[" + id + "]";

        for (var index = 0; index < numActiveUnits; ++index)
        {
            SerializedDynamicObject unit = null;
            if (!GetUnitFromDictionary(out unit, teamPrefix, index, ref param.dictionary))
            {
                return;
            }

            unit.transform.parent = transform;
        }
        ;
        param.SetComponentResult(className, true);
    }
Exemple #8
0
    public void SaveStaticObject(SerializedStaticObject.SendMessageStruct param)
    {
        var id = GetComponent <UniqueId>().ID;

        param.SetComponentResult(className, DictionaryTools <string, object> .TryToAdd(ref param.dictionary, className + "[" + id + "]._numEmited", _numEmited, true));
    }
Exemple #9
0
        public static Map Load(string file)
        {
            file = Path.Combine(@"Etoile\G4Dungeon\Map", file);

            string[] lines = FileTools.TextToLines(StringTools.ENCODING_SJIS.GetString(DDResource.Load(file)));
            int      c     = 0;

            string[] mapLines;

            {
                List <string> dest = new List <string>();

                while (c < lines.Length)
                {
                    string line = lines[c++];

                    if (line == "")
                    {
                        break;
                    }

                    dest.Add(line);
                }
                mapLines = dest.ToArray();
            }

            Dictionary <string, string> mapScripts = DictionaryTools.Create <string>();

            while (c < lines.Length)
            {
                string line = lines[c++];

                if (line.StartsWith(";"))                 // ? コメント
                {
                    continue;
                }

                if (line == "")
                {
                    break;
                }

                var tokens = line.Split("=".ToArray(), 2);

                string name  = tokens[0].Trim();
                string value = tokens[1].Trim();

                if (Regex.IsMatch(name, @"^[0-9A-Za-z]{2}(:[2468])?$") == false)
                {
                    throw new DDError();
                }

                if (value == "")
                {
                    throw new DDError();
                }

                mapScripts.Add(name, value);
            }

            Map map = LoadMap(mapLines, mapScripts);

            while (c < lines.Length)
            {
                string line = lines[c++];

                if (line.StartsWith(";"))                 // ? コメント
                {
                    continue;
                }

                var tokens = line.Split("=".ToArray(), 2);

                string name  = tokens[0].Trim();
                string value = tokens[1].Trim();

                if (name == "")
                {
                    throw new DDError();
                }
                if (value == "")
                {
                    throw new DDError();
                }

                map.AddProperty(name, value);
            }
            return(map);
        }
Exemple #10
0
        //private Dictionary<string, int> DictSenderName = new Dictionary<string, int>();
        //private Dictionary<string, int> DictSenderEmail = new Dictionary<string, int>();
        //private Dictionary<string, int> DictSenderCombo = new Dictionary<string, int>();

        //private DictionaryTools dt = new DictionaryTools();

        //private List<string> FolderList = new List<string>();

        //private int cnt_folder = 0;
        //private int cnt_mails = 0;
        //private string userpath;

        //private string[] badfolders = { "Junk", "Unwanted", "Trash", "Spam", "Posteingang", "Inbox" };

        //public void GetFolders(Outlook.Folder folder)
        //{
        //    Outlook.Folders childFolders =
        //        folder.Folders;
        //    if (childFolders.Count > 0)
        //    {
        //        foreach (Outlook.Folder childFolder in childFolders)
        //        {
        //            //Console.WriteLine(childFolder.FolderPath);
        //            FolderList.Add(childFolder.FolderPath);
        //            cnt_folder++;
        //            GetFolders(childFolder);
        //        }
        //    }
        //}

        //public void LearnFolders(Outlook.Folder folder, Boolean learn, int folderid)
        //{
        //    Outlook.Folders childFolders = folder.Folders;
        //    Boolean learning = learn;
        //    if (childFolders.Count > 0)
        //    {
        //        foreach (Outlook.Folder childFolder in childFolders)
        //        {
        //            if (childFolder.FolderPath.Contains(FolderList[folderid]))
        //            {
        //                learning = true;
        //            }
        //            else
        //            {
        //                learning = false;
        //            }
        //            foreach (string badfolder in badfolders)
        //            {
        //                if (childFolder.FolderPath.Contains(badfolder))
        //                {
        //                    learning = false;
        //                }
        //            }
        //            cnt_folder++;
        //            if (learning == true)
        //            {
        //                Console.WriteLine("learning from " + childFolder.FolderPath);
        //                try
        //                {
        //                    Items mails = childFolder.Items;
        //                    foreach (object mail in mails)
        //                    {
        //                        try
        //                        {
        //                            Outlook.MailItem thismail = (mail as Outlook.MailItem);
        //                            string senderName = thismail.SenderName;
        //                            string senderEmailAddress = thismail.SenderEmailAddress;
        //                            string senderCombo = senderName + "/" + senderEmailAddress;
        //                            if (DictSenderName.ContainsKey(senderName))
        //                                DictSenderName[senderName] = DictSenderName[senderName] + 1;
        //                            else
        //                                DictSenderName.Add(senderName, 1);
        //                            if (DictSenderEmail.ContainsKey(senderEmailAddress))
        //                                DictSenderEmail[senderEmailAddress] = DictSenderEmail[senderEmailAddress] + 1;
        //                            else
        //                                DictSenderEmail.Add(senderEmailAddress, 1);
        //                            if (DictSenderCombo.ContainsKey(senderCombo))
        //                                DictSenderCombo[senderCombo] = DictSenderCombo[senderCombo] + 1;
        //                            else
        //                                DictSenderCombo.Add(senderCombo, 1);
        //                            cnt_mails++;
        //                        }
        //                        catch (System.Exception ex)
        //                        {
        //                            Debug.WriteLine(ex.Message);
        //                        }
        //                    }
        //                }
        //                catch (System.Exception)
        //                { }
        //            }
        //            else
        //            {
        //                Console.WriteLine("Skipping folder " + childFolder.FolderPath);
        //            }

        //            LearnFolders(childFolder, false, folderid);
        //        }
        //    }
        //    userpath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
        //    dt.Write(DictSenderName, userpath + "\\dict-sender-name.bin");
        //    dt.Write(DictSenderEmail, userpath + "\\dict-sender-email.bin");
        //    dt.Write(DictSenderCombo, userpath + "\\dict-sender-combo.bin");

        //}

        static void Main(string[] args)
        {
            Outlook.Application outlook = new Outlook.Application();
            Outlook.Folder      root    = outlook.Session.DefaultStore.GetRootFolder() as Outlook.Folder;
            Learn learn = new Learn();

            int folderid = 0;
            var userpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\FinalFrontier";

            Console.WriteLine("---AVAILABLE FOLDERS---");
            learn.GetFolders(root);
            for (int i = 0; i < learn.FolderList.Count; i++)
            {
                Console.WriteLine(i + ". " + learn.FolderList[i]);
            }
            Console.Write("Please enter the number (without trailing .) of the folder you want to learn from recursively: ");
            try
            {
                folderid = short.Parse(Console.ReadLine());
            }
            catch (System.Exception)
            {
                Console.WriteLine("could not read the selected folder. exiting...");
                return;
            }

            Console.WriteLine();

            Console.WriteLine("---LEARNING MAIL HISTORY---");
            learn.LearnFolders(root, folderid);
            Console.WriteLine("learned " + " mails  recursively from, starting in " + learn.FolderList[folderid] + ".");

            Console.WriteLine("dictionary files have been written to " + "... keep these files where they are so that FinalFrontier can find them.");

            DictionaryTools dtLearn = new DictionaryTools();

            Console.WriteLine("---VERIFYING---");

            var result = new Dictionary <string, int>();

            foreach (var file in Directory.GetFiles(userpath))
            {
                if (file.EndsWith("-dict-sender-email.bin") ||
                    file.EndsWith("-dict-sender-name.bin") ||
                    file.EndsWith("-dict-sender-combo.bin"))
                {
                    foreach (var values in dtLearn.Read(file))
                    {
                        if (!result.ContainsKey(values.Key))
                        {
                            result.Add(values.Key, values.Value);
                        }
                    }

                    Console.WriteLine($"{Path.GetFileName(file)}: " + dtLearn.Read(file).Count() + " entries");
                }
            }

            //Console.WriteLine("dict-sender-name.bin: " + dtLearn.Read(userpath + "\\dict-sender-name.bin").Count() + " entries");
            //Console.WriteLine("dict-sender-email.bin: " + dtLearn.Read(userpath + "\\dict-sender-email.bin").Count() + " entries");
            //Console.WriteLine("dict-sender-combo.bin: " + dtLearn.Read(userpath + "\\dict-sender-combo.bin").Count() + " entries");

            Console.WriteLine("[hit key to exit]");

            Console.ReadKey();
        }
 public int Predict(double[] input)
 {
     double[] result = _neuralNetwork.Compute(input);
     return(DictionaryTools.DoublesToInt(result));
 }
Exemple #12
0
        private void MainSheet_DragDrop(object sender, DragEventArgs e)
        {
            this.BeforeDialog();

            try
            {
                if (Ground.I.OutputDir == "")
                {
                    throw new Exception("出力先フォルダを設定して下さい。");
                }

                if (e.Data.GetDataPresent(DataFormats.FileDrop) == false)
                {
                    throw new Exception("ファイル又はフォルダをドロップして下さい。");
                }

                this.AddedInfos             = new List <AudioInfo>();                // init
                this.AddedImageFiles        = new List <string>();                   // init
                this.AddedImageFileRejected = false;                                 // init
                this.KnownAudioFiles        = DictionaryTools.CreateSetIgnoreCase(); // init

                this.MS_GetAllRow().ForEach(info => this.KnownAudioFiles.Add(info.AudioFile));

                foreach (string path in (string[])e.Data.GetData(DataFormats.FileDrop))
                {
                    this.AddPath(path);
                }

                this.MainSheet.RowCount += this.AddedInfos.Count;

                if (this.AddedInfos.Count == 0 && 1 <= this.AddedImageFiles.Count && this.AddedImageFileRejected == false)
                {
                    this.MS_SetImageFiles(this.AddedImageFiles);
                }
                else
                {
                    this.AddedInfos.Sort((a, b) => StringTools.CompIgnoreCase(a.AudioFile, b.AudioFile));
                    this.MainSheet.ClearSelection();

                    for (int index = 0; index < this.AddedInfos.Count; index++)
                    {
                        int rowidx = this.MainSheet.RowCount - this.AddedInfos.Count + index;

                        this.MS_SetRow(rowidx, this.AddedInfos[index]);
                        this.MainSheet.Rows[rowidx].Selected = true;
                    }
                }
                this.AddedInfos             = null;     // clear
                this.AddedImageFiles        = null;     // clear
                this.AddedImageFileRejected = false;    // clear
                this.KnownAudioFiles        = null;     // clear
            }
            catch (Exception ex)
            {
                ProcMain.WriteLog(ex);

                MessageBox.Show(ex.Message, "ファイル又はフォルダの追加に失敗しました", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            this.StartMSMonitor();
            this.AfterDialog();
        }