[Depmix-commits] r479 - pkg/depmixS4/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jun 22 15:18:26 CEST 2011


Author: ingmarvisser
Date: 2011-06-22 15:18:25 +0200 (Wed, 22 Jun 2011)
New Revision: 479

Added:
   pkg/depmixS4/src/ddens.cc
   pkg/depmixS4/src/ddens.h
Modified:
   pkg/depmixS4/src/fb.cc
   pkg/depmixS4/src/fb.h
Log:
Added c-function for computing some intermediate results in log likelihood computation that are taking loads of time (not finished yet).

Added: pkg/depmixS4/src/ddens.cc
===================================================================
--- pkg/depmixS4/src/ddens.cc	                        (rev 0)
+++ pkg/depmixS4/src/ddens.cc	2011-06-22 13:18:25 UTC (rev 479)
@@ -0,0 +1,27 @@
+#include "ddens.h"
+
+extern "C" {
+
+void ddens(double *dens, double *res, int *dim) {
+	
+	Rprintf("dim 0: %d \n", dim[0]);
+	Rprintf("dim 1: %d \n", dim[1]);
+	Rprintf("dim 2: %d \n", dim[2]);
+	
+	for(int t=0; t<dim[0]; t++) {
+		Rprintf("t: %d \n", t);
+		for(int i=0; i<dim[1]; i++) {
+			Rprintf("i: %d \n", i);
+			res[t*dim[2]+i] = dens[i*dim[0]*dim[2]+t];
+			Rprintf("dens %f \n", dens[i*dim[0]*dim[2]+t]);
+			for(int j=1; j<dim[2]; j++) {
+				Rprintf("j: %d \n", j);
+				res[t*dim[2]+i] *= dens[i*dim[0]*dim[2]+j*dim[1]+t];
+				Rprintf("dens %f \n", dens[i*dim[0]*dim[2]+j*dim[1]+t]);
+				
+			}
+		}
+	}	
+}
+
+} // end extern "C"
\ No newline at end of file


Property changes on: pkg/depmixS4/src/ddens.cc
___________________________________________________________________
Added: svn:eol-style
   + native

Added: pkg/depmixS4/src/ddens.h
===================================================================
--- pkg/depmixS4/src/ddens.h	                        (rev 0)
+++ pkg/depmixS4/src/ddens.h	2011-06-22 13:18:25 UTC (rev 479)
@@ -0,0 +1,19 @@
+
+#ifndef DDENS
+#define DDENS 1
+
+#include <stdio.h>
+#include <stdlib.h>
+  
+extern "C" {
+	
+#include <R.h>    
+#include <Rmath.h>
+
+// compute the product of densities for each t
+// hopefully more efficient than apply?!?!?
+void ddens(double *dens, double *densOut, int *dim);
+	
+} //end extern "C"
+
+#endif
\ No newline at end of file


Property changes on: pkg/depmixS4/src/ddens.h
___________________________________________________________________
Added: svn:eol-style
   + native

Modified: pkg/depmixS4/src/fb.cc
===================================================================
--- pkg/depmixS4/src/fb.cc	2011-06-22 11:51:04 UTC (rev 478)
+++ pkg/depmixS4/src/fb.cc	2011-06-22 13:18:25 UTC (rev 479)
@@ -1,7 +1,5 @@
 #include "fb.h"
 
-// #include "matrix.h"
-
 extern "C" {
 
 // 	# Forward-Backward algorithm (used in Baum-Welch)
@@ -33,7 +31,6 @@
 
 // gamma is computed as alpha*beta/sca in R (no loop needed)
 
-
 void forwardbackward(int *hom, int *ns, int *nc, int *nt, int *ntimes, int *bt, int *et,
 					 double *init, double *trdens, double *dens, 
 					 double *alpha, double *beta, double *sca, double *xi) {

Modified: pkg/depmixS4/src/fb.h
===================================================================
--- pkg/depmixS4/src/fb.h	2011-06-22 11:51:04 UTC (rev 478)
+++ pkg/depmixS4/src/fb.h	2011-06-22 13:18:25 UTC (rev 479)
@@ -4,23 +4,16 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-/* #include <fstream.h> */
-
- 
-/* #include "matrix.h" */
   
 extern "C" {
 	
 #include <R.h>    
 #include <Rmath.h>
 
-// criterion for stopping optimization, used in bootstrapping
+// compute forward and backward variables, and xi
 void forwardbackward(int *hom, int *ns, int *nc, int *nt, int *ntimes, int *bt, int *et, 
 					 double *init, double *trdens, double *dens, 
 					 double *alpha, double *beta, double *sca, double *xi);
-
-// the main function that computes the forward backward vars, and gamma and xi
-/* void forwardbackward(double logl, double *init, int *linit); */
 	
 } //end extern "C"
 



More information about the depmix-commits mailing list