예제 #1
0
 def update_threshold(self, funding_pool: float, token_supply: float, max_proposal_request: float):
     if self.status == ProposalStatus.CANDIDATE:
         self.trigger = trigger_threshold(
             self.funds_requested, funding_pool, token_supply, max_proposal_request)
     else:
         self.trigger = np.nan
     return self.trigger
예제 #2
0
    def su_add_to_network(params, step, sL, s, _input, **kwargs):
        network = s["network"]
        funding_pool = s["funding_pool"]
        token_supply = s["token_supply"]
        gamma_func = params["gamma_func"]
        random_number_func = params["random_number_func"]
        if _input["new_proposal"]:
            proposed_by = _input["proposed_by_participant"]
            # Create the Proposal and add it to the network.
            rescale = funding_pool * config.scale_factor
            r_rv = gamma_func(config.funds_requested_alpha,
                              loc=config.funds_requested_min,
                              scale=rescale)
            proposal = Proposal(funds_requested=r_rv,
                                trigger=trigger_threshold(
                                    r_rv, funding_pool, token_supply,
                                    params["max_proposal_request"]))
            network, proposal_idx = add_proposal(network, proposal,
                                                 proposed_by,
                                                 random_number_func)

            if params.get("debug"):
                print(
                    "GenerateNewProposal: Participant {} created Proposal {}".
                    format(_input["proposed_by_participant"], proposal_idx))
        return "network", network
예제 #3
0
def add_proposals_and_relationships_to_network(
        n: nx.DiGraph, proposals: int, funding_pool: float,
        token_supply: float) -> nx.DiGraph:
    participant_count = len(n)
    for i in range(proposals):
        j = participant_count + i
        n.add_node(j, type="proposal", conviction=0, status="candidate", age=0)

        r_rv = gamma.rvs(3, loc=0.001, scale=10000)
        n.nodes[j]['funds_requested'] = r_rv
        n.nodes[j]['trigger'] = trigger_threshold(r_rv, funding_pool,
                                                  token_supply)

        for i in range(participant_count):
            n.add_edge(i, j)
            rv = np.random.rand()
            a_rv = 1 - 4 * (1 - rv) * rv  #polarized distribution
            n.edges[(i, j)]['affinity'] = a_rv
            n.edges[(i, j)]['tokens'] = 0
            n.edges[(i, j)]['conviction'] = 0
            n.edges[(i, j)]['type'] = 'support'


# Conflict Rate is a potential variable to optimize
# Relative Influence is a potential variable to optimize
        n = initial_conflict_network(n, rate=.25)
        n = initial_social_network(n, scale=1)
    return n
예제 #4
0
    def su_add_to_network(params, step, sL, s, _input, **kwargs):
        network = s["network"]
        funding_pool = s["funding_pool"]
        token_supply = s["token_supply"]
        scale_factor = 0.01
        if _input["new_proposal"]:
            # Create the Proposal and add it to the network.
            rescale = funding_pool * scale_factor
            r_rv = gamma.rvs(3, loc=0.001, scale=rescale)
            proposal = Proposal(funds_requested=r_rv,
                                trigger=trigger_threshold(
                                    r_rv, funding_pool, token_supply,
                                    params["max_proposal_request"]))
            network, proposal_idx = add_proposal(network, proposal)

            # add_proposal() has created support edges from other Participants
            # to this Proposal. If the Participant is the one who created this
            # Proposal, change his affinity for the Proposal to 1 (maximum).
            network.edges[_input["proposed_by_participant"],
                          proposal_idx]["affinity"] = 1
            if params.get("debug"):
                print(
                    "GenerateNewProposal: Participant {} created Proposal {}".
                    format(_input["proposed_by_participant"], proposal_idx))
        return "network", network
    def su_add_to_network(params, step, sL, s, _input, **kwargs):
        network = s["network"]
        funding_pool = s["funding_pool"]
        token_supply = s["token_supply"]
        gamma_func = params["gamma_func"]
        random_number_func = params["random_number_func"]
        if _input["new_proposal"]:
            # Create the Proposal and add it to the network.
            rescale = funding_pool * config.scale_factor
            r_rv = gamma_func(config.funds_requested_alpha,
                              loc=config.funds_requested_min,
                              scale=rescale)
            proposal = Proposal(funds_requested=r_rv,
                                trigger=trigger_threshold(
                                    r_rv, funding_pool, token_supply,
                                    params["max_proposal_request"]))
            network, proposal_idx = add_proposal(network, proposal,
                                                 random_number_func)

            # add_proposal() has created support edges from other Participants
            # to this Proposal. If the Participant is the one who created this
            # Proposal, set the participant's role as author and change his affinity for the Proposal to 1 (maximum).
            network.edges[_input["proposed_by_participant"],
                            proposal_idx]["support"] = \
                                network.edges[_input["proposed_by_participant"], proposal_idx]["support"]._replace(affinity=1, is_author=True)
            if params.get("debug"):
                print(
                    "GenerateNewProposal: Participant {} created Proposal {}".
                    format(_input["proposed_by_participant"], proposal_idx))
        return "network", network
