Skip to content

Instantly share code, notes, and snippets.

@bpesquet
Last active March 1, 2021 09:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpesquet/71551c12a8665e0df6d00d82a52e3c47 to your computer and use it in GitHub Desktop.
Save bpesquet/71551c12a8665e0df6d00d82a52e3c47 to your computer and use it in GitHub Desktop.
Bitmap bmp;
Random rd = new Random();
double xc1 = 200;
double yc1 = 200;
double rayon1 = 150;
double sigma1 = 5.0;
double xc2 = 350;
double yc2 = 220;
double rayon2 = 150;
double sigma2 = 5.0;
List<Point> E = new List<Point>();
double [,,] carte;
int nbl = 10;
int nbc = 10;
double coef = 0.1;
int[,] classes;
public MainForm()
{
InitializeComponent();
}
void affichage()
{
// on efface
for (int x = 0; x < pictureBox1.Width; x++)
for (int y = 0; y < pictureBox1.Height; y++)
bmp.SetPixel(x, y, Color.White);
for (int i=0; i<1000; i++)
{
int x = (int)E[i].x;
int y = (int)E[i].y;
bmp.SetPixel(x, pictureBox1.Height-1 - y, Color.Black);
}
// affichage des neurones en bleu
for (int x = 0; x < nbl; x++)
for (int y = 0; y < nbc; y++)
bmp.SetPixel((int)carte[x,y,0], pictureBox1.Height-1 - (int)carte[x,y,1], Color.Blue);
pictureBox1.Invalidate();
}
private void button1_Click(object sender, EventArgs e)
{
bmp = (Bitmap)pictureBox1.Image;
for (int i=0; i<500; i++)
{
double alpha, U1, U2, x, y, T1, r;
// Un point de C1
alpha = Math.PI * rd.NextDouble(); // entre 0 et PI
U1 = rd.NextDouble();
U2 = rd.NextDouble();
T1 = Math.Sqrt(-2 * Math.Log(U1)) * Math.Cos(2 * Math.PI * U2);
r = rayon1 + T1 * sigma1;
x = r * Math.Cos(alpha) + xc1;
y = r * Math.Sin(alpha) + yc1;
E.Add(new Point((float)x, (float)y));
// un point de C2
alpha = -Math.PI * rd.NextDouble(); // entre -PI et 0
U1 = rd.NextDouble();
U2 = rd.NextDouble();
T1 = Math.Sqrt(-2 * Math.Log(U1)) * Math.Cos(2 * Math.PI * U2);
r = rayon2 + T1 * sigma2;
x = r * Math.Cos(alpha) + xc2;
y = r * Math.Sin(alpha) + yc2;
E.Add(new Point((float)x, (float)y));
}
// Création de la carte SOm
carte = new double[nbl, nbc,2];
for (int x = 0; x < nbl; x++)
for (int y = 0; y < nbc; y++)
{
carte[x, y, 0] = rd.NextDouble() * 600;
carte[x, y, 1] = rd.NextDouble() * 600;
}
affichage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment