Example #1
0
        public ActionResult TrainMany(InputOutputViewModel vm)
        {
            vm.HopfieldOutput = new MatrixViewModel(64);
            vm.ARTOutput      = new MatrixViewModel(64);
            vm.patterns       = patterns;


            // trenowanie Hopfielda
            hp = new Hopfield();

            hp.TrainByPseudoInverse(patterns);

            //trenowanie ART
            art = new ART1();
            art.Train(teachingSet);
            //art.Train(patterns);

            art2 = new ART();
            art2.Train(teachingSet);

            int[,] randomPatterns = new int[10, 64];
            int[] numbers = new int[9];
            foreach (int i in numbers)
            {
                var rnd = new Random();
                numbers[i] = rnd.Next(0, 9);
            }



            ViewBag.Message = "Neural networks were trained by patterns.";

            return(View("Index", vm));
        }
 public override void RevertChanges()
 {
     SetupViewModel.RevertChanges();
     InputOutputViewModel.RevertChanges();
     USBViewModel.RevertChanges();
     MIDIViewModel.RevertChanges();
 }
        public static InputOutputViewModel CreateInputOutputViewModel(string name, string value, string mapsTo, string defaultValue, bool required, string recordSetName, bool emptyToNull)
        {
            var inputOutputViewModel =
                new InputOutputViewModel(name, value, mapsTo, defaultValue, required, recordSetName, emptyToNull);

            return(inputOutputViewModel);
        }
        public void InputOutputMappingViewModel_DefaultWithEmptyToNull_Expect_EmptyToNullString()
        {
            const string name          = "vehicleColor";
            const string value         = "vehicleColor";
            const string mapsTo        = "testMapsTo";
            var          defaultValue  = string.Empty;
            const string recordSetName = "testRecSetName";
            const bool   required      = true;

            _inputOutputViewModel = new InputOutputViewModel(name, value, mapsTo, defaultValue, required, recordSetName, true);
            var actual = _inputOutputViewModel.DisplayDefaultValue;

            Assert.AreEqual("Empty to NULL", actual);
        }
        public void InputOutputMappingViewModel_DefaultWithEmptyToNullDefaultValueSet_Expect_DefaultValue()
        {
            const string name          = "vehicleColor";
            const string value         = "vehicleColor";
            const string mapsTo        = "testMapsTo";
            const string defaultValue  = "default val";
            const string recordSetName = "testRecSetName";
            const bool   required      = true;

            _inputOutputViewModel = new InputOutputViewModel(name, value, mapsTo, defaultValue, required, recordSetName, true);
            string actual = _inputOutputViewModel.DisplayDefaultValue;

            Assert.AreEqual("Default: default val", actual);
        }
 public override void ApplyChanges <T>(T model)
 {
     if (model is SystemModel system)
     {
         SetupViewModel.ApplyChanges(system.Setup);
         InputOutputViewModel.ApplyChanges(system.InputOutput);
         USBViewModel.ApplyChanges(system.USB);
         MIDIViewModel.ApplyChanges(system.MIDI);
     }
     else
     {
         throw new ArgumentException("Model must be of type SystemModel.");
     }
 }
        IList <IInputOutputViewModel> CreateMappingList(string mappingDefinitions, IDev2LanguageParser parser, bool autoAddBrackets, bool isOutputMapping, FuzzyMatchVo fuzzyMatch = null)
        {
            IList <IInputOutputViewModel> result = new List <IInputOutputViewModel>();
            var concreteDefinitions = parser.ParseAndAllowBlanks(mappingDefinitions);

            foreach (var def in concreteDefinitions)
            {
                var injectValue = def.RawValue;
                if (autoAddBrackets)
                {
                    injectValue = CreateInjectValue(isOutputMapping, fuzzyMatch, def);
                }
                var injectMapsTo = def.MapsTo;

                // no saved mappings add brackets ;)
                if (!string.IsNullOrEmpty(injectMapsTo) && string.IsNullOrEmpty(SavedInputMapping))
                {
                    injectMapsTo = DataListUtil.AddBracketsToValueIfNotExist(injectMapsTo);
                }
                else
                {
                    if (def.IsRecordSet)
                    {
                        var tmp = injectValue.Replace("()", "(*)");
                        injectMapsTo = tmp; // tag it as the same ;)
                    }
                    else
                    {
                        injectMapsTo = injectValue; // tag it as the same ;)
                    }
                }

                // def.RecordSetName -> recordsetName
                var viewModel = new InputOutputViewModel(def.Name, injectValue, injectMapsTo, def.DefaultValue, def.IsRequired, def.RecordSetName, def.EmptyToNull);
                viewModel.IsObject = def.IsObject;
                if (def.IsObject)
                {
                    var complexObjectItemModel = _complexObjects.FirstOrDefault(model => model.Name == def.Name);
                    if (complexObjectItemModel != null)
                    {
                        viewModel.JsonString = complexObjectItemModel.GetJson();
                    }
                }
                result.Add(viewModel);
            }

            return(result);
        }
