def __init__(self, config=None, **kwargs): super(IntegralGrader, self).__init__(config, **kwargs) self.true_input_positions = self.validate_input_positions( self.config['input_positions']) # The below are copied from FormulaGrader.__init__ # Set up the various lists we use self.functions, self.random_funcs = construct_functions( self.config["whitelist"], self.config["blacklist"], self.config["user_functions"]) self.constants = construct_constants(self.config["user_constants"]) # TODO I would like to move this into construct_constants at some point, # perhaps giving construct_constants and optional argument specifying additional defaults if 'infty' not in self.constants: self.constants['infty'] = float('inf') # Construct the schema for sample_from # First, accept all VariableSamplingSets # Then, accept any list that RealInterval can interpret # Finally, single numbers or tuples of numbers will be handled by DiscreteSet schema_sample_from = Schema({ Required(varname, default=RealInterval()): Any(VariableSamplingSet, All(list, lambda pair: RealInterval(pair)), lambda tup: DiscreteSet(tup)) for varname in self.config['variables'] }) self.config['sample_from'] = schema_sample_from( self.config['sample_from'])
def validate_math_config(self): """Performs generic math configuration validation""" validate_blacklist_whitelist_config(self.default_functions, self.config['blacklist'], self.config['whitelist']) # Make a copy of self.default_variables, so we don't change the base version self.default_variables = self.default_variables.copy() # Remove any deleted user constants from self.default_variables remove_keys = [ key for key in self.config['user_constants'] if self.config['user_constants'][key] is None ] for entry in remove_keys: if entry in self.default_variables: del self.default_variables[entry] del self.config['user_constants'][entry] warn_if_override(self.config, 'variables', self.default_variables) warn_if_override(self.config, 'numbered_vars', self.default_variables) warn_if_override(self.config, 'user_constants', self.default_variables) warn_if_override(self.config, 'user_functions', self.default_functions) validate_no_collisions(self.config, keys=['variables', 'user_constants']) self.permitted_functions = get_permitted_functions( self.default_functions, self.config['whitelist'], self.config['blacklist'], self.config['user_functions']) # Set up the various lists we use self.functions, self.random_funcs = construct_functions( self.default_functions, self.config["user_functions"]) self.constants = construct_constants(self.default_variables, self.config["user_constants"]) self.suffixes = construct_suffixes(self.default_suffixes, self.config["metric_suffixes"]) # Construct the schema for sample_from # First, accept all VariableSamplingSets # Then, accept any list that RealInterval can interpret # Finally, single numbers or tuples of numbers will be handled by DiscreteSet schema_sample_from = Schema({ Required(varname, default=RealInterval()): Any(VariableSamplingSet, All(list, Coerce(RealInterval)), Coerce(DiscreteSet)) for varname in (self.config['variables'] + self.config['numbered_vars']) }) self.config['sample_from'] = schema_sample_from( self.config['sample_from'])
def __init__(self, config=None, **kwargs): """ Validate the FormulaGrader's configuration. First, we allow the ItemGrader initializer to construct the function list. We then construct the lists of functions, suffixes and constants. Finally, we refine the sample_from entry. """ super(FormulaGrader, self).__init__(config, **kwargs) # finish validating validate_blacklist_whitelist_config(self.default_functions, self.config['blacklist'], self.config['whitelist']) validate_no_collisions(self.config, keys=['variables', 'user_constants']) warn_if_override(self.config, 'variables', self.default_variables) warn_if_override(self.config, 'numbered_vars', self.default_variables) warn_if_override(self.config, 'user_constants', self.default_variables) warn_if_override(self.config, 'user_functions', self.default_functions) self.permitted_functions = get_permitted_functions( self.default_functions, self.config['whitelist'], self.config['blacklist'], self.config['user_functions']) # store the comparer utils self.comparer_utils = self.get_comparer_utils() # Set up the various lists we use self.functions, self.random_funcs = construct_functions( self.default_functions, self.config["user_functions"]) self.constants = construct_constants(self.default_variables, self.config["user_constants"]) self.suffixes = construct_suffixes(self.default_suffixes, self.config["metric_suffixes"]) # Construct the schema for sample_from # First, accept all VariableSamplingSets # Then, accept any list that RealInterval can interpret # Finally, single numbers or tuples of numbers will be handled by DiscreteSet schema_sample_from = Schema({ Required(varname, default=RealInterval()): Any(VariableSamplingSet, All(list, Coerce(RealInterval)), Coerce(DiscreteSet)) for varname in (self.config['variables'] + self.config['numbered_vars']) }) self.config['sample_from'] = schema_sample_from( self.config['sample_from'])
def __init__(self, config=None, **kwargs): super(IntegralGrader, self).__init__(config, **kwargs) self.true_input_positions = self.validate_input_positions( self.config['input_positions']) # The below are copied from FormulaGrader.__init__ validate_blacklist_whitelist_config(self.default_functions, self.config['blacklist'], self.config['whitelist']) validate_no_collisions(self.config, keys=['variables', 'user_constants']) warn_if_override(self.config, 'variables', self.default_variables) warn_if_override(self.config, 'user_constants', self.default_variables) warn_if_override(self.config, 'user_functions', self.default_functions) self.permitted_functions = get_permitted_functions( self.default_functions, self.config['whitelist'], self.config['blacklist'], self.config['user_functions']) self.functions, self.random_funcs = construct_functions( self.default_functions, self.config["user_functions"]) self.constants = construct_constants(self.default_variables, self.config["user_constants"]) # Construct the schema for sample_from # First, accept all VariableSamplingSets # Then, accept any list that RealInterval can interpret # Finally, single numbers or tuples of numbers will be handled by DiscreteSet schema_sample_from = Schema({ Required(varname, default=RealInterval()): Any(VariableSamplingSet, All(list, Coerce(RealInterval)), Coerce(DiscreteSet)) for varname in self.config['variables'] }) self.config['sample_from'] = schema_sample_from( self.config['sample_from'])