Commit 820fbd04 authored by Eva Lina Fesefeldt's avatar Eva Lina Fesefeldt
Browse files

Update INCG Vergleich Plots

parent 39fd89c7
......@@ -35,10 +35,10 @@ def vector_flat_shape_to_trainable_shape(v):
v2 = tf.reshape(v[slice1:slice2], (n,))
v3 = tf.reshape(v[slice2:slice3], (n,3))
v4 = tf.reshape(v[slice3:], (3,))
unit_vector_trainable_shape = [v1, v2, v3, v4]
return unit_vector_trainable_shape
vector_trainable_shape = [v1, v2, v3, v4]
return vector_trainable_shape
# Todo umschreiben für allgemeines n, allgemeines Model
# Todo umschreiben für allgemeines Model
def vector_trainable_shape_to_flat_shape(list):
p = 0
#Number of Parameters p
......
......@@ -5,6 +5,7 @@ from tensorflow.python.framework.dtypes import as_dtype
from tensorflow.python.ops.gen_math_ops import xlog1py_eager_fallback
import matplotlib.pyplot as plt
from math import sqrt
import random
from generate_dataset import generate_tictactoe
from jvp import _back_over_back_hvp
......@@ -16,6 +17,20 @@ from keras.models import Sequential
from keras.layers import Dense
from keras import backend as k
def analyse_dataset(x_train_hess):
x_train, y_train = generate_tictactoe()
n,m = x_train.shape
count = np.zeros(n)
for j in range(n):
for i in range(n):
test_1 = x_train[j,:]
test_2 = x_train_hess[i,:]
if np.array_equal(x_train[j,:], x_train_hess[i,:]):
count[j] += 1
return count
def norm_trainable_shape(x):
return sqrt(reelles_skalarprodukt_trainable_shape(x,x))
......@@ -249,10 +264,25 @@ for epoch in range(number_of_epochs):
x = model.get_weights()
filename_trainset = "train_set/hessianlearn_trainset_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
filename_trainlabels = "train_labels/hessianlearn_trainlabels_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
x_train = np.load(filename_trainset)
y_train = np.load(filename_trainlabels)
# Gewichte aus hessianlearn klauen
filename_weights = "hessianlearn_weights/hessianlearn_weights_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
x_hessianlearn_flat = np.load(filename_weights).astype('float32')
x = vector_flat_shape_to_trainable_shape(x_hessianlearn_flat)
model.set_weights(x)
# Datenset aus hessianlearn klauen
#filename_trainset = "train_set/hessianlearn_trainset_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
#filename_trainlabels = "train_labels/hessianlearn_trainlabels_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
#x_train = np.load(filename_trainset)
#y_train = np.load(filename_trainlabels)
#count = analyse_dataset(x_train)
if epoch>0:
random.Random(epoch-1).shuffle(x_train)
random.Random(epoch-1).shuffle(y_train)
filename_trainset = "results/incg_trainset_newton" + str(epoch) +"_gamma_" + str(gamma[0]) + ".npy"
np.save(filename_trainset, x_train)
g = gradient(model, x_train, y_train, loss_fn)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment