Esempio n. 1
0
        public OSMSetting(ExperimentType experiment_type)
        {
            common_weight         = 0.5;
            common_curiocity      = 0.5;
            dist_weight           = 0.5;
            malicious_dist_weight = 0; //0.8
            //int malicious_sensor_size = (int)(0.04 * agent_size);
            sample_size   = 1;
            change_round  = 0;
            dim           = 2;
            correct_dim   = 0;
            malicious_dim = 1;
            switch (experiment_type)
            {
            case ExperimentType.OSM_LFR_Bad_Each_Exponential:
                agent_size    = 100;
                algo          = AlgoEnum.OSMonly;
                targeth       = 0.9;
                sensor_weight = 0.8;     //0.8

                malicious_sensor_size = 0;
                op_form_threshold     = 0.9;

                bad_sensor_mode          = true;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Exponential;
                belief_update            = BeliefUpdateFunctionEnum.Bayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.OSM_LFR_Bad_Each_Shitei_SameOpinionBayse:
                agent_size    = 100;
                algo          = AlgoEnum.OSMonly;
                targeth       = 0.9;
                sensor_weight = 0.8;     //0.8

                malicious_sensor_size = 0;
                op_form_threshold     = 0.9;

                bad_sensor_mode          = true;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Shitei;
                belief_update            = BeliefUpdateFunctionEnum.SameOpinionAdjustBayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.OSM_LFR_Normal_Each_Exponential:
                agent_size        = 100;
                algo              = AlgoEnum.OSMonly;
                targeth           = 0.9;
                sensor_weight     = 0.8; //0.8
                op_form_threshold = 0.9;

                bad_sensor_mode          = true;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Exponential;
                belief_update            = BeliefUpdateFunctionEnum.Bayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.AAT_LFR_Bad_Each_Shitei:
                agent_size    = 100;
                algo          = AlgoEnum.AAT;
                targeth       = 0.9;
                sensor_weight = 0.55;     //0.8

                op_form_threshold = 0.9;
                sample_size       = 1;
                change_round      = 0;

                bad_sensor_mode          = true;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Shitei;
                belief_update            = BeliefUpdateFunctionEnum.Bayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.AAT_LFR_Bad_Each_Exponential:
                agent_size = 100;

                algo              = AlgoEnum.AAT;
                targeth           = 0.9;
                sensor_weight     = 0.8; //0.8
                op_form_threshold = 0.9;

                bad_sensor_mode          = true;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Exponential;
                belief_update            = BeliefUpdateFunctionEnum.Bayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.AAT_LFR_Bad_Each_Exponential_SameOpinionBayse:
                agent_size = 100;

                algo              = AlgoEnum.AAT;
                targeth           = 0.7;
                sensor_weight     = 0.8; //0.8
                op_form_threshold = 0.9;

                bad_sensor_mode          = true;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Exponential;
                belief_update            = BeliefUpdateFunctionEnum.SameOpinionAdjustBayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.AAT_LFR_Bad_Each_Shitei_SameOpinionBayse:
                agent_size = 100;

                algo              = AlgoEnum.AAT;
                targeth           = 0.8;
                sensor_weight     = 0.8; //0.8
                op_form_threshold = 0.9;

                bad_sensor_mode          = true;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Exponential;
                belief_update            = BeliefUpdateFunctionEnum.SameOpinionAdjustBayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.AAT_LFR_Normal_Each_Shitei:
                agent_size        = 100;
                algo              = AlgoEnum.AAT;
                targeth           = 0.9;
                sensor_weight     = 0.55; //0.8
                op_form_threshold = 0.8;

                bad_sensor_mode          = false;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Shitei;
                belief_update            = BeliefUpdateFunctionEnum.Bayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.AAT_LFR_Normal_Each_Exponential:
                agent_size = 100;
                algo       = AlgoEnum.AAT;
                targeth    = 0.9;

                sensor_weight     = 0.8; //0.8
                op_form_threshold = 0.9;

                bad_sensor_mode          = false;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Each;
                env_distribution         = EnvDistributionEnum.Exponential;
                belief_update            = BeliefUpdateFunctionEnum.Bayse;
                add_share_only_community = false;

                select_graph = GraphEnum.LFR;
                break;

            case ExperimentType.AAT_SW_Normal_Random_Exponential:
                agent_size = 100;

                algo    = AlgoEnum.AAT;
                targeth = 0.9;

                sensor_weight     = 0.8; //0.8
                op_form_threshold = 0.9;


                bad_sensor_mode          = false;
                opinion_share_num        = 1;
                sensor_arrange           = SensorArrangementEnum.Random;
                env_distribution         = EnvDistributionEnum.Exponential;
                belief_update            = BeliefUpdateFunctionEnum.Bayse;
                add_share_only_community = false;

                select_graph = GraphEnum.Grid2D;
                break;
            }
            sensor_size = (int)(0.05 * agent_size);
        }
Esempio n. 2
0
        void Test()
        {
            this.osm_setting = new OSMSetting(ExperimentType.AAT_SW_Normal_Random_Exponential);
            int      agent_size            = osm_setting.agent_size;
            int      dim                   = osm_setting.dim;
            int      correct_dim           = osm_setting.correct_dim;
            int      malicious_dim         = osm_setting.malicious_dim;
            AlgoEnum algo                  = osm_setting.algo;
            double   targeth               = osm_setting.targeth;
            double   common_weight         = osm_setting.common_weight;
            double   common_curiocity      = osm_setting.common_curiocity;
            double   sensor_weight         = osm_setting.sensor_weight;
            double   dist_weight           = osm_setting.dist_weight;
            double   malicious_dist_weight = osm_setting.malicious_dist_weight;
            int      sensor_size           = osm_setting.sensor_size;
            //int malicious_sensor_size = (int)(0.04 * agent_size);
            int malicious_sensor_size = osm_setting.malicious_sensor_size;
            var op_form_threshold     = osm_setting.op_form_threshold;
            int sample_size           = osm_setting.sample_size;
            int change_round          = osm_setting.change_round;

            bool bad_sensor_mode             = osm_setting.bad_sensor_mode;
            int  opinion_share_num           = osm_setting.opinion_share_num;
            bool is_add_share_only_community = osm_setting.add_share_only_community;

            EnvDistributionEnum      env_distribution = osm_setting.env_distribution;
            BeliefUpdateFunctionEnum belief_update    = osm_setting.belief_update;

            var belief_updater = new BeliefUpdater(belief_update).SetSensorWeightMode(SensorWeightEnum.DependSensorRate);

            GraphGeneratorBase graph_generator;

            switch (osm_setting.select_graph)
            {
            case GraphEnum.WS:
                graph_generator = new WS_GraphGenerator().SetNodeSize(agent_size).SetNearestNeighbors(6).SetRewireP(0.01);
                break;

            //case GraphEnum.PowerLawCluster:
            //graph_generator = new PC_GraphGenerator().SetNodeSize(500).SetRandomEdges(3).SetAddTriangleP(0.1);
            // break;
            case GraphEnum.BA:
                graph_generator = new BA_GraphGenerator().SetNodeSize(agent_size).SetAttachEdges(2);
                break;

            case GraphEnum.Grid2D:
                graph_generator = new Grid2D_GraphGenerator().SetNodeSize(agent_size);
                break;

            //case GraphEnum.ER:
            //graph_generator = new ER_GraphGenerator().SetNodeSize(agent_size).SetEdgeCreateP(0.01);
            //break;
            case GraphEnum.LFR:
                graph_generator = new LFR_GraphGenerator().SetNodeSize(agent_size);
                break;

            default:
                graph_generator = new LFR_GraphGenerator().SetNodeSize(agent_size);
                break;
            }
            graph_generator.SetOsmSetting(osm_setting);
            var pb     = new ExtendProgressBar(100);
            var graph  = graph_generator.Generate(0, pb);
            var layout = new KamadaKawai_LayoutGenerator(graph).Generate(pb);
            //var layout = new Circular_LayoutGenerator(graph).Generate();

            //LFRの時のみ
            List <List <int> > communityList = new List <List <int> >();

            if (osm_setting.select_graph == GraphEnum.LFR)
            {
                communityList = graph_generator.GetCommunity();
            }
            var init_belief_gene = new InitBeliefGenerator()
                                   .SetInitBeliefMode(mode: InitBeliefMode.NormalNarrow);
            //.SetInitBeliefMode(mode: InitBeliefMode.NormalWide);

            var subject_test = new OpinionSubject("test", dim);

            var sample_agent_test = new SampleAgent()
                                    .SetInitBeliefGene(init_belief_gene)
                                    .SetThreshold(op_form_threshold)
                                    .SetSubject(subject_test)
                                    .SetInitOpinion(Vector <double> .Build.Dense(dim, 0.0));

            var sensor_gene = new SensorGenerator()
                              //                .SetSensorSize((int)5);
                              .SetSensorSize(sensor_size, malicious_sensor_size);

            int agent_gene_seed = 11;//4
            var agent_gene_rand = new ExtendRandom(agent_gene_seed);


            var agent_network = new AgentNetwork()
                                .SetRand(agent_gene_rand)
                                .GenerateNetworkFrame(graph)
                                //.ApplySampleAgent(sample_agent_1, mode: SampleAgentSetMode.RandomSetRate, random_set_rate: 0.5)
                                //.ApplySampleAgent(sample_agent_2, mode: SampleAgentSetMode.RemainSet)
                                .ApplySampleAgent(sample_agent_test, mode: SampleAgentSetMode.RemainSet)
                                .SetBadSensorMode(osm_setting.bad_sensor_mode)
                                .SetSensorArrange(osm_setting.sensor_arrange)
                                .SetCommnityList(communityList)
                                .GenerateSensor(sensor_gene)
                                .SetLayout(layout);
            var bad_community_index = agent_network.GetBadCommunityIndex();

            int update_step_seed = 1;
            var update_step_rand = new ExtendRandom(update_step_seed);

            OSMBase osm = new OSM_Only();

            switch (algo)
            {
            case AlgoEnum.AAT:
                var osm_aat = new AAT_OSM();
                osm_aat.SetTargetH(targeth);
                osm = osm_aat;
                break;

            default:
                break;
            }
            osm.SetRand(update_step_rand);
            osm.SetAgentNetwork(agent_network, opinion_share_num);
            var subject_mgr_dic = new Dictionary <int, SubjectManager>();

            subject_mgr_dic.Add(0, new SubjectManagerGenerator()
                                .Generate(subject_test, dist_weight, correct_dim, sensor_weight, env_distribution, malicious_dim, malicious_dist_weight));
            //for (int i = 0; i < 1; i++)
            //{
            //  subject_mgr_dic.Add(i * change_round, new SubjectManagerGenerator().Generate(subject_test, dist_weight, i % dim, sensor_rate, EnvDistributionEnum.Turara));
            //}
            osm.SetSubjectManagerDic(subject_mgr_dic);
            osm.SetInitWeightsMode(mode: CalcWeightMode.FavorMyOpinion);
            osm.SetOpinionIntroInterval(osm_setting.op_intro_interval);
            osm.SetOpinionIntroRate(osm_setting.op_intro_rate);
            //osm.SetSensorCommonWeight(0.70);
            osm.SetBeliefUpdater(belief_updater);
            osm.SetAddShareCommunityOnly(is_add_share_only_community);

            osm.SetStopRound(osm_setting.stop_rounds);

            this.MyOSM = osm;
            this.MyAnimationForm.RegistOSM(osm, osm_setting.opinion_share_num, communityList, bad_community_index);
        }
Esempio n. 3
0
        public SubjectManager Generate(OpinionSubject opinion_subject, double dist_weight, int correct_dim, double sensor_weight, EnvDistributionEnum env_dis_mode, int malicious_dim = 0, double malicious_dist_weight = 0.0)
        {
            CustomDistribution env_dist           = null;
            CustomDistribution env_malicious_dist = null;

            switch (env_dis_mode)
            {
            case EnvDistributionEnum.Turara:
                env_dist = new Turara_DistGenerator(opinion_subject.SubjectDimSize, dist_weight, correct_dim).Generate();                           //maxとotherを計算して返す
                    env_malicious_dist = new Turara_DistGenerator(opinion_subject.SubjectDimSize, malicious_dist_weight, malicious_dim).Generate(); //同上
                break;

            case EnvDistributionEnum.Exponential:
                env_dist           = new Exponential_DistGenerator(opinion_subject.SubjectDimSize, dist_weight, correct_dim).Generate();
                env_malicious_dist = new Exponential_DistGenerator(opinion_subject.SubjectDimSize, malicious_dist_weight, malicious_dim).Generate();
                break;

            case EnvDistributionEnum.Shitei:
                env_dist           = new Shitei_DistGenerator(opinion_subject.SubjectDimSize, dist_weight, correct_dim).Generate();
                env_malicious_dist = new Shitei_DistGenerator(opinion_subject.SubjectDimSize, malicious_dist_weight, malicious_dim).Generate();
                break;
            }
            Debug.Assert(env_dist != null); //計算できてなかったらエラー
            Debug.Assert(env_malicious_dist != null);

            var subject_tv      = new OpinionSubject("good_tv", 3);
            var subject_test    = new OpinionSubject("test", opinion_subject.SubjectDimSize);
            var subject_company = new OpinionSubject("good_company", 2);

            double[] conv_array  = { 1, 0, 0, 1, 1, 0 };
            var      conv_matrix = Matrix <double> .Build.DenseOfColumnMajor(2, 3, conv_array); //2*3の形にリシェイプ

            var osm_env = new OpinionEnvironment()
                          .SetSubject(subject_test)
                          .SetCorrectDim(correct_dim)     //正しい次元
                          .SetMaliciousDim(malicious_dim) //間違った次元
                          .SetSensorWeight(sensor_weight) //センサウェイト
                          .SetCustomDistribution(env_dist)
                          .SetMaliciousCustomDistribution(env_malicious_dist);


            var subject_manager = new SubjectManager()                                              //サブジェクトマネージャー生成
                                  .AddSubject(subject_test)
                                  .RegistConversionMatrix(subject_tv, subject_company, conv_matrix) //オピニオンにサブジェクトマネージャーを登録.サブジェクトマネージャーに意見交換クラスとしてこれらの情報を登録
                                  .SetEnvironment(osm_env);                                         //環境をセット

            return(subject_manager);
        }