Skip to content

Commit

Permalink
edits with Chee
Browse files Browse the repository at this point in the history
  • Loading branch information
boris-kz committed Feb 2, 2024
1 parent 2630a57 commit 2cbf69d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
5 changes: 0 additions & 5 deletions frame_2D_alg/frame_blobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
UNFILLED = -1
EXCLUDED = -2


class Cder__t(NamedTuple):
dy: Any
dx: Any
Expand All @@ -59,26 +58,22 @@ class Cder__t(NamedTuple):
def get_pixel(self, y: Real, x: Real) -> Tuple[Real, Real, Real]:
return self.dy[y, x], self.dx[y, x], self.g[y, x]


class Cbox(NamedTuple):
n: Real
w: Real
s: Real
e: Real

# properties
@property
def cy(self) -> Real: return (self.n + self.s) / 2
@property
def cx(self) -> Real: return (self.w + self.e) / 2
@property
def slice(self) -> Tuple[slice, slice]: return slice(self.n, self.s), slice(self.w, self.e)

# operators:
def __add__(self, other: Cbox) -> Cbox:
"""Add 2 boxes."""
return Cbox(min(self.n, other.n), min(self.w, other.w), max(self.s, other.s), max(self.e, other.e))

# methods
def accumulate(self, y: Real, x: Real) -> Cbox:
"""Box coordinate accumulation."""
Expand Down
71 changes: 37 additions & 34 deletions frame_2D_alg/vectorize_edge_blob/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
prefix 'C' denotes class
postfix 't' denotes tuple, multiple ts is a nested tuple
postfix '_' denotes array name, vs. same-name elements
prefix '_' denotes prior of two same-name variables
prefix '_' denotes prior or not-self of two same-name variables
prefix 'f' denotes flag
1-3 letter names are normally scalars, except for P and similar classes,
capitalized variables are normally summed small-case variables,
Expand Down Expand Up @@ -102,6 +102,36 @@ def comp(self, other: Cdertuple, rn: Real) -> Tuple[Cmd, Cmd, Cmd]: # comp_de
return ddertuplet, valt, rdnt


class CP(CBase): # horizontal blob slice P, with vertical derivatives per param if derP, always positive

ptuple: Cptuple = z(Cptuple()) # latuple: I,G,M,Ma, angle(Dy,Dx), L
rnpar_H: list = z([])
derH: CderH = z(CderH()) # [(mtuple, ptuple)...] vertical derivatives summed from P links
valt: Cmd = z(Cmd(0, 0)) # summed from the whole derH
rdnt: Cmd = z(Cmd(1, 1))
dert_: list = z([]) # array of pixel-level derts, ~ node_
cells: set = z(set()) # pixel-level kernels adjacent to P axis, combined into corresponding derts projected on P axis.
roott: list = z([None,None]) # PPrm,PPrd that contain this P, single-layer
axis: Cangle = Cangle(0, 1) # prior slice angle, init sin=0,cos=1
yx: tuple = None
'''
link_H: list = z([[]]) # all links per comp layer, rng+ or der+
dxdert_: list = z([]) # only in Pd
Pd_: list = z([]) # only in Pm
Mdx: int = 0 # if comp_dx
Ddx: int = 0
'''

# it's conditional in comp_rng, and we need to pass A,S, so it should be in comp_slice?

This comment has been minimized.

Copy link
@khanh93vn

khanh93vn Feb 2, 2024

Collaborator

Sorry, could you explain more?

This comment has been minimized.

Copy link
@boris-kz

boris-kz Feb 2, 2024

Author Owner

Check how it works in agg_recursion and comp_rim here, we need to add A,S to each link before comp.

def comp(self, other: CP, link_: List[CderP], rn: Real, S: Real = None):

dertuplet, valt, rdnt = self.ptuple.comp(other.ptuple, rn=rn)

if valt.m > ave_Pm * rdnt.m or valt.d > ave_Pm * rdnt.d:
derH = CderH([dertuplet])
link_ += [CderP(derH=derH, valt=valt, rdnt=rdnt, _P=self, P=other, S=S)]


class CderH(list): # derH is a list of der layers or sub-layers, each = ptuple_tv
__slots__ = []

Expand Down Expand Up @@ -143,35 +173,6 @@ def comp(self, other: CderH, rn: Real, n: Real = inf) -> Tuple[CderH, Cmd, Cmd]:
return dderH, valt, rdnt # new derLayer,= 1/2 combined derH


class CP(CBase): # horizontal blob slice P, with vertical derivatives per param if derP, always positive