Example #8
0
    private void CreateOutput(ShellNodeConfigOutput output, object dataObject)
    {
        var vm = new InputOutputViewModel()
        {
            IsInput          = false,
            IsOutput         = true,
            DiagramViewModel = this.DiagramViewModel,
            Name             = output.Name,
            DataObject       = dataObject,
            Column           = output.Column,
            ColumnSpan       = output.ColumnSpan,
            IsNewLine        = output.IsNewRow
        };

        ContentItems.Add(vm);
    }
 protected override void CreateContent()
 {
     base.CreateContent();
     if (IsVisible(SectionVisibility.WhenNodeIsNotFilter))
     {
         var propertySelection = new InputOutputViewModel()
         {
             DataObject     = PropertyChangedNode.CollectionIn,
             Name           = "Collection",
             IsInput        = true,
             IsOutput       = false,
             IsNewLine      = true,
             AllowSelection = true
         };
         ContentItems.Add(propertySelection);
         AddPropertyFields();
     }
 }
Example #10
0
 protected override void CreateContent()
 {
     //base.CreateContent();
     foreach (var item in GraphItem.GraphItems.OfType <GenericSlot>())
     {
         var vm = new InputOutputViewModel()
         {
             Name             = item.Name,
             IsOutput         = item is IActionOut,
             IsInput          = !(item is IActionOut),
             DataObject       = item,
             IsNewLine        = true,
             DiagramViewModel = DiagramViewModel
         };
         ContentItems.Add(vm);
         if (vm.InputConnector != null)
         {
             vm.InputConnector.Style     = ConnectorStyle.Circle;
             vm.InputConnector.TintColor = UnityEngine.Color.green;
         }
     }
 }
