Exemplo n.º 1
0
def test_out_prediction():
    setting = SpatialSettings(debug = False, min_overlap = 1, desired_local_activity = 4, connected_pct = 1,
                               connected_perm = 0.01, xinput = 3, yinput = 3, potential_radius = 4, xdimension = 3,
                               ydimension = 3, initial_inhibition_radius = 1, permanence_inc = 0.1, permanence_dec = 0.1,
                               max_boost = 2, min_duty_cycle_fraction = 0.2)
    setting.debug = True

    setting.min_overlap = 1
    setting.desired_local_activity = 1
    setting.connected_pct = 1
    setting.xinput = 4
    setting.yinput = 4
    setting.potential_radius = 2
    setting.xdimension = 4
    setting.ydimension = 1
    setting.initial_inhibition_radius = 2

    r = Region(setting, SimpleMapper())
    inp = [[1, 0, 1, 0], [1, 0, 1, 0], [1, 0, 1, 0], [1, 0, 1, 0]]
    r.step_forward(inp)
    res = r.out_prediction([[1, 0, 1, 0]])
    # print(res)
    for i in range(len(res)):
        for j in range(len(res[0])):
            if inp[i][j] ==1:
                assert res[i][j] > 0
Exemplo n.º 2
0
from spatialPooler.sp_region import Region as SpatialPoolerRegion
from apps.settings import *

input_settings = InputSettings(SCALE=1, STEPS_NUMBER=300)
generator = ListImages(12)

spatial_settings = SpatialSettings(debug = False, min_overlap = 1, desired_local_activity = 2, connected_pct = 1,
                           connected_perm = 0.1, xinput = generator.square_size, yinput = generator.square_size,
                           potential_radius = 4, xdimension = 12, ydimension = 12, initial_inhibition_radius = 2,
                           permanence_inc = 0.02, permanence_dec = 0.1, max_boost = 2, min_duty_cycle_fraction = 0.2)

temporal_settings = TemporalSettings(region_size=spatial_settings.xdimension, column_size=4, initial_permanence=0.5,
                                     dendrite_activate_threshold=1, dendrite_permanence_inc_delta=0.02,
                                     dendrite_permanence_dec_delta=-0.1, passive_time_to_active_threshold=1000,
                                     synapse_threshold=0.45)


spatial_pooler_region = SpatialPoolerRegion(spatial_settings=spatial_settings, mapper=SquareMapperAutoRadius())
temporal_pooler_region = TemporalPoolerRegion(temporal_settings=temporal_settings)

for i in range(input_settings.STEPS_NUMBER):
    generator.out()
    outdata=spatial_pooler_region.step_forward(generator.get_data())
    print_matrix(to_binmatrix(outdata))
    temporal_pooler_region.step_forward(outdata)
    temporal_pooler_region.out_prediction()
    cols=temporal_pooler_region.columns
    imagined_input = spatial_pooler_region.out_prediction(cols, temporal_settings.region_size)

    generator.move()