-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
103 lines (56 loc) · 1.75 KB
/
main.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import numpy as np
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import backend as K
import os
import sys
from time import time
from ifor import find_average_depth
trainfile="training.npz"
testfile="test.npz"
#trainfile="playing.npz"
bag=32
indice=0
if len(sys.argv)>1:
indice=int(sys.argv[1])
x=np.load(trainfile)["q"]
tx=np.load(testfile)["q"]
def feature_bagging(x,tx,bag=bag):
#chooses a random subset of bag features, returns x', tx', features
features=np.random.choice(int(x.shape[1]),bag,replace=False)
x=np.stack([x[:,i] for i in features],axis=-1)
tx=np.stack([tx[:,i] for i in features],axis=-1)
return x,tx,features
def train_model(x,tx):
#trains a model, returns the normalized predictions on tx
pred=find_average_depth(x,tx,n_estimators=1)
return pred,1.0
def one_model():
xp,txp,feat=feature_bagging(x,tx,bag=bag)
pred, maximum=train_model(xp,txp)
return feat, pred, maximum
save_interval=5000
dex=0
os.makedirs("results",exist_ok=True)
feats,preds,maxima=[],[],[]
t0=time()
while True:
try:
feat,pred,maximum=one_model()
except Exception:
continue
feats.append(feat)
preds.append(pred)
maxima.append(maximum)
if len(preds)>=save_interval:
filenam=None
while filenam is None or os.path.isfile(filenam):
filenam=f"results/{indice}_{dex}.npz"
dex+=1
np.savez_compressed(filenam,feats=feats,preds=preds,maxima=maxima)
feats=[]
preds=[]
maxima=[]
print(f"did {dex*save_interval+len(feats)} models under {indice}")
timep=(time()-t0)/(dex*save_interval+len(feats))
print(f"Training time/Model: {timep}, {timep*save_interval}")