示例#1
0
    def __init__(self, time, score=None, biasPass=0):
        IRRELEVANT = 0
        ONLY_NON_DISCRIMINATORY = 1
        ONLY_DISCRIMINATORY = 2

        # Probabilistically finds the score: less likely to get large
        # magnitudes of scores
        if not score:
            for case in switch(biasPass):
                if case(IRRELEVANT):
                    self.score = int(np.random.normal(0, 3))
                    while (self.score == 0 or self.score > 5
                           or self.score < -5):
                        self.score = int(np.random.normal(0, 3))
                    break

                if case(ONLY_NON_DISCRIMINATORY):
                    self.score = int(np.random.normal(2.5, 1.5))
                    while (self.score <= 0 or self.score > 5):
                        self.score = int(np.random.normal(2.5, 1.5))
                    break

                if case(ONLY_DISCRIMINATORY):
                    self.score = int(np.random.normal(-2.5, 1.5))
                    while (self.score >= 0 or self.score < -5):
                        self.score = int(np.random.normal(-2.5, 1.5))
                    break

                if case():
                    sys.stderr.write("Invalid value for bias")
                    return False

        else:
            self.score = score

        # If bill has score < 0: hurts LGB sentiments
        self.isDiscriminatory = (self.score < 0)
        self.isPassed = False

        # Used to account for the time delay of the policy effect
        self.passTime = time
        self.prevEffect = 0
        self.curEffect = 0

        if not self.Policy_verifyPolicy(self.score, self.isPassed,
                                        self.passTime):
            return None
示例#2
0
    def __init__(self, time, score=None, biasPass=0):
        IRRELEVANT = 0
        ONLY_NON_DISCRIMINATORY = 1
        ONLY_DISCRIMINATORY = 2

        # Probabilistically finds the score: less likely to get large
        # magnitudes of scores
        if not score:
            for case in switch(biasPass):
                if case(IRRELEVANT):
                    self.score = int(np.random.normal(0, 3))
                    while (self.score == 0 or self.score > 5 or
                        self.score < -5):
                        self.score = int(np.random.normal(0, 3))
                    break

                if case(ONLY_NON_DISCRIMINATORY):
                    self.score = int(np.random.normal(2.5, 1.5))
                    while (self.score <= 0 or self.score > 5):
                        self.score = int(np.random.normal(2.5, 1.5))
                    break

                if case(ONLY_DISCRIMINATORY):
                    self.score = int(np.random.normal(-2.5, 1.5))
                    while (self.score >= 0 or self.score < -5):
                        self.score = int(np.random.normal(-2.5, 1.5))
                    break

                if case():
                    sys.stderr.write("Invalid value for bias")
                    return False

        else:
            self.score = score

        # If bill has score < 0: hurts LGB sentiments
        self.isDiscriminatory = (self.score < 0)
        self.isPassed = False

        # Used to account for the time delay of the policy effect
        self.passTime = time
        self.prevEffect = 0
        self.curEffect = 0

        if not self.Policy_verifyPolicy(self.score, self.isPassed, 
            self.passTime):
            return None
示例#3
0
#set number of simulations
trials = 100000

#create variable to count number of times found the car when switch doors
switchWins = 0
#run the simulation a number of times
for i in range(trials):
    #create 3 door objectts
    doorOne = Door()
    doorTwo = Door()
    doorThree = Door()

    #put car behind a random door
    x = random.randint(1, 3)
    for case in switch(x):
        if case(1):
            doorOne.setCar(True)
            break
        if case(2):
            doorTwo.setCar(True)
            break
        if case():
            doorThree.setCar(True)

    #select a random door
    y = random.randint(1, 3)
    for case in switch(y):
        if case(1):
            doorOne.setSelected(True)
            break
示例#4
0
from Read import row_count, column_count, start_position, end_position
from Switch import switch

WINDOW_TITLE = "PathFinder - Algoritmo Genético"

MAZE_WIDTH = column_count
MAZE_HEIGHT = row_count
BLOCK_SIZE = switch(MAZE_HEIGHT)

GENERATIONS = 100
POPULATION_SIZE = 100
MUTATION_RATE = 0.05

