Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SemiSupervisedEmbeddingFramework
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hamida Seba
SemiSupervisedEmbeddingFramework
Commits
e86fbbe0
Commit
e86fbbe0
authored
2 years ago
by
Ikenna Oluigbo
Browse files
Options
Downloads
Patches
Plain Diff
CNR encoding
parent
3d178d4c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CNI.py
+56
-0
56 additions, 0 deletions
CNI.py
with
56 additions
and
0 deletions
CNI.py
0 → 100644
+
56
−
0
View file @
e86fbbe0
'''
Compact neighborhood Encoding using Bijection Function
'''
import
math
import
numpy
as
np
from
builder
import
*
neighbor_labels
,
labels_dict
=
node_neighbor_labels
()
only_labels
=
list
(
set
(
labels_dict
.
values
()))
G
=
build_graph
()
def
cantor_pairing
(
x
,
y
):
if
x
>
(
y
+
x
-
1
):
return
0
if
y
+
x
-
1
==
1
:
return
1
st
=
1
i
=
1
t
=
y
while
t
<=
(
y
+
x
-
1
):
st
*=
t
t
+=
1
while
(
i
<=
x
)
and
(
st
%
i
==
0
)
and
(
st
>
0
):
st
=
st
/
i
i
+=
1
return
st
def
CNR
():
CNI_Nodes_log
=
{}
CNI_original
=
{}
for
node
in
G
.
nodes
:
visited
=
[]
CNI_list
=
[]
CNI_Sum
=
0
hop_labels
=
sorted
(
neighbor_labels
[
node
])
#Returns Labels of Node neighbors
hop_count
=
np
.
zeros
(
len
(
only_labels
))
for
label
in
only_labels
:
if
label
in
hop_labels
:
hop_count
[
only_labels
.
index
(
label
)]
=
hop_labels
.
count
(
label
)
#returns counts of unique neighbor labels
else
:
0
hop_count
=
[
int
(
n
)
for
n
in
hop_count
]
for
i
in
range
(
len
(
only_labels
)):
visited
.
append
(
hop_count
.
pop
(
0
))
CNI_list
.
append
((
only_labels
[
i
],
sum
(
visited
)))
#Returns the label, hop count sum pair
for
j
in
CNI_list
:
CNI_Sum
+=
cantor_pairing
(
j
[
0
],
j
[
1
])
CNI_original
[
node
]
=
int
(
CNI_Sum
)
if
CNI_Sum
==
1
:
CNI_Nodes_log
[
node
]
=
CNI_Sum
else
:
CNI_Nodes_log
[
node
]
=
math
.
log
(
CNI_Sum
)
return
(
CNI_original
,
CNI_Nodes_log
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment