Skip to content

Commit 19683ed

Browse files
author
sushmit
committed
SR :adding chapter 8 file and updating scalar multiplication for mat.py
1 parent 30b3c3c commit 19683ed

File tree

17 files changed

+972
-2
lines changed

17 files changed

+972
-2
lines changed

.DS_Store

0 Bytes
Binary file not shown.
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 8,
6+
"metadata": {
7+
"collapsed": false
8+
},
9+
"outputs": [],
10+
"source": [
11+
"#col_label_list = sorted(rowlist[0].D, key=hash)\n",
12+
"from vec import *\n",
13+
"from mat import *\n",
14+
"from matutil import *\n",
15+
"from echelon import *\n",
16+
"from vecutil import *\n",
17+
"from GF2 import one\n",
18+
"\n"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 19,
24+
"metadata": {
25+
"collapsed": false
26+
},
27+
"outputs": [
28+
{
29+
"name": "stdout",
30+
"output_type": "stream",
31+
"text": [
32+
"\n",
33+
" 0\n",
34+
" -----\n",
35+
" 0 | 1\n",
36+
" 1 | -89\n",
37+
" 2 | 0\n",
38+
"\n"
39+
]
40+
}
41+
],
42+
"source": [
43+
"def projection_matrix(v):\n",
44+
" v_norm = v * v\n",
45+
" return 0\n",
46+
"a0 = list2vec([1,-89,0])\n",
47+
"dict_a = {}\n",
48+
"dict_a[0] = a0\n",
49+
"print(coldict2mat(dict_a))"
50+
]
51+
}
52+
],
53+
"metadata": {
54+
"kernelspec": {
55+
"display_name": "Python 3",
56+
"language": "python",
57+
"name": "python3"
58+
},
59+
"language_info": {
60+
"codemirror_mode": {
61+
"name": "ipython",
62+
"version": 3
63+
},
64+
"file_extension": ".py",
65+
"mimetype": "text/x-python",
66+
"name": "python",
67+
"nbconvert_exporter": "python",
68+
"pygments_lexer": "ipython3",
69+
"version": "3.5.1"
70+
}
71+
},
72+
"nbformat": 4,
73+
"nbformat_minor": 0
74+
}

Chapter8.ipynb

Lines changed: 85 additions & 0 deletions
Large diffs are not rendered by default.

Dali.png

2.34 MB
Loading

QR.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2013 Philip N. Klein
2+
from orthonormalization import aug_orthonormalize
3+
from dictutil import dict2list, list2dict
4+
from matutil import mat2coldict, coldict2mat
5+
6+
def factor(A):
7+
col_labels = sorted(A.D[1], key=repr)
8+
Acols = dict2list(mat2coldict(A),col_labels)
9+
Qlist, Rlist = aug_orthonormalize(Acols)
10+
#Now make Mats
11+
Q = coldict2mat(Qlist)
12+
R = coldict2mat(list2dict(Rlist, col_labels))
13+
return Q,R

__pycache__/mat.cpython-35.pyc

0 Bytes
Binary file not shown.

age-height.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
age height
2+
18 76.1
3+
19 77
4+
20 78.1
5+
21 78.2
6+
22 78.8
7+
23 79.7
8+
24 79.9
9+
25 81.1
10+
26 81.2
11+
27 81.8
12+
28 82.8
13+
29 83.5

cancer_data.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Copyright 2013 Philip N. Klein
2+
from vec import Vec
3+
from matutil import rowdict2mat
4+
5+
def read_training_data(fname, D=None):
6+
"""Given a file in appropriate format, and given a set D of features,
7+
returns the pair (A, b) consisting of
8+
a P-by-D matrix A and a P-vector b,
9+
where P is a set of patient identification integers (IDs).
10+
11+
For each patient ID p,
12+
- row p of A is the D-vector describing patient p's tissue sample,
13+
- entry p of b is +1 if patient p's tissue is malignant, and -1 if it is benign.
14+
15+
The set D of features must be a subset of the features in the data (see text).
16+
"""
17+
file = open(fname)
18+
params = ["radius", "texture", "perimeter","area","smoothness","compactness","concavity","concave points","symmetry","fractal dimension"];
19+
stats = ["(mean)", "(stderr)", "(worst)"]
20+
feature_labels = set([y+x for x in stats for y in params])
21+
feature_map = {params[i]+stats[j]:j*len(params)+i for i in range(len(params)) for j in range(len(stats))}
22+
if D is None: D = feature_labels
23+
feature_vectors = {}
24+
patient_diagnoses = {}
25+
for line in file:
26+
row = line.split(",")
27+
patient_ID = int(row[0])
28+
patient_diagnoses[patient_ID] = -1 if row[1]=='B' else +1
29+
feature_vectors[patient_ID] = Vec(D, {f:float(row[feature_map[f]+2]) for f in D})
30+
return rowdict2mat(feature_vectors), Vec(set(patient_diagnoses.keys()), patient_diagnoses)

fft.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2013 Philip N. Klein
2+
def FFT(w, s):
3+
""""
4+
w should be a complex numbers such that w^n = 1
5+
where n is the number of elements in the list s
6+
of numbers.
7+
"""
8+
n = len(s)
9+
if n==1: return [s[0]]
10+
f0 = FFT(w*w, [s[i] for i in range(n) if i % 2 == 0])
11+
f1 = FFT(w*w, [s[i] for i in range(n) if i % 2 == 1])
12+
return [f0[j]+w**j*f1[j] for j in range(n//2)] + [f0[j]-w**(j+n//2)*f1[j] for j in range(n//2)]

flag.png

186 KB
Loading

0 commit comments

Comments
 (0)