private Node[] Epoch(int t, Drink inputDrink, Node[] nodesArray) { BestMatchingNodeMultiThreadedSearcher bestMatchingNodeMultiThreadedSearcher = new BestMatchingNodeMultiThreadedSearcher(nodesArray, processorsCount, inputDrink.FeaturesArray); int winningNodeIndex = bestMatchingNodeMultiThreadedSearcher.GetBestMatchingNodeIndex(); double neighbourhoodRadius = Radius(t); double learningRate = LearningRate(t); potentialsArray[winningNodeIndex] -= (_minNeuronPotential + maxNeuronRestTimeInv); UpdatePotentialsArray(maxNeuronRestTimeInv); System.Threading.Tasks.Parallel.ForEach(nodesArray, node => { double theta = Theta(t, nodesArray[winningNodeIndex], node, neighbourhoodRadius); if (theta > 0) { node.AdjustWeights(theta, learningRate, inputDrink.FeaturesArray); node.DrinkID = inputDrink.ID; } }); return nodesArray; }
private void RefreshListViewSimilarDrinks(Drink[] similarDrinksArray) { lv_SimilarDrinks.BeginUpdate(); lv_SimilarDrinks.Items.Clear(); lv_SimilarDrinks.LargeImageList.Images.Clear(); System.Collections.Concurrent.ConcurrentDictionary<int, Image> dictImages = new System.Collections.Concurrent.ConcurrentDictionary<int, Image>(); System.Threading.Tasks.Parallel.ForEach( similarDrinksArray, drink => { dictImages.TryAdd(drink.ID,GetDrinkImage(drink).ResizeImage(SIMILAR_DRINK_IMAGE_SIZE)); }); foreach(Drink drink in similarDrinksArray) { lv_SimilarDrinks.LargeImageList.Images.Add(drink.ID.ToString(),dictImages[drink.ID]); ListViewItem lvi = new ListViewItem(drink.Name); lvi.Tag = drink.Url; lvi.ImageKey = drink.ID.ToString(); lv_SimilarDrinks.Items.Add(lvi); } /* for (int i = 0; i < similarDrinksArray.Length; i++) { lv_SimilarDrinks.LargeImageList.Images.Add(GetDrinkImage(similarDrinksArray[i]).ResizeImage(SIMILAR_DRINK_IMAGE_SIZE)); ListViewItem lvi = new ListViewItem(similarDrinksArray[i].Name); lvi.Tag = similarDrinksArray[i].Url; lvi.ImageIndex = i; lv_SimilarDrinks.Items.Add(lvi); } */ lv_SimilarDrinks.EndUpdate(); }
private Node[] InitializeNodes(Drink[] trainingDataBaseArray) { List<Drink> trainingData = trainingDataBaseArray.ToList(); int nodesNumber = neuralMapWidth * neuralMapHeight; Node[] nodesArray = new Node[nodesNumber]; for (int i = 0; i < nodesNumber; i++) { if( trainingData.Count == 0) trainingData = trainingDataBaseArray.ToList(); int index = randomizer.Next(trainingData.Count); Drink drink = trainingData[index]; nodesArray[i] = new Node(trainingData[index].FeaturesArray,(i % neuralMapWidth) * distanceBetweenNeurons, (i / neuralMapWidth) * distanceBetweenNeurons, drink.ID); trainingData.RemoveAt(index); } return nodesArray; }
private Image GetDrinkImage(Drink drink) { if (drinksImagesDictionary.ContainsKey(drink.ID)) { return drinksImagesDictionary[drink.ID]; } else { Image drinkImage = GetImageFromUrl(drink.ImageUrl); drinksImagesDictionary.Add(drink.ID, drinkImage); return drinkImage; } }