|
|
Регистрация Восстановить пароль |
Повторная активизация e-mail |
Регистрация | Задать вопрос |
Заплачу за решение |
Новые сообщения |
Сообщения за день |
Расширенный поиск |
Правила |
Всё прочитано |
|
Опции темы | Поиск в этой теме |
02.03.2018, 18:08 | #1 |
Регистрация: 02.03.2018
Сообщений: 6
|
Разобрать код
using System;
using System.Collections.Generic; using System.IO; namespace Neuroweb { public class Neuron { private bool change = false; private int lastY = -1; private int pointCount = 0; private string FileName = ""; private StreamReader sr; private FileStream file; private StreamWriter sw; private char symbol; public List<double> w; public int LastY { get { return this.lastY; } } public char Symbol { get { return this.symbol; } } public int PointCount { get { return this.pointCount; } } public Neuron(char RecognizingSymbol, int PointCount) { this.symbol = RecognizingSymbol; this.SetFileName(); this.pointCount = PointCount + 1; this.w = new List<double>(this.pointCount); try { this.file = new FileStream(this.FileName, FileMode.Open); this.sr = new StreamReader((Stream)this.file); string s; while ((s = this.sr.ReadLine()) != null) { double result; double.TryParse(s, out result); this.w.Add(result); } this.sr.Close(); this.file.Close(); } catch { this.w.Clear(); this.change = true; this.FillW(); } if (this.w.Count >= this.pointCount) return; this.w.Clear(); this.change = true; this.FillW(); } private void SetFileName() { this.FileName = this.symbol.ToString() + ".txt"; } private void FillW() { Random random = new Random(DateTime.Now.Millisecond); for (int index = 0; index < this.w.Capacity; ++index) this.w.Add(random.NextDouble() * 0.3 * (random.Next(2) == 1 ? -1.0 : 1.0)); } public void Correct(List<byte> x, int delta, double speed) { this.change = true; for (int index = 0; index < this.w.Count; ++index) this.w[index] = this.w[index] + speed * (double)delta * (double)x[index]; } private double S(List<byte> x) { double num = 0.0; for (int index = 0; index < x.Count; ++index) num += this.w[index] * (double)x[index]; return num; } public double Y(List<byte> x) { double num = this.S(x); if (num >= 0.0) return num; else return 0.0; } public void Save() { if (!this.change) return; this.file = File.Create(this.FileName); this.sw = new StreamWriter((Stream)this.file); foreach (double num in this.w) { this.sw.WriteLine(num.ToString()); ((TextWriter)this.sw).Flush(); } this.sw.Close(); this.file.Close(); } } } |
Похожие темы | ||||
Тема | Автор | Раздел | Ответов | Последнее сообщение |
Разобрать код построчно | laucher | Помощь студентам | 1 | 14.10.2016 07:04 |
Не могу разобрать код | Gumi | Общие вопросы по Java, Java SE, Kotlin | 4 | 24.09.2014 11:22 |
Не могу разобрать код | Gumi | JavaScript, Ajax | 3 | 23.09.2014 16:44 |
Разобрать код С++ | Al-chan | Помощь студентам | 6 | 24.02.2013 21:15 |