Example #11
0
        protected virtual void CreateActionOuts()
        {
            foreach (var item in SequenceNode.GraphItems.OfType <IActionOut>())
            {
                var vm = new InputOutputViewModel()
                {
                    Name       = item.Name,
                    DataObject = item,
                    IsOutput   = true,
                    IsNewLine  =
                        item.ActionFieldInfo == null || item.ActionFieldInfo.DisplayType == null
                            ? true
                            : item.ActionFieldInfo.DisplayType.IsNewLine,
                    DiagramViewModel = DiagramViewModel
                };
                ContentItems.Add(vm);

                if (!(item is ActionBranch))
                {
                    vm.OutputConnector.Style     = ConnectorStyle.Circle;
                    vm.OutputConnector.TintColor = UnityEngine.Color.green;
                }
            }
        }
        public void MyTestInitialize()
        {
            var testObject = new InputOutputViewModelTestObject();

            _inputOutputViewModel = new InputOutputViewModel(testObject.Name, testObject.Value, testObject.MapsTo, testObject.DefaultValue, testObject.Required, testObject.RecordSetName);
        }
 void SetInputOutputMappingViewModelFromTestMappingObject(InputOutputViewModelTestObject mappingObject)
 {
     _inputOutputViewModel = InputOutputViewModelFactory.CreateInputOutputViewModel(mappingObject.Name, mappingObject.Value, mappingObject.MapsTo, mappingObject.DefaultValue, mappingObject.Required, mappingObject.RecordSetName);
 }
        protected override void CreateContent()
        {
            var inputs = Handler.HandlerInputs;

            if (IsVisible(SectionVisibility.WhenNodeIsNotFilter))
            {
                //if (inputs.Length > 0)
                //    ContentItems.Add(new GenericItemHeaderViewModel()
                //    {
                //        Name = "Mappings",
                //        DiagramViewModel = DiagramViewModel,
                //        IsNewLine = true,
                //    });



                foreach (var item in inputs)
                {
                    var vm = new InputOutputViewModel()
                    {
                        DataObject     = item,
                        Name           = item.Title,
                        IsInput        = true,
                        IsOutput       = false,
                        IsNewLine      = true,
                        AllowSelection = true
                    };
                    ContentItems.Add(vm);
                }
            }
            else
            {
                foreach (var handlerIn in inputs)
                {
                    var handlerItem = handlerIn.Item;
                    if (handlerItem != null)
                    {
                        foreach (var component in handlerItem.SelectComponents)
                        {
                            var component1 = component;

                            ContentItems.Add(new GenericItemHeaderViewModel()
                            {
                                Name          = component.Name,
                                IsBig         = true,
                                IsNewLine     = true,
                                NodeViewModel = this,
                            });
                            //ContentItems.Add(new GenericItemHeaderViewModel()
                            //{
                            //    Name = component.Name,
                            //    DataObject = component,
                            //    IsNewLine = true
                            //});
                            ContentItems.Add(new GenericItemHeaderViewModel()
                            {
                                Name          = "Properties",
                                IsNewLine     = true,
                                NodeViewModel = this,
                                //DataObject = component,
                                AddCommand = new LambdaCommand("", () =>
                                {
                                    var item = new PropertiesChildItem()
                                    {
                                        Node = component1
                                    };
                                    DiagramViewModel.CurrentRepository.Add(item);
                                    item.Name      = item.Repository.GetUniqueName("Collection");
                                    item.IsEditing = true;
                                    DataObjectChanged();
                                })
                            });
                            foreach (var property in component.Properties)
                            {
                                ContentItems.Add(new ScaffoldNodeTypedChildItem <PropertiesChildItem> .ViewModel(property, this));
                            }

                            ContentItems.Add(new GenericItemHeaderViewModel()
                            {
                                Name          = "Collections",
                                IsNewLine     = true,
                                NodeViewModel = this,
                                //DataObject = component,
                                AddCommand = new LambdaCommand("", () =>
                                {
                                    var item = new CollectionsChildItem {
                                        Node = component1
                                    };
                                    DiagramViewModel.CurrentRepository.Add(item);
                                    item.Name      = item.Repository.GetUniqueName("Collection");
                                    item.IsEditing = true;
                                    DataObjectChanged();
                                })
                            });
                            foreach (var property in component.Collections)
                            {
                                ContentItems.Add(new ScaffoldNodeTypedChildItem <CollectionsChildItem> .ViewModel(property, this));
                            }
                        }
                    }
                }
            }
            base.CreateContent();
        }
        /// <summary>
        /// Creates the mapping list.
        /// </summary>
        /// <param name="mappingDefinitions">The mapping definitions.</param>
        /// <param name="parser">The parser.</param>
        /// <param name="autoAddBrackets">if set to <c>true</c> [automatic add brackets].</param>
        /// <param name="isOutputMapping">if set to <c>true</c> [is output mapping].</param>
        /// <param name="fuzzyMatch">The fuzzy match.</param>
        /// <returns></returns>
        private IList <IInputOutputViewModel> CreateMappingList(string mappingDefinitions, IDev2LanguageParser parser, bool autoAddBrackets, bool isOutputMapping, FuzzyMatchVo fuzzyMatch = null)
        {
            IList <IInputOutputViewModel> result = new List <IInputOutputViewModel>();
            IList <IDev2Definition>       concreteDefinitions = parser.ParseAndAllowBlanks(mappingDefinitions);

            foreach (var def in concreteDefinitions)
            {
                var injectValue = def.RawValue;
                if (autoAddBrackets)
                {
                    // When output mapping we need to replace the recordset name if present with MasterRecordset
                    //
                    string masterRecordsetName;
                    if (isOutputMapping && def.IsRecordSet && fuzzyMatch != null)
                    {
                        var field = def.Name;

                        string recordsetName = fuzzyMatch.FetchMatch(def.Name, def.RecordSetName);
                        if (!string.IsNullOrEmpty(recordsetName))
                        {
                            masterRecordsetName = recordsetName;
                        }
                        else
                        {
                            // we have no match, use the current mapping value ;)
                            masterRecordsetName = def.RecordSetName;
                        }

                        injectValue = FormatString(masterRecordsetName, field);
                    }
                    else
                    {
                        if (def.IsRecordSet)
                        {
                            if (fuzzyMatch != null)
                            {
                                string recordsetName = fuzzyMatch.FetchMatch(def.Name, def.RecordSetName);
                                masterRecordsetName = !String.IsNullOrEmpty(recordsetName) ? recordsetName : def.RecordSetName;
                            }
                            else
                            {
                                masterRecordsetName = def.RecordSetName;
                            }

                            injectValue = FormatString(masterRecordsetName, def.Name);
                        }
                        else
                        {
                            injectValue = DataListUtil.AddBracketsToValueIfNotExist(def.Name);
                        }
                    }
                }
                var injectMapsTo = def.MapsTo;

                // no saved mappings add brackets ;)
                if (!string.IsNullOrEmpty(injectMapsTo) && string.IsNullOrEmpty(SavedInputMapping))
                {
                    injectMapsTo = DataListUtil.AddBracketsToValueIfNotExist(injectMapsTo);
                }
                else
                {
                    if (def.IsRecordSet)
                    {
                        var tmp = injectValue.Replace("()", "(*)");
                        injectMapsTo = tmp; // tag it as the same ;)
                    }
                    else
                    {
                        injectMapsTo = injectValue; // tag it as the same ;)
                    }
                }

                // def.RecordSetName -> recordsetName
                var viewModel = new InputOutputViewModel(def.Name, injectValue, injectMapsTo, def.DefaultValue, def.IsRequired, def.RecordSetName, def.EmptyToNull);
                viewModel.IsObject = def.IsObject;
                if (def.IsObject)
                {
                    var complexObjectItemModel = _complexObjects.FirstOrDefault(model => model.Name == def.Name);
                    if (complexObjectItemModel != null)
                    {
                        viewModel.JsonString = complexObjectItemModel.GetJson();
                    }
                }
                result.Add(viewModel);
            }

            return(result);
        }
Example #16
0
        public ActionResult Index(bool?selection)
        {
            ViewBag.Message = "";
            var vm = new InputOutputViewModel();

            vm.Input          = new MatrixViewModel(64);
            vm.HopfieldOutput = new MatrixViewModel(64);
            vm.ARTOutput      = new MatrixViewModel(64);

            //vm.Weights = new double[64, 64];
            if (selection == true && selection != null)
            {
                vm.Input.neurons = Enumerable.Repeat(1, 64).ToArray();
            }

            int[,] newDisturbed = patterns;
            string[] stringDisturbed = new string[patterns.Length / 64];;

            for (int i = 0; i < patterns.Length / 64; i++)
            {
                Random rnd = new Random();
                int    r1  = rnd.Next(1, 63);
                int    r2  = rnd.Next(1, 63);
                //int r3 = rnd.Next(1, 63);
                //int r4 = rnd.Next(1, 63);
                //int r5 = rnd.Next(1, 63);
                //int r6 = rnd.Next(1, 63);
                //int r7 = rnd.Next(1, 63);
                //int r8 = rnd.Next(1, 63);
                //int r9 = rnd.Next(1, 63);
                //int r10 = rnd.Next(1, 63);
                //int r11 = rnd.Next(1, 63);
                //int r12 = rnd.Next(1, 63);
                //int r13 = rnd.Next(1, 63);
                //int r14 = rnd.Next(1, 63);
                //int r15 = rnd.Next(1, 63);
                //int r16 = rnd.Next(1, 63);
                //int r17 = rnd.Next(1, 63);
                //int r18 = rnd.Next(1, 63);
                //int r19 = rnd.Next(1, 63);
                //int r20 = rnd.Next(1, 63);
                //int r21 = rnd.Next(1, 63);
                //int r22 = rnd.Next(1, 63);
                //int r23 = rnd.Next(1, 63);
                //int r24 = rnd.Next(1, 63);
                //int r25 = rnd.Next(1, 63);

                newDisturbed[i, r1] = patterns[i, r1] == 0 ? 1 : 0;
                newDisturbed[i, r2] = patterns[i, r2] == 0 ? 1 : 0;
                //newDisturbed[i, r3] = patterns[i, r3] == 0 ? 1 : 0;
                //newDisturbed[i, r4] = patterns[i, r4] == 0 ? 1 : 0;
                //newDisturbed[i, r5] = patterns[i, r5] == 0 ? 1 : 0;
                //newDisturbed[i, r6] = patterns[i, r6] == 0 ? 1 : 0;
                //newDisturbed[i, r7] = patterns[i, r7] == 0 ? 1 : 0;
                //newDisturbed[i, r8] = patterns[i, r8] == 0 ? 1 : 0;
                //newDisturbed[i, r9] = patterns[i, r9] == 0 ? 1 : 0;
                //newDisturbed[i, r10] = patterns[i, r10] == 0 ? 1 : 0;
                //newDisturbed[i, r11] = patterns[i, r11] == 0 ? 1 : 0;
                //newDisturbed[i, r12] = patterns[i, r12] == 0 ? 1 : 0;
                //newDisturbed[i, r13] = patterns[i, r13] == 0 ? 1 : 0;
                //newDisturbed[i, r14] = patterns[i, r14] == 0 ? 1 : 0;
                //newDisturbed[i, r15] = patterns[i, r15] == 0 ? 1 : 0;
                //newDisturbed[i, r16] = patterns[i, r16] == 0 ? 1 : 0;
                //newDisturbed[i, r17] = patterns[i, r17] == 0 ? 1 : 0;
                //newDisturbed[i, r18] = patterns[i, r18] == 0 ? 1 : 0;
                //newDisturbed[i, r19] = patterns[i, r19] == 0 ? 1 : 0;
                //newDisturbed[i, r20] = patterns[i, r20] == 0 ? 1 : 0;
                //newDisturbed[i, r21] = patterns[i, r21] == 0 ? 1 : 0;
                //newDisturbed[i, r22] = patterns[i, r22] == 0 ? 1 : 0;
                //newDisturbed[i, r23] = patterns[i, r23] == 0 ? 1 : 0;
                //newDisturbed[i, r24] = patterns[i, r24] == 0 ? 1 : 0;
                //newDisturbed[i, r25] = patterns[i, r25] == 0 ? 1 : 0;
                //newDisturbed.SetValue(patterns[i, random] == 0 ? 1 : 0, i, random);



                stringDisturbed[i] = string.Join("", newDisturbed.GetRow(i));
            }


            System.IO.File.WriteAllLines(@"C:\Patterns\symulacje\disturbed.txt", stringDisturbed);
            disturbed   = newDisturbed;
            vm.patterns = disturbed;

            var manyPatterns = System.IO.File.ReadAllLines(@"C:\Patterns\newPatterns012zmiany.txt");

            int[,] patternsNew = new int[manyPatterns.Count(), 64];

            int u = 0;

            foreach (string line in manyPatterns)
            {
                int[] lineArray = line.Select(c => Convert.ToInt32(c.ToString())).ToArray();
                patternsNew.SetRow(u, lineArray);
                u++;
            }

            teachingSet = patternsNew;

            var slightlyDisturbedPatterns = System.IO.File.ReadAllLines(@"C:\Patterns\orderedLekko2.txt");

            int[,] newPatterns = new int[slightlyDisturbedPatterns.Count(), 64];

            int w = 0;

            foreach (string line in slightlyDisturbedPatterns)
            {
                int[] lineArray = line.Select(c => Convert.ToInt32(c.ToString())).ToArray();
                newPatterns.SetRow(w, lineArray);
                w++;
            }

            slightlyDisturbed = newPatterns;

            // vm.patterns = slightlyDisturbed;

            var heavilyDisturbedPatterns = System.IO.File.ReadAllLines(@"C:\Patterns\orderedMocno.txt");

            int[,] newPatterns2 = new int[heavilyDisturbedPatterns.Count(), 64];

            int x = 0;

            foreach (string line in heavilyDisturbedPatterns)
            {
                int[] lineArray = line.Select(c => Convert.ToInt32(c.ToString())).ToArray();
                newPatterns2.SetRow(x, lineArray);
                x++;
            }

            heavilyDisturbed = newPatterns2;

            //vm.patterns = heavilyDisturbed;

            var negatives = System.IO.File.ReadAllLines(@"C:\Patterns\newPatternsNegative.txt");

            int[,] negativePatterns = new int[negatives.Count(), 64];

            int v = 0;

            foreach (string line in negatives)
            {
                int[] lineArray = line.Select(c => Convert.ToInt32(c.ToString())).ToArray();
                negativePatterns.SetRow(v, lineArray);
                v++;
            }

            negative = negativePatterns;

            //vm.patterns = negative;

            return(View(vm));
        }