ptuple: Cptuple = z(Cptuple()) # latuple: I,G,M,Ma, angle(Dy,Dx), L
rnpar_H: list = z([])
derH: CderH = z(CderH()) # [(mtuple, ptuple)...] vertical derivatives summed from P links
valt: Cmd = z(Cmd(0, 0)) # summed from the whole derH
rdnt: Cmd = z(Cmd(1, 1))
dert_: list = z([]) # array of pixel-level derts, ~ node_
cells: set = z(set()) # pixel-level kernels adjacent to P axis, combined into corresponding derts projected on P axis.
roott: list = z([None,None]) # PPrm,PPrd that contain this P, single-layer
axis: Cangle = Cangle(0, 1) # prior slice angle, init sin=0,cos=1
yx: tuple = None
'''
add L,S,A from links?
optional:
link_H: list = z([[]]) # all links per comp layer, rng+ or der+
dxdert_: list = z([]) # only in Pd
Pd_: list = z([]) # only in Pm
Mdx: int = 0 # if comp_dx
Ddx: int = 0
'''

def comp(self, other: CP, link_: List[CderP], rn: Real, S: Real = None):
dertuplet, valt, rdnt = self.ptuple.comp(other.ptuple, rn=rn)
if valt.m > ave_Pm * rdnt.m or valt.d > ave_Pm * rdnt.d:
derH = CderH([dertuplet])
link_ += [CderP(derH=derH, valt=valt, rdnt=rdnt, _P=self, P=other, S=S)]


class CderP(CBase): # tuple of derivatives in P link: binary tree with latuple root and vertuple forks

_P: CP # higher comparand
Expand All @@ -186,10 +187,10 @@ class CderP(CBase): # tuple of derivatives in P link: binary tree with latuple

def comp(self, link_: List[CderP], rn: Real):
dderH, valt, rdnt = self._P.derH.comp(self.P.derH, rn=rn, n=len(self.derH))

if valt.m > ave_Pd * rdnt.m or valt.d > ave_Pd * rdnt.d:
self.derH |= dderH; self.valt = valt; self.rdmt = rdnt # update derP not form new one
link_ += [self]

'''
max n of tuples per der layer = summed n of tuples in all lower layers: 1, 1, 2, 4, 8..:
lay1: par # derH per param in vertuple, layer is derivatives of all lower layers:
Expand All @@ -198,9 +199,11 @@ def comp(self, link_: List[CderP], rn: Real):
lay4: [[m,d], [md,dd], [[md1,dd1],[mdd,ddd]]]: 3 sLays, <=2 ssLays
'''


class Cgraph(CBase): # params of single-fork node_ cluster per pplayers

class Cgraph(CBase): # params of single-fork node_ cluster
'''
We may need nested ext: top level summed from link_, lower levels from nodes, per level of node_ hierarchy.
That's parallel to aggH( subH, so we should have ext packed in each subLay and aggLev, same as in derH?
'''

This comment has been minimized.

Copy link
@khanh93vn

khanh93vn Feb 2, 2024

Collaborator

Could you point to documentation of this kind of structure?

This comment has been minimized.

Copy link
@boris-kz

boris-kz Feb 2, 2024

Author Owner

Internalised positional params, right now it's angle A, sparsity S, and node_ len L. They're all summed from links, and then in higher der layers we have their derivatives: der_ext. We have them in links, Gs, and derHv, now adding to subHv and aggHv. Check comp_derHv and comp_ext.

fd: int = 0 # fork if flat layers?
ptuple: Cptuple = z(Cptuple()) # default P
derH: CderH = z(CderH()) # from PP, not derHv
Expand Down
6 changes: 4 additions & 2 deletions frame_2D_alg/vectorize_edge_blob/comp_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,16 @@ def sum2PP(root, P_, derP_, base_rdn, fd): # sum links in Ps and Ps in PP
P.derH += derH; P.valt += valt; P.rdnt += rdnt + (base_rdn, base_rdn) # P.derH sums link derH s
_P = derP._P # bilateral accum downlink, reverse d signs:
_P.derH -= derH; _P.valt += valt; _P.rdnt += rdnt + (base_rdn, base_rdn)
PP.A += derP.A
PP.S += derP.S
PP.link_ += [derP]

celly_,cellx_ = [],[]
for P in P_:
# accum Ps:
PP.ptuple += P.ptuple # accum ptuple
for y, x in P.cells:
PP.box = PP.box.accumulate(y, x)
for y,x in P.cells:
PP.box = PP.box.accumulate(y,x)
celly_ += [y]; cellx_ += [x]
# unilateral sum:
PP.derH += P.derH
Expand Down

0 comments on commit 2cbf69d

Please sign in to comment.