def build_model(state_len, num_classes): print("Building model...") model = Sequential() model.add(Projection(state_len, input_shape=(1, state_len))) model.add(Proj2Prob(state_len, input_shape=(1, state_len))) model.add(EigenDist(num_classes, input_shape=(1, state_len))) model.add(Flatten()) model.summary() # model.compile(loss=keras.losses.categorical_crossentropy, # model.compile(loss=keras.losses.mean_squared_error, model.compile(loss=categorical_bernoulli_crossentropy, optimizer=keras.optimizers.Adadelta(), metrics=['accuracy']) return model
def build_model_do(state_len, num_classes, activation="relu", to_raise=True, to_reduce=True, raise_quadratic=True, reduce_quadratic=True): global ECMM print("Building model...") if to_raise: raised_dim = 128 if not raise_quadratic: RaDO = RaiseDimensionNonQuadratic else: RaDO = RaiseDimension # RaDO = ReduceDimension else: raised_dim = state_len RaDO = RaiseDimensionIdentity state_len1 = raised_dim if to_reduce: reduced_dim = 64 if not reduce_quadratic: ReDO = ReduceDimensionNonQuadratic else: ReDO = ReduceDimension else: reduced_dim = state_len1 ReDO = ReduceDimensionIdentity inputs = Input(shape=(1, state_len)) # 1 raise_dimension1 = RaDO(raised_dim, input_shape=(1, state_len), name="rado") projection1 = Projection(state_len1, input_shape=(1, state_len1), name="p1") proj2prob1 = Proj2Prob(state_len1, input_shape=(1, state_len1)) eigen_dist1 = ECMM(num_classes, input_shape=(1, state_len1), name="l1") flatten1 = Flatten(name="1st_fold") reduce_dimension1 = ReDO(reduced_dim, input_shape=(1, state_len1), name="redo") # 2 state_len2 = reduced_dim projection2 = Projection(state_len2, input_shape=(1, state_len2), name="p2") proj2prob2 = Proj2Prob(state_len2, input_shape=(1, state_len2)) eigen_dist2 = ECMM(num_classes, input_shape=(1, state_len2), name="l2") flatten2 = Flatten(name="2nd_fold") # 1 a0 = raise_dimension1(inputs) a1 = projection1(a0) a2 = proj2prob1(a1) o1 = flatten1(eigen_dist1(a2)) a1 = reduce_dimension1(a1) # 2 b1 = projection2(a1) b2 = proj2prob2(b1) o2 = flatten2(eigen_dist2(b2)) model = Model(inputs, outputs=[o1, o2]) return model
def build_model_dnn(state_len, num_classes, to_raise=True, to_reduce=True, activation="relu"): global ECMM print("Building model...") raised_dim = 128 reduced_dim = 128 inputs = Input(shape=(1, state_len)) # 1 if to_raise: state_len1 = raised_dim dense1 = Dense(state_len1, activation=activation) else: state_len1 = state_len dense1 = RaiseDimensionIdentity(state_len1, input_shape=(1, state_len)) reshape1 = Reshape((1, state_len1), input_shape=(state_len1, )) projection1 = Projection(state_len1, input_shape=(1, state_len1)) proj2prob1 = Proj2Prob(state_len1, input_shape=(1, state_len1)) eigen_dist1 = ECMM(num_classes, input_shape=(1, state_len1)) flatten1 = Flatten(name="1st_fold") # 2 # flatten2_dense = Flatten() if to_reduce: state_len2 = reduced_dim dense2 = Dense(state_len2, activation=activation) else: state_len2 = state_len1 dense2 = ReduceDimensionIdentity(state_len2, input_shape=(1, state_len1)) reshape2 = Reshape((1, state_len2), input_shape=(state_len2, )) projection2 = Projection(state_len2, input_shape=(1, state_len2)) proj2prob2 = Proj2Prob(state_len2, input_shape=(1, state_len2)) eigen_dist2 = ECMM(num_classes, input_shape=(1, state_len2)) flatten2 = Flatten(name="2nd_fold") # 1 if to_raise: a1 = Flatten()(inputs) a2 = dense1(a1) a2 = reshape1(a2) else: a2 = inputs a3 = projection1(a2) a4 = proj2prob1(a3) o1 = flatten1(eigen_dist1(a4)) # 2 # b1 = flatten2_dense(a1) if to_reduce: a3 = Flatten()(a3) b1 = dense2(a3) b2 = reshape2(b1) else: b2 = a3 b3 = projection2(b2) b4 = proj2prob2(b3) o2 = flatten2(eigen_dist2(b4)) model = Model(inputs, outputs=[o1, o2]) return model