Esempio n. 1
0
        def check_attempt(self, params):
		
		#unpack params
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		hint = ''
		
		matches = find_matches(params)	
		#print "Prob 8 Part 3 matches: ", matches
		try:
                        
			if '*' not in self.attempt:
				hint = 'If the probability of event A is (1/2) is the probability of event B is (1/4), then what is the probability of A and B? (Note that in this problem, event A is the case that opponent 1 wins and B is the case where opponent 2 wins, given that opponent 1 did not.): (1/2)*(__).'
				return hint,'1/4'

			else:
				return '',''

 	
                except Exception:
                        return '',''
		return '',''
Esempio n. 2
0
        def check_attempt(self, params):
		
		#unpack params
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		hint = ''

		matches = find_matches(params)
		matching_node = [m[0] for m in matches]
		
		try:
                        
			if '^' in self.attempt or '**' in self.attempt:
                        	hint='The exponent operator (^ or **) is not relevant to this question.' 
			
			elif 'P' in self.attempt:
				hint='Is order important in this case?'

			elif ('R.0' in matching_node and 'R.1' in matching_node):
				
				if '+' in self.attempt:
                        		hint='Do you think \'+\' is correct choice in this case?'
			
 

			if len(hint)>0:
                                return hint + ' How many card pairs are there having a black colored number 2 card and a number 9 card in a deck? (Ignore the order)','2*4' 
			else:
				return '',''
                        
                except Exception:
                        return '',''
Esempio n. 3
0
	def check_attempt(self, params):
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		matches = find_matches(params)		
		matching_node = [m[0] for m in matches]

		try:
			if 'i' in self.attempt:
				hint='The answer should not contain variable i. '
			elif 'x' in self.attempt or 'X' in self.attempt:
				hint='The answer should not contain variable x. '
			elif '-' in self.attempt and '-' not in self.answer:
				hint='The subtraction operation is not required. '
			elif 'R.1' in matching_node:
				hint='The constant used in the numerator of expectation value expression is different. '
			else:
				hint='Find the expectation values for each random variable X_i by replacing i and the find the expectation of linear combination of random variables. '
			
			if len(hint)>0:
				return hint+ ' What is the expectation value of E[2X + 3Y], where X and Y are random variable and E[X] =2 , E[Y] =1 ',' 2*2 + 3*1'
			else:
				return '',''

		except Exception:
			return '',''
Esempio n. 4
0
        def check_attempt(self, params):
		
		#unpack params
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		hint = ''
	
		matches = find_matches(params)
		matching_node = [m[0] for m in matches]

		try: 

			if not('^' in self.attempt or '**' in self.attempt):
				hint='Can you think of using ^ operation in the expression.'
	
			elif ('R.0' not in matching_node and 'R.1' in matching_node) or ('R.0' in matching_node and 'R.1' not in matching_node):
				hint='Check the variance values of corresponding random variables.'
			
			elif self.answer in self.attempt:
				hint='Variance of any constant term is zero.'	
 			

			if len(hint)>0:
                                return hint + ' Let say r.v. X has mean of 1 and variance of 2, r.v. Z = 3X + 1 then var(Z) = var(3X+1) = (3^2)*var(X) = ?  (write final value only)','18' 
			else:
				return '',''
                        
                except Exception:
                        return '',''
Esempio n. 5
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            if '^' in self.attempt:
                hint='This problem does not involve the power function (^).'
                return hint + 'How many cards do we have to choose? ', '5'
            #check if the form of the parse tree has the right
            #shape: an operator and two leafs that correspond to
            #the operands
            elif '+' in self.attempt:
                hint='Are you sure addition is the correct operator? '
                return hint + 'If a poker hand contains at least one royal card, how many non-royal cards can there be at most?', '4'
            elif '-' not in self.attempt:
                hint = 'You might have to remove cases.'
                return hint + 'If a poker hand contains at least one royal card, how many non-royal cards can there be at most?', '4'
            elif 'C(' not in self.attempt and '!' not in self.attempt:
                hint='Missing choose function in the answer. '
                return hint + 'How many possible ways are there to get 5 cards correct out of 32? C(_,5)', '32'

            else:
                return "",""

        except Exception:
            return '',''
