module(...,package.seeall) -------------------------------funções--------------------------- -- calcula o ajuste em uma determinada janela de tamanho "size_window" function WindowfitCalculator(cs1,attr1, cs2, attr2, size_window, cell_starter) local sum_difer_in_window = 0 --local current_cell = cs1:getCell(cell_starter) --print("begin") for i = 0 , size_window , 1 do for j = 0 , size_window , 1 do --print("entrou") c = Coord{x = cell_starter.x + i, y = cell_starter.y + j} cell_1 = cs1:getCell(c) if cell_1 ~= nil then cell_2 = cs2:getCell(c) --print(cell_1[attr1], cell_2[attr2]) -- implementação da diferença entre as cenas sum_difer_in_window = sum_difer_in_window + (cell_1[attr1] - cell_2[attr2])^2 --print(sum_difer_in_window) end end end --print("end") --io.read() return math.sqrt(sum_difer_in_window) end -- verifica a dimensão maxima do espaço celular function selectBiggestAxisCell(cs) local BiggestCell = {["x"] = 0, ["y"] = 0} forEachCell(cs, function(cell) if BiggestCell.x < cell.x then BiggestCell.x = cell.x end if BiggestCell.y < cell.y then BiggestCell.y = cell.y end end ) local Dimension if BiggestCell.x == BiggestCell.y then Dimension = BiggestCell.x elseif BiggestCell.x > BiggestCell.y then Dimension = BiggestCell.x else Dimension = BiggestCell.y end return Dimension end -- função que faz transcorrer a janela de amostragem pelo espaço celular function WindowRun(cs1, attr1, cs2, attr2, size_window, reso_max, axis_max) local i, j local cell_pointer, horizontal_limit, side_limit local fits_sum = 0 local amount_window = 0 for i = 0, reso_max, 1 do for j = 0, reso_max, 1 do cell_pointer = {x = j , y = i} fits_sum = fits_sum + WindowfitCalculator(cs1, attr1, cs2, attr2, size_window - 1, cell_pointer) -- reconhece que encostou na lateral amount_window = amount_window + 1 side_limit = j + size_window if side_limit > reso_max then break end end -- reconhece que encostou no fundo horizontal_limit = i + size_window -- reconhece que chegou ao fim do espaço celular, e retorna o tamanho da janela com -- a média dos ajustes das janelas if horizontal_limit > reso_max then return size_window, fits_sum/amount_window end end end function multipleResolutionMethod(cs1, attr1, cs2, attr2) if cs1:size() ~= cs2:size() then print("Error: Data bases with diferrent sizes") return nil end local reso_max = selectBiggestAxisCell(cs1) local table_of_fits = {} local size_window local size,fit print("Estimating agreement between celular spaces. Please, wait a moment...") for size_window = 1, reso_max + 1 , 1 do size, fit = WindowRun(cs1, attr1, cs2, attr2, size_window, reso_max) table_of_fits[size_window] = {SizeWindow = size, fitWindow = fit} end -- gera o grafico dos ajustes cell_fit = Cell{size = 0 , fit = 0} cell_fit:createObserver( OBSERVERS.GRAPHIC, {"fit","size"}, {"Multiple Resolution","Fit's Curve","Window Size","Fit"} ) print("Window Size","Window fit") for i, window in ipairs(table_of_fits) do cell_fit.size = window.SizeWindow cell_fit.fit = window.fitWindow print(window.SizeWindow, window.fitWindow) cell_fit:notifyObservers() end return table_of_fits end