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

Performance in Filtering Algorithms #633

Closed
ssbanerje opened this issue Dec 1, 2016 · 3 comments
Closed

Performance in Filtering Algorithms #633

ssbanerje opened this issue Dec 1, 2016 · 3 comments

Comments

@ssbanerje
Copy link

ssbanerje commented Dec 1, 2016

I am trying to figure out how to efficiently implement a factoring algorithm in Figaro. Please have a look at the following code:

import com.cra.figaro.language._
import com.cra.figaro.library.collection._
import com.cra.figaro.algorithm.filtering._

object test {

  lazy val init = () => {
    val u = Universe.createNew()
    val a = new FixedSizeArray[Int](100, (i) => Constant[Int](0)("val"+i, u))
    compute_sum(a, u)
    u
  }

  lazy val transition = (u: Universe) => {
    val next = Universe.createNew()
    val a = new FixedSizeArray[Int](100, (i) => Apply(u.getElementByReference[Int]("val"+i), Flip(0.5), (v: Int, f: Boolean) => {
      if (f) v + 1 else v - 1
    })("val"+i, next))
    compute_sum(a, next)
    next
  }

  def compute_sum(a: FixedSizeArray[Int], u:Universe) = {
    // CASE 1
    a.map{(i) => i>0}.count(_)
    // CASE 2
    a.map{(i) => i>0}.count{(b) => b}("ANSWER1", u)
  }

  def main(args: Array[String]): Unit = {
    val inf = FactoredFrontier(init(), transition, 50)
    inf.start

    for (i <- 1 to 1000) {
      inf.advanceTime()
      println(i)
      println(inf.computeCurrentExpectation[Int]("ANSWER1", (i:Int) => i))
    }

    inf.kill
  }
}

When I use CASE 1 in compute_sum, the program finishes in a few seconds. However when I use CASE 2 it takes much much more time (~30 mins: 100x??). I dont quite understand why these two are different in performance.

@bruttenberg
Copy link
Collaborator

bruttenberg commented Dec 1, 2016 via email

@ssbanerje
Copy link
Author

ssbanerje commented Dec 1, 2016

Thanks @bruttenberg . That definitely helps...

Are there any "best-practices" guides available for getting the best performance out of a model. I am trying to model a system which computes factored frontier over 20k-30k variables (~100k size state space). Figaro doesn't seem to scale to this size of a model.

As far as I can gather from the web, Figaro has the ability to recognize repeated (and independent) sub-models and can optimize the overall computation by memoizing the results from these sub-models. How do I ensure these optimizations are always successfully applied?

@bruttenberg
Copy link
Collaborator

bruttenberg commented Dec 1, 2016 via email

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