-
Notifications
You must be signed in to change notification settings - Fork 17
/
example_cnn.py
32 lines (24 loc) · 955 Bytes
/
example_cnn.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
32
from effective_dimension import Model, EffectiveDimension, ClassicalNeuralNetwork
import numpy as np
import matplotlib.pyplot as plt
# This is an example file to create a classical model and compute its effective dimension
# create ranges for the number of data, n
n = [5000, 8000, 10000, 40000, 60000, 100000, 150000, 200000, 500000, 1000000]
# specify the size of your neural network
nnsize = [4, 4, 4, 2]
# specify number of data samples and parameter sets to estimate the effective dimension
num_inputs = 100
num_thetas = 100
# create the model
cnet = ClassicalNeuralNetwork(nnsize)
# compute the effective dimension
ed = EffectiveDimension(cnet, num_thetas=num_thetas, num_inputs=num_inputs)
f, trace = ed.get_fhat()
effdim = ed.eff_dim(f, n)
# true dimension of the model
d = cnet.d
# plot the normalised effective dimension
plt.plot(n, np.array(effdim)/d)
plt.xlabel('number of data')
plt.ylabel('normalised effective dimension')
plt.show()