Esempio n. 6
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            #check if the form of the parse tree has the right
            #shape: an operator and two leafs that correspond to
            #the operands
            if len(self.att_tree) == 3 and self.att_tree[1][
                    0] == 'X' and self.att_tree[2][0] == 'X':
                if 'R.1' in matching_node and 'R.0.0' in matching_node:
                    hint = "The denominator is correct. "
                    return hint + "How many different ways to select 2 heads in the H/T sequence of length 3(order doesn't matter)?", "C(3,2)"
                elif 'R.1' in matching_node:
                    hint = "The denominator is correct. "
                    return hint + "How many different ways to select 2 heads in the H/T sequence of length 3?", "C(3,2)"
                elif 'R.0' in matching_node:
                    hint = "The numerator is correct. "
                    return hint + "What is the number of all possible H/T sequence of length 3?", "2^3"
            return "", ""

        except Exception:
            return '', ''
Esempio n. 7
0
    def check_attempt(self, params):

        #unpack params
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        hint = ''

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:

            if '^' in self.attempt or '**' in self.attempt:
                hint = 'The exponent operator (^ or **) is not relevant to this question.'

            elif 'P' in self.attempt:
                hint = 'Is order important in this case?'

            elif ('R.0' in matching_node and 'R.1' in matching_node):

                if '+' in self.attempt:
                    hint = 'Do you think \'+\' is correct choice in this case?'

            if len(hint) > 0:
                return hint + ' How many card pairs are there having a black colored number 2 card and a number 9 card in a deck? (Ignore the order)', '2*4'
            else:
                return '', ''

        except Exception:
            return '', ''
Esempio n. 8
0
	def check_attempt(self, params):
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		matches = find_matches(params)		
		matching_node = [m[0] for m in matches]

		try:
			print "custom hint"
			if 'i' in self.attempt:
				hint='The answer should not contain variable i. '
			elif 'x' in self.attempt or 'X' in self.attempt:
				hint='The answer should not contain variable x. '
			elif '-' in self.attempt and '-' not in self.answer:
				hint='The subtraction operation is not required. '
			else:
				hint='Find the variance values for each random variable X_i by replacing i and the find the variance of linear combination of random variables. '
			
			if len(hint)>0:
				return hint+ ' What is the Variance value of Var[2X + 3Y], where X and Y are independent random variable and Var(X) = 3, Var(Y) =1. ',' 2*2*3 + 3*3*1'
			else:
				return '',''

		except Exception:
			return '',''
Esempio n. 9
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            if '^' in self.attempt:
                hint = 'This problem does not involve the power function (^).'
                return hint + 'How many cards do we have to choose? ', '5'
            #check if the form of the parse tree has the right
            #shape: an operator and two leafs that correspond to
            #the operands
            elif '+' in self.attempt:
                hint = 'Are you sure addition is the correct operator? '
                return hint + 'If a poker hand contains at least one royal card, how many non-royal cards can there be at most?', '4'
            elif '-' not in self.attempt:
                hint = 'You might have to remove cases.'
                return hint + 'If a poker hand contains at least one royal card, how many non-royal cards can there be at most?', '4'
            elif 'C(' not in self.attempt and '!' not in self.attempt:
                hint = 'Missing choose function in the answer. '
                return hint + 'How many possible ways are there to get 5 cards correct out of 32? C(_,5)', '32'

            else:
                return "", ""

        except Exception:
            return '', ''
Esempio n. 10
0
        def check_attempt(self, params):
		
		#unpack params
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		hint = ''
		
		matches = find_matches(params)
		matching_node = [m[0] for m in matches] 
		

		try:
                        
			if 'R.1' in matching_node and 'R.0' not in matching_node:
				hint = "The denominator is correct. Here you need a 3 and either a 6 or A on the turn and river to get straight in given situation of cards. So the number of such card pairs, ignoring order, is?"
				return hint,'4*8'

			elif 'R.0' in matching_node and 'R.1' not in matching_node:
				hint = "The numerator is correct."
			
				
			
			if len(hint)>0:
                                return hint + ' Let say you have a heart with number 2 and a diamond with 4. How many ways you can choose three cards from remaining(52 minus 2) deck of cards? C(_,3) ','50' 
			else:
				return '',''

 	
                except Exception:
                        return '',''
Esempio n. 11
0
    def check_attempt(self, params):

        #unpack params
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        hint = ''

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:

            if 'R.0.1' in matching_node and 'R.0.0' in matching_node:

                return 'The distribution choice is correct! Are these events dependent(0) or Independent(1) (Choose: 0 or 1)?', '1'

            elif 'R.0' in matching_node:

                return 'The numerator is correct! Hint: What is the P(head) when both head and tail are equally likely?', '1/2'

            elif 'R.1' in matching_node and ('R.0.1' not in matching_node
                                             or 'R.0.0' not in matching_node):

                hint = 'Denominator is correct!'

            if len(hint) > 0:
                return hint + ' What should be the distribution here(Choose 0 for Exponential or 1 for Poisson)', '1'
            else:
                return '', ''

        except Exception:
            return '', ''
Esempio n. 12
0
        def check_attempt(self, params):
		
		#unpack params
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		hint = ''
	
		matches = find_matches(params)
		matching_node = [m[0] for m in matches]
		
		try:
                        
			if '^' in self.attempt or '**' in self.attempt:
                        	hint='The exponent operator (^ or **) is not relevant to this question.' 
			
			elif 'R.0' not in matching_node:
				hint='Make sure you are using correct scaling factors and mean values for corresponding random variables.'
			
			elif 'R.0' in matching_node and 'R.1' not in matching_node:
				hint='Make sure you are using correct additive constant value.'	
 			

			if len(hint)>0:
                                return hint + ' Let say r.v. X has mean of 1 and variance of 2, r.v. Z = 2X + 1 then E(Z) = E(2X+1) = 2E(X) + 1 = ?  (write final value only)','3' 
			else:
				return '',''
                        
                except Exception:
                        return '',''
Esempio n. 13
0
	def check_attempt(self, params):
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		matches = find_matches(params)
		matching_node = [m[0] for m in matches]

		try:
			#check if the form of the parse tree has the right
			#shape: an operator and two leafs that correspond to
			#the operands
			if len(self.att_tree)==3 and self.att_tree[1][0]=='X' and self.att_tree[2][0]=='X':
				if 'R.1' in matching_node and 'R.0.0' in matching_node:
					hint = "The denominator is correct. "
					return hint + "How many different ways to select 2 heads in the H/T sequence of length 3(order doesn't matter)?","C(3,2)"
				elif 'R.1' in matching_node:
					hint = "The denominator is correct. "
					return hint + "How many different ways to select 2 heads in the H/T sequence of length 3?","C(3,2)"
				elif 'R.0' in matching_node:
					hint = "The numerator is correct. "
					return hint + "What is the number of all possible H/T sequence of length 3?", "2^3"
			return "", ""

		except Exception:
			return '',''
Esempio n. 14
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            print "custom hint"
            if 'i' in self.attempt:
                hint = 'The answer should not contain variable i. '
            elif 'x' in self.attempt or 'X' in self.attempt:
                hint = 'The answer should not contain variable x. '
            elif '-' in self.attempt and '-' not in self.answer:
                hint = 'The subtraction operation is not required. '
            else:
                hint = 'Find the variance values for each random variable X_i by replacing i and the find the variance of linear combination of random variables. '

            if len(hint) > 0:
                return hint + ' What is the Variance value of Var[2X + 3Y], where X and Y are independent random variable and Var(X) = 3, Var(Y) =1. ', ' 2*2*3 + 3*3*1'
            else:
                return '', ''

        except Exception:
            return '', ''
Esempio n. 15
0
        def check_attempt(self, params):
		
		#unpack params
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		
		hint = ''
		
		matches = find_matches(params)
		#print "PROBLEM 8 PART 2: ", matches
 		
 
 		try:
			if '/' not in self.attempt:
				hint = 'To calculate the probability that an event occurs, divide the size of the event by the size of the outcome space. What is the size of the event in this case?'
				return hint,'3'
                         
 			elif '1-' not in self.attempt:
 				hint = 'The conditional probability that you win a coin toss given that you bet on heads, is 1-probability(opponent wins) = 1-(___).'
 				return hint,'1/2'
 
 			elif 'C' not in self.attempt:
 				hint = 'If you are choosing 2 cards from a pool of 26 from which 3 cards have already been drawn, how many choices do you have?: C(26-3,__)'
 				return hint, '2'
 			else:
 				return '',''

  	
                except Exception:
			return '',''
		return '',''
