Advertisement
Guest User

Untitled

a guest
Aug 2nd, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "time"
  5.  
  6. "github.com/leesper/go_rng"
  7. )
  8.  
  9. type PsaInput struct {
  10. Id int
  11. Variable string
  12. Input_file string
  13. Distribution string
  14. Min float64
  15. Max float64
  16. Mean float64
  17. SD float64
  18. Alpha float64
  19. Beta float64
  20. }
  21.  
  22. type TransitionProbability struct {
  23. Id int
  24. From_id int
  25. To_id int
  26. Tp_base float64
  27. PSA_id int
  28. }
  29.  
  30. type Input struct {
  31. PsaInputs []PsaInput
  32. TransaitionProbabilities []TransitionProbability
  33. }
  34.  
  35. var Inputs Input
  36.  
  37. func main() {
  38. Inputs.TransaitionProbabilities = make([]TransitionProbability, 10, 10)
  39. }
  40.  
  41. func generateNewValue(psaInput PsaInput) float64 {
  42. var valueToReturn float64
  43. switch psaInput.Distribution {
  44.  
  45. case "beta":
  46. betaGen := rng.NewBetaGenerator(time.Now().UnixNano()) // seed the generator
  47. valueToReturn = betaGen.Beta(psaInput.Alpha, psaInput.Beta)
  48.  
  49. case "gamma":
  50. // betaGen := rng.NewBetaGenerator(time.Now().UnixNano()) // seed the generator
  51. // valueToReturn = betaGen.Beta(Inputs.Psa.Alpha, Inputs.Psa.beta)
  52.  
  53. case "normal":
  54. // betaGen := rng.NewBetaGenerator(time.Now().UnixNano()) // seed the generator
  55. // valueToReturn = betaGen.Beta(Inputs.Psa.Alpha, Inputs.Psa.beta)
  56.  
  57. }
  58. return valueToReturn
  59. }
  60.  
  61. func runPsa(Inputs Input) {
  62. for i := 0; i < len(Inputs.PsaInputs); i++ {
  63. psaInput := Inputs.PsaInputs[i]
  64. inputFile := psaInput.Input_file
  65.  
  66. switch inputFile {
  67.  
  68. case "transition_probabilities":
  69.  
  70. for p := 0; p < len(Inputs.TransaitionProbabilities); p++ {
  71. transitionProbability := Inputs.TransaitionProbabilities[p]
  72. if transitionProbability.PSA_id == psaInput.Id {
  73. newValue := generateNewValue(psaInput)
  74. transitionProbability.Tp_base = newValue
  75. }
  76. }
  77.  
  78. case "states":
  79.  
  80. // for transitionProbability := range Inputs.TransaitionProbabilities {
  81. // if transitionProbability.PSA_id == psaInput.Id {
  82. // newValue := generateNewValue(psaInput)
  83. // transitionProbability.Tp_base = newValue
  84. // }
  85. // }
  86.  
  87. } // end switch
  88.  
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement