public List <EchantillonDonne> ReadAllFromEchantillon(Echantillon echantillon)
        {
            List <EchantillonDonne> liste_echantillons_donnes = new List <EchantillonDonne>();
            RendezVousDAO           rendezVousManager         = new RendezVousDAO();
            Produit produit = new Produit();

            if (OpenConnection())
            {
                command             = manager.CreateCommand();
                command.CommandText = "SELECT * " +
                                      "FROM echantillon_donne " +
                                      "WHERE id_echantillon = @id_echantillon";

                command.Parameters.AddWithValue("@id_echantillon", echantillon.Id_echantillon);

                // Lecture des résultats
                dataReader = command.ExecuteReader();

                while (dataReader.Read())
                {
                    liste_echantillons_donnes.Add(new EchantillonDonne((int)dataReader["quantite"],
                                                                       echantillon,
                                                                       rendezVousManager.Read((int)dataReader["id_rdv"], false),
                                                                       produit));
                }
                dataReader.Close();
                CloseConnection();
            }

            return(liste_echantillons_donnes);
        }
        /// <summary>
        /// Récupère une Echantillon à partir d'un identifiant de client
        /// </summary>
        /// <param name="Identifiant">Identifant de Echantillon</param>
        /// <returns>Un Echantillon </returns>
        public static Echantillon Get(Int32 identifiant)
        {
            //Connection
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["LaboSPPPConnectionString"];
            SqlConnection connection = new SqlConnection(connectionStringSettings.ToString());
            //Commande
            String requete = @"SELECT Identifiant, Libelle, NumLot, DatePeinture, IdentifiantProduit FROM Echantillon
                                WHERE Identifiant = @Identifiant";
            SqlCommand commande = new SqlCommand(requete, connection);

            //Paramètres
            commande.Parameters.AddWithValue("Identifiant", identifiant);

            //Execution
            connection.Open();
            SqlDataReader dataReader = commande.ExecuteReader();

            dataReader.Read();

            //1 - Création du Echantillon
            Echantillon echantillon = new Echantillon();
            echantillon.Identifiant = dataReader.GetInt32(0);
            echantillon.NumLot = dataReader.GetString(1);
            echantillon.DatePeinture = dataReader.GetDateTime(2);
            echantillon.produit.Identifiant = dataReader.GetInt32(3);

            dataReader.Close();
            connection.Close();
            return echantillon;
        }
