Coder Social home page Coder Social logo

Correctness of evaluateNode about flips HOT 5 CLOSED

TysonMN avatar TysonMN commented on July 16, 2024
Correctness of evaluateNode

from flips.

Comments (5)

matthewcrews avatar matthewcrews commented on July 16, 2024

I'm going to have to think about this. I'm wanting to setup a test which will validate correct/incorrect behavior. I will setup some tests tomorrow and see if we are getting the intended behavior.

from flips.

TysonMN avatar TysonMN commented on July 16, 2024

If I tweak the expression, maybe it will be easier to tell if this is the correct behavior or not.

Multiply (2.0, AddFloat (2.0, Empty)) + AddFloat (-2.0, Empty)

I negated the last float. Now the actual output from evaluateNode is [ 4.0; -4.0 ], which then sums to 0. Instead, I expect the output of evaluateNode to be [ 4.0; -2.0 ], which sums to 2.

Now amplify this by replacing every occurrence of 2 with n for some large n. The actual output after summing remains 0 while I expect the the output after summing to be n / 2.

Should the output after summing be exactly 0 or arbitrarily far away from it?

from flips.

matthewcrews avatar matthewcrews commented on July 16, 2024

I'm going to have this fixed today and put out a new release

from flips.

matthewcrews avatar matthewcrews commented on July 16, 2024

It is definitely wrong.

This code:

let d = Decision.createBoolean "d1"
let e = 2.0 * (1.0 * d) + 1.0 * d
let r = LinearExpression.Reduce e

Produces

val r : ReducedLinearExpression =
  { DecisionTypes = dict [(DecisionName "d1", Boolean)]
    Coefficients = dict [(DecisionName "d1", 4.0)]
    Offset = 0.0 }

But should produce this

val r : ReducedLinearExpression =
  { DecisionTypes = dict [(DecisionName "d1", Boolean)]
    Coefficients = dict [(DecisionName "d1", 3.0)]
    Offset = 0.0 }

The reason that it is not causing a problem in our current code is that we don't have cases where we are multiplying LinearExpression in this way.

I believe this is the correct implementation:

| AddLinearExpression (lExpr, rExpr) ->
    evaluateNode (multiplier, state) lExpr (fun (_, lState) -> evaluateNode (multiplier, lState) rExpr cont)

The behavior would technically equivalent to what you proposed @TysonMN because the state is made up of mutable collections.

from flips.

TysonMN avatar TysonMN commented on July 16, 2024

Yep, that implementation also works. I see the test you added in 90f4940. It looks great.

from flips.

Related Issues (20)

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.