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

Small fix for neural net constraint #573

Closed

Conversation

Alexander-Schiendorfer
Copy link

The definition of fzn_neural_net seems odd by using the last element of first_edge instead of EDGE for the last neuron.

forall(i in NODE diff INPUTS) (
            let { int: first = first_edge[i];
                  int: last = if i = max(NODE) then max(index_set(first_edge))

which should be

forall(i in NODE diff INPUTS) (
            let { int: first = first_edge[i];
                  int: last = if i = max(NODE) then max(index_set(EDGE))

That might explain why a dummy element is needed according to the documentation:

image

To debug all of that, I've copied the definition of fzn_neural_net and added a few traces:
nn_example_mzn.zip
nn_kodierung

With the original definition, I get an empty set of parents for the last neuron

Neuron 4 first 3, last 4
Inputs [X_INTRODUCED_0_, X_INTRODUCED_1_], weights [-3.0, 2.0], -2.0
Neuron 5 first 5, last 6
Inputs [X_INTRODUCED_18_, X_INTRODUCED_27_], weights [0.0, 1.0], 1.0
Neuron 6 first 7, last 6
Inputs [], weights [], -1.0

whereas the proposed change fixes that:

Neuron 4 first 3, last 4
Inputs [X_INTRODUCED_0_, X_INTRODUCED_1_], weights [-3.0, 2.0], -2.0
Neuron 5 first 5, last 6
Inputs [X_INTRODUCED_18_, X_INTRODUCED_27_], weights [0.0, 1.0], 1.0
Neuron 6 first 7, last 8
Inputs [X_INTRODUCED_18_, X_INTRODUCED_27_], weights [2.0, 0.0], -1.0

Additionally, it might make sense to pass an array from node ids to NEURON_TYPE (e.g., the hidden neurons might use non-linearities but only the output neurons should use LINEAR, or SOFTMAX once it becomes available :-) )

Cheers,
Alex

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

Successfully merging this pull request may close these issues.

None yet

1 participant