private void button1_Click(object sender, EventArgs e) { string query = textBox1.Text; string hasil_cosine = tfidfcosine(query); string[] parts1 = hasil_cosine.Split(';'); string hasilkalimat; if (parts1.Length > 1) { label2.Text = "Hasil Metode TF-IDF-COSINE Similarity 1: " + parts1[0]; hasilkalimat = parts1[0]; } else { label2.Text = "Hasil Metode TF-IDF-COSINE Similarity: " + parts1[0]; hasilkalimat = parts1[0]; } //label1.Text = tfidfcosine(query); //label1.Text = jaccard_similarity(query); //WMPLib.WindowsMediaPlayer wplayer = new WMPLib.WindowsMediaPlayer(); //if (index_jawaban == 0) //{ // wplayer.URL = "obat_minum.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 0) //{ // wplayer.URL = "obat_minum.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 1) //{ // wplayer.URL = "obat.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 2) //{ // wplayer.URL = "nonton_minum.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 3) //{ // wplayer.URL = "nonton.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 3) //{ // wplayer.URL = "remot.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 4) //{ // wplayer.URL = "mandi_minum.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 5) //{ // wplayer.URL = "sabun.mp3"; // wplayer.controls.play(); //} //if (index_jawaban == 6) //{ // wplayer.URL = "minum.mp3"; // wplayer.controls.play(); //} ///REINFORCEMENT QLearning q = new QLearning { Episodes = 1000, Alpha = 0.1, Gamma = 0.9, MaxExploreStepsWithinOneEpisode = 1000 }; var opponentStyles = new List <double[]>(); // kemungkinan model final state (opponent) //tujuan,harga,terimakasih,selamatpagi,dealing opponentStyles.Add(new[] { 0.2, 0.2, 0.2, 0.2, 0.2 }); //begin opponentStyles.Add(new[] { 0.1, 0.6, 0.1, 0.1, 0.1 }); //tujuan opponentStyles.Add(new[] { 0.1, 0.1, 0.1, 0.1, 0.6 }); //harga opponentStyles.Add(new[] { 0.1, 0.6, 0.1, 0.1, 0.1 }); //terimakasih opponentStyles.Add(new[] { 0.1, 0.1, 0.6, 0.1, 0.1 }); //selamat pagi opponentStyles.Add(new[] { 0.1, 0.1, 0.1, 0.1, 0.6 }); //dealing int index = new Random().Next(opponentStyles.Count); var opponent = opponentStyles[index]; // opponent probability pick double tujuanOpponent = opponent[0]; double hargaOpponent = opponent[1]; double terimakasihOpponent = opponent[2]; double selamatpagiOpponent = opponent[3]; double dealingOpponent = opponent[4]; QAction fromTo; QState state; string stateName; string stateNameNext; // ----------- Begin Insert the path setup here ----------- // insert the end states here q.EndStates.Add(StateNameEnum.tujuan.EnumToString()); q.EndStates.Add(StateNameEnum.harga.EnumToString()); q.EndStates.Add(StateNameEnum.terima_kasih.EnumToString()); q.EndStates.Add(StateNameEnum.selamat_pagi.EnumToString()); q.EndStates.Add(StateNameEnum.dealing.EnumToString()); // State Begin sembarang ini stateName = StateNameEnum.tujuan.EnumToString(); q.AddState(state = new QState(stateName, q)); //Console.Write("Masukkan perintah: "); //name = Console.ReadLine(); //Console.WriteLine("Perintah = {0}", name); //string testString; //Console.Write("Enter a string - "); //testString = Console.ReadLine(); //Console.WriteLine("You entered '{0}'", testString); // action Pusing //if (name == "pusing") if (hasilkalimat == "tujuan") { stateNameNext = StateNameEnum.tujuan.EnumToString(); state.AddAction(fromTo = new QAction(stateName, new QActionName(stateName, stateNameNext))); // action outcome probability //NAMA NEXT NYA fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.tujuan.EnumToString(), tujuanOpponent) { Reward = 0 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.harga.EnumToString(), hargaOpponent) { Reward = 10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.terima_kasih.EnumToString(), terimakasihOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.selamat_pagi.EnumToString(), selamatpagiOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.dealing.EnumToString(), dealingOpponent) { Reward = -10 }); q.RunTraining(); q.PrintQLearningStructure(); q.ShowPolicy(); //Console.WriteLine("\n** Opponent style **"); Console.WriteLine(string.Format("style is tujuan {0} harga {1} terimakasih {2} selamatpagi {3} dealing", opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty())); //label5.Text= string.Format("Model: Pusing {0} Panas {1} Minum {2} Mandi {3} Bosan {4} Remote {5} Obat {6}", //opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty(), opponent[5].Pretty(), opponent[6].Pretty()); double max = Double.MinValue; string actionName = "nothing"; foreach (QAction action in state.Actions) { foreach (QActionResult actionResult in action.ActionsResult) { if (actionResult.QEstimated > 0.15) { max = actionResult.QEstimated; actionName = action.ActionName.ToString(); Console.WriteLine("Jawaban= " + actionResult + "?"); label5.Text = "Jawaban= " + actionResult + "?" + "\n"; //textBox2.Text = "Apakah anda ingin " + actionResult + " ? " + "\n"; } } } ////dibukani //Console.WriteLine(string.Format("From state {0} do action {1}, max QEstimated is {2}", // state.StateName, actionName, max.Pretty())); //Console.WriteLine(string.Format("Dari State {0} melakukan aksi {1} didapatkan Estimasi Nilai Q maksimal = {2}", // state.StateName, actionName, max.Pretty())); } //// action Panas if (hasilkalimat == "harga") { stateNameNext = StateNameEnum.harga.EnumToString(); state.AddAction(fromTo = new QAction(stateName, new QActionName(stateName, stateNameNext))); // action outcome probability //NAMA NEXT NYA fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.tujuan.EnumToString(), tujuanOpponent) { Reward = 0 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.harga.EnumToString(), hargaOpponent) { Reward = 10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.terima_kasih.EnumToString(), terimakasihOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.selamat_pagi.EnumToString(), selamatpagiOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.dealing.EnumToString(), dealingOpponent) { Reward = -10 }); q.RunTraining(); q.PrintQLearningStructure(); q.ShowPolicy(); //Console.WriteLine("\n** Opponent style **"); Console.WriteLine(string.Format("style is tujuan {0} harga {1} terimakasih {2} selamatpagi {3} dealing", opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty())); //label5.Text= string.Format("Model: Pusing {0} Panas {1} Minum {2} Mandi {3} Bosan {4} Remote {5} Obat {6}", //opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty(), opponent[5].Pretty(), opponent[6].Pretty()); double max = Double.MinValue; string actionName = "nothing"; foreach (QAction action in state.Actions) { foreach (QActionResult actionResult in action.ActionsResult) { if (actionResult.QEstimated > 0.15) { max = actionResult.QEstimated; actionName = action.ActionName.ToString(); Console.WriteLine("Jawaban= " + actionResult + "?"); label5.Text = "Jawaban= " + actionResult + "?" + "\n"; //textBox2.Text = "Apakah anda ingin " + actionResult + " ? " + "\n"; } } } ////dibukani //Console.WriteLine(string.Format("From state {0} do action {1}, max QEstimated is {2}", // state.StateName, actionName, max.Pretty())); //Console.WriteLine(string.Format("Dari State {0} melakukan aksi {1} didapatkan Estimasi Nilai Q maksimal = {2}", // state.StateName, actionName, max.Pretty())); } if (hasilkalimat == "terima kasih") { stateNameNext = StateNameEnum.terima_kasih.EnumToString(); state.AddAction(fromTo = new QAction(stateName, new QActionName(stateName, stateNameNext))); // action outcome probability //NAMA NEXT NYA fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.tujuan.EnumToString(), tujuanOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.harga.EnumToString(), hargaOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.terima_kasih.EnumToString(), terimakasihOpponent) { Reward = 10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.selamat_pagi.EnumToString(), selamatpagiOpponent) { Reward = 0 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.dealing.EnumToString(), dealingOpponent) { Reward = 0 }); q.RunTraining(); q.PrintQLearningStructure(); q.ShowPolicy(); //Console.WriteLine("\n** Opponent style **"); Console.WriteLine(string.Format("style is tujuan {0} harga {1} terimakasih {2} selamatpagi {3} dealing", opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty())); //label5.Text= string.Format("Model: Pusing {0} Panas {1} Minum {2} Mandi {3} Bosan {4} Remote {5} Obat {6}", //opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty(), opponent[5].Pretty(), opponent[6].Pretty()); double max = Double.MinValue; string actionName = "nothing"; foreach (QAction action in state.Actions) { foreach (QActionResult actionResult in action.ActionsResult) { if (actionResult.QEstimated > 0.15) { max = actionResult.QEstimated; actionName = action.ActionName.ToString(); Console.WriteLine("Jawaban= " + actionResult + "?"); label5.Text = "Jawaban= " + actionResult + "?" + "\n"; //textBox2.Text = "Apakah anda ingin " + actionResult + " ? " + "\n"; } } } ////dibukani //Console.WriteLine(string.Format("From state {0} do action {1}, max QEstimated is {2}", // state.StateName, actionName, max.Pretty())); //Console.WriteLine(string.Format("Dari State {0} melakukan aksi {1} didapatkan Estimasi Nilai Q maksimal = {2}", // state.StateName, actionName, max.Pretty())); } if (hasilkalimat == "selamat pagi") { stateNameNext = StateNameEnum.selamat_pagi.EnumToString(); state.AddAction(fromTo = new QAction(stateName, new QActionName(stateName, stateNameNext))); // action outcome probability //NAMA NEXT NYA fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.tujuan.EnumToString(), tujuanOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.harga.EnumToString(), hargaOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.terima_kasih.EnumToString(), terimakasihOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.selamat_pagi.EnumToString(), selamatpagiOpponent) { Reward = 10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.dealing.EnumToString(), dealingOpponent) { Reward = -10 }); q.RunTraining(); q.PrintQLearningStructure(); q.ShowPolicy(); //Console.WriteLine("\n** Opponent style **"); Console.WriteLine(string.Format("style is tujuan {0} harga {1} terimakasih {2} selamatpagi {3} dealing", opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty())); //label5.Text= string.Format("Model: Pusing {0} Panas {1} Minum {2} Mandi {3} Bosan {4} Remote {5} Obat {6}", //opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty(), opponent[5].Pretty(), opponent[6].Pretty()); double max = Double.MinValue; string actionName = "nothing"; foreach (QAction action in state.Actions) { foreach (QActionResult actionResult in action.ActionsResult) { if (actionResult.QEstimated > 0.15) { max = actionResult.QEstimated; actionName = action.ActionName.ToString(); Console.WriteLine("Jawaban= " + actionResult + "?"); label5.Text = "Jawaban= " + actionResult + "?" + "\n"; //textBox2.Text = "Apakah anda ingin " + actionResult + " ? " + "\n"; } } } ////dibukani //Console.WriteLine(string.Format("From state {0} do action {1}, max QEstimated is {2}", // state.StateName, actionName, max.Pretty())); //Console.WriteLine(string.Format("Dari State {0} melakukan aksi {1} didapatkan Estimasi Nilai Q maksimal = {2}", // state.StateName, actionName, max.Pretty())); } // action Bosan if (hasilkalimat == "dealing") { stateNameNext = StateNameEnum.dealing.EnumToString(); state.AddAction(fromTo = new QAction(stateName, new QActionName(stateName, stateNameNext))); // action outcome probability //NAMA NEXT NYA fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.tujuan.EnumToString(), tujuanOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.harga.EnumToString(), hargaOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.terima_kasih.EnumToString(), terimakasihOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.selamat_pagi.EnumToString(), selamatpagiOpponent) { Reward = -10 }); fromTo.AddActionResult(new QActionResult(fromTo, StateNameEnum.dealing.EnumToString(), dealingOpponent) { Reward = 10 }); q.RunTraining(); q.PrintQLearningStructure(); q.ShowPolicy(); //Console.WriteLine("\n** Opponent style **"); Console.WriteLine(string.Format("style is tujuan {0} harga {1} terimakasih {2} selamatpagi {3} dealing", opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty())); //label5.Text= string.Format("Model: Pusing {0} Panas {1} Minum {2} Mandi {3} Bosan {4} Remote {5} Obat {6}", //opponent[0].Pretty(), opponent[1].Pretty(), opponent[2].Pretty(), opponent[3].Pretty(), opponent[4].Pretty(), opponent[5].Pretty(), opponent[6].Pretty()); double max = Double.MinValue; string actionName = "nothing"; foreach (QAction action in state.Actions) { foreach (QActionResult actionResult in action.ActionsResult) { if (actionResult.QEstimated > 0.15) { max = actionResult.QEstimated; actionName = action.ActionName.ToString(); Console.WriteLine("Jawaban= " + actionResult + "?"); label5.Text = "Jawaban= " + actionResult + "?" + "\n"; //textBox2.Text = "Apakah anda ingin " + actionResult + " ? " + "\n"; } } } ////dibukani //Console.WriteLine(string.Format("From state {0} do action {1}, max QEstimated is {2}", // state.StateName, actionName, max.Pretty())); //Console.WriteLine(string.Format("Dari State {0} melakukan aksi {1} didapatkan Estimasi Nilai Q maksimal = {2}", // state.StateName, actionName, max.Pretty())); } //// ----------- End Insert the path setup here ----------- }