async private void buttonRunLearning_Click(object sender, EventArgs e) { var total_rounds = (int)this.numericUpDownAllRounds.Value; var round_steps = (int)this.numericUpDownAllSteps.Value; var round_seed = (int)this.numericUpDownLearningSeed.Value; I_Network network = this.MyOSM.MyNetwork; I_Algo algo = this.MyOSM.MyAlgo; I_AgentSet agent_set = this.MyOSM.MyAgentSet; if (network == null || algo == null || agent_set == null) { return; } this.MyOSM.Initialize(); this.IsLearning = true; await Task.Run(() => { //var exp = new Exp_NoExperiment(total_rounds, round_steps, round_seed, this.MyOSM); //exp.Run(); this.MyOSM.RunRounds(total_rounds, round_steps, round_seed); this.MyMF.MyAnimationForm.UpdatePictureBox(); }); this.IsLearning = false; }
public void SetWeightDicList(List <I_CandidateSet> canset_list, I_Network network) { var wei_dic_list = new List <Dictionary <int, double> >(); foreach (var node in network.NodeList) { var canset = canset_list.First(_canset => _canset.NodeID == node.NodeID); var can_wei = canset.GetCanWeight(canset.SelectCanIndex); var wei_dic = new Dictionary <int, double>(); foreach (var nei_id in node.NeighborNodeIDList) { var nei = network.NodeList.First(nei_node => nei_node.NodeID == nei_id); var sur_indi_list = this.Value.Where(sur => sur.SourceNodeID == node.NodeID).ToList(); //var my_sur_indi = this.Value.First(sur => sur.SourceNodeID == node.NodeID); var my_sur_indi = sur_indi_list.First(sur => sur.TargetNodeID == nei_id); var max_sur_indi = sur_indi_list.OrderByDescending(sur => sur.CurValue).First(); var wei_value = (my_sur_indi.CurValue / max_sur_indi.CurValue) * can_wei + 0.5; wei_dic.Add(nei_id, wei_value); } wei_dic_list.Add(wei_dic); } this.WeightDic = wei_dic_list; }
public void InitializePlaySteps(I_Network network, I_AgentSet agent_set) { agent_set.InitBelief(); agent_set.InitOpinion(); agent_set.InitCounts(); this.MyPlayOneStep.Initialize(); }
public BasicAgentSetFactory(I_Network network, InfoEnum init_op, double g_sigama, double r_sigma) { this.MyNetwork = network; this.InitOpinion = init_op; this.GreenSigma = g_sigama; this.RedSigma = r_sigma; }
public void RunOneRoundWithoutPlaySteps(I_Network network, I_AgentSet agent_set, int current_round) { foreach (var agent in agent_set.AgentList) { if (agent.IsChanged) { agent.ChangedRoundList.Add(current_round); } if (agent.IsReceived) { agent.ReceiveRoundList.Add(current_round); } } this.MyOSMLog.RecordOneRound(network, agent_set, current_round); this.EstAwaRates.Run(agent_set, this.CandidateSetList, current_round); this.SlctWeiStrategies.Run(this.CandidateSetList, agent_set, current_round); var weight_list = this.CandidateSetList.Select(can => can.GetCanWeight(can.SelectCanIndex)).ToList(); agent_set.SetWeightList(weight_list); agent_set.InitBelief(); agent_set.InitOpinion(); agent_set.InitCounts(); this.MyPlayOneStep.Initialize(); }
public KK_LayoutGenerator(I_Network network) { this.MyNetwork = network; this.MyLayoutEnum = LayoutEnum.KamadaKawai; var path = Properties.Settings.Default.LayoutGeneratorPath + "kamada_kawai_layout.py"; this.GeneratePath = path; }
public void Run(I_Network network, I_AgentSet agent_set, bool env_send, InfoEnum correct, InfoEnum incorrect) { this.SendOpinion.Run(network, agent_set, env_send, correct, incorrect); var send_message_queue = this.SendOpinion.SendMessageQueue; this.ReceiveOpinion.ReceiveMessageQueue = send_message_queue; this.ReceiveOpinion.Run(network, agent_set); }
public Circular_LayoutGenerator(I_Network network) { this.MyNetwork = network; this.MyLayoutEnum = LayoutEnum.Circular; var path = Properties.Settings.Default.LayoutGeneratorPath + "circular_layout.py"; this.GeneratePath = path; }
public Shell_LayoutGenerator(I_Network network) { this.MyNetwork = network; this.MyLayoutEnum = LayoutEnum.Shell; var path = Properties.Settings.Default.LayoutGeneratorPath + "shell_layout.py"; this.GeneratePath = path; }
public FR_LayoutGenerator(I_Network network) { this.MyNetwork = network; this.MyLayoutEnum = LayoutEnum.FruchtermanReingold; var path = Properties.Settings.Default.LayoutGeneratorPath + "fruchterman_reingold_layout.py"; this.GeneratePath = path; }
public Random_LayoutGenerator(I_Network network) { this.MyNetwork = network; this.MyLayoutEnum = LayoutEnum.Random; var path = Properties.Settings.Default.LayoutGeneratorPath + "random_layout.py"; this.GeneratePath = path; }
public void Run(I_Network network, I_AgentSet agent_set, bool env_send, InfoEnum correct, InfoEnum incorrect) { this.SendMessageQueue = new Queue <I_Message>(); if (env_send) { this.SendEnvMessage(network, agent_set, correct, incorrect, this.OpinionIntroductionRate); } this.SendAgentMessage(network, agent_set); }
public void RunOneRound(I_Network network, I_AgentSet agent_set, int current_round, int round_steps) { for (int i = 0; i < round_steps; i++) { this.PlayOneStep(network, agent_set, InfoEnum.Green, InfoEnum.Red); } this.RunOneRoundWithoutPlaySteps(network, agent_set, current_round); return; }
private void buttonGenerateAgentNetwork_Click(object sender, EventArgs e) { this.MyMF.PlayStop(); I_Network network = this.MyOSM.MyNetwork; if (network == null) { return; } this.GenerateAgentWithAlgo(network); }
public SurpriseIndicatorSet(I_Network network, I_AgentSet agent_set) { this.Value = new List <I_SurpriseIndicator>(); double init_value = 0.01; foreach (var node in network.NodeList) { foreach (var nei_id in node.NeighborNodeIDList) { this.Value.Add(new SurpriseIndicator(node.NodeID, nei_id, init_value)); } } }
public List <I_CandidateSet> Generate(I_Network network, I_AgentSet agent_set) { List <I_CandidateSet> canset_list = new List <I_CandidateSet>(); I_CandidateSet canset; foreach (var node in network.NodeList) { canset = new SusceptCandidateSet(node, agent_set.AgentList[node.NodeID], this.StepSize); canset_list.Add(canset); } return(canset_list); }
void SendAgentMessage(I_Network network, I_AgentSet agent_set) { foreach (var agent in agent_set.AgentList) { if (agent.SendReadyMessageQueue.Count == 0) { continue; } while (agent.SendReadyMessageQueue.Count > 0) { var message = agent.SendReadyMessageQueue.Dequeue(); this.SendMessageQueue.Enqueue(message); } } }
public Exp_NoExperiment(int total_rounds, int round_steps, int round_seed, I_OSM osm) { this.TotalRounds = total_rounds; this.RoundSteps = round_steps; this.RoundSeed = round_seed; this.MyAlgo = osm.MyAlgo; this.MyNetwork = osm.MyNetwork; this.MyAgentSet = osm.MyAgentSet; this.ExpName = "NoExp"; var dt = DateTime.Now; this.DataName = dt.ToString("yyyy-MM-dd-HH-mm-ss"); this.BasePath = Environment.CurrentDirectory; this.OutputFolderPath = this.BasePath + "\\" + OutputLog.BaseLogFolderName + "\\" + this.ExpName + "\\" + this.DataName; OutputLog.SafeCreateDirectory(this.OutputFolderPath); }
/// <summary> /// 生成とラウンド開始時に呼び出してagentsetを初期化. /// </summary> /// <param name="network"></param> /// <param name="agent_set"></param> public void Initialize(I_Network network, I_AgentSet agent_set) { agent_set.InitBelief(); agent_set.InitOpinion(); agent_set.InitCounts(); agent_set.InitRoundInfo(); this.SurpriseIndicatorSet.Initialize(); this.MyPlayOneStep.Initialize(); this.CandidateSetList = GeneCanWeights.Generate(network, agent_set); this.SurpriseIndicatorSet.SetWeightDicList(this.CandidateSetList, network); var wei_dic_list = this.SurpriseIndicatorSet.WeightDic; agent_set.SetInitWeightDicList(wei_dic_list); }
public void Initialize(I_Network network, I_AgentSet agent_set) { agent_set.InitBelief(); agent_set.InitOpinion(); agent_set.InitCounts(); agent_set.InitRoundInfo(); this.MyPlayOneStep.Initialize(); this.CandidateSetList = GeneCanWeights.Generate(network, agent_set); var weight_list = this.CandidateSetList.Select(can => can.GetCanWeight(can.InitSelectCanIndex)).ToList(); //weight_list = weight_list.Select(w => 0.8).ToList(); agent_set.SetInitWeightList(weight_list); }
Matrix GetBaseMatrix(I_Network network, I_AgentSet agent_set) { this.SetAgentViewList(network); this.SetEdgeViewList(network, agent_set); var CentralX = this.pictureBoxAnimation.ClientSize.Width / 2; var CentralY = this.pictureBoxAnimation.ClientSize.Height / 2; this.ViewX += CentralX; this.ViewY += CentralY; var base_matrix = new Matrix(); base_matrix.Scale(this.ViewScale, this.ViewScale); base_matrix.Translate(this.ViewX, this.ViewY); return(base_matrix); }
internal void SetEdgeViewList(I_Network network, I_AgentSet agent_set) { this.EdgeViewList = new List <EdgeView>(); foreach (var edge in network.EdgeList) { Point s_point = new Point((int)this.AgentViewList[edge.SourceNodeID].X, (int)this.AgentViewList[edge.SourceNodeID].Y); Point t_point = new Point((int)this.AgentViewList[edge.TargetNodeID].X, (int)this.AgentViewList[edge.TargetNodeID].Y); Dictionary <int, double> s_wei_dic = null; Dictionary <int, double> t_wei_dic = null; if (agent_set != null) { s_wei_dic = agent_set.AgentList.First(agent => agent.NodeID == edge.SourceNodeID).WeightDic; t_wei_dic = agent_set.AgentList.First(agent => agent.NodeID == edge.TargetNodeID).WeightDic; } this.EdgeViewList.Add(new EdgeView(s_point, edge.SourceNodeID, t_point, edge.TargetNodeID, edge.EdgeID, s_wei_dic, t_wei_dic)); } }
public void RecordOneRound(I_Network network, I_AgentSet agent_set, int current_round) { int green_count = 0; int red_count = 0; int undeter_count = 0; foreach (var agent in agent_set.AgentList) { switch (agent.Opinion) { case InfoEnum.Undeter: undeter_count++; break; case InfoEnum.Green: green_count++; break; case InfoEnum.Red: red_count++; break; default: break; } } double all_count = green_count + red_count + undeter_count; var list = new List <double>(); list.Add(green_count / all_count); list.Add(red_count / all_count); list.Add(undeter_count / all_count); this.RoundResults.Rows.Add(current_round, list[0], list[1], list[2]); Console.WriteLine($"round: {current_round,3} green: {list[0]:f3} red: {list[1]:f3} undeter: {list[2]:f3}"); if (!this.IsRecordingRounds) { return; } OutputLog.OutputLogCSV(this.RoundResults, this.OutputRoundFilePath); }
internal void SetAgentViewList(I_Network network) { this.AgentViewList = new List <AgentView>(); var layout = network.MyLayout; var ori_min_x = layout.PosList.Select(pos => pos.X).Min(); var ori_max_x = layout.PosList.Select(pos => pos.X).Max(); var ori_min_y = layout.PosList.Select(pos => pos.Y).Min(); var ori_max_y = layout.PosList.Select(pos => pos.Y).Max(); var ori_width = Math.Abs(ori_max_x - ori_min_x); var ori_height = Math.Abs(ori_max_y - ori_min_y); var width_div = this.FixClientWidth() / ori_width; var height_div = this.FixClientHeight() / ori_height; width_div /= 1.1; height_div /= 1.1; var pos_scale = (int)Math.Min(width_div, height_div); foreach (var node in network.NodeList) { int x = (int)(layout.PosList[node.NodeID].X * pos_scale); int y = (int)(layout.PosList[node.NodeID].Y * pos_scale); int r = (int)(this.FixClientWidth() / Math.Pow(layout.PosList.Count, 2)); if (r == 0) { r = 1; } int w = r / 2; int d = node.NeighborNodeIDList.Count; this.AgentViewList.Add(new AgentView(x, y, r, w, node.NodeID, d, this.NodeSizeScale)); } var ave_central_x = layout.PosList.Select(pos => pos.X).Average(); var ave_central_y = layout.PosList.Select(pos => pos.Y).Average(); this.ViewX = -1 * (int)(ave_central_x * pos_scale) + this.ViewOriginX; this.ViewY = -1 * (int)(ave_central_y * pos_scale) + this.ViewOriginY; }
void SendEnvMessage(I_Network network, I_AgentSet agent_set, InfoEnum correct, InfoEnum incorrect, double op_intro_rate) { this.OpinionIntroCounts++; if (this.OpinionIntroCounts < this.OpinionIntroductionDuration) { return; } this.OpinionIntroCounts = 0; this.EnvOpinionCounts++; var correct_opinion = correct; var incorrect_opinion = incorrect; foreach (var agent in agent_set.AgentList) { if (!(agent.IsSensor)) { continue; } if (RandomPool.Get(SeedEnum.PlayStepSeed).NextDouble() > op_intro_rate) { continue; } var env_info = InfoEnum.Undeter; if (RandomPool.Get(SeedEnum.PlayStepSeed).NextDouble() < agent.SensorAccuracy) { env_info = correct_opinion; } else { env_info = incorrect_opinion; } this.SendMessageQueue.Enqueue(new Message(-1, agent.NodeID, env_info)); } }
async void GenerateAgentWithAlgo(I_Network network) { InfoEnum init_op = (InfoEnum)Enum.Parse(typeof(InfoEnum), this.comboBoxInitOpinion.Text, true); int agent_seed = (int)this.numericUpDownAgentSeed.Value; double g_sigma = (double)this.numericUpDownGreenSigma.Value; double r_sigma = (double)this.numericUpDownRedSigma.Value; int sensor_num = (int)this.numericUpDownSensorNum.Value; double sensor_rate = (double)this.numericUpDownSensorRate.Value; double sensor_acc = (double)this.numericUpDownSensorAccuracy.Value; double op_intro_rate = (double)this.numericUpDownOpinionIntroRate.Value; int op_intro_duration = (int)this.numericUpDownOpinionIntroDuration.Value; var t_awa_rate = (double)this.numericUpDownTargetH.Value; I_AgentSet agent_set = new BasicAgentSetFactory(network, init_op, g_sigma, r_sigma).Generate(agent_seed, AgentInitMode.Normal); I_Algo algo = null; //agent if (this.checkBoxSensorRateEnabled.Checked) { var s_num = (int)Math.Floor(network.NodeList.Count * sensor_rate); agent_set.SetSensors(s_num, sensor_acc); } else { agent_set.SetSensors(sensor_num, sensor_acc); } this.MyOSM.MyAgentSet = agent_set; //algo if (this.radioButtonAAT.Checked) { switch ((AlgoEnum)Enum.Parse(typeof(AlgoEnum), this.comboBoxAAT.Text, true)) { case AlgoEnum.OriginalAAT: var gcw = new GeneratingCanWeights(); var ear = new EstimatingAwaRates(); var sws = new SelectingWeiStrategies(t_awa_rate); var pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion()); algo = new AAT_Algo(AlgoEnum.OriginalAAT, gcw, ear, sws, pos); break; case AlgoEnum.HCII_AATD: var hcii_aatd_gcw = new GeneratingCanWeights(); var hcii_aatd_ear = new HCII_AATD_EstimatingAwaRates(); var hcii_sws = new SelectingWeiStrategies(t_awa_rate); var hcii_aatd_pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion()); algo = new AAT_Algo(AlgoEnum.HCII_AATD, hcii_aatd_gcw, hcii_aatd_ear, hcii_sws, hcii_aatd_pos); break; case AlgoEnum.AATD: var aatd_gcw = new GeneratingCanWeights(); var aatd_ear = new AATD_EstimatingAwaRates(); var aatd_sws = new AATD_SelectingWeiStrategies(t_awa_rate, 2, agent_set.AgentList.Count); var aatd_pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion()); algo = new AAT_Algo(AlgoEnum.AATD, aatd_gcw, aatd_ear, aatd_sws, aatd_pos); break; case AlgoEnum.AATD_NoTargetH: var aatd_noth_gcw = new GeneratingCanWeights(); var aatd_noth_ear = new AATD_EstimatingAwaRates(); var aatd_noth_sws = new AATD_SelectingWeiStrategies(1.0, 2, agent_set.AgentList.Count); var aatd_noth_pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new ReceiveOpinion()); algo = new AAT_Algo(AlgoEnum.AATD, aatd_noth_gcw, aatd_noth_ear, aatd_noth_sws, aatd_noth_pos); break; case AlgoEnum.IWT: var iwt_gcw = new GeneratingCanSusceptWeight(); var iwt_ear = new IWT_EstimatingAwaRates(); var iwt_sws = new SelectingWeiStrategies(t_awa_rate); var sur_indi_set = new SurpriseIndicatorSet(network, agent_set); var iwt_pos = new PlayOneStep(new SendOpinion(op_intro_rate, op_intro_duration), new IWT_ReceiveOpinion(sur_indi_set)); algo = new IWT_Algo(AlgoEnum.IWT, iwt_gcw, iwt_ear, iwt_sws, iwt_pos, sur_indi_set); break; } } this.MyOSM.MyAlgo = algo; this.IsGeneratingAgentNetwork = true; await Task.Run(() => { this.MyOSM.Initialize(); this.MyAF.UpdatePictureBox(); }); this.IsGeneratingAgentNetwork = false; }
public void PlayOneStep(I_Network network, I_AgentSet agent_set, InfoEnum correct, InfoEnum incorrect) { this.MyPlayOneStep.Run(network, agent_set, true, correct, incorrect); }
public void InitializeRunRounds(I_Network network, I_AgentSet agent_set) { this.Initialize(network, agent_set); }
public void Run(I_Network network, I_AgentSet agent_set) { if (this.ReceiveMessageQueue.Count == 0) { return; } while (this.ReceiveMessageQueue.Count > 0) { var message = this.ReceiveMessageQueue.Dequeue(); var target_agent = agent_set.AgentList.First(agent => agent.NodeID == message.TargetNodeID); var pre_opinion = target_agent.Opinion; var pre_belief = target_agent.Belief; double wei = 0; I_SurpriseIndicator sur_indi = null; if (message.SourceNodeID < 0) { wei = target_agent.SensorAccuracy; } else { sur_indi = this.SurpriseIndicatorSet.Value.Where(indi => indi.SourceNodeID == message.TargetNodeID).First(indi => indi.TargetNodeID == message.SourceNodeID); wei = target_agent.WeightDic.First(dic => dic.Key == message.SourceNodeID).Value; } var message_op = message.MessageOpinion; //belief update if (target_agent.IsSensor) { target_agent.Belief = OpinionBeliefUpdater.UpdateBelief(pre_belief, target_agent.SensorAccuracy, message_op); } else { target_agent.Belief = OpinionBeliefUpdater.UpdateBelief(pre_belief, wei, message_op); } if (message.SourceNodeID >= 0) { sur_indi.InputOpinion(message_op, target_agent.Belief); } if (message_op == InfoEnum.Green) { target_agent.ReceiveGreenCounts++; } if (message_op == InfoEnum.Red) { target_agent.ReceiveRedCounts++; } target_agent.IsReceived = (target_agent.InitBelief != target_agent.Belief) ? true : false; //opinion update target_agent.Opinion = OpinionBeliefUpdater.UpdateOpinion(pre_opinion, target_agent.Belief, target_agent.GreenSigma, target_agent.RedSigma); target_agent.IsChanged = (target_agent.InitOpinion != target_agent.Opinion) ? true : false; var op_change = (pre_opinion != target_agent.Opinion) ? true : false; //send message if (op_change) { var neighbor_id_list = network.NodeList[target_agent.NodeID].NeighborNodeIDList; foreach (var nei_id in neighbor_id_list) { var new_message = new Message(target_agent.NodeID, nei_id, target_agent.Opinion); target_agent.SendReadyMessageQueue.Enqueue(new_message); } } } }