public MatchingPair MapMatch(LostAndFoundIndexedItem loss, LostAndFoundIndexedItem finding)
        {
            var pair = Map(loss, finding);

            pair.PercentMatch = 1;
            return(pair);
        }
        public MatchingPair Map(LostAndFoundIndexedItem loss, LostAndFoundIndexedItem finding)
        {
            var pair = new MatchingPair
            {
                LossDateOfIncident    = MapDate(loss.DateOfIncident),
                FindingDateOfIncident = MapDate(finding.DateOfIncident),

                /*LossEasyFindNo = MapIdentifier(loss.EasyFindNo),
                 * FindingEasyFindNo = MapIdentifier(finding.EasyFindNo),
                 * LossBagTag = MapIdentifier(loss.BagTag),
                 * FindingBagTag = MapIdentifier(loss.BagTag),*/



                // TODO:
//        Description
//        LossLocation
            };

            pair.LossCategory    = MapCategory(loss.CategoryID, loss.SubCategoryID);
            pair.FindingCategory = MapCategory(finding.CategoryID, finding.SubCategoryID);

            pair.LossColors    = MapColors(loss.Attributes.OfType <ColorValueAttribute>());
            pair.FindingColors = MapColors(finding.Attributes.OfType <ColorValueAttribute>());

            //*
            MapBool(pair.LossAttributes, loss.Attributes.OfType <BoolAttribute>());
            MapBool(pair.FindingAttributes, finding.Attributes.OfType <BoolAttribute>());
            //*/

            MapDouble(pair.LossAttributes, loss.Attributes.OfType <DoubleAttribute>());
            MapDouble(pair.FindingAttributes, finding.Attributes.OfType <DoubleAttribute>());

            pair.LossMoney    = MapMoney(loss.Attributes.OfType <MoneyValueAttribute>());
            pair.FindingMoney = MapMoney(finding.Attributes.OfType <MoneyValueAttribute>());

            MapInteger(pair.LossAttributes, loss.Attributes.OfType <IntegerAttribute>());
            MapInteger(pair.FindingAttributes, finding.Attributes.OfType <IntegerAttribute>());

            return(pair);
        }
Пример #3
0
        public static void Main(string[] args)
        {
            if (args.Length != 4)
            {
                Console.WriteLine("Usage: NeuralDemo.exe network.dat tree.dat training.json test.json reindex.json");
            }
            var networkFileame   = args[0];
            var treeFilename     = args[1];
            var trainingFilename = args[2];
            var testFilename     = args[3];
            var reindexFilename  = args[4];

            XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net.config"));
            var stopWatch = new Stopwatch();

            stopWatch.Start();
            var network = Network.Load(networkFileame);

            stopWatch.Stop();
            Console.WriteLine("Network loaded in {0}.", stopWatch.Elapsed);

            stopWatch.Restart();
            DecisionTree tree;

            using (var fileStream = File.OpenRead(treeFilename))
                tree = Serializer.Load <DecisionTree>(fileStream);
            stopWatch.Stop();
            Console.WriteLine("DecisionTree loaded in {0}.", stopWatch.Elapsed);

            stopWatch.Restart();
            var deserializer = new ReindexDeserializer(reindexFilename);
            var data         = deserializer.Deserialize();

            stopWatch.Stop();
            Console.WriteLine("Data loaded in {0}.", stopWatch.Elapsed);

            stopWatch.Restart();
            var mapperSettings = ItemMapperSettings.FromDeserialized(data);
            var mapper         = new MatchedItemsMapper(mapperSettings);

            stopWatch.Stop();
            Console.WriteLine("Mapper loaded in {0}.", stopWatch.Elapsed);

            /*stopWatch.Restart();
             * //var loader = new BinaryDataLoader(reindexFilename, trainingFilename, testFilename);
             * //var loader = new JsonDataLoader(reindexFilename, false, false, false);
             * var loader = new JsonPairDataLoader(reindexFilename, trainingFilename, testFilename);
             * var learningData = loader.Load();
             * stopWatch.Stop();
             * Console.WriteLine("Pairs loaded in {0}", stopWatch.Elapsed);*/

            var items = data.Items.Where(item => item.ItemType == LostAndFoundIndexedItem.Type.Loss).ToArray();

            Console.WriteLine("Ready.");
            Console.WriteLine();

            while (true)
            {
                Console.WriteLine("Enter some data on the item you found:");
                var date          = EnterData("Date of finding");
                var money         = EnterData("Money");
                var attributeList = new List <AttributeBase>();
                if (money != null)
                {
                    attributeList.Add(new MoneyValueAttribute {
                        Value = new MoneyValue {
                            Currency = "EUR", Value = Convert.ToDecimal(money)
                        }
                    });
                }
                var color = EnterData("Color (#HTML-Code)");
                if (color != null)
                {
                    attributeList.Add(new ColorValueAttribute {
                        Value = color
                    });
                }

                var finding = new LostAndFoundIndexedItem
                {
                    CategoryID     = "ff61ce82-db05-b000-07ff-0000000000" + EnterData("CategoryID (ff61ce82-db05-b000-07ff-0000000000XX)"),
                    SubCategoryID  = "b988f940-db05-b000-07ff-0000000000" + EnterData("SubCategoryID (b988f940-db05-b000-07ff-0000000000XX)"),
                    DateOfIncident = date != null?Convert.ToDateTime(date) : new DateTime(1999, 12, 31),
                                         Attributes = attributeList,
                };

                var results = new List <Tuple <LostAndFoundIndexedItem, MatchingPair, int> >();
                Parallel.ForEach(items, item =>
                {
                    var pair               = mapper.Map(item, finding);
                    pair.PercentMatch      = network.Compute(pair.ToVectorArray(new Dictionary <string, IndexableAttributeMetadata>())).Single();
                    var decisionTreeResult = tree.Decide(pair.ToVectorArray(new Dictionary <string, IndexableAttributeMetadata>()));

                    lock (results)
                    {
                        results.Add(new Tuple <LostAndFoundIndexedItem, MatchingPair, int>(item, pair, decisionTreeResult));
                    }
                });

                Console.WriteLine("Top 5 Neural Network Results:");
                Console.WriteLine(string.Join(Environment.NewLine,
                                              results.OrderByDescending(result => result.Item2.PercentMatch)
                                              .Take(5)
                                              .Select(result => string.Format("{0}%\t{1}", result.Item2.PercentMatch * 100, result.Item1.RecordNumber))));

                Console.WriteLine("Decision Tree Results:");
                Console.WriteLine(string.Join(Environment.NewLine,
                                              results.Where(result => result.Item3 == 1)
                                              .Select(result => string.Format("{0}%\t{1}", result.Item3 * 100, result.Item1.RecordNumber))));

                Console.Write("Enter next item? [Y/n]");
                var next = Console.ReadLine();
                if (!string.IsNullOrEmpty(next) && next.ToLower() != "y")
                {
                    return;
                }
            }
        }