Esempio n. 16
0
def evaluate_test(ans, att):
	ans = ans.strip("\[")
	ans = ans.strip("\]")
	ans = ans.replace("{","")
	ans = ans.replace("}","")
	att = att.strip("'")
	try:
		update_sql = """UPDATE eval_info 
						SET attempt = %s
						SET answer = %s"""
		db_cursor.execute(update_sql,(att,ans))
		db.commit()
	except:
		db.rollback()
		print "Database has been rolled back because of an Exception !!!"
		#print(traceback.format_exc())  

	p = make_params(ans, att)
	if p == {}:
		#logger.info("param empty from evaluate")
		return False
	att_value = get_numerical_answer(p['att_tree'])
	ans_value = get_numerical_answer(p['ans_tree'])
	final_pairs = find_matches(p)
	#logger.info("output matching: {0}.".format(final_pairs))

	if len(final_pairs) == 1 and final_pairs[0][0] == 'R':
		return True
	elif check_w_tol(ans_value, att_value):
		return True
	else:
		return False
Esempio n. 17
0
    def check_attempt(self, params):

        #unpack params
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        hint = ''

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:

            if 'R.1' in matching_node and 'R.0' not in matching_node:
                hint = "The denominator is correct. Here you need a 3 and either a 6 or A on the turn and river to get straight in given situation of cards. So the number of such card pairs, ignoring order, is?"
                return hint, '4*8'

            elif 'R.0' in matching_node and 'R.1' not in matching_node:
                hint = "The numerator is correct."

            if len(hint) > 0:
                return hint + ' Let say you have a heart with number 2 and a diamond with 4. How many ways you can choose three cards from remaining(52 minus 2) deck of cards? C(_,3) ', '50'
            else:
                return '', ''

        except Exception:
            return '', ''
Esempio n. 18
0
    def check_attempt(self, params):

        #unpack params
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        hint = ''

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:

            if not ('^' in self.attempt or '**' in self.attempt):
                hint = 'Can you think of using ^ operation in the expression.'

            elif ('R.0' not in matching_node and 'R.1' in matching_node) or (
                    'R.0' in matching_node and 'R.1' not in matching_node):
                hint = 'Check the variance values of corresponding random variables.'

            elif self.answer in self.attempt:
                hint = 'Variance of any constant term is zero.'

            if len(hint) > 0:
                return hint + ' Let say r.v. X has mean of 1 and variance of 2, r.v. Z = 3X + 1 then var(Z) = var(3X+1) = (3^2)*var(X) = ?  (write final value only)', '18'
            else:
                return '', ''

        except Exception:
            return '', ''
Esempio n. 19
0
    def check_attempt(self, params):

        #unpack params
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        hint = ''

        matches = find_matches(params)
        #print "PROBLEM 8 PART 2: ", matches

        try:
            if '/' not in self.attempt:
                hint = 'To calculate the probability that an event occurs, divide the size of the event by the size of the outcome space. What is the size of the event in this case?'
                return hint, '3'

            elif '1-' not in self.attempt:
                hint = 'The conditional probability that you win a coin toss given that you bet on heads, is 1-probability(opponent wins) = 1-(___).'
                return hint, '1/2'

            elif 'C' not in self.attempt:
                hint = 'If you are choosing 2 cards from a pool of 26 from which 3 cards have already been drawn, how many choices do you have?: C(26-3,__)'
                return hint, '2'
            else:
                return '', ''

        except Exception:
            return '', ''
        return '', ''
def check_attempt(params):
    final_pairs=find_matches(params)
    if len(final_pairs)>0:
        for node,value,ans_piece,attempt_piece in final_pairs:
            if value>10 or value != int(value):
                if attempt_piece != ans_piece:
                    return 'The sub-expression {0} is correct, it could also be written as {1}'.format(attempt_piece,ans_piece)
                else:
                    return 'The sub-expression {0} is correct'.fromat(attempt_piece)
    return ""
