ARC environment classes

ARC Fitness

Factory


source

ARCFitnessFactory


def ARCFitnessFactory(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Initialize self. See help(type(self)) for accurate signature.

BaseARCFitness


source

BaseARCFitness


def BaseARCFitness(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Base class of an ARCFitness. This class is not used directly by developers, but defines the functionality common to all.

SumSquareOfDiff


source

SumSquareOfDiff


def SumSquareOfDiff(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

A function that sums the square of the diffrences of two arrays.

AverageMaxOfDiff


source

AverageMaxOfDiff


def AverageMaxOfDiff(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

A function that sums the square of the diffrences of two arrays.

Euclidean


source

Euclidean


def Euclidean(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

A function that sums the square of the diffrences of two arrays.

# import random
# random.seed(1)
np.random.seed(1)
# Create a 2-dimensional 3 by 3 numpy array of random floats from 0 to 9
random_array = np.random.uniform(4, 5, (3, 3))
print(random_array)
array_of_fours = np.full((3, 3), 4)
print(array_of_fours)
euc = Euclidean()
metric = euc(array_of_fours, random_array,  ['cells'])
print(metric)
np.random.seed(2)
random_array = np.random.uniform(4.49, 4.5, (3, 3))
print(random_array)
metric = euc(array_of_fours, random_array,  ['cells'])
print(metric)
[[4.417022   4.72032449 4.00011437]
 [4.30233257 4.14675589 4.09233859]
 [4.18626021 4.34556073 4.39676747]]
[[4 4 4]
 [4 4 4]
 [4 4 4]]
1.0610244787055576
[[4.49435995 4.49025926 4.49549662]
 [4.49435322 4.49420368 4.49330335]
 [4.49204649 4.49619271 4.49299655]]
0.49619270966350637

ARCDataProcessor


source

ARCDataProcessor


def ARCDataProcessor(
    config_dict, arc_dict
):

Initialize self. See help(type(self)) for accurate signature.

# Example usage:
print('Example using dims only')
config_dict = {
    'control_set': ['dims'],
    'input_set': ['env'],
    'dataset': 'train',
    'index': 0
}

arc_dict = {
    'test': [{'input': [[7, 0, 7], [7, 0, 7], [7, 7, 0]]}],
    'train': [
        {'input': [[0, 7, 7], [7, 7, 7], [0, 7, 7]], 'output': [[0, 0, 0, 0, 7, 7, 0, 7, 7], [0, 0, 0, 7, 7, 7, 7, 7, 7], [0, 0, 0, 0, 7, 7, 0, 7, 7], [0, 7, 7, 0, 7, 7, 0, 7, 7], [7, 7, 7, 7, 7, 7, 7, 7, 7], [0, 7, 7, 0, 7, 7, 0, 7, 7], [0, 0, 0, 0, 7, 7, 0, 7, 7], [0, 0, 0, 7, 7, 7, 7, 7, 7], [0, 0, 0, 0, 7, 7, 0, 7, 7]]}
        # Add more entries as needed
    ]
}

gp = ARCDataProcessor(config_dict, arc_dict)
info = gp.create_info()
print(info)
ins = gp.get_env_inputs_names()
print('names', ins)
inds = gp.get_env_inputs_indexes()
print('indexes', inds)

state, info = gp.get_state()
print(info)
print('fitness', gp.fitness_function(), state)
print()

for i in range(-2,-4,-1):
    actions = [i]
    gp.apply_actions(actions)
    state, info = gp.get_state()
    print(info)
    # print(len(values))
    print('fitness', gp.fitness_function(), state)
    print()
Example using dims only
{'num_actions': 1, 'grid_shape': 'equal', 'dims': 1}
names ['IWE']
indexes [0]
{'num_actions': 1, 'grid_shape': 'equal', 'dims': 1}
fitness 72 {'inputs': {'dims': {'env': (3,)}}}

{'num_actions': 1, 'grid_shape': 'equal', 'dims': 1}
fitness 128 {'inputs': {'dims': {'env': (1,)}}}

{'num_actions': 1, 'grid_shape': 'equal', 'dims': 1}
fitness 128 {'inputs': {'dims': {'env': (1,)}}}
# Example usage:

# print('Example using env inputs only')
# config_dict = {
#     'control_set': ['cells'],
#     'input_set': ['env'],
#     'dataset': 'train',
#     'index': 0
# }

# gp = ARCDataProcessor(config_dict, arc_dict)
# info = gp.create_info()
# print(info)
# ins = gp.get_env_inputs_names()
# print('names', ins)
# inds = gp.get_env_inputs_indexes()
# print('indexes', inds)

# state, info = gp.get_state()
# print(info)
# print('fitness', gp.fitness_function(), state)
# print()

# for i in range(-2,-4,-1):
#     actions = [i for j in range(info['num_actions'])]
#     print(actions)
#     gp.apply_actions(actions)
#     state, info = gp.get_state()
#     print(info)
#     # print(len(values))
#     print('fitness', gp.fitness_function(), state)
#     print()
# Example usage:

# print('Example using cells only')
# config_dict = {
#     'control_set': ['cells'],
#     'input_set': ['env','inputs'],
#     # 'input_set': ['env','inputs', 'outputs'],
#     'dataset': 'train',
#     'index': 0
# }

# gp = ARCDataProcessor(config_dict, arc_dict)
# info = gp.create_info()
# print(info)

# ins = gp.get_env_inputs_names()
# print('names', ins)
# inds = gp.get_env_inputs_indexes()
# print('indexes', inds)

# state, info = gp.get_state()
# print(info)
# print('fitness', gp.fitness_function(), state)
# print()

ARCEnv


source

ARCEnv


def ARCEnv(
    namespace:str=''
):

The main OpenAI Gym class. It encapsulates an environment with arbitrary behind-the-scenes dynamics. An environment can be partially or fully observed.

The main API methods that users of this class need to know are:

step
reset
render
close
seed

And set the following attributes:

action_space: The Space object corresponding to valid actions
observation_space: The Space object corresponding to valid observations
reward_range: A tuple corresponding to the min and max possible rewards

Note: a default reward range set to [-inf,+inf] already exists. Set it if you want a narrower range.

The methods are accessed publicly as “step”, “reset”, etc…

Example

# import pygame
# # Example usage:
# if os.name == 'nt': 
#     props = {'dir': 'C:\\packages\\arc-prize-2024', 'file_prefix':'arc-agi_training_', 'code':'007bbfb7', 'control_set': ['dims'], 'input_set': ['env'],'dataset': 'train'}
#     file_name = os.path.join(props['dir'], props['file_prefix']) + 'challenges.json' 
#     challenges_manager = ChallengesDataManager(file_name)
#     data = challenges_manager.get_data_for_key(props['code'])
#     print(data)
#     # arc_dict={}
#     # arc_dict['data'] = data
#     arc_env = ARCEnv()
#     arc_env.initialise(props, data)
#     arc_env.render()
#     #    print(state, fitness, done)
#     # print(arc_env.dimensions)
#     for i in range(6):
#         state, fitness, done, info = arc_env.step([1])
#         # print(state, fitness, done)
#         print(state, fitness, done, info)
#         arc_env.render()
#         sleep(1)
# sleep(2)
# arc_env.close()