added multiple outputs (nonorthogonal), sligthly improving the quality

This commit is contained in:
Simon Klüttermann 2021-09-19 19:19:53 +02:00
parent ed0d441974
commit db113b651b
1 changed files with 9 additions and 6 deletions

View File

@ -53,6 +53,8 @@ class stroo():
ng=ngramtrafo(data,s.grams, n=s.n) ng=ngramtrafo(data,s.grams, n=s.n)
p=s.model.predict(ng) p=s.model.predict(ng)
p=(p-s.m)**2 p=(p-s.m)**2
while len(p.shape)>1:
p=np.mean(p,axis=1)
return p return p
@ -69,24 +71,25 @@ def train_model(data,n=3):
ngrams=multigramm(data,n=n) ngrams=multigramm(data,n=n)
data=ngramtrafo(data,ngrams,n=n) data=ngramtrafo(data,ngrams,n=n)
pm=0.0 pm=[0.0]
while pm**2<0.0001: while np.mean(pm)**2<0.0001:
#tensorflow stuff (not at all optimised) #tensorflow stuff (not at all optimised)
inp=keras.Input(data.shape[1:]) inp=keras.Input(data.shape[1:])
q=inp q=inp
q=keras.layers.Dense(10,activation="relu",use_bias=False)(q) q=keras.layers.Dense(10,activation="relu",use_bias=False)(q)
q=keras.layers.Dense(4,activation="relu",use_bias=False)(q) q=keras.layers.Dense(7,activation="relu",use_bias=False)(q)
q=keras.layers.Dense(1,activation="relu",use_bias=False)(q) os=3
q=keras.layers.Dense(os,activation="relu",use_bias=False)(q)
model=keras.models.Model(inp,q) model=keras.models.Model(inp,q)
model.compile("adam","mse") model.compile("adam","mse")
model.fit(data,np.ones(len(data),dtype="float"), model.fit(data,np.ones((len(data),os),dtype="float"),
batch_size=100, batch_size=100,
epochs=50, epochs=50,
validation_split=0.1) validation_split=0.1)
pm=np.mean(model.predict(data)) pm=np.mean(model.predict(data),axis=0)
return stroo(model,ngrams,n=n,m=pm) return stroo(model,ngrams,n=n,m=pm)