Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a Custom Function that only accepts Input Variables #19

Closed
Sean-Reilly opened this issue Oct 29, 2021 · 5 comments
Closed

Creating a Custom Function that only accepts Input Variables #19

Sean-Reilly opened this issue Oct 29, 2021 · 5 comments

Comments

@Sean-Reilly
Copy link

Hello again,

I've been attempting for the past month or so to create a custom function to use in function_set to help DSO find the expression we're looking to regress into. This custom function is a simple binomial (1-x1), and our goal is to make it so that it only places an open input variable into the custom function and uses the binomial as a building block for the expression. Right now I've tried using the priors currently in place to do so, such as the relational prior and const prior, but nothing has made it so that x1 is the only thing it attempts to put in that slot. Do you have any suggestions on how to get this to work?

If you need any clarification, let me know

  • Sean
@brendenpetersen
Copy link
Collaborator

To clarify, you want a function like this:

def binom(x):
    return 1 - x

And you want a constraint that the argument must be an input variable? For example the traversals [binom, x1], [binom, x2], or [sin, mul, binom, x2, x1] would all be valid, but [binom, sin, x1] would not?

@Sean-Reilly
Copy link
Author

Yes, and we don't want [binom,binom,x] as well. I've tried using a relational prior to do this, so far to no luck.

@Sean-Reilly
Copy link
Author

Just wanted to check back in, I've had some minor success using the relational prior to get it to most of the time run with solely input variables, but due to using it some sacrifices had to be made, i.e. we couldn't include the full function set besides the input variable as the targets of the relational constraint and had to make sure that at least one function remained. This leads to the continued issue of the binom functions nesting. Do you have any insights into how to do this more effectively?

@brendenpetersen
Copy link
Collaborator

The standard RelationalConstraint should work just fine here.

The only tricky part is that you will have to adjust the LengthConstraint to allow sequences with minimum length 2. Otherwise you will get some conflicts or "collisions" between those two constraints. With the default minimum length of 4, then if you sample binom first, then you have no more options--can't choose input variables because of LengthConstraint and you can't choose non-input variables because of RelationalConstraint. Setting the minimum length to 2 avoids this. This issue may explain why you had tried to leave binom off the targets list (which is another way to avoid the collision).

I added this to my config:

"prior" : {
  "relational" : {
    "on" : true,
    "targets" : ["add", "sub", "mul", "div", "sin", "cos", "exp", "log", "binom"],
    "relationship" : "child",
    "effectors" : ["binom"]
  },
  "length" : {
    "on" : true,
    "min_" : 2,
    "max_" : 30
  }
}

I ran on the Nguyen-1 benchmark (edited to include binom) and it even finds a solution utilizing binom:

[00:00:00:16.55] Training epoch 73/100, current best R: 1.0000

	** New best
	Reward: 0.9999999999999998
	Count Off-policy: 0
	Count On-policy: 1
	Originally on Policy: True
	Invalid: False
	Traversal: mul,add,add,x1,x1,add,mul,x1,x1,binom,x1,x1
	Expression:
	     ⎛  2                   ⎞
	  x₁⋅⎝x₁  + 2⋅x₁ + binom(x₁)⎠

[00:00:00:16.55] Early stopping criteria met; breaking early.

@Sean-Reilly
Copy link
Author

This worked for me as well Thank you much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants