コード例 #1
0
ファイル: gradientDescent.py プロジェクト: ciyer64/cs182
def runGeneticAlgorithm():
	popN = 100 # n number of chromos per population
	genesPerCh = 54
	max_iterations = 1000
  	chromos = geneticAlgorithm.generatePop(popN) #generate new population of random chromosomes
  	iterations = 0

  	while True:
  		if (iterations == max_iterations):
	 		rankedPop = geneticAlgorithm.rankPop(chromos) 
	 		#print(len(rankedPop))
	 		#print rankedPop
	  		chromos = []
	  		agent = geneticAlgorithm.iteratePop(rankedPop, popN, True)
	  		listKeys = agent[0]
	  		keyNames = []
	  		for i in range(len(listKeys)):
	  			if (listKeys[i] == 1):
	  				keyNames.append(allKeys[i])
	  		print agent
	  		print keyNames
	  		break
		# take the pop of random chromos and rank them based on their fitness score/proximity to target output
		rankedPop = geneticAlgorithm.rankPop(chromos) 
		#print rankedPop

  		chromos = []
  		chromos = geneticAlgorithm.iteratePop(rankedPop, popN, False)
		
  		iterations += 1
コード例 #2
0
ファイル: outer.py プロジェクト: Rarlegend/cs182
import myownq
import random
import util
import math
import geneticAlgorithm

#list of all fundamentals used including price
allKeys = ['"ACCOCI"', '"ASSETS"', '"ASSETSC"', '"ASSETSNC"', '"BVPS"', '"CAPEX"', '"CASHNEQ"', '"COR"', '"CURRENTRATIO"', '"DE"', '"DEBT"', '"DEPAMOR"', '"DILUTIONRATIO"', '"DPS"', '"EBIT"', '"EBITDA"', '"EBT"', '"EPS"', '"EPSDIL"', '"EQUITY"', '"FCF"', '"FCFPS"', '"GP"', '"INTANGIBLES"', '"INTEXP"', '"INVENTORY"', '"LIABILITIES"', '"LIABILITIESC"', '"LIABILITIESNC"', '"NCF"', '"NCFCOMMON"', '"NCFDEBT"', '"NCFDIV"', '"NCFF"', '"NCFI"', '"NCFO"', '"NCFX"', '"NETINC"', '"NETINCCMN"', '"NETINCDIS"', '"PAYABLES"', '"PB"', '"PREFDIVIS"', '"RECEIVABLES"', '"RETEARN"', '"REVENUE"', '"RND"', '"SGNA"', '"SHARESWA"', '"SHARESWADIL"', '"TANGIBLES"', '"TAXEXP"', '"TBVPS"', '"WORKINGCAPITAL"']
#list with price removed
keys = ['"ACCOCI"', '"ASSETS"', '"ASSETSC"', '"ASSETSNC"', '"BVPS"', '"CAPEX"', '"CASHNEQ"', '"COR"', '"CURRENTRATIO"', '"DE"', '"DEBT"', '"DEPAMOR"', '"DILUTIONRATIO"', '"DPS"', '"EBIT"', '"EBITDA"', '"EBT"', '"EPS"', '"EPSDIL"', '"EQUITY"', '"FCF"', '"FCFPS"', '"GP"', '"INTANGIBLES"', '"INTEXP"', '"INVENTORY"', '"LIABILITIES"', '"LIABILITIESC"', '"LIABILITIESNC"', '"NCF"', '"NCFCOMMON"', '"NCFDEBT"', '"NCFDIV"', '"NCFF"', '"NCFI"', '"NCFO"', '"NCFX"', '"NETINC"', '"NETINCCMN"', '"NETINCDIS"', '"PAYABLES"', '"PB"', '"PREFDIVIS"', '"RECEIVABLES"', '"RETEARN"', '"REVENUE"', '"RND"', '"SGNA"', '"SHARESWA"', '"SHARESWADIL"', '"TANGIBLES"', '"TAXEXP"', '"TBVPS"', '"WORKINGCAPITAL"']
gradientEpsilon = 0.01
popN = 25 # n number of chromos per population
genesPerCh = 54
max_iterations = 5000
chromos = geneticAlgorithm.generatePop(popN) #generate new population of random chromosomes
iterations = 0

#stochastic descent with random restarts
def runStochasticDescent():
	initialized = False
	#randomly select 10 fundamentals to use
	selectedKeys = random.sample(keys, 10)
	#add in price
	selectedKeys += ['"PRICE"']
	remainingKeys = [key for key in keys if key not in selectedKeys]
	hashVal = hash(tuple(selectedKeys))
	#store the scores for this set of fundamentals
	fScoreCorrect = dict()
	fScoreRewards = dict()
	previousState = dict()
	visited = []