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

division function: protected_div #4

Closed
xiaomocandy opened this issue Feb 13, 2019 · 1 comment
Closed

division function: protected_div #4

xiaomocandy opened this issue Feb 13, 2019 · 1 comment

Comments

@xiaomocandy
Copy link
Contributor

Hi,I am writing a thesis with GEP. Thanks for your project and I found a problem when using the examples.

def protected_div(x1, x2):
    if abs(x2) < 1e-6:
        return 1
    return x1 / x2

This protected division is defined to avoid dividing by zero.But how can it be used when you predict the aim value with the target function you've got by GEP. I've got many 'inf' in my prediction.And this is caused by the real division when using 'eval' to calculate. I am new in GEP. Do you know how does the GEP algorithm solve the division?

@ShuhuaGao
Copy link
Owner

Hi. If you have got many 'inf', one possible reason is that your model during evolution has generated very huge values. Can you confirm that it is produced by protected_div? If so, you should change protected_div to limit the value of the result. For example,

def protected_div(x1, x2):
    if abs(x2) < 1e-8:
        return 1	# anything you like
    r = x1 / x2
    if r > 1e8:
	return 1000  # anything you like
    elif r < -1e8:
	return -1000
    return r

Other causes may be computations like log when the input is very close to 0.

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