Esempio n. 21
0
def check_attempt(params):
    final_pairs = find_matches(params)
    if len(final_pairs) > 0:
        for node, value, ans_piece, attempt_piece in final_pairs:
            if value > 20 or value != int(value):
                if attempt_piece != ans_piece:
                    return 'The sub-expression {0} is correct, it could also be written as {1}'.format(
                        attempt_piece, ans_piece)
                else:
                    return 'The sub-expression {0} is correct.'.format(
                        attempt_piece)
    return ""
Esempio n. 22
0
	def check_attempt(self, params):
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		matches = find_matches(params)

		try:
			if ("-1" not in self.attempt):
				return "Having, for example, 6 choices for digits 1 and 3, how many choices remain for digits 2 and 4?","6-1"
			return "", ""
		except:
			return "", ""
Esempio n. 23
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            return "What is E(X) in terms of N if the coin is unbiased and fair? ___ * N", "0.5"

        except Exception:
            return '', ''
Esempio n. 24
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            return "What is the sum of (X-u)^2?","10"

        except Exception:
            return '',''
Esempio n. 25
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            return 'Enter 1 if true: The cumulative distribution function gives the proportion of customers served within 10 minutes. ', '1'

        except Exception:
            return '', ''
Esempio n. 26
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)

        try:
            if ("-1" not in self.attempt):
                return "Having, for example, 6 choices for digits 1 and 3, how many choices remain for digits 2 and 4?", "6-1"
            return "", ""
        except:
            return "", ""
Esempio n. 27
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            return 'If X and Y are independent and P(X) = P(Y) = 0.5, what is P(X,Y)?', '0.25'

        except Exception:
            return '', ''
Esempio n. 28
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            return 'How many customers are served on average in 10 minutes if the average checkout time is 5 minutes? ', '2'

        except Exception:
            return '', ''
Esempio n. 29
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            return "What is E(X) in terms of N if the coin is unbiased and fair? ___ * N","0.5"

        except Exception:
            return '',''
Esempio n. 30
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            hint = 'Recall the formula to find the expected value of E(XY) when X and Y are independent.'
            return hint + ' If the probability that X and Y happen is 1/2, X has the value 4, and Y has the value 6, what is the E(XY)?', '6'

        except Exception:
            return '', ''
Esempio n. 31
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            hint = 'Recall how to find the correlation coefficient between X and Y.'
            return hint + ' If Cov(X,Y) is 4, sqrt(Var(X)) is 2 and sqrt(Var(Y)) is 2, what is the correlation coefficient between X and Y?', '1'

        except Exception:
            return '', ''
def common_subexpressions(params):
    final_pairs=find_matches(params)
    if len(final_pairs)>0:
        for node,value,ans_piece,attempt_piece in final_pairs:
            if value>10 or value != int(value):
                # print hint
                if node=='R': # attempt is correct
                    sub_type='answer'
                else:
                    sub_type='sub-expression'
                if attempt_piece != ans_piece:
                    return 'The {0} {1} is correct, it could also be written as {2}'.format(sub_type,attempt_piece,ans_piece)
                else:
                    return 'The {0} {1} is correct'.format(sub_type,attempt_piece)
Esempio n. 33
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            hint = 'Recall the formula to find covariance.'
            return hint + ' If E(XY) is 4, E(X)E(Y) is 2, what is Cov(X,Y)?', '2'

        except Exception:
            return '', ''
Esempio n. 34
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            hint = 'The Expectation of X is the sum of all X values times the probability of that value.'
            return hint + 'If X is a flip of an unbiased coin, and heads = 1, what is E[X]??', '0.5'

        except Exception:
            return '', ''
Esempio n. 35
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            hint = 'The Variance of X is E[X^2] - (E[X})^2. '
            return hint + 'If X is a flip of an unbiased coin, and heads = 1, what is Var[X]??', '0.25'

        except Exception:
            return '',''
Esempio n. 36
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            hint = 'The marginal distribution of X is the sum of all Y values.'
            return hint + ' If P(Y=1,X=2) = P(Y=2,X=2) = P(Y=3,X=2) = 0.1, what is P(X=2)?', '0.3'

        except Exception:
            return '', ''