START_COORDS = start_position
END_COORDS = end_position
示例#5
0
#set number of simulations
trials = 100000

#create variable to count number of times found the car when switch doors
switchWins = 0
#run the simulation a number of times
for i in range(trials):
	#create 3 door objectts
	doorOne = Door()
	doorTwo = Door()
	doorThree = Door()

	#put car behind a random door
	x = random.randint(1,3)
	for case in switch(x):
		if case(1):
			doorOne.setCar(True)
			break
		if case(2):
			doorTwo.setCar(True)
			break
		if case():
			doorThree.setCar(True)

	#select a random door
	y = random.randint(1,3)
	for case in switch(y):
		if case(1):
			doorOne.setSelected(True)
			break
示例#6
0
table = HashTable(430007)
for line in file:
	table.insert(line.replace("\n",""))
cols = table.collisions
print("Number of collisions = {}\n\n".format(cols))

#loop until user decides to exit
while True:
	x = int(input("\n1) Print all words\n2) Search for a word\n3) Quit\n"))

	#If user presses...
	#1..Print all words in table and print collisions of each word
	#2..Ask user to enter a word and search for that word
	#3..Exit loop
	stop = False
	for case in switch(x):
		if case(1):
			table.printTable()
			break
		if case(2):
			word = input("\nEnter word to be searched for:")
			table.getSlot(word)
			break
		if case(3):
			stop = True
			break
		if case():
			print("Invalid input\n")

	if stop:
		break
  def evaluate_state(self):
    msg = user_event_msg()  
    msg.user_id = self.mid_
    msg.message = 'none'

    for case in switch(self.state__):

      if case('IDLE'):
        if self.current_state_msg.outside_workspace:
            msg.event_id = 'workspace_event'
            msg.message = 'outside_workspace'
            self.state__ = 'OUTSIDE_WORKSPACE'
            break
        # Hand Events
        msg.event_id = 'hand_event'
        if self.current_state_msg.hands_on_head:
            msg.message = 'hands_on_head'
            self.state__ = 'HANDS_HEAD'
            break
        if self.current_state_msg.hands_together:
          msg.message = 'hands_together'
          self.state__ = 'HANDS_TOGETHER'
          break
        if self.current_state_msg.right_elbow_click:
          msg.message = 'right_elbow_click'
          self.state__ = 'RIGHT_ELBOW_CLICK'
          break
        if self.current_state_msg.left_elbow_click:
          msg.message = 'left_elbow_click'
          self.state__ = 'LEFT_ELBOW_CLICK'
          break
        break

      if case('OUTSIDE_WORKSPACE'):
        if not self.current_state_msg.outside_workspace:
          self.state__ = 'IDLE'
        break

      if case('HANDS_TOGETHER'):
        if not self.current_state_msg.hands_together:
          self.state__ = 'IDLE'
        break

      if case('HANDS_HEAD'):
        if not self.check_joint_dist(self.head_limit_,'left_hand','head'):
          self.state__ = 'IDLE'
          break
        elif not self.check_joint_dist(self.head_limit_,'right_hand','head'):
          self.state__ = 'IDLE'
          break
        break

      if case('RIGHT_ELBOW_CLICK'):
        if not self.current_state_msg.right_elbow_click:
          self.state__ = 'IDLE'
        break

      if case('LEFT_ELBOW_CLICK'):
        if not self.current_state_msg.left_elbow_click:
          self.state__ = 'IDLE'
        break

    # Check for populated message and publish
    if 'none' not in msg.message:
      self.user_event_pub_.publish(msg)
    pass
