1import os.path 2import itertools 3import Tools 4import random 5import numpy as np 6import scipy.special as sp 7 8NBTESTSAMPLES = 500 9 10def softmax(v): 11 m = sp.softmax(v) 12 return(np.argmax(m)+1) 13 14def writeTest(config,nb,vecDim): 15 dims=[] 16 inputsA=[] 17 outputs=[] 18 outputsSamples = [] 19 20 21 dims.append(NBTESTSAMPLES) 22 dims.append(vecDim) 23 24 25 for _ in range(0,NBTESTSAMPLES): 26 va = np.abs(np.random.randn(vecDim)) 27 va = va / np.sum(va) 28 29 r = sp.softmax(va) 30 outputsSamples += list(r) 31 outputs.append(np.argmax(r)+1) 32 inputsA += list(va) 33 34 35 inputsA=np.array(inputsA) 36 outputs=np.array(outputs) 37 outputsSamples=np.array(outputsSamples) 38 39 config.writeInput(nb, inputsA,"InputA") 40 config.writeInputS16(nb, dims,"Dims") 41 42 config.writeReferenceS16(nb, outputs,"Ref") 43 config.writeReference(nb, outputsSamples,"Samples") 44 45 46 47 48def writeTests(config): 49 writeTest(config,1,21) 50 51def generatePatterns(): 52 PATTERNDIR = os.path.join("Patterns","NN","Softmax",) 53 PARAMDIR = os.path.join("Parameters","NN","Softmax") 54 55 configq7=Tools.Config(PATTERNDIR,PARAMDIR,"q7") 56 57 writeTests(configq7) 58 59 60if __name__ == '__main__': 61 generatePatterns()