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

how use equation by custom? #1

Open
lab021rnd opened this issue Aug 21, 2017 · 1 comment
Open

how use equation by custom? #1

lab021rnd opened this issue Aug 21, 2017 · 1 comment

Comments

@lab021rnd
Copy link

lab021rnd commented Aug 21, 2017

i can't use custom equation? can I know about that.? I want use y = 0.5 * (a * x^3 + b*x^2 +c * x) * z^2
thank you!

@lab021rnd lab021rnd changed the title how use equation custom? how use equation by custom? Aug 21, 2017
@KhaledSharif
Copy link
Collaborator

Hi @lab021rnd, thanks for your question! You can define your custom equation similar to how it is done inside Athena, like so:

from athena.equations import get_symbols
def CustomEquation(s, x, x_symbolic, z, z_symbolic):
    offset, variables = 3, 2  # 3 free variables, 2 data-defined variables

    a, b, c = [s.w[s._wc + i] for i in range(offset)]
    syms = get_symbols(1, offset + variables + 1)
    x_s, z_s = syms[-1], syms[-2]

    # this is our TensorFlow equation definition
    eq = 0.5 * (a * x**3 + b*x**2 + c*x) * z**2

    # this is our Sympy equation definition
    equation_string = 0.5 * (syms[0] * x_s**3 + syms[1]*x_s**2 + syms[2]*x_s) * z_s**2

    parameters_list = [[x_symbolic, x_s], [z_symbolic, z_s]] + [[s.w[s._wc + i], syms[i]] for i in range(offset)]

    return {"equation": eq, "parameters": parameters_list, "symbolic": equation_string, "offset": offset}

Then you can call it from inside a model definition, just as you do with any other equation type, as so:

model = AdditiveModel(fw)
model.add(CustomEquation, "x", "z")

This is not very straightforward at the moment, I'll admit, and I hope to work on simplifying this process in the future. Please tell me if this works when you try it out.

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