from keras.models import Model
from tensorflow.keras.optimizers import SGD
from keras.layers import Input, Dense
from keras.initializers import glorot_normal


class classifier:

    # Constructor
    def __init__(self, num_features=2, learning_rate=0.01, momentum=0.9, seed=0, hidden_activation_fun = 'tanh', hidden_units = 8):
        # parameters
        self.num_features = num_features
        self.learning_rate = learning_rate
        self.momentum = momentum
        self.seed = seed
        self.hidden_units = hidden_units
        self.hidden_activation_fun = hidden_activation_fun
        self.model = self.create_nn()

        # model
        self.model = self.create_nn()
        # self.model.summary()

        # prepare model for training
        self.model.compile(
            optimizer=SGD(lr=self.learning_rate, momentum=self.momentum),
            loss='binary_crossentropy',
            metrics=['accuracy']
        )

    def create_nn(self):
        # Input layer
        X_input = Input(shape=(self.num_features,))

        #  Hidden layer
        X = Dense(
            units=8,
            activation='tanh',
            use_bias=True,
            kernel_initializer=glorot_normal(seed=self.seed),
            bias_initializer='zeros'
        )(X_input)

        # Output layer
        y_out = Dense(
            units=1,
            activation="sigmoid",
            use_bias=True,
            kernel_initializer=glorot_normal(seed=self.seed),
            bias_initializer='zeros'
        )(X)

        # Model
        return Model(inputs=X_input, outputs=y_out)
