public NeuronNetwork Start() { //запуск потоков обучения нс for (int i = 0; i < threads.Length; i++) { threads[i].Start(); } //запуск ожидания результата Wait(); //теперь усредняем веса всех нейронок и записываем их в результат NeuronNetwork answer = (NeuronNetwork)networks[0].network.Clone(); for (int layer = 0; layer < answer.layers.Count - 1; layer++) { var L = answer.layers[layer]; for (int neuron = 0; neuron < L.neurons.Count; neuron++) { var N = L.neurons[neuron]; double sumW = 0; for (int weight = 0; weight < N.outWeights.Length; weight++) { foreach (var a in networks) { sumW += a.network.layers[layer].neurons[neuron].outWeights[weight]; } sumW /= networks.Length; N.outWeights[weight] = sumW; } } } return(answer); }
static void Main(string[] args) { //pobranie i konwersja bazy iris double[][] iris_dataset; iris_dataset = getdata_iris("C:/Users/profsor500/Desktop/Studia/SystemySztucznejInteligencji/iris_dataset.txt"); //utwoprzenie sieci neuronowej NeuronNetwork NN = new NeuronNetwork(); //pierwsza warstwa musi mieć 4 neurony - 4 dane wejściowe NN.AddLayer(4, 4); //kazda kolejna warstwa musi mieć tyle neuronów, co poprzednia protonów, aby uprościć przekazywanie danych NN.AddLayer(4, 4); NN.AddLayer(4, 4); NN.AddLayer(4, 4); //ostatnia warstwa musi mieć 3 Synapsy, co odpowiada 3 wyjściom. NN.AddLayer(4, 3); //NN.print(); /* * for (int i = 0; i < iris_dataset.Length; i++) * { * Console.Write(i + ") "); * print_table(NN.provide(iris_dataset[i].Take(4).ToArray())); * } */ NN.CheckEfficiency(iris_dataset, 4); Console.ReadKey(); }
public PasswordChecker(string datasetFile) { _nn = new NeuronNetwork(COUNT_IPNUT_NEURONS, LEARNING_RATE); foreach (var line in File.ReadLines(datasetFile)) { var data = line.Split(" "); try { var result = int.Parse(data[1]); switch (result) { case 0: result = -1; break; case 1: result = 0; break; case 2: result = 1; break; default: continue; } _nn.Train(result, ParsePassword(data[0])); } catch { } } }
private void Start() { startPos = pos; Burn(); generate.bacteris.Add(this); nn = new NeuronNetwork(1, new int[] { generate.countFoods *2 + 2, 30, 20, 14, 2 }); }
private void Form1_Load(object sender, EventArgs e) { nNet = new NeuronNetwork(784, 200, 1); nNet.addLayer(200, layerType.HiddenLayer); nNet.addLayer(200, layerType.HiddenLayer); nNet.addLayer(10, layerType.OutputLayer); NetRep.loadNet(nNet); }
// Use this for initialization void Start() { list = new List <Dataset>(); nn = new NeuronNetwork(2, 4, 1) { learning_rate = 0.15f }; }
public PostureRecognition(PatternType patternType, DataTrainingType dataTrainingType, int iterations) { this.networkPattern = PatternResolver <InputDataType, OutputDataType> .ResolvePattern(patternType, dataTrainingType); var activationFunction = new ActivationFunction(); activationFunction.InitializeSigmodeFunction(1.0); network = new NeuronNetwork(activationFunction, iterations); }
private Thread[] threads; //обучающие потоки public MultithreadedLearning(uint networksCount, LearningData[] datas, NeuronNetwork proto, uint genCount, double learningRate) { networks = new LearningMachine[networksCount]; threads = new Thread[networksCount]; for (int i = 0; i < networksCount; i++) { //создание машин обучения для каждой нс int index = i; networks[i] = new LearningMachine((NeuronNetwork)proto.Clone()); networks[i].Edit(datas, genCount, learningRate); threads[i] = new Thread(new ThreadStart(networks[index].StartLearning)); //создание потока обучение } }
private void CopyNN(NeuronNetwork nn) { rate = nn.rate; layers = new Layer[nn.layers.Length]; for (int cl = 0; cl < nn.layers.Length; cl++) { Layer l = nn.layers[cl]; layers[cl] = new Layer(l.size, l.nextSize); System.Array.Copy(l.neurons, layers[cl].neurons, l.size); System.Array.Copy(l.biases, layers[cl].biases, l.size); for (int cn = 0; cn < l.size; cn++) { for (int cw = 0; cw < l.nextSize; cw++) { layers[cl].weights[cn][cw] = l.weights[cn][cw]; } } } }
public void TestMethod1() { var neuronNetwork = new NeuronNetwork(2, 6, new NeuronNetworkContext { Derivative = x => x * (1 - x), Function = x => 1.0 / (1.0 + Math.Exp(-x)), LearnEpoch = 10000, LearnStep = 0.5, ErrorTolerance = 0.001 }); neuronNetwork.Train(new[] { new[] { 1d, 0d }, new[] { 0d, 1d }, new[] { 1d, 1d }, new[] { 0d, 0d } }, new[] { 1d, 1d, 0d, 0d }, (i, i1) => { }); var result = neuronNetwork.Process(new[] { 1d, 1d }); Assert.IsTrue(result < 0.5); result = neuronNetwork.Process(new[] { 1d, 0d }); Assert.IsTrue(result > 0.5); }
public void Selection(NeuronNetwork nn1, NeuronNetwork nn2) { for (int cl = 0; cl < nn1.layers.Length; cl++) { Layer l = nn1.layers[cl]; Layer l2 = nn2.layers[cl]; for (int cn = 0; cn < l.size; cn++) { for (int cw = 0; cw < l.nextSize; cw++) { int p = Random.Range(0, 2); if (p == 1) { layers[cl].weights[cn][cw] = l.weights[cn][cw]; } else { layers[cl].weights[cn][cw] = l2.weights[cn][cw]; } } } } }
protected Trainer(int numberOfChromosomes, NeuronNetwork nn) { _generation = Generation.Make(numberOfChromosomes, nn.NumberOfSynapses); _nn = nn; }
public LearningMachine(NeuronNetwork network) { this.network = (NeuronNetwork)network.Clone(); this.network.Create(); this.network.GenerateRandomWeights(-1, 1); }
public NeuronNetwork(NeuronNetwork nn1, NeuronNetwork nn2) { CopyNN(nn1); Selection(nn1, nn2); }
public NeuronNetworkSpecification(NeuronNetwork neuronNetwork) { this.neuronNetwork = neuronNetwork; }
public NeuronNetwork(NeuronNetwork nn) { CopyNN(nn); }
public static Trainer Make(int populationSize, NeuronNetwork nn) { return new Trainer(populationSize, nn); }
public BP(NeuronNetwork network, double learningRate = 0.9) { this.network = network; this.LearningRate = learningRate; }