0% found this document useful (0 votes)
18 views21 pages

Pseudo Code

The document contains pseudo code for calculating mutual information between features of a dataset and finding the densest subgraph after excluding nodes. It shows code for excluding one node, two nodes, and three nodes to find the subgraph with maximum density in each case. Various machine learning libraries are imported and mutual information scores between all features are calculated and stored in a matrix. The matrix is then processed to find the total connection strength for each subgraph after excluding nodes and identify the configuration with highest density.

Uploaded by

ikvklxpglf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views21 pages

Pseudo Code

The document contains pseudo code for calculating mutual information between features of a dataset and finding the densest subgraph after excluding nodes. It shows code for excluding one node, two nodes, and three nodes to find the subgraph with maximum density in each case. Various machine learning libraries are imported and mutual information scores between all features are calculated and stored in a matrix. The matrix is then processed to find the total connection strength for each subgraph after excluding nodes and identify the configuration with highest density.

Uploaded by

ikvklxpglf
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

1.

Pseudo code for Finding


mutual info:
IMPORT csv

IMPORT numpy as np

IMPORT pandas as pd

IMPORT matplotlib.pyplot as plt

IMPORT seaborn as sns

from sklearn.model_selection IMPORT train_test_split

from sklearn.feature_selection IMPORT mutual_info_classif

from sklearn.metrics IMPORT mutual_info_score

from sklearn.ensemble IMPORT RandomForestClassifier

from sklearn.metrics IMPORT accuracy_score


from sklearn.feature_selection IMPORT VarianceThreshold,
mutual_info_classif, mutual_info_regression

from sklearn.feature_selection IMPORT SelectKBest, SelectPercentile

SET datafile TO open('diabetes.csv', 'r')

SET datareader TO csv.reader(datafile, delimiter Is Equals to ';')

data Is Equals to []

SET isHeading TO True

FOR row IN datareader:

IF not isHeading:

(list(map(float,row[0].split(",")))) to data

SET isHeading TO False

SET actual_data TO []
FOR i IN range(len(data[0])):

SET temp TO []

FOR j IN range(len(data)):

append(data[j][i]) to temp

append(temp) to actual_data

SET actual_data TO actual_data[:len(actual_data)-1]

lg Is Equals to []

DEFINE FUNCTION my_function(fname, lname):

OUTPUT(fname + " " + lname)


CALL my_function("Emil", "Refsnes")

FOR i IN range(len(actual_data)):

FOR j IN range(len(actual_data)):

IF i Is Not Equal to j:

SET a , b TO actual_data[i], actual_data[j]

a Is Equals to np.array(a)

b Is Equals to np.array(b)

append(mutual_info_score(a,b)) to lg

OUTPUT(len(lg))

OUTPUT(lg)
2. Pseudo code for Finding
densest subgraph after
excluding one node:
IMPORT csv

IMPORT numpy as np

IMPORT pandas as pd

IMPORT matplotlib.pyplot as plt

IMPORT seaborn as sns

from sklearn.feature_selection IMPORT mutual_info_classif

from sklearn.metrics IMPORT mutual_info_score

from sklearn.model_selection IMPORT train_test_split

from sklearn.ensemble IMPORT RandomForestClassifier

from sklearn.metrics IMPORT accuracy_score


from sklearn.feature_selection IMPORT VarianceThreshold,
mutual_info_classif, mutual_info_regression

from sklearn.feature_selection IMPORT SelectKBest, SelectPercentile

SET datafile TO open('diabetes.csv', 'r')

SET datareader TO csv.reader(datafile, delimiter=';')

SET data TO []

SET isHeading TO True

FOR row IN datareader:

IF not isHeading:

append (list(map(float,row[0].split(",")))) to data

SET isHeading TO False

SET actual_data TO []
FOR i IN range(len(data[0])):

SET temp TO []

FOR j IN range(len(data)):

append (data[j][i]) to temp

append (temp) to actual_data

SET actual_data TO actual_data[:len(actual_data)-1]

lg EQUALS []

FOR i IN range(len(actual_data)):

SET temp TO []

FOR j IN range(len(actual_data)):
IF i is Not Equals to j:

SET a , b TO actual_data[i], actual_data[j]

SET a TO np.array(a)

SET b TO np.array(b)

append (mutual_info_score(a,b)) to temp

ELSE:

append (0.0) to temp

append(temp) to lg

SET mx_density TO -1

SET excluded_node TO -1

FOR i IN range(len(lg)):

SET curr_sum TO 0
FOR j IN range(len(lg)):

FOR k IN range(len(lg[0])):

IF j is Not Equals to i and k is Not Equals to i:

curr_sum += lg[j][k]

SET curr_density TO curr_sum / 16.0

OUTPUT("density after excluding node",i, "is ", curr_density)

IF curr_density > mx_density:

SET mx_density TO curr_density

SET excluded_node TO i

OUTPUT("max density:",mx_density)

OUTPUT("The node which we are excluding:",excluded_node)


3. Pseudo code for After
excluding 2 node:
IMPORT csv

IMPORT numpy as np

