home | news | discuss | issues | license LURE: row |
|
---|---|
Rows in a tabletim@menzies.us A |
local ID= require "id"
local LST= require "lists"
local NUM= require "num"
|
|
local function create()
return {id=ID.new(), cells={}} end
|
When |
local function update(i,cells,t)
i.cells=LST.copy(cells)
for _,head in pairs(t.all.cols) do
head.what.update(head, cells[head.pos]) end
return i end
|
Copied |
local function copy(i)
local j = create()
j.cells = LST.copy(i.cells) -- get different cells
j.id = i.id -- keep their same id (for reference purposes)
return j end
|
The distance between two |
local function distance(i,j,t)
local d,n,p=0,10^-64,0.5
for _,col in pairs(t.x.cols) do
local f = col.what.distance
local d1,n1 = f(col, i.cells[col.pos], j.cells[col.pos])
d = d + d1
n = n + n1 end
return d^p / n^p end
|
A |
local function x(i,west,east,t, c)
local c= c or distance(west,east,t)
local b= distance(i,east,t)
local a= distance(i,west, t)
return (a^2 + c^2 - b^2) / (2*c),c
end
|
Imagine we have some function |
local function extrapolate(i,west, east,f,t,c)
local x0,c = x(i,west,east,t,c)
local x1,x2,y1,y2 = 0,c,f(west,t), f(east,t)
local m = (y2 - y1) / (x2 - x1) -- rise/run
local b = y2 - m*x2 -- the slope
return m * x0 + b end
|
To see if row |
local function dominate1(i,j,t)
local e,n = 2.71828,#t.goals
local sum1,sum2=0,0
for _,col in pairs(t.goals) do
local w= col.weight
local x= NUM.norm(col, i.cells[col.pos])
local y= NUM.norm(col, j.cells[col.pos])
sum1 = sum1 - e^(w * (x-y)/n)
sum2 = sum2 - e^(w * (y-x)/n)
end
return sum1/n < sum2/n end
|
Count how many times row |
local function dominate(i,t,f)
f = f or dominate1
local tmp = 0
for x,j in pairs(t.rows) do
if i.id ~= j.id then
if f(i,j,t) then
tmp= tmp + 1 end end end
return tmp end
|
External Interface |
return {create=create, update=update,distance=distance,dominate=dominate,copy=copy}
|
LegalLURE, Copyright (c) 2017, Tim Menzies All rights reserved, BSD 3-Clause License Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|