#!/usr/bin/env python3 # -*- coding: utf-8 -*- #use evolutionFit to solve math problem import numpy as np from PSNN import model, layers netmodel = model([layers.dense(1)]) inaccuracy = 1e-14 def mycubic(model): # 2*x*x*x + 5*x*x = 10 x = model.predict([])[0] loss = abs(10 - (2 * x * x * x + 5 * x * x)) return loss netmodel.create(inputs=(0, )) drate = 1 lastlost = 0 while True: loss = netmodel.evolutionFit(rate=drate, replication=200, lossfunc=mycubic,
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import numpy as np from PSNN import model, layers, activation netmodel = model([ layers.dense(2, activation.sigmoid()), layers.dense(1, activation.sigmoid()) ]) netmodel.debug = True netmodel.create(inputs=(3, )) inputs = np.array([ [0, 0, 1], #0 [0, 0, 0], #0 [1, 0, 0], #1 [1, 1, 1], #1 [0, 1, 0], #1 [0, 1, 1] #1 ]) targets = np.array([ [0], [0], [1], [1], [1], [1],
def getITArray(directory, target): imgs = glob.glob(directory + "/*.png") out = ([], []) for loc in imgs: img = Image.open(loc).convert('L') # convert image to 8-bit grayscale WIDTH, HEIGHT = img.size data = list(img.getdata()) # convert image data to a list of integers out[0].append([data[offset:offset+WIDTH] for offset in range(0, WIDTH*HEIGHT, WIDTH)]) out[1].append(target) return out netmodel = model([ layers.flatten(), layers.activation(activation.tanh()), layers.dense(30, activation.tanh()), layers.dense(20, activation.tanh()), layers.dense(10, activation.sigmoid()) ]) netmodel.debug = True netmodel.create( inputs=(28,28) ) # get learn data from images learn = { "inputs": [], "targets": [] }