示例#8
0
    def NetworkBase_getDepressOdds(self, onlyMinority=0, withSupport=0,
            checkDensity=False):
        # Everyone with < 0.10 support will be considered "NOT supported"
        NO_SUPPORT = .75

        # Used to calculate when the z-score is ".75" (never exact: 
        # use a bounded set to compensate)
        cutoffRange = [.90, 1.10]

        # Used for checking the parameters passed in: whether check
        # for the nodes with a property, without, or without regard
        ONLY_WANT_WITH = 2
        ONLY_WANT_WITHOUT = 1
        IRRELEVANT = 0
        
        # Determines which agents to check based on parameter
        for case in switch(onlyMinority):
            if case(ONLY_WANT_WITH):
                agents = self.NetworkBase_getMinorityNodes()
                break
            if case(ONLY_WANT_WITHOUT):
                agents = self.NetworkBase_getMinorityNodes(
                    wantMinority=False)
                break
            if case(IRRELEVANT):
                agents = self.NetworkBase_getAgentArray()
                break
            if case():
                sys.stderr.write("Minority bool must be 0, 1, 2")
                return False

        # Agent count: defaulted to number of agents being analyzed
        count = len(agents)
        totalDepression = 0
        for case in switch(withSupport):
            # Gets total depression of those with support
            if case(ONLY_WANT_WITH):
                for agent in agents:
                    z = self.NetworkBase_getSupportZScore(agent)
                    if z > NO_SUPPORT:
                        totalDepression += agent.currentDepression
                break

            # Gets depression of those without support
            if case(ONLY_WANT_WITHOUT): 
                for agent in agents:
                    z = self.NetworkBase_getSupportZScore(agent)
                    if z <= NO_SUPPORT:
                        totalDepression += agent.currentDepression
                break

            # Gets depression for all the agents in check
            if case(IRRELEVANT):
                # If calculating odds for specific level of density
                if checkDensity:
                    # Have to redo count for only agents in cutoff
                    count = 0
                    for agent in agents:
                        z = self.NetworkBase_getDensityZScore(agent)
                        if cutoffRange[0] < z:
                            totalDepression += agent.currentDepression
                            count += 1

                else:
                    for agent in agents:
                        totalDepression += agent.currentDepression
                break

            if case():
                sys.stderr.write("Support bool must be 0, 1, 2")
                return False

        if not count:
            return 0.0
        
        prob = totalDepression/count
        return prob/(1 - prob)
示例#9
0
    def evaluate_state(self):
        msg = user_event_msg()
        msg.user_id = self.mid_
        msg.message = 'none'

        for case in switch(self.state__):

            if case('IDLE'):
                if self.current_state_msg.outside_workspace:
                    msg.event_id = 'workspace_event'
                    msg.message = 'outside_workspace'
                    self.state__ = 'OUTSIDE_WORKSPACE'
                    break
                # Hand Events
                msg.event_id = 'hand_event'
                if self.current_state_msg.hands_on_head:
                    msg.message = 'hands_on_head'
                    self.state__ = 'HANDS_HEAD'
                    break
                if self.current_state_msg.hands_together:
                    msg.message = 'hands_together'
                    self.state__ = 'HANDS_TOGETHER'
                    break
                if self.current_state_msg.right_elbow_click:
                    msg.message = 'right_elbow_click'
                    self.state__ = 'RIGHT_ELBOW_CLICK'
                    break
                if self.current_state_msg.left_elbow_click:
                    msg.message = 'left_elbow_click'
                    self.state__ = 'LEFT_ELBOW_CLICK'
                    break
                break

            if case('OUTSIDE_WORKSPACE'):
                if not self.current_state_msg.outside_workspace:
                    self.state__ = 'IDLE'
                break

            if case('HANDS_TOGETHER'):
                if not self.current_state_msg.hands_together:
                    self.state__ = 'IDLE'
                break

            if case('HANDS_HEAD'):
                if not self.check_joint_dist(self.head_limit_, 'left_hand',
                                             'head'):
                    self.state__ = 'IDLE'
                    break
                elif not self.check_joint_dist(self.head_limit_, 'right_hand',
                                               'head'):
                    self.state__ = 'IDLE'
                    break
                break

            if case('RIGHT_ELBOW_CLICK'):
                if not self.current_state_msg.right_elbow_click:
                    self.state__ = 'IDLE'
                break

            if case('LEFT_ELBOW_CLICK'):
                if not self.current_state_msg.left_elbow_click:
                    self.state__ = 'IDLE'
                break

        # Check for populated message and publish
        if 'none' not in msg.message:
            self.user_event_pub_.publish(msg)
        pass