Exemple #3
0
        //public double Run(double[] pLstEntrees, double[] pLstSortiesAApprendre)
        //{
        //    double totalError = _OldError;

        //    int i = 0;
        //    while (i < _MaxIterations && totalError > _Momentum)
        //    {
        //        _OldError = totalError;
        //        totalError = 0;

        //        // Calcule les sorties de l'échantillon d'entrées
        //        double[] lstSortiesCalculees = _Network.Compute(pLstEntrees);

        //        // Compare les entrées calculées avec les entrées (réelles) à apprendre
        //        for (int j = 0; j < lstSortiesCalculees.Length; j++)
        //        {
        //            // Différence entre les entrées à apprendre et les entrées à apprendre
        //            double error = pLstSortiesAApprendre[j] - lstSortiesCalculees[j];
        //            // Cumul de la différence au carré
        //            totalError += (error * error);
        //        }

        //        // Calcul des nouveaux poids par rétropropagation
        //        AdjustWeights(CEchantillon(pLstEntrees,pLstSortiesAApprendre), _LearningRate);

        //        // Changer le taux
        //        if (totalError >= _OldError)
        //        {
        //            _LearningRate = _LearningRate / 2.0;
        //        }

        //        // Information et incrément
        //        i++;
        //    }

        //    return totalError;
        //}


        //public void Run()
        //{
        //    int i = 0;
        //    double totalError = Double.PositiveInfinity;
        //    double oldError = Double.PositiveInfinity;
        //    double totalGeneralisationError = Double.PositiveInfinity;
        //    double oldGeneralisationError = Double.PositiveInfinity;
        //    Boolean betterGeneralisation = true;

        //    while (i < _MaxIterations && totalError > _Momentum && betterGeneralisation)
        //    {
        //        oldError = totalError;
        //        totalError = 0;
        //        oldGeneralisationError = totalGeneralisationError;
        //        totalGeneralisationError = 0;

        //        // Evaluation
        //        foreach (Echantillon point in _LstEchantillons.TrainingPoints)
        //        {
        //            double[] outputs = _Network.Compute(point);
        //            for (int outNb = 0; outNb < outputs.Length; outNb++)
        //            {
        //                double error = point.Sorties[outNb] - outputs[outNb];
        //                totalError += (error * error);
        //            }

        //            // Calcul des nouveaux poids par rétropropagation
        //            AdjustWeights(point, _LearningRate);
        //        }

        //        // Généralisation
        //        foreach (Echantillon point in _LstEchantillons.GeneralisationPoints)
        //        {
        //            double[] outputs = _Network.Compute(point);
        //            for (int outNb = 0; outNb < outputs.Length; outNb++)
        //            {
        //                double error = point.Sorties[outNb] - outputs[outNb];
        //                totalGeneralisationError += (error * error);
        //            }
        //        }
        //        if (totalGeneralisationError > oldGeneralisationError)
        //        {
        //            betterGeneralisation = false;
        //        }

        //        // Changer le taux
        //        if (totalError >= oldError)
        //        {
        //            _LearningRate = _LearningRate / 2.0;
        //        }

        //        // Information et incrément
        //        i++;
        //    }
        //}

        #endregion

        #region Implémentation

        // Algo d'apprentissage
        private void AdjustWeights(Echantillon pEchantillon, double pLearningRate)
        {
            // Deltas pour les sorties
            double[] outputDeltas = new double[_NbreNeuronesSortis];
            for (int i = 0; i < _NbreNeuronesSortis; i++)
            {
                double output         = _Network.NeuronesSortis[i].Sortie;
                double expectedOutput = pEchantillon.Sorties[i];
                outputDeltas[i] = output * (1 - output) * (expectedOutput - output);
            }

            // Deltas pour les neurones cachés
            double[] hiddenDeltas = new double[_NbreNeuronesCaches];
            for (int i = 0; i < _NbreNeuronesCaches; i++)
            {
                double hiddenOutput = _Network.NeuronesCaches[i].Sortie;
                double sum          = 0.0;
                for (int j = 0; j < _NbreNeuronesSortis; j++)
                {
                    sum += outputDeltas[j] * _Network.NeuronesSortis[j].Weight(i);
                }
                hiddenDeltas[i] = hiddenOutput * (1 - hiddenOutput) * sum;
            }

            double value;

            // Ajustement des poids des neurones de sortie
            for (int i = 0; i < _NbreNeuronesSortis; i++)
            {
                Neuron outputNeuron = _Network.NeuronesSortis[i];
                for (int j = 0; j < _NbreNeuronesCaches; j++)
                {
                    value = outputNeuron.Weight(j) + pLearningRate * outputDeltas[i] * _Network.NeuronesCaches[j].Sortie;
                    outputNeuron.AdjustWeight(j, value);
                }
                // Et biais
                value = outputNeuron.Weight(_NbreNeuronesCaches) + pLearningRate * outputDeltas[i] * 1.0;
                outputNeuron.AdjustWeight(_NbreNeuronesCaches, value);
            }

            // Ajustement des poids des neurones cachés
            for (int i = 0; i < _NbreNeuronesCaches; i++)
            {
                Neuron hiddenNeuron = _Network.NeuronesCaches[i];
                for (int j = 0; j < _NbreEntrees; j++)
                {
                    value = hiddenNeuron.Weight(j) + pLearningRate * hiddenDeltas[i] * pEchantillon.Entrees[j];
                    hiddenNeuron.AdjustWeight(j, value);
                }
                // Et biais
                value = hiddenNeuron.Weight(_NbreEntrees) + pLearningRate * hiddenDeltas[i] * 1.0;
                hiddenNeuron.AdjustWeight(_NbreEntrees, value);
            }
        }
        public static void Insert(Echantillon echantillon)
        {
            //Connexion
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = "LaboSPPPConnectionString";
            connection.Open();
            //Commande
            SqlCommand commande = new SqlCommand();
            commande.Connection = connection;
            commande.CommandText = "INSERT INTO Echantillon( NumLot, DatePeinture, IdentifiantProduit) VALUES(@NumLot, @DatePeinture, @IdentifiantProduit)";
            commande.Parameters.AddWithValue("Libelle", echantillon.NumLot);
            commande.Parameters.AddWithValue("DatePeinture", echantillon.DatePeinture);
            commande.Parameters.AddWithValue("IdentifiantProduit", echantillon.produit.Identifiant);
            //Execution de la commande
            commande.ExecuteNonQuery();

            connection.Close();
        }
Exemple #5
0
        private void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            RadioButton radioBtn = (RadioButton)sender;
            string      nom      = radioBtn.Content.ToString();

            double[] sorties = new double[_LstSorties.Count];

            for (int i = 0; i < _LstSorties.Count; i++)
            {
                sorties[i] = 0;
                if (_LstSorties.Observable[i].Nom == nom)
                {
                    sorties[i] = 1;
                }
            }

            Echantillon echantillon = new Echantillon(_LstEntrees.Doubles, sorties);

            _MaA.Apprendre(echantillon);

            NouvelEchantillon();
        }
