def detect(self):
        self.__generate_random_routes()

        num_honests = len(self.honests_truth)
        route_len = int(
         self.route_len_scaler * math.sqrt(num_honests) *\
          math.log10(num_honests)
        )
        walks = self.__walk_random_routes(route_len)

        verified_honests = self.__accept_honests_from_verifiers(walks)
        self._vote_honests_predicted(verified_honests)

        return sypy.Results(self)
Example #2
0
    def detect(self):
        structure = self.network.graph.structure.copy()

        self.dendogram.add_node(structure)
        self.__construct_dendogram(structure, 1)

        sub_structures = self.dendogram.nodes()
        sub_structures.remove(structure)

        communities = []
        for sub_structure in sub_structures:
            communities.append(sub_structure.nodes())

        self._vote_honests_predicted(communities)
        return sypy.Results(detector=self)
Example #3
0
    def detect(self):

        network_trust = self.__initialize_graph()

        while self.num_iterations != 0:
            network_trust = self.__propagate_network_trust(network_trust)
            self.num_iterations = self.num_iterations - 1

        ranked_trust = self.__rank_network(network_trust)

        #TODO figure out what pivot does
        pivot_mark = (int)(self.pivot * len(ranked_trust))
        verified_honests = [
            honest_node for honest_node, trust in ranked_trust[pivot_mark:]
        ]

        self._vote_honests_predicted([verified_honests])
        return sypy.Results(self)
Example #4
0
    def detect(self):
        num_iterations = math.log10(
            self.network.graph.order()) * self.num_iterations_scaler
        num_iterations = (int)(math.ceil(num_iterations))

        network_trust = self.__initialize_network_trust()

        while num_iterations != 0:
            network_trust = self.__propagate_network_trust(network_trust)
            num_iterations = num_iterations - 1

        ranked_trust = self.__normalize_and_rank_network_trust(network_trust)

        pivot_mark = (int)(self.pivot * len(ranked_trust))
        verified_honests = [
            honest_node for honest_node, trust in ranked_trust[pivot_mark:]
        ]
        self._vote_honests_predicted([verified_honests])

        return sypy.Results(self)
Example #5
0
    def detect(self):
        num_edges = self.network.left_region.graph.size()
        num_instances = int(self.num_instances_scaler * math.sqrt(num_edges))

        region_stats = self.network.left_region.get_region_stats()

        (lower_mtime, upper_mtime) = region_stats.mixing_time()
        route_len = int(self.route_len_scaler * math.ceil(upper_mtime))

        self.__generate_secure_random_routes(num_instances)
        suspects_tails = self.__walk_secure_random_routes(route_len,
                                                          num_instances,
                                                          verify=False)

        self.__generate_secure_random_routes(num_instances)
        verifiers_tails = self.__walk_secure_random_routes(
            route_len, num_instances)

        verified_honests = self.__accept_honests_from_verifiers(
            suspects_tails, verifiers_tails, num_instances)
        self._vote_honests_predicted(verified_honests)

        return sypy.Results(self)
Example #6
0
    def detect(self):
        bcc = nx.biconnected_components(self.network.graph.structure)

        self._vote_honests_predicted(bcc)
        return sypy.Results(detector=self)
Example #7
0
    def detect(self):
        self.__grow_community()
        community = self.honests_graph.nodes()

        self._vote_honests_predicted([community])
        return sypy.Results(detector=self)
