charles-river-analytics / figaro

Figaro Programming Language and Core Libraries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with coding

toncho11 opened this issue · comments

I want to create a model, a distribution over "SuggestToWatchMovie" and "TellWeatherForecast". So I have two prob variables: SuggestToWatchMovie and TellWeatherForecast and I modify them based on some conditions (watchedMovieYesterday, etc). The problem comes to how to choose between the two. The solution below is definitely not the optimal? Can you propose the proper way of using Figaro Elements to code that?

         if (IsMorningOrEvening)

            if (watchedMovieYesterday)
              SuggestToWatchMovie = Flip(0.7)
             else
              SuggestToWatchMovie = Flip(0.9)

          else SuggestToWatchMovie = Flip(0.1)

          if (IsWeatherForecastGood)
            TellWeatherForecast = Flip(0.9)
          else
            TellWeatherForecast = If(InAGoodMood,
              Flip(0.5),
              Flip(0.1)
            )

          mainAlgorithm.start()

          val makeSuggestion = Select(
            mainAlgorithm.probability(SuggestToWatchMovie,true) -> "SuggestToWatchMovie",
            mainAlgorithm.probability(TellWeatherForecast,true) -> "TellWeatherForecast"
          );

          mainAlgorithm.stop()

Can you please comment on the code above? Is it OK to use an algorithm to calculate the probabilities and then use them in a Select element?

Hi,

I'm having a hard time trying to figure out what you're trying to do. The code you've presented is technically correct in that you will create a new Select element that has some probability of selecting "SuggestToWatch" or "TellWeatherForecast". But I can't tell you if this is correct from a modeling point of view since it's really up to what you are trying to do.