Esempio n. 37
0
def common_subexpressions(params):
    final_pairs=find_matches(params)
        if len(final_pairs)>0:
            for node,value,ans_piece,attempt_piece in final_pairs:
                if value>10 or value != int(value):
                    # print hint
                    if node=='R': # attempt is correct
                        sub_type='answer'
                    else:
                        sub_type='sub-expression'
                    if attempt_piece != ans_piece:
                        return 'The {0} {1} is correct, it could also be written as {2}'.format(sub_type,attempt_piece,ans_piece)
                    else:
                        return 'The {0} {1} is correct'.fromat(sub_type,attempt_piece)
Esempio n. 38
0
	def check_attempt(self, params):
		self.attempt = params['attempt'] #student's attempt
		self.answer = params['answer'] #solution
		self.att_tree = params['att_tree'] #attempt tree
		self.ans_tree = params['ans_tree'] #solution tree
		matches = find_matches(params)       

		try:
			for m in matches:
				if 'R.0' not in m:
					return "If you have 3 spot and 4 choices per spot, what should be the base for your exponential expression?","4"
				if 'R.1' not in m:
					return "If you have 3 spots and 4 choices per spot, what should be the exponent in your expression?", "3"
				if ("^" not in self.attempt):
					return "If there are 3 spots and 4 choices for each spot, what format should your answer be in? 4^_", "3"
				else:
					return "If there are 3 spots, and 4 choices for each spot, is the total number of combinations 3^4 or 4^3?","4^3" 
		except:
			return "", ""
Esempio n. 39
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree
        matches = find_matches(params)

        try:
            for m in matches:
                if 'R.0' not in m:
                    return "If you have 3 spot and 4 choices per spot, what should be the base for your exponential expression?", "4"
                if 'R.1' not in m:
                    return "If you have 3 spots and 4 choices per spot, what should be the exponent in your expression?", "3"
                if ("^" not in self.attempt):
                    return "If there are 3 spots and 4 choices for each spot, what format should your answer be in? 4^_", "3"
                else:
                    return "If there are 3 spots, and 4 choices for each spot, is the total number of combinations 3^4 or 4^3?", "4^3"
        except:
            return "", ""
Esempio n. 40
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            for m in matching_node:
                if ('R.0' not in m) or ('R.1' not in m):
                    hint='Are the two dice dependent or not? What does that say about linearity of expectation.'
            if len(hint)>0:
                return hint ,'What is E(X + Y), where X and Y are independent random variable. E(X)=1 and E(Y)=2?','1+2'
            else:
                return '',''

        except Exception:
            return '',''
Esempio n. 41
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            for m in matching_node:
                if ('R.0' not in m) or ('R.1' not in m):
                    hint = 'Are the two dice dependent or not? What does that say about linearity of expectation.'
            if len(hint) > 0:
                return hint, 'What is E(X + Y), where X and Y are independent random variable. E(X)=1 and E(Y)=2?', '1+2'
            else:
                return '', ''

        except Exception:
            return '', ''
Esempio n. 42
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            for m in matching_node:
                if ('R.0' not in m) or ('R.1' not in m):
                    hint='To solve for k, express k in terms of expectation, which value you have from previous part.'
            if len(hint)>0:
                return hint ,'What is the bound for variable Y to have more than 5 if mean of Y, or E(Y) is 5/2 ?','5/(5/2)'
            else:
                return '',''

        except Exception:
            return '',''
Esempio n. 43
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            for m in matching_node:
                if 'R.1' not in m:
                    hint='Since the dice is biased, use linearity of expectation to calculate the expectation for each outcome separately'
                if 'R.0' not in m:
                    hint='Since the dice is biased, use linearity of expectation to calculate the expectation for each outcome separately'
            if len(hint)>0:
                return hint+ 'What is the expectation of number of heads coin flips where P(head)=3/4?','0*(1/4) + 1*(3/4)'
            else:
                return '',''

        except Exception:
            return '',''
Esempio n. 44
0
    def check_attempt(self, params):
        self.attempt = params['attempt'] #student's attempt
        self.answer = params['answer'] #solution
        self.att_tree = params['att_tree'] #attempt tree
        self.ans_tree = params['ans_tree'] #solution tree

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            for m in matching_node:
                if 'R.1' in m:
                    hint='When probability is twice as high, its 2 times the original. '
                if 'R.1.0' in m:
                    hint='Remember that the sum formula from 1 to n is  n(n+1)/2. '
            if len(hint)>0:
                return hint+ ' What is the sum from 1 to 5','5(5+1)/2'
            else:
                return '',''

        except Exception:
            return '',''
