Giter VIP home page Giter VIP logo

Comments (5)

asksak avatar asksak commented on September 15, 2024

The code assumes that binary operators are infix. No prefix binary operator is handled correctly, viz., 'atan2(a,b)', 'pow(a,b)'. While atan2 is noted as "NOT supported at this time" in file operators_list.txt, we do not so denote pow.

  • I propose to add 'pow(a,b)' to the "NOT supported" list, with a parenthetical note that the infix form (a**b) is supported.

Additionally, 'pow' appears twice in the set 'operators' in base_class.py, first as "ast.Pow: tf.pow, # e.g., a ** 2", and later as "'pow': tf.pow, # e.g., pow(a, b)".

  • I propose striking the latter.

Hello,

a^b is a good idea, I've been looking for operators to add.

Will do it and post the method.

Regards

Aymen

from karoo_gp.

kstaats avatar kstaats commented on September 15, 2024

from karoo_gp.

rll2021 avatar rll2021 commented on September 15, 2024

No, I do not, but the suggestion I made above is a two line fix.
I have not heard from Asksak, so I don't know if he has anything.

from karoo_gp.

asksak avatar asksak commented on September 15, 2024

No, I do not, but the suggestion I made above is a two line fix.
I have not heard from Asksak, so I don't know if he has anything.

Hello,

The first (pow) is ** in operators and is x^2, while the second (pow) is pow in operators which is a^b so I did this in labels:

def fx_eval_label(self, tree, node_id):
	
		'''
		Evaluate all or part of a Tree (starting at node_id) and return a raw mutivariate expression ('algo_raw').
		
		This method is called once per Tree, but may be called at any time to prepare an expression for any full or 
		partial (branch) Tree contained in 'population'. Pass the starting node for recursion via the local variable 
		'node_id' where the local variable 'tree' is a copy of the Tree you desire to evaluate.
		
		Called by: fx_eval_poly, fx_eval_label (recursively)
		
		Arguments required: tree, node_id
		'''
		
		# if tree[6, node_id] == 'not': tree[6, node_id] = ', not' # temp until this can be fixed at data_load
		
		node_id = int(node_id)
		
		if tree[8, node_id] == '0': # arity of 0 for the pattern '[term]'
			return tree[6, node_id] # 'node_label' (function or terminal)
			
		else:
			if tree[8, node_id] == '1': # arity of 1 for the explicit pattern 'not [term]'
				return tree[6, node_id] + self.fx_eval_label(tree, tree[9, node_id])	 # rll 20210201

			elif tree[8, node_id] == '2': # arity of 2 for the pattern '[func] [term] [func]'
				if tree[6, node_id] == 'min':
					return tree[6, node_id]  + self.fx_eval_label(tree, tree[9, node_id]) + self.fx_eval_label(tree, tree[10, node_id]) #asksak
				if tree[6, node_id] == 'max':
					return tree[6, node_id]  + self.fx_eval_label(tree, tree[9, node_id]) + self.fx_eval_label(tree, tree[10, node_id]) #asksak
				if tree[6, node_id] == 'pow':
					return tree[6, node_id]  + self.fx_eval_label(tree, tree[9, node_id]) + self.fx_eval_label(tree, tree[10, node_id]) #asksak, could combine all three lines with OR
				else:
					return self.fx_eval_label(tree, tree[9, node_id]) + tree[6, node_id] + self.fx_eval_label(tree, tree[10, node_id])	#asksak
				
			elif tree[8, node_id] == '3': # arity of 3 for the explicit pattern 'if [term] then [term] else [term]'
				# This fails in sympify. rll 20210206
				#This needs a new set of code. #asksak
				return tree[6, node_id] + self.fx_eval_label(tree, tree[9, node_id]) + ' then ' + self.fx_eval_label(tree, tree[10, node_id]) + ' else ' + self.fx_eval_label(tree, tree[11, node_id])

Note THE ARITY:

operator, arity
+,2
-,2
*,2
/,2
**,2
min,2
max,2
pow,2
sqrt,1
abs,1
log,1
cos,1
sin,1
exp,1
expm1,1

I will add all the code when I learn where and how to upload on GitHub.

As a side note (so far)

  1. I added min, max
  2. I fixed arity
  3. I modified fx_eval_label for compatibility
  4. I added dynamic mutation and standard mutation, both selectable at program startup
  5. I optimized memory utilization of the program (collected garbage)
  6. I optimized variable assignment
  7. I optimized loops
  8. I removed all '(' and ',' from fx_eval_label which I had added but turned out to interfere with sympy, kstaats version was better.
  9. I tested all the above with known test functions and all results solved in a few generations.

Will update u soon

from karoo_gp.

kstaats avatar kstaats commented on September 15, 2024

from karoo_gp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.