forked from edoliberty/frequent-directions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exampleUsage.py
31 lines (25 loc) · 824 Bytes
/
exampleUsage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from __future__ import print_function
import sys
from numpy.linalg import norm
from numpy import dot
from syntheticDataMaker import SyntheticDataMaker
from frequentDirections import FrequentDirections
n = 500
d = 100
ell = 20
k = 5
# this is only needed for generating input vectors
dataMaker = SyntheticDataMaker()
dataMaker.initBeforeMake(d, k, signal_to_noise_ratio=10.0)
# This is where the sketching actually happens
sketcher = FrequentDirections(d,ell)
for i in range(n):
row = dataMaker.makeRow()
sketcher.append(row)
sketch = sketcher.get()
# Here is where you do something with the sketch.
# The sketch is an ell by d matrix
# For example, you can compute an approximate covariance of the input
# matrix like this:
approxCovarianceMatrix = dot(sketch.transpose(),sketch)
print(approxCovarianceMatrix)