嗨,我目前有一个数组,其中包含文本文件的所有值,并且当前它在运行时读取文件,但我想在运行时为数组中的每个值生成输出。现在,在读回所有值后程序运行结束时,我有一个输出,但我想在程序打印回的每个值旁边生成一个输出列表。输出是使用训练算法创建的。这是我的代码:
这是我定义数组和其他变量的地方:
`double[] x = new double [3501];`
double output = 1;
double netSum;
double input = 0;
double[] x_P = new double[3501];
double error = input - output;
Random r = new Random();
double[] weights = { r.NextDouble(), r.NextDouble(), r.NextDouble() };
double learningrate = 0.1;
double delta; enter code here
这是将文本文件放入数组的位置:
try
{
using (StreamReader sr = new StreamReader("test.txt"))
{
for (int y = 0; y < 3501; y++)
{
String line = sr.ReadLine();
x[y] = Double.Parse(line);
Console.WriteLine(line);
}
}
这是我用来创建输出的算法:
while (error != 0.01)
{
error = 1;
foreach (double x_value in x)
{
netSum = 0.01;
double i = 1;
for (i = 1; i < 3501; i++)
{
netSum = x[1] * weights[1] + x[2] * weights[2];
}
x_P[2] = Sigmoid(netSum);
output = x_P[2];
if (output >= error)
{
for (i = 1; i < 3501; i++)
{
delta = x_value - output;
error = x[2] - x_P[2];
weights[(int)i] += learningrate * delta * x_value;
error += Math.Abs(error);
}
}
}
Console.WriteLine(output);
Console.ReadLine();
}
}
catch (Exception e)
{
// Log the exception and quit...
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
public static double Sigmoid(double x)
{
return 1 / (1 + Math.Exp(-x));
}
public double Derivative(double x)
{
double s = Sigmoid(x);
return s * (1 - s);
}
所以我基本上希望在打印值时为 x 中的每个值打印输出,有人可以帮助我吗?