public static int SampleInput(myVector sampleInput, Network N) { float sum; float Error = 0; int foundID = -35; int correctID = 25; int Counter = 0; ClearInputs(N); //float NormalizationCoef = 1 / sampleInput.GetVector().Count; float NormalizationCoef = 1.0f / 50.0f; var WordsList = sampleInput.GetVector(); var InputLayer = N.getNetwork().Where(o => o.type == 0).ToList(); var HiddenLayer = N.getNetwork().Where(o => o.type == 1).ToList(); var OutputLayer = N.getNetwork().Where(o => o.type == 2).ToList(); //while (foundID != correctID && Counter < 20) //{ // sum = 0; // N = ClearInputs(N); // Pierwsza iteracja for (int i = 0; i < sampleInput.GetVector().Count; i++) { InputLayer[i].Input = (float)WordsList[i]; } // Druga iteracja CalculateInput(InputLayer); SigmoidFunction(HiddenLayer, NormalizationCoef); // Trzecia iteracja CalculateInput(HiddenLayer); SigmoidFunction(OutputLayer, NormalizationCoef); // Liczenie wyniku foundID = -OutputLayer.OrderBy(o => o.Input).Reverse().FirstOrDefault().ID - 1; // correctID = -CorrectId(sampleInput, OutputLayer) - 1; // // // Dopasowywanie wag // sum = SumInputs(OutputLayer, sum); // Error = (OutputLayer[correctID].Input - OutputLayer[foundID].Input) / sum; // if (foundID != correctID) // { // AdjustWeights(HiddenLayer, Error); // AdjustWeights(InputLayer, Error); // } // Counter++; //} return(foundID); }
public void InitializeNetwork() { classes = DataClass.CreateDataClasses(bow); classes = TestFunctions.CreateFullSet(classes, bow); myVector x = new myVector(); { x = bow.GetVectorsList()[0]; WithoutHiddenLayerNetwork = NeuralConstruction.CreateDefaultNetwork(x.GetVector().Count, classes); NeuralConstruction.SampleWeight(WithoutHiddenLayerNetwork, bow.GetVectorsList(), classes); NeuralNetwork = NeuralConstruction.CreateNewDefaultNetwork(x.GetVector().Count, classes, 5); } }
public static int OldSampleInput(myVector sampleInput, Network N) { var vector = sampleInput.GetVector(); int id = 0; // Zerujemy inputy foreach (var neuron in N.getNetwork()) { neuron.Input = 0; } // Pierwsza iteracja for (int i = 0; i < vector.Count; i++) { // int index = vector[i]; var neuron = N.getNetwork().ElementAt(i); neuron.Input = (float)vector[i]; } // Druga iteracja for (int i = 0; i < vector.Count; i++) { // int index = vector[i]; var neuron = N.getNetwork().ElementAt(i); var ConnectionVector = neuron.GetConnectionsOld(); for (int j = vector.Count, k = 0; k < ConnectionVector.Count; j++, k++) { N.getNetwork().ElementAt(j).Input += neuron.Input * neuron.GetWeights()[k]; } } int connectionCount = N.getNetwork()[0].GetConnectionsOld().Count(); double max = 0; for (int i = vector.Count; i < vector.Count + connectionCount; i++) { var neuron = N.getNetwork().ElementAt(i); if (neuron.Input > max) { max = neuron.Input; id = (-neuron.ID) - 1; } } return(id); }