Esempio n. 45
0
    def check_attempt(self, params):
        self.attempt = params['attempt']  #student's attempt
        self.answer = params['answer']  #solution
        self.att_tree = params['att_tree']  #attempt tree
        self.ans_tree = params['ans_tree']  #solution tree

        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            for m in matching_node:
                if 'R.1' not in m:
                    hint = 'Since the dice is biased, use linearity of expectation to calculate the expectation for each outcome separately'
                if 'R.0' not in m:
                    hint = 'Since the dice is biased, use linearity of expectation to calculate the expectation for each outcome separately'
            if len(hint) > 0:
                return hint + 'What is the expectation of number of heads coin flips where P(head)=3/4?', '0*(1/4) + 1*(3/4)'
            else:
                return '', ''

        except Exception:
            return '', ''
Esempio n. 46
0
def evaluate(ans, att):
	ans = ans.strip("\[")
  	ans = ans.strip("\]")
  	ans = ans.replace("{","")
  	ans = ans.replace("}","")
  	att = att.strip("'")
  	#logger.info("evaluating attempt: {0}, answer: {1}.".format(att, ans))
	p = make_params(ans, att)
	if p == {}:
		#logger.info("param empty from evaluate")
		return False
	att_value = get_numerical_answer(p['att_tree'])
	ans_value = get_numerical_answer(p['ans_tree'])
	final_pairs = find_matches(p)
	#logger.info("output matching: {0}.".format(final_pairs))

	if len(final_pairs) == 1 and final_pairs[0][0] == 'R':
		return True
	elif check_w_tol(ans_value, att_value):
		return True
	else:
		return False
Esempio n. 47
0
    def check_attempt(self, params):
        self.attempt = params["attempt"]  # student's attempt
        self.answer = params["answer"]  # solution
        self.att_tree = params["att_tree"]  # attempt tree
        self.ans_tree = params["ans_tree"]  # solution tree
        matches = find_matches(params)
        matching_node = [m[0] for m in matches]

        try:
            if "^" in self.attempt:
                hint = "This problem does not involve the power function (^)."
                return hint + "How many cards do we have to choose? ", "5"
            # check if the form of the parse tree has the right
            # shape: an operator and two leafs that correspond to
            # the operands
            elif "+" in self.attempt:
                hint = "Are you sure addition is the correct operator? "
                return (
                    hint
                    + "If a poker hand contains at least one royal card, how many non-royal cards can there be at most?",
                    "4",
                )
            elif "-" not in self.attempt:
                hint = "You might have to remove cases."
                return (
                    hint
                    + "If a poker hand contains at least one royal card, how many non-royal cards can there be at most?",
                    "4",
                )
            elif "C(" not in self.attempt and "!" not in self.attempt:
                hint = "Missing choose function in the answer. "
                return hint + "How many possible ways are there to get 5 cards correct out of 32? C(_,5)", "32"

            else:
                return "", ""

        except Exception:
            return "", ""


if __name__=="__main__":
    sys.path.append('../src')
    from parsetrees.expr_parser.Eval_parsed import parse_and_eval
    from collections import Counter

    if len(sys.argv)==3:   #parameters are two expressions
        params={}
        params['answer']=sys.argv[1]
        params['attempt']=sys.argv[2]
        params['ans_tree']=parse_and_eval(params['answer'])
        params['att_tree']=parse_and_eval(params['attempt'])
        print 'params=',params
        final_pairs=find_matches(params)
        for item in final_pairs:
            print "node=%s, value=%s, The piece %s in your answer is correct, it can also be expressed as %s"%(item[0],item[1],item[3],item[2])

    elif len(sys.argv)==2: # param is the name of a file containing a dump of attempts with their parse trees and variables
        file=open(sys.argv[1],'r')
        print file.readline()
        print file.readline()

        Clusters=Counter()
        Reps={}
        i=1
        for line in file.readlines():
            i+=1
            if len(line)>1000:
                print 'long line error in line',i