Browse Source

IFS weight update implementation

Yann Weber 4 years ago
parent
commit
454173322a
2 changed files with 39 additions and 2 deletions
  1. 30
    1
      rpn_ifs.c
  2. 9
    1
      rpn_ifs.h

+ 30
- 1
rpn_ifs.c View File

@@ -132,9 +132,38 @@ int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx)
132 132
 	return 0;
133 133
 }
134 134
 
135
+int rpn_ifs_run(rpn_ifs_t *rifs, size_t n)
136
+{
137
+	return 0;
138
+}
139
+
135 140
 int rpn_ifs_weight_update(rpn_ifs_t *rifs)
136 141
 {
137
-	return 1;
142
+	unsigned long int weight_sum;
143
+	size_t i, j, max;
144
+	rpn_if_t **proba;
145
+
146
+	proba = rifs->if_proba;
147
+	bzero(rifs->if_proba, sizeof(rpn_if_t*)*255);
148
+
149
+	weight_sum = 0;
150
+
151
+	for(i=0; i < rifs->if_sz; i++)
152
+	{
153
+		weight_sum += rifs->weight[i];
154
+	}
155
+	j=0;
156
+	for(i=0; i < rifs->if_sz; i++)
157
+	{
158
+		max = rifs->weight[i] * 255 / weight_sum;
159
+		while(max)
160
+		{
161
+			*proba = rifs->rpn_if[i];
162
+			max--;
163
+			j++;
164
+		}
165
+	}
166
+	return 0;
138 167
 }
139 168
 
140 169
 rpn_expr_t **rpn_ifs_flat_rpn(rpn_ifs_t *rifs)

+ 9
- 1
rpn_ifs.h View File

@@ -65,7 +65,7 @@ struct rpn_ifs_s
65 65
 	/**@brief Stores the original chance of choosing corresponding IF */
66 66
 	unsigned int *weight;
67 67
 	/** @brief Stores an array of 255 pointers on IF allowing fast
68
-	 * random choice */
68
+	 * random choice. Last ptr can be NULL*/
69 69
 	rpn_if_t *if_proba[255];
70 70
 
71 71
 	/**@brief Stores the RPN expressions pointer of the IF contained in
@@ -107,6 +107,14 @@ size_t rpn_ifs_add_if(rpn_ifs_t *rifs, unsigned int weight);
107 107
  */
108 108
 int rpn_ifs_del_if(rpn_ifs_t *rifs, size_t if_idx);
109 109
 
110
+/**@brief Call IFS n times
111
+ * @note Make n random choices and call corresponding IF
112
+ * @param rifs The iterated function system
113
+ * @param n consecutive IFS calls
114
+ * @return 1 if error else 0
115
+ */
116
+int rpn_ifs_run(rpn_ifs_t *rifs, size_t n);
117
+
110 118
 /**@brief Updates the @ref rpn_ifs_s.if_proba array using
111 119
  * @ref rpn_ifs_s.if_proba values
112 120
  * @param rifs The iterated function system

Loading…
Cancel
Save