示例#1
0
def _make_modules(entropy, num_modules_composed):
    """Returns modules given "difficulty" parameters."""
    fns = {
        'gcd': gcd,
        'lcm': lcm,
        'div_remainder': div_remainder,
        'is_prime': is_prime,
        'is_factor': is_factor,
        'round_number': round_number,
        'place_value': place_value,
        'list_prime_factors': list_prime_factors,
    }

    # These modules don't have both pure and composed.
    modules = {
        'base_conversion': functools.partial(base_conversion, *entropy),
    }

    sample_args_pure = composition.PreSampleArgs(1, 1, *entropy)
    sample_args_composed = composition.PreSampleArgs(num_modules_composed[0],
                                                     num_modules_composed[1],
                                                     *entropy)

    for name, module in six.iteritems(fns):
        modules[name] = functools.partial(module, None, sample_args_pure)
        modules[name + '_composed'] = functools.partial(
            module, None, sample_args_composed)

    return modules
示例#2
0
def _make_modules(entropy):
    """Returns modules given "difficulty" parameters."""
    sample_args_pure = composition.PreSampleArgs(1, 1, *entropy)
    sample_args_composed = composition.PreSampleArgs(2, 4, *entropy)

    return {
        # Solving equations:
        'polynomial_roots':
        functools.partial(polynomial_roots, None, sample_args_pure),
        'polynomial_roots_composed':
        functools.partial(polynomial_roots, None, sample_args_composed),
        'linear_1d':
        functools.partial(solve_linear_1d, None, sample_args_pure),
        'linear_1d_composed':
        functools.partial(solve_linear_1d, None, sample_args_composed),
        'linear_2d':
        functools.partial(solve_linear_2d, None, sample_args_pure),
        'linear_2d_composed':
        functools.partial(solve_linear_2d, None, sample_args_composed),

        # Sequences:
        'sequence_next_term':
        functools.partial(sequence_next_term, *entropy),
        'sequence_nth_term':
        functools.partial(sequence_nth_term, *entropy),
    }
def test_extra():
  """Returns dict of extrapolation testing modules."""
  sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE)
  add_sub_sample_args_pure = composition.PreSampleArgs(
      1, 1, *_ADD_SUB_ENTROPY_EXTRAPOLATE)

  train_length = arithmetic.length_range_for_entropy(_ENTROPY_TRAIN[1])[1]
  def extrapolate_length():
    return random.randint(
        train_length + 1, train_length + _EXTRAPOLATE_EXTRA_LENGTH)

  def add_sub_multiple_longer():
    return add_sub_multiple(_INT, sample_args_pure, length=extrapolate_length())
  def mul_div_multiple_longer():
    return mul_div_multiple(_INT, sample_args_pure, length=extrapolate_length())
  def mixed_longer():
    return mixed(_INT, sample_args_pure, length=extrapolate_length())

  return {
      'add_or_sub_big': functools.partial(
          add_or_sub, None, add_sub_sample_args_pure),
      'mul_big': functools.partial(mul, None, sample_args_pure),
      'div_big': functools.partial(div, None, sample_args_pure),
      'add_sub_multiple_longer': add_sub_multiple_longer,
      'mul_div_multiple_longer': mul_div_multiple_longer,
      'mixed_longer': mixed_longer,
  }
def _make_modules(entropy, add_sub_entropy):
  """Returns modules given "difficulty" parameters."""
  sample_args_pure = composition.PreSampleArgs(1, 1, *entropy)
  add_sub_sample_args_pure = composition.PreSampleArgs(1, 1, *add_sub_entropy)

  # TODO(b/124039105): consider composed modules?
  return {
      # Addition and subtraction of integers (and decimals)
      'add_or_sub': functools.partial(
          add_or_sub, None, add_sub_sample_args_pure),
      'add_sub_multiple': functools.partial(
          add_sub_multiple, _INT, sample_args_pure),
      'add_or_sub_in_base': functools.partial(
          add_or_sub_in_base, sample_args_pure),

      # Multiplication and division
      'mul': functools.partial(mul, None, sample_args_pure),
      'div': functools.partial(div, None, sample_args_pure),
      'mul_div_multiple': functools.partial(
          mul_div_multiple, _INT_OR_RATIONAL, sample_args_pure),

      # All together!
      'mixed': functools.partial(mixed, _INT_OR_RATIONAL, sample_args_pure),

      # And some other arithmetic-related stuff.
      'nearest_integer_root': functools.partial(
          nearest_integer_root, sample_args_pure),
      'simplify_surd': functools.partial(simplify_surd, None, sample_args_pure),
  }
