Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Cnr
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
Cnr
Commits
996d673a
Commit
996d673a
authored
3 years ago
by
Ikenna Oluigbo
Browse files
Options
Downloads
Patches
Plain Diff
CNI encoding
parent
3aae5642
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
+64
-0
64 additions, 0 deletions
CNI.py
with
64 additions
and
0 deletions
CNI.py
0 → 100644
+
64
−
0
View file @
996d673a
import
math
import
numpy
as
np
from
prettytable
import
PrettyTable
from
build_graph
import
*
G
=
build
()
nodes_array
=
np
.
array
(
G
.
nodes
)
#nx.write_gpickle(G, "proteins.pkl")
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
CNI
():
neighbor_labels
=
node_neighbor_labels
(
G
)
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
]
#print(node, '>>>', 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
]
=
round
(
math
.
log
(
CNI_Sum
),
2
)
return
CNI_original
,
CNI_Nodes_log
CNI_original
,
CNI_log
=
CNI
()
CNI_Table
=
PrettyTable
([
'
Node ID
'
,
'
CNI ORIGINAL
'
,
'
CNI LOG VALUES
'
])
for
i
in
range
(
len
(
CNI_original
.
keys
())):
CNI_Table
.
add_row
([
nodes_array
[
i
],
CNI_original
[
nodes_array
[
i
]],
CNI_log
[
nodes_array
[
i
]]])
#print(CNI_Table)
\ No newline at end of file
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