Hi I currently have a array that has all the values of a text file in it and currently have it reading back the file when it runs but I want to produce outputs for each value in the array when it runs. Right now I have one output produced at the end of when the program runs after all the values have been read back but I want to produce a list of outputs next to each value the program prints back. The output has been created using a training algorithm. Here is my code :
This is where I define my array and my other variables:
`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
This is where a put the text file into the array :
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);
}
}
Here is the algorithm I use to create the output:
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);
}
So I basically want outputs printed for each value in x when the values are printed would someone be able to help me out?