This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.decomposition import PCA | |
pca = PCA(n_components=5) | |
X_pca = pca.fit_transform(X) | |
print("Relative importance (fraction of unity):") | |
print(pca.explained_variance_ratio_) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.datasets import make_classification | |
n_features = 20 | |
feature_names = [f"x_{n}" for n in range(n_features)] | |
class_names = ['0', '1'] | |
X, y = make_classification(n_samples=1000, | |
n_features=n_features, n_informative=5, | |
n_redundant=5, n_repeated=0, | |
n_classes=2, n_clusters_per_class=1, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import networkx as nx | |
import dimod | |
from dwave.system import LeapHybridDQMSampler | |
... | |
dqm = dimod.DiscreteQuadraticModel() | |
num_nodes = G.number_of_nodes() | |
for i in G.nodes: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
y = [0 for _ in range(n)] | |
for i in range(n): | |
for k in range(Ap[i], Ap[i+1]): | |
j = Aj[k] | |
y[i] += Ax[k] * v[j] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def csr_to_csc(m, n, Ax, Aj, Ap): | |
nnz = len(Ax) | |
Bx = [0 for _ in range(nnz)] | |
Bi = [0 for _ in range(nnz)] | |
Bp = [0 for _ in range(m+1)] | |
# Count elements in each column: | |
cnt = [0 for _ in range(n)] | |
for k in range(nnz): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
m = 3 | |
n = 4 | |
S = [[None for _ in range(n+1)] for _ in range(m+1)] | |
def explore(i, j): | |
if i < 0 or j < 0 or i > m or j > n: | |
return 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
m = 3 | |
n = 4 | |
S = [[None for _ in range(n+1)] for _ in range(m+1)] | |
for i in range(m): | |
for j in range(n): | |
if i==0 or j==0: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
values = [5, 10, 15] | |
weights = [1, 2, 3] | |
W = 5 | |
n = len(values) | |
S = [[None for _ in range(W + 1)] for _ in range(n + 1)] | |
def knapsack(w, v, W, i): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env/python | |
graph = { | |
'A' : ['B','C'], | |
'B' : ['D', 'E'], | |
'C' : ['F'], | |
'D' : [], | |
'E' : [], | |
'F' : [] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/env/python | |
graph = { | |
'A' : ['B','C'], | |
'B' : ['D', 'E'], | |
'C' : ['F'], | |
'D' : [], | |
'E' : [], | |
'F' : [] | |
} |