public XorNeuralNet(bool predefined) { if (predefined) { const double w1 = 0.5d, w2 = 0.3d, w3 = 0.4d, w4 = 0.2d, b0 = 0.5d, b1 = 0.3d, w5 = 0.8d, w6 = 0.9d, b2 = 0.8d; net0 = new Perceptron(new[] { w1, w3 }, b0); net1 = new Perceptron(new[] { w2, w4 }, b1); output = new OutputPerceptron(new[] { w5, w6 }, b2); } else { var r = new Random(42); net0 = new Perceptron(new[] { r.NextDouble(), r.NextDouble() }, r.NextDouble()); net1 = new Perceptron(new[] { r.NextDouble(), r.NextDouble() }, r.NextDouble()); output = new OutputPerceptron(new[] { r.NextDouble(), r.NextDouble() }, r.NextDouble()); } }
private void loadDataBasesToolStripMenuItem_Click(object sender, EventArgs e) { try { using (var open = new OpenFileDialog { Title = Resources.Form1_saveDataBasesToolStripMenuItem_Click_Выберете_базу_данных, Filter = "База Данных|*.IIDB" }) { if (open.ShowDialog() == DialogResult.OK) { using (var str = File.OpenRead(open.FileName)) { var bf = new BinaryFormatter(); var temp = (SaveStructure)bf.Deserialize(str); _perceptron = temp.Perceptron; _teacher = new Teacher(_perceptron); _imageHeight = temp.ImageHeight; _imageWidth = temp.ImageWidth; _neuronCount = temp.NeuronCount; } } } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private Brain() { random = new Random(); xBall = new Perceptron(); yBall = new Perceptron(); myPaddle = new Perceptron(); theirPaddle = new Perceptron(); }
private void CreatePerceptronWithTeacher() { try { perceptron = new Perceptron(width * height, layerSizes); teacher = new Teacher(perceptron); } catch (Exception ex) { MessageBox.Show("В ходе выполнения программы произошла ошибка.\n" + ex.Message); } }
public Form1() { InitializeComponent(); //Первая цифра колличество нейронов. //Вторая цифра колличество элементов векторном представлении картинки //Для размера картинки 64x64 будет произведение _perceptron = new Perceptron(_neuronCount, _imageWidth * _imageHeight); _teacher = new Teacher(_perceptron); pictureBox1.Image = new Bitmap(_imageWidth, _imageHeight); _formThread = new Thread(UpdateForm); _formThread.Start(); label6.Text = "v: " + ProductVersion; }
private void settingsToolStripMenuItem_Click(object sender, EventArgs e) { var sett = new settingsForm(_neuronCount, _imageWidth, _imageHeight); sett.ShowDialog(); if (!sett.ItsClosed) { _imageHeight = sett.GetImageHeight; _imageWidth = sett.GetImageWidth; _neuronCount = sett.GetNeuronCount; _perceptron = new Perceptron(_neuronCount, _imageWidth * _imageHeight); _teacher = new Teacher(_perceptron); } }
public PerceptronDirectParametersVisualizer(IPerceptron perceptron, DirectParametersVisualizationType visualizationType) { VisualizationType = visualizationType; Unit = perceptron; switch (VisualizationType) { case DirectParametersVisualizationType.SquareOfRGB: if (Math.Sqrt(Unit.InputsNumber / 3) % 1 != 0) { throw new ArgumentException("Visualization Impossible because of wrong size", "perceptron"); } ImageWidth = (int)Math.Sqrt(Unit.InputsNumber / 3); ImageHeight = (int)Math.Sqrt(Unit.InputsNumber / 3); break; case DirectParametersVisualizationType.SquareOfGray: if (Math.Sqrt(Unit.InputsNumber) % 1 != 0) { throw new ArgumentException("Visualization Impossible because of wrong size", "perceptron"); } ImageWidth = (int)Math.Sqrt(Unit.InputsNumber); ImageHeight = (int)Math.Sqrt(Unit.InputsNumber); break; case DirectParametersVisualizationType.BeltOfRGB: if ((Unit.InputsNumber / 3) % 1 != 0) { throw new ArgumentException("Visualization Impossible because of wrong size", "perceptron"); } ImageWidth = 1; ImageHeight = (int)Unit.InputsNumber / 3; break; case DirectParametersVisualizationType.BeltOfGray: ImageWidth = 1; ImageHeight = (int)Unit.InputsNumber; break; } }
/// <summary> /// Конструктор /// </summary> /// <param name="perceptron">Персептрон</param> public Teacher(IPerceptron perceptron) { _perceptron = perceptron; }
public PerceptronUnderTraining(IEnumerable <ITraversableUnitReadOnly <IUnitUnderTraining, IConnectionUnderTraining, IUnitActivationTraining> > inputUnits, IPerceptron <IUnit, IConnection, IUnitActivation <IUnit> > perceptron = null) { _perceptron = perceptron ?? new Perceptron(inputUnits); Network = new LayeredUnitCollection <IUnitUnderTraining, IConnectionUnderTraining, IUnitActivationTraining>(inputUnits).GetLayeredUnits(); }
/// <summary> /// Serializes a perceptron as JSON and returns the result. /// </summary> /// <typeparam name="TUnit">The declared type of the Unit</typeparam> /// <typeparam name="TConnection">The declared type of the connection</typeparam> /// <typeparam name="TUnitActivation">The declared type of the unit activation</typeparam> /// <param name="perceptron">The perceptron to be serialized</param> /// <returns>A string representation of the perceptron that can later be deserialized back into an IPerceptron</returns> public string SerializeJson <TUnit, TConnection, TUnitActivation>(IPerceptron <TUnit, TConnection, TUnitActivation> perceptron) where TUnit : IUnit where TConnection : IConnection where TUnitActivation : IUnitActivation <TUnit> { var unitMapping = new Dictionary <ITraversableUnitReadOnly <TUnit, TConnection, TUnitActivation>, SimpleUnit>(); var simpleUnits = new List <List <SimpleUnit> >(); foreach (var layer in perceptron.Network) { var simpleUnitLayer = new List <SimpleUnit>(); foreach (var unit in layer) { var simpleUnit = new SimpleUnit { UnitActivationType = unit.UnitActivation.GetType(), UnitType = unit.UnitActivation.Properties.GetType(), UnitPropertiesType = unit.UnitActivation.Properties.GetType() }; MapPropertiesToDictionary(unit.UnitActivation.Properties, simpleUnit.Properties); simpleUnitLayer.Add(simpleUnit); unitMapping.Add(unit, simpleUnit); } simpleUnits.Add(simpleUnitLayer); } var simpleConnections = new List <SimpleConnection>(); foreach (var connection in unitMapping.SelectMany(u => u.Key.IncomingConnections)) { var inSimple = unitMapping[connection.InputUnit]; var outSimple = unitMapping[connection.OutputUnit]; var simpleConnection = new SimpleConnection { InputUnit = inSimple, OutputUnit = outSimple, Weight = connection.Properties.Weight, Name = connection.Properties.Name, ConnectionType = connection.Properties.GetType() }; MapPropertiesToDictionary(connection.Properties, simpleConnection.Properties); simpleConnections.Add(simpleConnection); } var data = new PerceptronJson { SimpleUnits = simpleUnits.Select(layer => layer.ToArray()).ToArray(), SimpleConnections = simpleConnections.ToArray(), PerceptronType = perceptron.GetType() }; return(JsonConvert.SerializeObject(data, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Serialize, PreserveReferencesHandling = PreserveReferencesHandling.Objects, })); }
public void SetUp() { _wrappedPerceptronMock = new Mock <IPerceptron <IUnit, IConnection, IUnitActivation <IUnit> > >(); _perceptron = new OneHotPerceptron(_wrappedPerceptronMock.Object); }
/// <param name="perceptron"> Перцептрон. </param> public Teacher(IPerceptron perceptron) => (Perceptron, PrecisionLog) = (perceptron, new List <float>());
protected OneHotPerceptron() { _perceptron = new Perceptron(); }
public OneHotPerceptron(IEnumerable <ITraversableUnitReadOnly <IUnit, IConnection, IUnitActivation <IUnit> > > inputUnits) { _perceptron = new Perceptron(inputUnits); }
public OneHotPerceptron(IPerceptron <IUnit, IConnection, IUnitActivation <IUnit> > wrapped) { _perceptron = wrapped; }
public PerceptronProblemPair(IPerceptron perceptron, IPerceptronProblem problem) { Perceptron = perceptron; Problem = problem; }