charles-river-analytics / figaro

Figaro Programming Language and Core Libraries
Other
756 stars 151 forks source link

Problem with coding #729

Open toncho11 opened 6 years ago

toncho11 commented 6 years ago

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()
toncho11 commented 6 years ago

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?

bruttenberg commented 6 years ago

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.