Bonjour,

je souhaite obtenir la parité des nombres qui sont affichés sur un afficheur à 7 leds. Pour cela, j'ai utilisé un perceptron à 7 entrées et une sortie.

Voici l'énoncé exacte de ce que je dois faire :

http://www-lih.univ-lehavre.fr/~duto...Perceptron.pdf

C'est la partie parité qui m'intéresse ici. Voici le code JAVA que j'ai utilisé :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import java.text.DecimalFormat;
import java.text.NumberFormat;
 
 
public class Afficheur {
 
	int[][] patterns = { 
	    { 1, 1, 1, 1, 1, 1, 0 }, //0
	    { 0, 1, 1, 0, 0, 0, 0 }, //1
	    { 1, 1, 0, 1, 1, 0, 1 }, //2
	    { 1, 1, 1, 1, 0, 0, 1 }, //3
	    { 0, 1, 1, 0, 0, 1, 1 }, //4
	    { 1, 0, 1, 1, 0, 1, 1 }, //5
	    { 1, 0, 1, 1, 1, 1, 1 }, //6
	    { 1, 1, 1, 0, 0, 0, 0 }, //7
	    { 1, 1, 1, 1, 1, 1, 1 }, //8
	    { 1, 1, 1, 1, 0, 1, 1 } };//9
 
 
	int[][] teachingOutput = { 
	    { 0 },
	    { 1 }, 
	    { 0 },
	    { 1 }, 
	    { 0 },
	    { 1 }, 
	    { 0 },
	    { 1 }, 
	    { 0 },
	    { 1 } };
			//{ 0 , 1 , 0 , 1 , 0 , 1 , 0 , 1 , 0, 1 } };
 
 
	int numberOfInputNeurons = patterns[0].length;
	int numberOfOutputNeurons = teachingOutput[0].length;
	int numberOfPatterns = patterns.length;
	double[][] weights;
 
	public Afficheur() {
		System.out.println("numberOfInputNeurons : "+numberOfInputNeurons);
		System.out.println("numberOfOutputNeurons : "+numberOfOutputNeurons);
		System.out.println("numberOfPatterns : "+numberOfPatterns);
	    weights = new double[numberOfInputNeurons][numberOfOutputNeurons];
	}
 
	public void deltaRule() 
	{
		//System.out.println("delatarule");
		boolean allCorrect = false;
		boolean error = false;
		double learningFactor = 0.9;
		while (!allCorrect) 
		{
			error = false;
			for (int i = 0; i < numberOfPatterns; i++) 
			{				
				int[] output = setOutputValues(i);
				for (int j = 0; j < numberOfOutputNeurons; j++) 
				{
				    if (teachingOutput[i][j] != output[j]) 
				    {
				        for (int k = 0; k < numberOfInputNeurons; k++) 
				        {
				            weights[k][j] = weights[k][j] + learningFactor
				                    * patterns[i][k]
				                    * (teachingOutput[i][j] - output[j]);
				        }
				    }
				}
				for (int z = 0; z < output.length; z++) 
				{
				    if (output[z] != teachingOutput[i][z])
				        error = true;
				}
 
			 }
			if (!error) 
			{
				allCorrect = true;
			}
		}
	}
 
	int[] setOutputValues(int patternNo) 
	{
		double seuil = 0.7;
		double net=0;
		int[] result = new int[numberOfOutputNeurons];
		int[] toImpress = patterns[patternNo];
		for (int i = 0; i < toImpress.length; i++) 
		{			
			for (int j = 0; j < result.length; j++) 
			{
			    /*net = weights[0][j] * toImpress[0] + weights[1][j]
			            * toImpress[1] + weights[2][j] * toImpress[2]
			            + weights[3][j] * toImpress[3];*/
				for (int k = 0; k < numberOfInputNeurons; k++) 
		        {
					net+=weights[k][j] * toImpress[k];
		        }
 
			    if (net > seuil)
			        result[j] = 1;
			    else
			        result[j] = 0;
			    //net=0;
			}
 
		}
		return result;
	}
 
	public void printMatrix(double[][] matrix) {
 
		for (int i = 0; i < matrix.length; i++) {
		    for (int j = 0; j < matrix[i].length; j++) {
		        NumberFormat f = NumberFormat.getInstance();
		        if (f instanceof DecimalFormat) {
		            DecimalFormat decimalFormat = ((DecimalFormat) f);
		            decimalFormat.setMaximumFractionDigits(1);
		            decimalFormat.setMinimumFractionDigits(1);
		            System.out.print("(" + f.format(matrix[i][j]) + ")");
		        }
		    }
		    System.out.println();
		}
 
	}
 
	public void verif()
	{
		double net=0;
		for (int i = 0; i < numberOfPatterns; i++) 
		{
			for (int k = 0; k < numberOfInputNeurons; k++) 
			{
				net+=weights[k][0] * patterns[i][k];
				//System.out.println(weights[k][0]+" * "+patterns[i][k]+" calcul "+net);
			}
			System.out.println(i+" : "+net);
			net=0;
		}
 
	}
 
 
	public static void main(String[] args)
	{		
		Afficheur p = new Afficheur();
		System.out.println("Poids de depart : ");
		p.printMatrix(p.weights);
		p.deltaRule();
		System.out.println("Poids apres apprentissage: ");
		p.printMatrix(p.weights);
		System.out.println("Resultat : ");
		p.verif();
	}
}
Le soucis est qu' après l'apprentissage je n'obtiens pas les bons poids. J'ai relu entièrement mon code et j'ai même démandé à un collègue de regarder, mais on ne trouve pas la faille. Soit elle est petite et on ne la voit pas soit on a mal compris le perceptron.

Merci d'avance, si quelqu'un peut m'éclairer
@+