Example #8
0
    def runDetectionAlgorithms(nodes_val,
                               id_to_edges,
                               active_detectors=all_detectors):
        """ Takes in the data from a location validation procedure and executes 
		the default detection algorithms on it (unless overridden). Returns three
		dicts, each indexed by the active detector labels. These three dicts are of 
		SyPy.Result objects (confusion matricies), of node_id to predicted node type,
		and of node_id to node p-value (only available for Simple and Iterative). """
        D_SIMP = SybilDetection.D_SIMP
        D_ITER = SybilDetection.D_ITER
        D_PRED = SybilDetection.D_PRED
        D_RANK = SybilDetection.D_RANK
        D_SIMP_P = SybilDetection.D_SIMP_P
        D_ITER_P = SybilDetection.D_ITER_P
        D_LHCO = SybilDetection.D_LHCO
        results = {}

        val_all_ids = {node.id for node in nodes_val}
        val_syb_ids = {node.id for node in nodes_val if node.type == "syb"}
        val_mal_ids = {node.id for node in nodes_val if node.type == "mal"}
        val_syb_fraction = len(val_syb_ids) / len(nodes_val)
        network = SybilDetection.__createSyPyNetwork__(nodes_val, id_to_edges)
        dist_prob_fun = None

        id_to_node = {node.id: node for node in nodes_val}

        if D_SIMP in active_detectors:
            det_results = {}
            pred_syb_ids, pvals = GraphAnalysis.simpleSybilDetection(
                nodes_val, id_to_edges)
            sypy_results = sypy.Results(val_node_ids=val_all_ids,
                                        true_syb_ids=val_syb_ids,
                                        true_mal_ids=val_mal_ids,
                                        pred_syb_ids=pred_syb_ids)
            det_results["res_sypy"] = sypy_results
            det_results["res_string"] = SybilDetection.__genResultString__(
                sypy_results)
            det_results["id_to_pval"] = pvals
            det_results["id_to_type"] = {
                node_id: ("sybil" if node_id in sypy_results.pred_syb_ids else
                          "non-sybil")
                for node_id in val_all_ids
            }
            det_results["init_syb_ids"] = sypy_results.initial_sybils
            results[D_SIMP] = det_results

        if D_ITER in active_detectors:
            det_results = {}
            pred_syb_ids, pvals = GraphAnalysis.iterativeSybilDetection(
                nodes_val, id_to_edges)
            sypy_results = sypy.Results(val_node_ids=val_all_ids,
                                        true_syb_ids=val_syb_ids,
                                        true_mal_ids=val_mal_ids,
                                        pred_syb_ids=pred_syb_ids)
            det_results["res_sypy"] = sypy_results
            det_results["res_string"] = SybilDetection.__genResultString__(
                sypy_results)
            det_results["id_to_pval"] = pvals
            det_results["id_to_type"] = {
                node_id: ("sybil" if node_id in sypy_results.pred_syb_ids else
                          "non-sybil")
                for node_id in val_all_ids
            }
            det_results["init_syb_ids"] = sypy_results.initial_sybils
            results[D_ITER] = det_results

        if D_PRED in active_detectors:
            det_results = {}
            sypy_results = sypy.SybilPredictDetector(
                network, pivot=val_syb_fraction).detect()
            det_results["res_sypy"] = sypy_results
            det_results["res_string"] = SybilDetection.__genResultString__(
                sypy_results)
            det_results["id_to_pval"] = {}
            det_results["id_to_type"] = {
                node_id: ("sybil" if node_id in sypy_results.pred_syb_ids else
                          "non-sybil")
                for node_id in val_all_ids
            }
            det_results["init_syb_ids"] = sypy_results.initial_sybils
            results[D_PRED] = det_results

        if D_RANK in active_detectors:
            det_results = {}
            sypy_results = sypy.SybilRankDetector(
                network, pivot=val_syb_fraction).detect()
            det_results["res_sypy"] = sypy_results
            det_results["res_string"] = SybilDetection.__genResultString__(
                sypy_results)
            det_results["id_to_pval"] = {}
            det_results["id_to_type"] = {
                node_id: ("sybil" if node_id in sypy_results.pred_syb_ids else
                          "non-sybil")
                for node_id in val_all_ids
            }
            det_results["init_syb_ids"] = sypy_results.initial_sybils
            results[D_RANK] = det_results

        if D_SIMP_P in active_detectors:
            det_results = {}
            if dist_prob_fun == None:
                X, Ys, Y_RANSAC = GraphAnalysis.calcGlobalPDF(
                    id_to_node, id_to_edges)
                dist_prob_fun = lambda dist: np.interp(
                    dist, X, Y_RANSAC, left=0.95, right=0.05)
            pred_syb_ids, pvals = GraphAnalysis.simpleSybilDetection(
                nodes_val, id_to_edges, dist_prob_fun=dist_prob_fun)
            sypy_results = sypy.Results(val_node_ids=val_all_ids,
                                        true_syb_ids=val_syb_ids,
                                        true_mal_ids=val_mal_ids,
                                        pred_syb_ids=pred_syb_ids)
            det_results["res_sypy"] = sypy_results
            det_results["res_string"] = SybilDetection.__genResultString__(
                sypy_results)
            det_results["id_to_pval"] = pvals
            det_results["id_to_type"] = {
                node_id: ("sybil" if node_id in sypy_results.pred_syb_ids else
                          "non-sybil")
                for node_id in val_all_ids
            }
            det_results["init_syb_ids"] = sypy_results.initial_sybils
            results[D_SIMP_P] = det_results

        if D_ITER_P in active_detectors:
            det_results = {}
            if dist_prob_fun == None:
                X, Ys, Y_RANSAC = GraphAnalysis.calcGlobalPDF(
                    id_to_node, id_to_edges)
                dist_prob_fun = lambda dist: np.interp(
                    dist, X, Y_RANSAC, left=0.95, right=0.05)
            pred_syb_ids, pvals = GraphAnalysis.iterativeSybilDetection(
                nodes_val, id_to_edges, dist_prob_fun=dist_prob_fun)
            sypy_results = sypy.Results(val_node_ids=val_all_ids,
                                        true_syb_ids=val_syb_ids,
                                        true_mal_ids=val_mal_ids,
                                        pred_syb_ids=pred_syb_ids)
            det_results["res_sypy"] = sypy_results
            det_results["res_string"] = SybilDetection.__genResultString__(
                sypy_results)
            det_results["id_to_pval"] = pvals
            det_results["id_to_type"] = {
                node_id: ("sybil" if node_id in sypy_results.pred_syb_ids else
                          "non-sybil")
                for node_id in val_all_ids
            }
            det_results["init_syb_ids"] = sypy_results.initial_sybils
            results[D_ITER_P] = det_results

        if D_LHCO in active_detectors:
            det_results = {}
            pred_syb_ids = GraphAnalysis.likelihoodSybilDetection(
                nodes_val, id_to_edges)
            sypy_results = sypy.Results(val_node_ids=val_all_ids,
                                        true_syb_ids=val_syb_ids,
                                        true_mal_ids=val_mal_ids,
                                        pred_syb_ids=pred_syb_ids)
            det_results["res_sypy"] = sypy_results
            det_results["res_string"] = SybilDetection.__genResultString__(
                sypy_results)
            det_results["id_to_pval"] = {}
            det_results["id_to_type"] = {
                node_id: ("sybil" if node_id in sypy_results.pred_syb_ids else
                          "non-sybil")
                for node_id in val_all_ids
            }
            det_results["init_syb_ids"] = sypy_results.initial_sybils
            results[D_LHCO] = det_results

        return results