@SuppressWarnings("unchecked")
	public void initializeModel(String imageFolderLocation, int row, int col) throws IOException {
		imageSplitImp is = new imageSplitImp();
		List<Double[]> split = is.splitFolder(imageFolderLocation, row, col);
		M = split.size();
	    codebook cb = new codebook();
	    List<Double[]> descriptors = cb.getSIFT(imageFolderLocation) ;
	    List<Double[]> dict = cb.kmeans(descriptors);
	    List<List<Double[]>> features = cb.getFeature();
	    V = dict.size();
		nmk = new int [M][K];
		nkt = new int[K][V];
		nmkSum = new int[M];
		nktSum = new int[K];
		phi = new double[K][V];
		theta = new double[M][K];

		//initialize documents index array
		doc = new ArrayList [M];
		File folder = new File(imageFolderLocation);
	    File[] listOfFiles = folder.listFiles();
	    imageWordsimp iw = new imageWordsimp();
	    List<Integer[]> words = iw.matchWords(imageFolderLocation, dict, features);
		for(int m = 0; m < M; m++){
			doc[m] = new ArrayList<Integer> ();
			File f = listOfFiles[m / splitNum];
			int splitCount = m % splitNum;
			double rowleft = splitCount / row * is.getHeight();
			double colleft = splitCount % col * is.getWidth();
			SIFTfeatureImp sift = new SIFTfeatureImp();
			List<Double[]> keypoints = sift.siftKeyPoints(imageFolderLocation + f.getName());
			for(int i = 0; i < keypoints.size(); i++) {
				if(keypoints.get(i)[0] >= rowleft && keypoints.get(i)[0] <= rowleft + is.getHeight() && keypoints.get(i)[1] >= colleft && keypoints.get(i)[1] <= colleft + is.getWidth())
					doc[m].add(words.get(m)[i]);
			}
		}

		//initialize topic label z for each word
		z = new int[M][];
		for(int m = 0; m < M; m++){
			int N = doc[m].size();
			z[m] = new int[N];
			for(int n = 0; n < N; n++){
				int initTopic = (int)(Math.random() * K);// From 0 to K - 1
				z[m][n] = initTopic;
				//number of words in doc m assigned to topic initTopic add 1
				nmk[m][initTopic]++;
				//number of terms doc[m][n] assigned to topic initTopic add 1
				nkt[initTopic][doc[m].get(n)]++;
					// total number of words assigned to topic initTopic add 1
					nktSum[initTopic]++;
			}
			 // total number of words in document m is N
			nmkSum[m] = N;
		}
	}