Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
mcc-experiments
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container 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
Maxime BURON
mcc-experiments
Commits
94ce96b6
Commit
94ce96b6
authored
4 months ago
by
Maxime BURON
Browse files
Options
Downloads
Patches
Plain Diff
first commit
parents
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
mar.net
+76
-0
76 additions, 0 deletions
mar.net
mcc.py
+77
-0
77 additions, 0 deletions
mcc.py
test.net
+53
-0
53 additions, 0 deletions
test.net
with
206 additions
and
0 deletions
mar.net
0 → 100644
+
76
−
0
View file @
94ce96b6
net {
name = mar;
software = "aGrUM 1.17.1";
node_size = (50 50);
}
node A {
states = (0 1 );
label = "A";
ID = "A";
}
node B {
states = (0 1 );
label = "B";
ID = "B";
}
node C {
states = (0 1 );
label = "C";
ID = "C";
}
node Ia {
states = (0 1 );
label = "Ia";
ID = "Ia";
}
node Ib {
states = (0 1 );
label = "Ib";
ID = "Ib";
}
node Ic {
states = (0 1 );
label = "Ic";
ID = "Ic";
}
potential (A) {
data = ( 0.561407 0.438593);
}
potential ( B | A ) {
data =
(( 0.515132 0.484868) % A=0
( 0.371633 0.628367)); % A=1
}
potential ( C | B ) {
data =
(( 0.515132 0.484868) % B=0
( 0.371633 0.628367)); % B=1
}
potential (Ia) {
data = ( 0.8 0.2);
}
potential ( Ib | A ) {
data =
(( 0.664707 0.335293) % A=0
( 0.344864 0.655136)); % A=1
}
potential ( Ic | B ) {
data =
(( 0.664707 0.335293) % B=0
( 0.344864 0.655136)); % B=1
}
This diff is collapsed.
Click to expand it.
mcc.py
0 → 100755
+
77
−
0
View file @
94ce96b6
#!.venv/bin/python3
import
pyAgrum
as
gum
import
psycopg2
import
sys
import
argparse
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"
BNFile
"
,
help
=
"
Bayesian network file
"
)
parser
.
add_argument
(
"
DBSize
"
,
help
=
"
size of the database
"
)
args
=
parser
.
parse_args
()
# inputs
bn_file
=
args
.
BNFile
db_size
=
int
(
args
.
DBSize
)
out_file
=
"
mcc.csv
"
table_name
=
"
test
"
# loading the BN file
bn
=
gum
.
loadBN
(
bn_file
)
var_names
=
sorted
(
list
(
bn
.
names
()))
# generating the CSV file
g
=
gum
.
BNDatabaseGenerator
(
bn
)
g
.
drawSamples
(
db_size
)
g
.
toCSV
(
out_file
)
# PG connection
conn
=
psycopg2
.
connect
(
database
=
"
mcc
"
,
user
=
'
postgres
'
,
password
=
'
postgres
'
,
host
=
'
127.0.0.1
'
,
port
=
'
5432
'
)
conn
.
autocommit
=
True
cursor
=
conn
.
cursor
()
# deleting the existing table
deletion_sql
=
"
DROP TABLE IF EXISTS {};
"
.
format
(
table_name
)
cursor
.
execute
(
deletion_sql
)
# creating the table to store the
col_def
=
map
(
lambda
name
:
"
{} int NOT NULL
"
.
format
(
name
),
var_names
)
creation_sql
=
"
CREATE TABLE {}({});
"
.
format
(
table_name
,
"
,
"
.
join
(
col_def
))
print
(
creation_sql
)
cursor
.
execute
(
creation_sql
)
# loading the CSV data to the table
with
open
(
out_file
,
"
r
"
)
as
file
:
next
(
file
)
# skip the header's line
cursor
.
copy_from
(
file
,
table_name
,
sep
=
"
,
"
,
null
=
""
)
missing_selects
=
[]
for
v
in
var_names
:
if
not
v
.
lower
().
startswith
(
'
i
'
)
and
v
[
1
:]
not
in
var_names
:
missing_selects
.
append
(
"
case when i{}=1 then NULL ELSE {} END
"
.
format
(
v
,
v
))
elif
not
v
.
lower
().
startswith
(
'
i
'
):
missing_selects
.
append
(
v
)
missing_data_table
=
"
{}_star
"
.
format
(
table_name
)
deletion_sql
=
"
DROP TABLE IF EXISTS {};
"
.
format
(
missing_data_table
)
cursor
.
execute
(
deletion_sql
)
missing_data_sql
=
"
CREATE TABLE {} AS SELECT {} FROM {}
"
.
format
(
missing_data_table
,
"
,
"
.
join
(
missing_selects
),
table_name
)
print
(
missing_data_sql
)
cursor
.
execute
(
missing_data_sql
)
###### Imputation
import
numpy
as
np
import
pandas
as
pd
from
sklearn.impute
import
KNNImputer
cursor
.
execute
(
"
SELECT * FROM {}
"
.
format
(
missing_data_table
))
tuples_list
=
cursor
.
fetchall
()
df
=
pd
.
DataFrame
(
tuples_list
)
imputer
=
KNNImputer
(
n_neighbors
=
2
)
impute
=
imputer
.
fit_transform
(
df
)
print
(
impute
)
This diff is collapsed.
Click to expand it.
test.net
0 → 100644
+
53
−
0
View file @
94ce96b6
net {
name = unnamedBN;
software = "aGrUM 1.17.1";
node_size = (50 50);
}
node B {
states = (0 1 );
label = "B";
ID = "B";
}
node A {
states = (0 1 );
label = "A";
ID = "A";
}
node Ia {
states = (0 1 );
label = "Ia";
ID = "Ia";
}
node Ib {
states = (0 1 );
label = "Ib";
ID = "Ib";
}
potential ( B | A ) {
data =
(( 0.515132 0.484868) % A=0
( 0.371633 0.628367)); % A=1
}
potential (A) {
data = ( 0.561407 0.438593);
}
potential (Ib) {
data = ( 0.8 0.2);
}
potential ( Ia | B ) {
data =
(( 0.664707 0.335293) % B=0
( 0.344864 0.655136)); % B=1
}
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