def _make_modules(entropy):
    """Returns modules given "difficulty" parameters."""
    sample_args_pure = composition.PreSampleArgs(1, 1, *entropy)
    sample_args_composed = composition.PreSampleArgs(2, 4, *entropy)
    sample_args_mixed = composition.PreSampleArgs(1, 4, *entropy)

    return {
        'coefficient_named':
        functools.partial(coefficient_named, None, sample_args_pure),
        'evaluate':
        functools.partial(evaluate, None, sample_args_pure),
        'evaluate_composed':
        functools.partial(evaluate, None, sample_args_composed),
        # TODO(b/124038948): consider doing pure sample args for 'add'?
        'add':
        functools.partial(add, None, sample_args_mixed),
        'expand':
        functools.partial(expand, None, sample_args_pure),
        'collect':
        functools.partial(collect, None, sample_args_pure),
        'compose':
        functools.partial(compose, None, sample_args_mixed),

        # Rearranging powers:
        'simplify_power':
        functools.partial(simplify_power, None, sample_args_pure),
    }
示例#6
0
def _make_modules(entropy):
  """Returns modules given "difficulty" parameters."""
  sample_args_pure = composition.PreSampleArgs(1, 1, *entropy)
  sample_args_composed = composition.PreSampleArgs(2, 4, *entropy)

  return {
      'differentiate_composed': functools.partial(
          differentiate_univariate, None, sample_args_composed),
      'differentiate': functools.partial(differentiate, None, sample_args_pure),
  }
 def shard_spec(self, shard):
     if shard == 0:
         entropy = composition.PreSampleArgs(1, 1, *_ADD_SUB_ENTROPY_TRAIN)
         entropy_fn = _entropy_for_pair
         bounded = False
     else:
         entropy = composition.PreSampleArgs(1, 1,
                                             *_ADD_SUB_ENTROPY_EXTRAPOLATE)
         entropy_fn = _entropy_for_ood_hard_pair
         bounded = True
     return entropy, entropy_fn, bounded
示例#8
0
def test_extra():
    """Returns dict of extrapolation testing modules."""
    sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE)

    def sort_count():
        lower = _sort_count_range(_ENTROPY_TRAIN[1])[1]
        return random.randint(lower + 1, lower + _EXTRAPOLATION_EXTRA_COUNT)

    def closest_count():
        lower = _closest_count_range(_ENTROPY_TRAIN[1])[1]
        return random.randint(lower + 1, lower + _EXTRAPOLATION_EXTRA_COUNT)

    def kth_biggest_more():
        return kth_biggest(sample_args_pure, count=sort_count())

    def sort_more():
        return sort(sample_args_pure, count=sort_count())

    def closest_more():
        return closest(sample_args_pure, count=closest_count())

    return {
        'kth_biggest_more': kth_biggest_more,
        'sort_more': sort_more,
        'closest_more': closest_more,
    }
示例#9
0
def test_extra():
    """Returns dict of extrapolation testing modules."""
    sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE)
    return {
        'polynomial_roots_big':
        functools.partial(polynomial_roots, None, sample_args_pure),
    }
示例#10
0
def test_extra():
    """Returns dict of extrapolation testing modules."""
    sample_args_pure = composition.PreSampleArgs(1, 1, *_ENTROPY_EXTRAPOLATE)
    return {
        'round_number_big': functools.partial(round_number, None,
                                              sample_args_pure),
        'place_value_big': functools.partial(place_value, None,
                                             sample_args_pure),
    }
示例#11
0
def _make_modules(entropy):
    """Returns modules given "difficulty" parameters."""
    sample_args_pure = composition.PreSampleArgs(1, 1, *entropy)
    sample_args_composed = composition.PreSampleArgs(2, 4, *entropy)

    return {
        'pair':
        functools.partial(pair, sample_args_pure),
        'pair_composed':
        functools.partial(pair, sample_args_composed),
        'kth_biggest':
        functools.partial(kth_biggest, sample_args_pure),
        'kth_biggest_composed':
        functools.partial(kth_biggest, sample_args_composed),
        'closest':
        functools.partial(closest, sample_args_pure),
        'closest_composed':
        functools.partial(closest, sample_args_composed),
        'sort':
        functools.partial(sort, sample_args_pure),
        'sort_composed':
        functools.partial(sort, sample_args_composed),
    }