Example #17
0
        /// <summary>
        /// Creates the mapping list.
        /// </summary>
        /// <param name="mappingDefinitions">The mapping definitions.</param>
        /// <param name="parser">The parser.</param>
        /// <param name="autoAddBrackets">if set to <c>true</c> [automatic add brackets].</param>
        /// <param name="isOutputMapping">if set to <c>true</c> [is output mapping].</param>
        /// <param name="fuzzyMatch">The fuzzy match.</param>
        /// <returns></returns>
        private IList <IInputOutputViewModel> CreateMappingList(string mappingDefinitions, IDev2LanguageParser parser, bool autoAddBrackets, bool isOutputMapping, FuzzyMatchVo fuzzyMatch = null)
        {
            IList <IInputOutputViewModel> result = new List <IInputOutputViewModel>();
            IList <IDev2Definition>       concreteDefinitions = parser.ParseAndAllowBlanks(mappingDefinitions);


            var masterRecordsetName = string.Empty;

            foreach (var def in concreteDefinitions)
            {
                var injectValue = def.RawValue;

                if (!string.IsNullOrEmpty(injectValue) || IsWorkflow)
                {
                    if (autoAddBrackets)
                    {
                        // When output mapping we need to replace the recordset name if present with MasterRecordset
                        //
                        if (isOutputMapping && def.IsRecordSet && fuzzyMatch != null)
                        {
                            var field = DataListUtil.ExtractFieldNameFromValue(injectValue);

                            if (IsWorkflow)
                            {
                                field = def.Name;
                            }

                            string recordsetName = fuzzyMatch.FetchMatch(def.Name, def.RecordSetName);
                            if (!string.IsNullOrEmpty(recordsetName))
                            {
                                masterRecordsetName = recordsetName;
                            }
                            else
                            {
                                // we have no match, use the current mapping value ;)
                                masterRecordsetName = !IsWorkflow?DataListUtil.ExtractRecordsetNameFromValue(injectValue) : def.RecordSetName;
                            }


                            injectValue = FormatString(masterRecordsetName, field);
                        }
                        else
                        {
                            if (def.IsRecordSet)
                            {
                                if (fuzzyMatch != null)
                                {
                                    string recordsetName = fuzzyMatch.FetchMatch(def.Name, def.RecordSetName);
                                    masterRecordsetName = !String.IsNullOrEmpty(recordsetName) ? recordsetName : def.RecordSetName;
                                }
                                else
                                {
                                    masterRecordsetName = def.RecordSetName;
                                }

                                injectValue = FormatString(masterRecordsetName, def.Name);
                            }
                            else
                            {
                                injectValue = DataListUtil.AddBracketsToValueIfNotExist(!IsWorkflow ? injectValue : def.Name);
                            }
                        }
                    }
                }
                else
                {
                    if (!def.IsRecordSet)
                    {
                        if (!String.IsNullOrEmpty(def.RawValue) && String.IsNullOrEmpty(SavedInputMapping))
                        {
                            injectValue = DataListUtil.AddBracketsToValueIfNotExist(def.Name);
                        }
                    }
                    else
                    {
                        if (!isOutputMapping)
                        {
                            var field = def.Name;

                            if (fuzzyMatch != null && def.IsRecordSet)
                            {
                                if (string.IsNullOrEmpty(masterRecordsetName))
                                {
                                    string recordsetName = fuzzyMatch.FetchMatch(def.Name, def.RecordSetName);
                                    masterRecordsetName = !string.IsNullOrEmpty(recordsetName) ? recordsetName : def.RecordSetName;
                                }

                                injectValue = DataListUtil.ComposeIntoUserVisibleRecordset(masterRecordsetName,
                                                                                           string.Empty, field);
                                injectValue = DataListUtil.AddBracketsToValueIfNotExist(injectValue);
                            }
                            else
                            {
                                if (!String.IsNullOrEmpty(def.RawValue) && String.IsNullOrEmpty(SavedInputMapping))
                                {
                                    injectValue = FormatString(def.RecordSetName, def.Name);
                                }
                            }
                        }
                        else
                        {
                            if (!String.IsNullOrEmpty(def.RawValue) && String.IsNullOrEmpty(SavedOutputMapping))
                            {
                                injectValue = FormatString(def.RecordSetName, def.Name);
                            }
                        }
                    }
                }

                var injectMapsTo = def.MapsTo;

                // no saved mappings add brackets ;)
                if (!string.IsNullOrEmpty(injectMapsTo) && string.IsNullOrEmpty(SavedInputMapping))
                {
                    injectMapsTo = DataListUtil.AddBracketsToValueIfNotExist(injectMapsTo);
                }
                else
                {
                    if (def.IsRecordSet)
                    {
                        var tmp = injectValue.Replace("()", "(*)");
                        injectMapsTo = tmp; // tag it as the same ;)
                    }
                    else
                    {
                        injectMapsTo = injectValue; // tag it as the same ;)
                    }
                }

                // def.RecordSetName -> recordsetName
                var viewModel = new InputOutputViewModel(def.Name, injectValue, injectMapsTo, def.DefaultValue, def.IsRequired, def.RecordSetName, def.EmptyToNull);

                result.Add(viewModel);
            }

            return(result);
        }