Exemple #6
0
        //public void Create(Echantillon echantillon)
        //{
        //    if (OpenConnection())
        //    {
        //        command = manager.CreateCommand();
        //        command.CommandText = "INSERT INTO echantillon " +
        //                              "(id_produit, quantite, concentration, libelle) " +
        //                              "VALUES (@id_produit, @quantite, @concentration, @libelle)";

        //        command.Parameters.AddWithValue("@id_produit", echantillon.Produit.Id_produit);
        //        command.Parameters.AddWithValue("@quantite", echantillon.Quantite);
        //        command.Parameters.AddWithValue("@concentration", echantillon.Concentration);
        //        command.Parameters.AddWithValue("@libelle", echantillon.Libelle);


        //        command.ExecuteNonQuery();

        //        CloseConnection();
        //    }
        //}

        public Echantillon Read(int id_echantillon, bool isReadFromEchantillonDonnes)
        {
            Echantillon echantillon = new Echantillon();

            if (OpenConnection())
            {
                ProduitDAO          produitManager           = new ProduitDAO();
                EchantillonDonneDAO enchantillonDonneManager = new EchantillonDonneDAO();

                command             = manager.CreateCommand();
                command.CommandText = "SELECT * " +
                                      "FROM echantillon " +
                                      "WHERE id_echantillon = @id_echantillon";

                command.Parameters.AddWithValue("@id_echantillon", id_echantillon);

                // Lecture des résultats
                dataReader = command.ExecuteReader();

                while (dataReader.Read())
                {
                    echantillon.Id_echantillon = (int)dataReader["id_echantillon"];
                    echantillon.Produit        = produitManager.Read((int)dataReader["id_produit"], isReadFromEchantillonDonnes);
                    echantillon.Quantite       = (int)dataReader["quantite"];
                    echantillon.Concentration  = (int)dataReader["concentration"];
                    echantillon.Libelle        = (string)dataReader["libelle"];

                    if (!isReadFromEchantillonDonnes)
                    {
                        //Debug.WriteLine("   JE NE SUIS PAS LU ET C BIEN");
                        echantillon.Liste_echantillons_donnes = enchantillonDonneManager.ReadAllFromEchantillon(echantillon);
                    }
                }
                dataReader.Close();
                CloseConnection();
            }

            return(echantillon);
        }
Exemple #7
0
        private void ApprendreEchantillon(Echantillon pEchantillon)
        {
            double[] lstSortiesSouhaitees = pEchantillon.Sorties;
            double[] lstSortiesCalculees  = _Reseau.CalculerSorties(pEchantillon.Entrees);

            //for (int i = 0; i < lstSortiesCalculees.Length; i++)
            //{
            //    _ErreurTotaleEntreSorties += lstSortiesSouhaitees[i] - lstSortiesCalculees[i];
            //}

            // Algoritme de rétro-propagation de gradient
            double tauxApprentissage = _TauxApprentissage;

            //Répéter
            int iteration = 0;

            //_NbreIterations = 1;
            while (iteration < _NbreIterations)   // TODO : ajouter un critère
            {
                // Calcul des Deltas des neurones de la couche de sorties
                CalculerDeltaNeuronesCoucheSortie(lstSortiesSouhaitees, lstSortiesCalculees);

                // Calcul des Deltas des Couches cachées
                CalculerDeltaNeuronesCouchesCachees();

                // MAJ de tous les poids
                MajPoidsReseau(tauxApprentissage);

                tauxApprentissage = tauxApprentissage * 0.8;    //TODO : voir si meilleur évaluation du taux d'apprentissage

                // Recalcule des nouvelles sorties avec les nouveaux poids
                lstSortiesCalculees = _Reseau.CalculerSorties(pEchantillon.Entrees);

                iteration++;
            }
        }
