using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Zadanie1
{
public class Perceptron
{
private const int size = 25;
private double[] weights
= new double[size
];
private Random rand
= new Random
();
public Perceptron()
{
// losuję wagi weights[i] małe, bliskie 0
for (int i = 0; i < size; i++) weights[i] = rand.NextDouble();
}
public double Output(double[] input) //do inputu dodac gdziekolwiek jedynkę
{
double suma = 0;
for (int i = 0; i < size; i++) suma = suma + input[i] * weights[i];
return suma;
}
public void Train(double[][] data, int iter)
{
//prog bledu; error,zeby nie uczyl sie w nieskonczonosc
double ERROR = 0.000000001;
double error = 1;
//stala uczenia
double learnConst = 0.00001;
double index = 0;
for (int i = 0; i < iter; i++)
{
foreach (double[] x in data)
{
double y = x[x.Length - 1];
for (int l = 0; l < size; l++) weights[l] = weights[l] + learnConst * (y - Output(x)) * x[l];
}
error = CheckError(data);
if (error < ERROR) break;
}
}
//checkerror z wykładu wzór
public double CheckError(double[][] data)
{
double result = 0;
double tmp;
double C;
foreach (double[] x in data)
{
tmp = Output(x);
C = x[25];
result = result + Math.Pow(tmp - C, 2);
}
return result;
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Zadanie1
{
class Perceptrons
{
private Perceptron[] perceptrons;
private int N = 10;
public Perceptrons()
{
perceptrons
= new Perceptron
[N
];
for (int i
= 0; i
< N
; i
++) perceptrons
[i
] = new Perceptron
();
}
public void TrainPerceptrons()
{
for (int i = 0; i < N; i++)
{
Debug.WriteLine("Zaczynam uczyć: {0}", i);
perceptrons[i].Train(NumbersSamples.makeDataForPercepton(i), 30000);
}
}
public List<int> getCorrectPerceptrons(double[] input)
{
List
<int> wynik
= new List
<int>();
//zliczamy ilosc dobrych porownan, gdy perceptron rozpozna cyfre
for(int i = 0; i < N; i++)
{
if (perceptrons[i].Output(input) > 0) wynik.Add(i);
}
return wynik;
}
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}