Example #18
0
        public ActionResult TestMany(InputOutputViewModel vm)
        {
            vm.HopfieldOutput = new MatrixViewModel(64);
            vm.ARTOutput      = new MatrixViewModel(64);
            vm.patterns       = disturbed;

            var testPatterns = disturbed;

            var vector       = vm.Input.neurons;
            var x            = string.Join("", vector);
            var y            = string.Join(",", vector);
            int failCountHP  = 0;
            int failCountART = 0;

            var outputVectorHP   = new int[testPatterns.Length / 64];
            var outputVectorART  = new int[testPatterns.Length / 64];
            var outputVectorART2 = new int[testPatterns.Length / 64];

            if (hp == null || art == null || hp.trained == false || art.trained == false)
            {
                ViewBag.Message = "You have to train neural networks before testing.";
                return(View("Index", vm));
            }

            string[] stringOupputART;
            for (int i = 0; i < testPatterns.Length / 64; i++)
            {
                var outMatrixHP = hp.Test(testPatterns.GetRow(i));
                var outART      = art.Test(testPatterns.GetRow(i));
                var outART2     = art2.Test(testPatterns.GetRow(i));
                var outHP       = hp.NeuronOutput(outMatrixHP, patterns);

                if (outART >= 10)
                {
                    outART = outART % 10;
                }
                if (outHP >= 10)
                {
                    outHP = outHP % 10;
                }
                if (outART2 >= 10)
                {
                    outART2 = outART2 % 10;
                }

                //outHP = patternsOrder.IndexOf(outHP);
                outART  = outART == -1 ? -1 : patternsOrder[outART];
                outART2 = outART2 == -1 ? -1 : patternsOrder[outART2];

                //vm.HopfieldOutput.neurons = outputHP;
                outputVectorHP[i]   = outHP;
                outputVectorART[i]  = outART;
                outputVectorART2[i] = outART2;

                if (outHP != i)
                {
                    failCountHP++;
                }
                if (outART != i)
                {
                    failCountART++;
                }
            }

            string stringHP        = string.Join("", outputVectorHP);
            string stringART       = string.Join("", outputVectorART);
            string stringFailCount = $"HP: {failCountHP}, ART: {failCountART}";

            System.IO.File.WriteAllText(@"C:\Patterns\responseHP.txt", stringHP);
            System.IO.File.WriteAllText(@"C:\Patterns\responseART.txt", stringART);

            System.IO.File.WriteAllText(@"C:\Patterns\symulacje\responseHP.txt", stringHP);
            System.IO.File.WriteAllText(@"C:\Patterns\symulacje\responseART.txt", stringART);

            System.IO.File.WriteAllText(@"C:\Patterns\symulacje\bledy.txt", stringFailCount);

            var outputMatrixHP = hp.Test(vm.Input.neurons);
            var outputART      = art.Test(vm.Input.neurons);
            //var outputART = art2.Test(vm.Input.neurons);
            var outputHP = hp.NeuronOutput(outputMatrixHP, teachingSet);

            if (outputART >= 10)
            {
                outputART = outputART % 10;
            }
            if (outputHP >= 10)
            {
                outputHP = outputHP % 10;
            }

            if (outputHP == -1)
            {
                ViewBag.Message = "Hopfield cannot recognize pattern.";
            }
            else
            {
                vm.HopfieldOutput.neurons = patternsChangeOrder.GetRow(outputHP);
            }

            if (outputART == -1)
            {
                ViewBag.Message = "ART cannot recognize pattern.";
            }
            else
            {
                vm.ARTOutput.neurons = patternsChangeOrder.GetRow(outputART);
            }

            return(View("Index", vm));
        }