Exemple #8
0
        //public void Update(Echantillon echantillon)
        //{
        //    if (OpenConnection())
        //    {
        //        command = manager.CreateCommand();
        //        command.CommandText = "UPDATE echantillon " +
        //                              "SET id_echantillon=@id_echantillon, id_produit=@id_produit, quantite=@quantite,  concentration=@concentration, libelle=@libelle " +
        //                              "WHERE echantillon.id_echantillon = @id_echantillon";

        //        command.Parameters.AddWithValue("@id_echantillon", echantillon.Id_echantillon);
        //        command.Parameters.AddWithValue("@id_produit", echantillon.Produit.Id_produit);
        //        command.Parameters.AddWithValue("@quantite", echantillon.Quantite);
        //        command.Parameters.AddWithValue("@concentration", echantillon.Concentration);
        //        command.Parameters.AddWithValue("@libelle", echantillon.Libelle);

        //        // Update ligne frais ?

        //        command.ExecuteNonQuery();
        //        CloseConnection();
        //    }
        //}

        //public void Delete(Echantillon echantillon)
        //{
        //    if (OpenConnection())
        //    {
        //        command = manager.CreateCommand();
        //        command.CommandText = "DELETE FROM echantillon " +
        //                              "WHERE id_echantillon = @id_echantillon";
        //        command.Parameters.AddWithValue("@id_echantillon", echantillon.Id_echantillon);

        //        // Delete ligne frais
        //        command.ExecuteNonQuery();
        //        CloseConnection();
        //    }
        //}

        public List <Echantillon> ReadAllFromProduit(Produit produit)
        {
            List <Echantillon> liste_echantillons = new List <Echantillon>();

            if (OpenConnection())
            {
                EchantillonDonneDAO echantillonDonneManager = new EchantillonDonneDAO();
                Echantillon         echantillon             = new Echantillon();

                command             = manager.CreateCommand();
                command.CommandText = "SELECT * " +
                                      "FROM echantillon " +
                                      "WHERE id_produit = @id_produit";

                command.Parameters.AddWithValue("@id_produit", produit.Id_produit);

                // Lecture des résultats
                dataReader = command.ExecuteReader();

                while (dataReader.Read())
                {
                    echantillon.Produit                   = produit;
                    echantillon.Id_echantillon            = (int)dataReader["id_echantillon"];
                    echantillon.Quantite                  = (int)dataReader["quantite"];
                    echantillon.Libelle                   = (string)dataReader["libelle"];
                    echantillon.Concentration             = (int)dataReader["concentration"];
                    echantillon.Liste_echantillons_donnes = echantillonDonneManager.ReadAllFromEchantillon(echantillon);

                    liste_echantillons.Add(echantillon);
                }
                dataReader.Close();
                CloseConnection();
            }

            return(liste_echantillons);
        }
Exemple #9
0
 public void Apprendre(Echantillon pEchantillon)
 {
     ApprendreEchantillon(pEchantillon);
 }
        /// <summary>
        /// Récupère une liste de Echantillon à partir de la base de données
        /// </summary>
        /// <returns>Une liste de client</returns>
        public static List<Echantillon> List()
        {
            //Récupération de la chaine de connexion
            //Connection
            ConnectionStringSettings connectionStringSettings = ConfigurationManager.ConnectionStrings["LaboSPPPConnectionString"];
            SqlConnection connection = new SqlConnection(connectionStringSettings.ToString());
            //Commande
            String requete = "SELECT Identifiant, Libelle, NumLot, DatePeinture, IdentifiantProduit FROM Echantillon";
            connection.Open();
            SqlCommand commande = new SqlCommand(requete, connection);
            //execution

            SqlDataReader dataReader = commande.ExecuteReader();

            List<Echantillon> list = new List<Echantillon>();
            while (dataReader.Read())
            {

                //1 - Créer un Echantillon à partir des donner de la ligne du dataReader
                Echantillon echantillon = new Echantillon();
                echantillon.Identifiant = dataReader.GetInt32(0);
                echantillon.NumLot = dataReader.GetString(1);
                echantillon.DatePeinture = dataReader.GetDateTime(2);
                echantillon.produit.Identifiant = dataReader.GetInt32(3);

                //2 - Ajouter ce Echantillon à la list de client
                list.Add(echantillon);
            }

            dataReader.Close();
            connection.Close();
            return list;
        }
        public static void Update(Echantillon echantillon)
        {
            SqlConnection connection = new SqlConnection();
            connection.ConnectionString = "LaboSPPPConnectionString";
            connection.Open();
            SqlCommand commande = new SqlCommand();
            commande.Connection = connection;
            string requete = "UPDATE Echantillon  SET Libelle=@Libelle  WHERE Identifiant=@Identifiant";
            commande.Parameters.AddWithValue("identifiant", echantillon.Identifiant);
            commande.Parameters.AddWithValue("Libelle", echantillon.NumLot);
            commande.Parameters.AddWithValue("DatePeinture", echantillon.DatePeinture);
            commande.Parameters.AddWithValue("IdentifiantProduit", echantillon.produit.Identifiant);

            commande.CommandText = requete;
            commande.ExecuteNonQuery();

            connection.Close();
        }