IMPORT pandas as pd

IMPORT matplotlib.pyplot as plt

IMPORT seaborn as sns

from sklearn.feature_selection IMPORT mutual_info_classif

from sklearn.metrics IMPORT mutual_info_score

from sklearn.model_selection IMPORT train_test_split

from sklearn.ensemble IMPORT RandomForestClassifier


from sklearn.metrics IMPORT accuracy_score

from sklearn.feature_selection IMPORT VarianceThreshold,


mutual_info_classif, mutual_info_regression

from sklearn.feature_selection IMPORT SelectKBest,


SelectPercentile

SET datafile TO open('diabetes.csv', 'r')

SET datareader TO csv.reader(datafile, delimiter=';')

SET data TO []

SET isHeading TO True

FOR row IN datareader:

IF not isHeading:

append(list(map(float,row[0].split(",")))) TO data

SET isHeading TO False


SET actual_data TO []

FOR i IN range(len(data[0])):

SET temp TO []

FOR j IN range(len(data)):

append(data[j][i]) TO temp

append(temp) TO actual_data

SET actual_data TO actual_data[:len(actual_data)-1]

SET lg TO []
FOR i IN range(len(actual_data)):

SET temp TO []

FOR j IN range(len(actual_data)):

IF i IS NOT EQUALS TO j:

SET a , b TO actual_data[i], actual_data[j]

SET a EQUALS TO np.array(a)

SET b EQUALS TO np.array(b)

append(mutual_info_score(a,b)) TO temp

ELSE:

append(0.0) TO temp

append(temp) TO lg
SET mx_density TO -1

SET excluded_node TO []

FOR firstNode IN range(len(lg)):

FOR secondNode IN range(firstNode + 1, len(lg)):

SET curr_sum TO 0

FOR j IN range(len(lg)):

FOR k IN range(len(lg[0])):

IF j NOT EQUALS TO firstNode and k NOT EQUALS TO


firstNode and j NOT EQUALS TO secondNode and k NOT
EQUALS TO secondNode:

curr_sum += lg[j][k]

SET curr_density TO curr_sum / 16.0


OUTPUT("density after excluding node",firstNode," and
",secondNode, " is ", curr_density)

IF curr_density > mx_density:

SET mx_density TO curr_density

SET excluded_node TO [firstNode,secondNode]

OUTPUT("max density:",mx_density)

OUTPUT("The node which we are


excluding:",excluded_node)

4. Pseudo code for after


excluding 3 nodes.
IMPORT csv
IMPORT numpy as np

IMPORT pandas as pd

IMPORT matplotlib.pyplot as plt

IMPORT seaborn as sns

from sklearn.feature_selection IMPORT mutual_info_classif

from sklearn.metrics IMPORT mutual_info_score

from sklearn.model_selection IMPORT train_test_split

from sklearn.ensemble IMPORT RandomForestClassifier

from sklearn.metrics IMPORT accuracy_score

from sklearn.feature_selection IMPORT VarianceThreshold,


mutual_info_classif, mutual_info_regression

from sklearn.feature_selection IMPORT SelectKBest, SelectPercentile

SET datafile TO open('diabetes.csv', 'r')


SET datareader TO csv.reader(datafile, delimiter TO ';')

SET data TO []

SET isHeading TO True

FOR row IN datareader:

IF not isHeading:

append(list(map(float,row[0].split(",")))) to data

SET isHeading TO False

SET actual_data TO []

FOR i IN range(len(data[0])):

SET temp TO []

FOR j IN range(len(data)):
append(data[j][i]) to temp

append(temp) to actual_data

SET actual_data TO actual_data[:len(actual_data)-1]

SET lg TO []

FOR i IN range(len(actual_data)):

SET temp TO []

FOR j IN range(len(actual_data)):

IF i NOT EQUALS TO j:

SET a , b TO actual_data[i], actual_data[j]

SET a TO np.array(a)
SET b TO np.array(b)

append(mutual_info_score(a,b)) to temp

ELSE:

append(0.0) to temp

append(temp) to lg

SET mx_density TO -1

SET excluded_node TO []

FOR firstNode IN range(len(lg)):

FOR secondNode IN range(firstNode + 1, len(lg)):

FOR thirdNode IN range(secondNode + 1, len(lg)):

SET curr_sum TO 0

FOR j IN range(len(lg)):
FOR k IN range(len(lg[0])):

IF j NOT EQUALS TO firstNode and k NOT EQUALS TO


firstNode and j NOT EQUALS TO secondNode and k NOT EQUALS TO
secondNode and j NOT EQUALS TO thirdNode and k NOT EQUALS
TO thirdNode:

curr_sum += lg[j][k]

SET curr_density TO curr_sum / 16.0

OUTPUT("density after excluding


node",firstNode,",",secondNode,"," , thirdNode, " is ", curr_density)

IF curr_density > mx_density:

SET mx_density TO curr_density

SET excluded_node TO [firstNode, secondNode,


thirdNode]

OUTPUT("max density:",mx_density)

OUTPUT("The node which we are excluding:",excluded_node)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy