PERCEPTRONIC
This commit is contained in:
parent
be9041cd6f
commit
d79d1123d1
@ -60,6 +60,9 @@
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Model\CstApplication.cs" />
|
||||
<Compile Include="Model\Perceptron.cs" />
|
||||
<Compile Include="Model\GestionPerceptrons.cs" />
|
||||
<Compile Include="Model\Squelette.cs" />
|
||||
<Compile Include="Presenter\JouerMp3.cs" />
|
||||
<Compile Include="Presenter\JouerSon.cs" />
|
||||
<Compile Include="App.xaml.cs">
|
||||
|
@ -11,7 +11,7 @@ namespace JeuHoy_WPF
|
||||
//Nombre de figure de danse dans l'application.
|
||||
public const int NBFIGURE = 10;
|
||||
//Constante pour la Kinect
|
||||
public const int SKELETONCOUNT = 6;
|
||||
public const int SKELETONCOUNT = 10;
|
||||
public const int KINECT_DISPLAY_WIDTH = 320;
|
||||
public const int KINECT_DISPLAY_HEIGHT = 240;
|
||||
|
||||
|
82
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/GestionPerceptrons.cs
Normal file
82
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/GestionPerceptrons.cs
Normal file
@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JeuHoy_WPF_Natif.Model {
|
||||
public class GestionPerceptrons {
|
||||
private Dictionary<string, Perceptron> _lstPerceptrons = new Dictionary<string, Perceptron>();
|
||||
private IGestionFichiers _gestionSortie = new GestionFichiersSorties();
|
||||
private List<Squelette> _lstData = new List<Squelette>();
|
||||
|
||||
/// <summary>
|
||||
/// Constructeur
|
||||
/// </summary>
|
||||
public GestionPerceptrons() {
|
||||
for (char x = '0'; x <= '9'; ++x)
|
||||
_lstPerceptrons.Add(x.ToString(), new Perceptron(x.ToString()));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Charge les échantillons d'apprentissage sauvegardé sur le disque.
|
||||
/// </summary>
|
||||
/// <param name="fichier">Le nom du fichier</param>
|
||||
public void ChargerCoordonnees(string fichier) { _lstData = _gestionSortie.ChargerCoordonnees(fichier); }
|
||||
|
||||
/// <summary>
|
||||
/// Sauvegarde les échantillons d'apprentissage sauvegardé sur le disque.
|
||||
/// </summary>
|
||||
/// <param name="fichier">Le nom du fichier</param>
|
||||
/// <returns>En cas d'erreur retourne le code d'erreur</returns>
|
||||
public int SauvegarderCoordonnees(string fichier) => _gestionSortie.SauvegarderCoordonnees(fichier, _lstData);
|
||||
|
||||
/// <summary>
|
||||
/// Entraine les perceptrons avec un nouveau caractère
|
||||
/// </summary>
|
||||
/// <param name="coordo">Les nouvelles coordonnées</param>
|
||||
/// <param name="reponse">La réponse associé(caractère) aux coordonnées</param>
|
||||
/// <returns>Le résultat de la console</returns>
|
||||
public string Entrainement(Squelette coordo, string reponse) {
|
||||
StringWriter sw = new StringWriter();
|
||||
|
||||
if (reponse != "") {
|
||||
coordo.Reponse = reponse;
|
||||
_lstData.Add(coordo);
|
||||
}
|
||||
|
||||
if (_lstData is null)
|
||||
return "";
|
||||
|
||||
foreach (Perceptron perc in _lstPerceptrons.Values)
|
||||
sw.WriteLine(perc.Entrainement(_lstData));
|
||||
return sw.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Test le perceptron avec de nouvelles coordonnées.
|
||||
/// </summary>
|
||||
/// <param name="coord">Les nouvelles coordonnées</param>
|
||||
/// <returns>Retourne la liste des valeurs possibles du perceptron</returns>
|
||||
public string Tester(Squelette coord) {
|
||||
string resultat = "";
|
||||
|
||||
foreach (Perceptron perc in _lstPerceptrons.Values)
|
||||
if (perc.TesterNeurone(coord))
|
||||
resultat += perc.Reponse;
|
||||
|
||||
if (resultat == "")
|
||||
resultat = "?";
|
||||
|
||||
return resultat;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Obtient une liste des coordonées.
|
||||
/// </summary>
|
||||
/// <returns>Une liste des coordonées.</returns>
|
||||
public IList<Squelette> ObtenirCoordonnees() => _lstData;
|
||||
|
||||
}
|
||||
}
|
90
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/Perceptron.cs
Normal file
90
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/Perceptron.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using JeuHoy_WPF;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace JeuHoy_WPF_Natif.Model {
|
||||
public class Perceptron {
|
||||
private double _cstApprentissage;
|
||||
private double[] _poidsSyn;
|
||||
private string _reponse = "?";
|
||||
public string Reponse { get => _reponse; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructeur de la classe. Crée un perceptron pour une réponse(caractère) qu'on veut identifier le pattern(modèle)
|
||||
/// </summary>
|
||||
/// <param name="reponse">La classe que défini le perceptron</param>
|
||||
public Perceptron(string reponse) {
|
||||
Random _rand = new Random();
|
||||
_reponse = reponse;
|
||||
_cstApprentissage = CstApplication.CONSTANTEAPPRENTISSAGE;
|
||||
|
||||
_poidsSyn = new double[CstApplication.SKELETONCOUNT * 2];
|
||||
for (int x = 0; x < CstApplication.SKELETONCOUNT - 1; ++x)
|
||||
_poidsSyn[x] = _rand.NextDouble();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Faire l'apprentissage sur un ensemble de coordonnées. Ces coordonnées sont les coordonnées de tous les caractères analysés.
|
||||
/// </summary>
|
||||
/// <param name="lstCoord">La liste de coordonnées pour les caractères à analysés.</param>
|
||||
/// <returns>Les paramètres de la console</returns>
|
||||
public string Entrainement(List<Squelette> lstCoord) {
|
||||
int iNbItérations = 0,
|
||||
iNbErreurs = 0;
|
||||
double dSum = 0,
|
||||
dPourSucc = 0;
|
||||
|
||||
do {
|
||||
iNbErreurs = 0;
|
||||
foreach (Squelette coord in lstCoord) {
|
||||
dSum = _poidsSyn[0];
|
||||
|
||||
for (int j = 1; j < _poidsSyn.Length; ++j)
|
||||
dSum += _poidsSyn[j] * coord.Points[j - 1];
|
||||
|
||||
int iRes = (dSum >= 0) ? 1 : 0;
|
||||
int iErr = (_reponse == coord.Reponse ? 1 : 0) - iRes;
|
||||
|
||||
if (iErr != 0) {
|
||||
_poidsSyn[0] = _cstApprentissage;
|
||||
for (int j = 1; j < _poidsSyn.Length; ++j)
|
||||
_poidsSyn[j] += _cstApprentissage * iErr * coord.Points[j - 1];
|
||||
++iNbErreurs;
|
||||
}
|
||||
}
|
||||
dPourSucc = (double)(lstCoord.Count - iNbErreurs) / (double)lstCoord.Count * 100.0;
|
||||
++iNbItérations;
|
||||
}
|
||||
while (dPourSucc < CstApplication.POURCENTCONVERGENCE && iNbItérations < CstApplication.MAXITERATION);
|
||||
|
||||
return $"Perceptron: {_reponse}; Itérations: {iNbItérations} Taux Réussite: {dPourSucc.ToString("0.00")} %"; ;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calcul la valeur(vrai ou faux) pour un les coordonnées d'un caractère. Permet au perceptron d'évaluer la valeur de vérité.
|
||||
/// </summary>
|
||||
/// <param name="vecteurSyn">Les poids synaptiques du perceptron</param>
|
||||
/// <param name="entree">Le vecteur de bit correspondant aux couleurs du caractère</param>
|
||||
/// <returns>Vrai ou faux</returns>
|
||||
public int ValeurEstime(double[] vecteurSyn, double[] entree) {
|
||||
double dSum = vecteurSyn[0];
|
||||
|
||||
for (int j = 1; j < vecteurSyn.Length; ++j)
|
||||
dSum += vecteurSyn[j] * entree[j - 1];
|
||||
|
||||
return (dSum >= 0) ? CstApplication.VRAI : CstApplication.FAUX;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interroge la neuronnes pour un ensembles des coordonnées(d'un caractère).
|
||||
/// </summary>
|
||||
/// <param name="squel"></param>
|
||||
/// <returns></returns>
|
||||
public bool TesterNeurone(Squelette squel) => ValeurEstime(_poidsSyn, squel.Points) == CstApplication.VRAI ? true : false;
|
||||
}
|
||||
}
|
62
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/Squelette.cs
Normal file
62
JeuHoyEtudiants/JeuHoy_WPF_Natif/Model/Squelette.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using JeuHoy_WPF;
|
||||
using Microsoft.Kinect;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace JeuHoy_WPF_Natif.Model {
|
||||
public class Squelette {
|
||||
static private JointType[] _joints = new JointType[CstApplication.SKELETONCOUNT] {
|
||||
JointType.HandLeft,
|
||||
JointType.HandRight,
|
||||
JointType.ElbowLeft,
|
||||
JointType.ElbowRight,
|
||||
JointType.FootLeft,
|
||||
JointType.FootRight,
|
||||
JointType.KneeRight,
|
||||
JointType.KneeLeft,
|
||||
JointType.SpineBase,
|
||||
JointType.Neck
|
||||
};
|
||||
|
||||
private double[] _sque = new double[CstApplication.SKELETONCOUNT * 2];
|
||||
private string _rep = "?";
|
||||
|
||||
public string Reponse { get => _rep; set => _rep = value; }
|
||||
|
||||
public double[] Points => _sque;
|
||||
|
||||
public Squelette(KinectSensor kin, Body body, string reponse) {
|
||||
Vector trans = (Vector)GetPoint(kin, body.Joints[JointType.Head].Position, new Vector(0,0));
|
||||
|
||||
for (int i = 0; i < CstApplication.SKELETONCOUNT; ++i) {
|
||||
Point po = GetPoint(kin, body.Joints[_joints[i]].Position, trans);
|
||||
|
||||
_sque[i * 2] = po.X;
|
||||
_sque[i * 2 + 1] = po.Y;
|
||||
}
|
||||
|
||||
_rep = reponse;
|
||||
}
|
||||
|
||||
private Point GetPoint(KinectSensor sensor, CameraSpacePoint position, Vector trans) {
|
||||
Point point = new System.Windows.Point();
|
||||
|
||||
DepthSpacePoint depthPoint = sensor.CoordinateMapper.MapCameraPointToDepthSpace(position);
|
||||
point.X = float.IsInfinity(depthPoint.X) ? 0.0 : depthPoint.X;
|
||||
point.Y = float.IsInfinity(depthPoint.Y) ? 0.0 : depthPoint.Y;
|
||||
|
||||
// La Kinect pour Xbox One utilise également le SDK 2 de Microsoft, et sa résolution de profondeur est de 512x424 pixels.
|
||||
//// Ainsi, la résolution de la carte de profondeur pour la Kinect pour Xbox One est également de 512x424 pixels.
|
||||
point.X = point.X / 512;
|
||||
point.Y = point.Y / 424;
|
||||
|
||||
return Point.Subtract(point, trans);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user