def __load_data(self): [ self.trainData, self.trainDataSymbols, self.trainTargets, self.trainTargetsSymbols, self.trainTargetClasses, self.testData, self.testDataSymbols, self.testTargets, self.testTargetsSymbols, self.validationData, self.validationDataSymbols, self.validationTargets, self.validationTargetsSymbols, self.validationTargetClasses ] = data.loadDataSet() self._data_loaded = True
from framework.models import Sequential from framework.activations import ReLU, Sigmoid from framework.layers import Linear from framework.losses import MSE from framework.optimizers import SGD from framework import FloatTensor as Tensor import matplotlib.pyplot as plt import utilites from data import loadDataSet if __name__ == "__main__": plt.ion() simple = False data = loadDataSet(one_hot=False) # Create simple linear calssifier model lin1 = Linear(2, 10) relu1 = ReLU() lin2 = Linear(10, 10) relu2 = ReLU() lin3 = Linear(10, 1) sig1 = Sigmoid() model = Sequential([lin1, relu1, lin2, relu2, lin3, sig1]) # Training model epochs_per_step = 1 for e in range(0, 100, epochs_per_step): # Testing model on training data pred_labels = model.predict(x=Tensor(data.test.data))
def getDontCare(size=1568): ret = [] for i in range(size): ret.append(0.5) return ret # Load Datasets [ trainData, trainDataSymbols, trainTargets, trainTargetsSymbols, trainTargetClasses, testData, testDataSymbols, testTargets, testTargetsSymbols, validationData, validationDataSymbols, validationTargets, validationTargetsSymbols, validationTargetClasses ] = data.loadDataSet() trainDataCombined = [] trainTargetsCombined = [] testDataCombined = [] validationDataCombined = [] validationTargetsCombined = [] for index, item in enumerate(trainData): trainDataCombined.append( np.concatenate((item, trainDataSymbols[index]), axis=0)) for i in range(70): for index, item in enumerate(trainData): trainDataCombined.append( np.concatenate((getDontCare(), trainDataSymbols[index]), axis=0)) for index, item in enumerate(trainTargets):
for i, indv in enumerate(parents): if random.random() > pc: while True: tmp = copy.deepcopy(indv) chromosome = exchange_chromosome(nodes, tmp.chromosome) if nodes.is_feasible(chromosome): break offspring = Individual(i + 1, chromosome) else: offspring = Individual(i + 1, indv.chromosome) offsprings.append(offspring) return offsprings if __name__ == '__main__': nodes = loadDataSet('data5.xml') chromosome1 = [{ 1: 1, 2: 4, 3: 7, 4: 10, 5: 6, 6: 12, 7: 5, 8: 11 }, { 1: 2, 2: 8, 3: 3, 4: 9 }]
from framework.models import Sequential from framework.activations import ReLU, Sigmoid from framework.layers import Linear from framework.losses import MSE from framework.optimizers import Adam # SGD import utilites from data import loadDataSet if __name__ == "__main__": data = loadDataSet(one_hot=True) # Create simple linear calssifier model lin1 = Linear(2, 25, std=0.1) relu1 = ReLU() lin2 = Linear(25, 25, std=0.1) relu2 = ReLU() lin3 = Linear(25, 25, std=0.1) relu3 = ReLU() lin4 = Linear(25, 2, std=0.1) sig1 = Sigmoid() model = Sequential([lin1, relu1, lin2, relu2, lin3, relu3, lin4, sig1]) loss = MSE() optimizer = Adam() # Training model model.train(x=data.train.data, y=data.train.labels, batch_size=8, optimizer=optimizer, loss=loss,