Michi commited on 2012-06-11 09:33:09
Zeige 1 geänderte Dateien mit 64 Einfügungen und 4 Löschungen.
... | ... |
@@ -57,14 +57,74 @@ minimum_lin=min(lin_arr) |
57 | 57 |
best_m_lin = m_vec[which(lin_arr == minimum_lin,arr.ind=TRUE)[2]] |
58 | 58 |
best_b_lin = b_vec[which(lin_arr == minimum_lin,arr.ind=TRUE)[1]] |
59 | 59 |
points(x_vec, linrel(x_vec,best_m_lin,best_b_lin), type="l", col="blue", xlab='x',ylab='f(x)=y') |
60 |
-minimum_con=min(lin_arr) |
|
60 |
+minimum_con=min(con_arr) |
|
61 | 61 |
best_b_con = b_vec[which(con_arr == minimum_con,arr.ind=TRUE)[1]] |
62 | 62 |
points(x_vec, rep(conrel(best_b_lin),41), type="l", col="yellow", xlab='x',ylab='f(x)=y') |
63 | 63 |
|
64 | 64 |
#Probelm3 |
65 | 65 |
norm = function(a) 1/sum(a) * a |
66 | 66 |
|
67 |
-posterior_qua = exp(-0.5 *(norm(qua_arr) - minimum_qua)) |
|
68 |
-posterior_lin = exp(-0.5 *(norm(lin_arr) - minimum_lin)) |
|
69 |
-posterior_con = exp(-0.5 *(norm(con_arr) - minimum_con)) |
|
67 |
+posterior_qua = exp(-0.5 *(norm(qua_arr) - norm(qua_arr)[which(qua_arr == minimum_qua,arr.ind=TRUE)])) |
|
68 |
+posterior_lin = exp(-0.5 *(norm(lin_arr) - norm(lin_arr)[which(lin_arr == minimum_lin,arr.ind=TRUE)])) |
|
69 |
+posterior_con = exp(-0.5 *(norm(con_arr) - norm(con_arr)[which(con_arr == minimum_con,arr.ind=TRUE)])) |
|
70 | 70 |
|
71 |
+ |
|
72 |
+#integration numerically function |
|
73 |
+int = function(x_vec, y_vec){ |
|
74 |
+ A=0 |
|
75 |
+ step=(max(x_vec)-min(x_vec))/(length(x_vec)) |
|
76 |
+ for (i in y_vec){ |
|
77 |
+ A=A+step*i |
|
78 |
+ } |
|
79 |
+ return(A) |
|
80 |
+} |
|
81 |
+ |
|
82 |
+dim_m = length(m_vec) |
|
83 |
+dim_a = length(a_vec) |
|
84 |
+dim_b = length(b_vec) |
|
85 |
+ |
|
86 |
+#Marginalization of posterior_quad over a |
|
87 |
+int_qua_a=array(0, c(dim_m, dim_b)) |
|
88 |
+for (i in (1:dim_m)){ |
|
89 |
+ for (j in (1:dim_b)){ |
|
90 |
+ I=int(a_vec, norm(posterior_qua[j,i,])) |
|
91 |
+ int_qua_a[i,j]=I |
|
92 |
+ } |
|
93 |
+} |
|
94 |
+ |
|
95 |
+#Marginalization of posterior_quad over b |
|
96 |
+int_qua_b=array(0, c(dim_m, dim_a)) |
|
97 |
+for (i in (1:dim_m)){ |
|
98 |
+ for (j in (1:dim_a)){ |
|
99 |
+ I=int(b_vec, norm(posterior_qua[,i,j])) |
|
100 |
+ int_qua_b[i,j]=I |
|
101 |
+ } |
|
102 |
+} |
|
103 |
+#Marginalization of posterior_quad over m |
|
104 |
+int_qua_m=array(0, c(dim_a, dim_b)) |
|
105 |
+for (i in (1:dim_a)){ |
|
106 |
+ for (j in (1:dim_b)){ |
|
107 |
+ I=int(m_vec, norm(posterior_qua[j,,i])) |
|
108 |
+ int_qua_m[i,j]=I |
|
109 |
+ } |
|
110 |
+} |
|
111 |
+ |
|
112 |
+#Marginalization of posterior_lin over b and m |
|
113 |
+int_lin_b=array(0, dim=c(length(m_vec))) |
|
114 |
+for (i in (1:length(m_vec))){ |
|
115 |
+ I=int(b_vec, norm(posterior_lin[i,])) |
|
116 |
+ int_lin_b[i]=I |
|
117 |
+} |
|
118 |
+ |
|
119 |
+int_lin_m=array(0, dim=c(length(b_vec))) |
|
120 |
+for (i in (1:length(b_vec))){ |
|
121 |
+ I=int(m_vec, norm(posterior_lin[,i])) |
|
122 |
+ int_lin_m[i]=I |
|
123 |
+} |
|
124 |
+ |
|
125 |
+ |
|
126 |
+#Marginalization of posterior_con over b |
|
127 |
+ |
|
128 |
+int_lin_m=array(0, dim=c(dim_b)) |
|
129 |
+I=int(b_vec, norm(posterior_con)) |
|
130 |
+int_con_b=I |
|
71 | 131 |