예제 #6
0
 def has_enough_conviction(self, funding_pool: float, token_supply: float, max_proposal_request):
     """
     It's just a conviction < threshold check, but we recalculate the
     trigger_threshold so that the programmer doesn't have to remember to run
     update_threshold before running this method.
     """
     if self.status == ProposalStatus.CANDIDATE:
         threshold = trigger_threshold(
             self.funds_requested, funding_pool, token_supply, max_proposal_request)
         if self.conviction < threshold:
             return False
         return True
     else:
         raise(Exception(
             "Proposal is not a Candidate Proposal and so asking it if it will pass is inappropriate"))
예제 #7
0
def bootstrap_network(n_participants: List[TokenBatch], n_proposals: int, funding_pool: float, token_supply: float, max_proposal_request: float) -> nx.DiGraph:
    """
    Convenience function that creates a network ready for simulation in
    the Python notebook in one line.
    """
    n = create_network(n_participants)

    for _ in range(n_proposals):
        idx = len(n)
        r_rv = gamma.rvs(3, loc=0.001, scale=10000)
        n.add_node(idx, item=Proposal(funds_requested=r_rv, trigger=trigger_threshold(
            r_rv, funding_pool, token_supply, max_proposal_request)))

    n = setup_support_edges(n)
    n = setup_conflict_edges(n)
    n = setup_influence_edges_bulk(n)
    return n
예제 #8
0
def bootstrap_network(n_participants: List[TokenBatch], n_proposals: int, funding_pool: float, token_supply: float, max_proposal_request: float, probability_func, random_number_func, gamma_func, exponential_func) -> nx.DiGraph:
    """
    Convenience function that creates a network ready for simulation in
    the Python notebook in one line.
    """
    n = create_network(n_participants, probability_func, random_number_func)

    for _ in range(n_proposals):
        idx = len(n)
        r_rv = gamma_func(3, loc=0.001, scale=10000)
        n.add_node(idx, item=Proposal(funds_requested=r_rv, trigger=trigger_threshold(
            r_rv, funding_pool, token_supply, max_proposal_request)))

    n = setup_support_edges(n, random_number_func)
    n = setup_conflict_edges(n, random_number_func)
    # n = setup_influence_edges_bulk(n, exponential_func)  # TODO: Disabled as these aren't being used on any model policy
    return n
예제 #9
0
    def su_add_to_network(params, step, sL, s, _input):
        network = s["network"]
        funding_pool = s["funding_pool"]
        token_supply = s["token_supply"]
        scale_factor = 0.01
        if _input["new_proposal"]:
            # Create the Proposal and add it to the network.
            rescale = funding_pool * scale_factor
            r_rv = gamma.rvs(3, loc=0.001, scale=rescale)
            proposal = Proposal(funds_requested=r_rv,
                                trigger=convictionvoting.trigger_threshold(r_rv, funding_pool, token_supply))
            network, j = add_proposal(network, proposal)

            # add_proposal() has created support edges from other Participants
            # to this Proposal. If the Participant is the one who created this
            # Proposal, change his affinity for the Proposal to 1 (maximum).
            network.edges[_input["proposed_by_participant"], j]["affinity"] = 1
        return "network", network
예제 #10
0
    def test_small_proposal_should_have_low_threshold(self):
        threshold = trigger_threshold(10, 1000, 10000000, 0.2)

        # This number is not special, just used to make sure everything stays the same
        self.assertEqual(threshold, 5540166.20498615)
예제 #11
0
 def test_small_proposal_should_have_low_threshold(self):
     threshold = trigger_threshold(10, 1000, 10000000)
     print(threshold)