Giter Site home page Giter Site logo

wenkokke / amethyst Goto Github PK

View Code? Open in Web Editor NEW
7.0 7.0 0.0 4.73 MB

Agda library for verifying neural networks.

Home Page: https://wenkokke.github.io/amethyst/

License: Other

Python 15.56% Agda 70.27% Shell 0.73% Makefile 12.24% Dockerfile 1.20%
agda neural-networks smt-solver

amethyst's Introduction

amethyst's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

amethyst's Issues

Exponential blow-up when translating networks into SMT constraints

I'm trying to get an auto-encoder example up and running and to do so I need to refer to the values of the neurons in the hidden layer inside the constraints, rather than just the network inputs and outputs.

While I was investigating how best to do this, I notice that we don't have an SMT variable for each neuron value but instead just define the expression for the ouput of layer $i$ in terms of the expressions for layer $i - 1$. This means fewer variables, but an exponential blow-up in the size of the final expressions generated.

For example, even with a simple 1 hidden layer network

layer1 : Layer Float 2 1
layer1 = record
  { weights    = [ 3.0 ] ∷ [ 2.0 ] ∷ []
  ; biases     = [ 0.2 ]
  ; activation = relu
  }

layer2 : Layer Float 1 2
layer2 = record
  { weights    = (-2.0-1.0 ∷ []) ∷ []
  ; biases     = -0.1-0.2 ∷ []
  ; activation = relu
  }

we get the expression:
(assert (and (= __1 (ite (<= (+ (- 0.1) (+ (* (ite (<= (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0))) 0.0) 0.0 (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0)))) (- 2.0)) 0.0)) 0.0) 0.0 (+ (- 0.1) (+ (* (ite (<= (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0))) 0.0) 0.0 (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0)))) (- 2.0)) 0.0)))) (and (= __0 (ite (<= (+ (- 0.2) (+ (* (ite (<= (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0))) 0.0) 0.0 (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0)))) (- 1.0)) 0.0)) 0.0) 0.0 (+ (- 0.2) (+ (* (ite (<= (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0))) 0.0) 0.0 (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0)))) (- 1.0)) 0.0)))) true)))

which contains the subexpression (+ (* (ite (<= (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0))) 0.0) 0.0 (+ 0.2 (+ (* __3 3.0) (+ (* __2 2.0) 0.0))) no less then four times.

I'm not sure how clever z3 and marabou are, and if they do common subexpression identification, but even so I'm pretty sure that any solver is going to choke if we continue to take this approach for deeper networks. Not to mention that Amethyst may fall over even generating such expressions.

I would recommend that we switch to generating a variable for the output of each neuron in the network. @wenkokke is there any reason why this representation would have drawbacks? Obviously there's an increase in the number of variables, but I feel like this gives the solvers more flexibility as it is presumably much easier for them to eliminate the extra variables if they want to, but much harder for them to recover them.

Unexpected SAT solver conclusions

At the moment I can't seem to get z3 to fail. For example if in AND-Gate-2-Sigmoid-1 we have the following code which type checks fine:

script : Script [] (Reals 2 ++ Reals 1) (SAT ∷ [])
script = withReflectedNetworkAsScript model $ λ where
  -- give names to input and output nodes
  iv@(i₀ ∷ i₁ ∷ []) ov@(o₀ ∷ [])
  -- give remainder of the smt-lib script
     assert (i₀ == 0·0f ∧ i₁ == 0·0f ⇒ o₀ == 0·0f)
    ∷ assert (i₀ == 0·0f ∧ i₁ == 1·0f ⇒ o₀ == 0·0f)
    ∷ assert (i₀ == 1·0f ∧ i₁ == 0·0f ⇒ o₀ == 0·0f)
    ∷ assert (i₀ == 1·0f ∧ i₁ == 1·0f ⇒ o₀ == 1·0f)
    ∷ check-sat
    ∷ []

_ : z3 script ≡ sat ∷ []
_ = refl

However changing the first assertion to:

assert (i₀ == 0·0f ∧ i₁ == 0·0f ⇒ o₀ == 1·0f)

also appears to type-check which is more than a little worrying....

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.