Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > .NET Frameworks (точка нет фреймворки) > C# (си шарп)
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 02.03.2018, 18:08   #1
SadZhaba
 
Регистрация: 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();
}
}
}
SadZhaba вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Разобрать код построчно 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