Пример #1
0
float dtw_windowed(void * seq1v, void * seq2v, int seq1_len, int seq2_len, int window) {
    // THIS WILL SEGFAULT IF seq1 AND seq2 ARE NOT (n,m)x4
    float* seq1 = (float*) seq1v;
    float* seq2 = (float*) seq2v;
    float* distance_mat = make_mat(seq1_len, seq2_len, INFINITY);
    //printf("n: %d, m: %d\n", seq1_len, seq2_len);
    distance_mat[int_pos(0,0, seq1_len)] = 0;
    window = MAX(window, abs(seq1_len - seq2_len));
    //printf("Window: %d\n", window);
    int i, j;
    for (i = 1; i < seq1_len; i++) {
        //for (j = MAX(1, i-window); j < MIN(seq2_len,i+window); j++) {
        for (j = 1; j < seq2_len; j++) {
            // Wish there was a better way to do this...
            float eucl_dist = euclidean(seq1[int_pos(i,0,4)], seq1[int_pos(i,1,4)], seq2[int_pos(j,0,4)], seq2[int_pos(j,1,4)]);
            float cosi_dist = cosine(seq1[int_pos(i,2,4)], seq1[int_pos(i,3,4)], seq2[int_pos(j,2,4)], seq2[int_pos(j,3,4)]);
            distance_mat[int_pos(i,j,seq2_len)] = (eucl_dist + cosi_dist) + MIN(distance_mat[int_pos(i-1,j-1,seq2_len)], 
                                                                                MIN(distance_mat[int_pos(i-1,j,seq2_len)],
                                                                                    distance_mat[int_pos(i,j-1,seq2_len)]));
        }   
    }
    // find minimal value along the last column as our distance
    float retval = distance_mat[int_pos(seq1_len-1, seq2_len-1, seq2_len)];
    free(distance_mat);
    return retval;
}
TEST_F(MatrixTest, MatrixScalarOperatorsTest) {
	ASSERT_EQ(empty, empty + 1.);
	ASSERT_EQ(empty, empty - 1.);
	ASSERT_EQ(empty, empty * 1.);
	ASSERT_EQ(empty, empty / 1.);
	ASSERT_ANY_THROW(empty / 0.);

	ASSERT_ANY_THROW(some / 0.);
	ASSERT_TRUE(cmp_matr_double(
			some + 10., make_mat({
			{  5 ,  5, 10, 21 , 25 },
			{  6 ,  8, 25,  -3, 23 },
			{  0 ,  8, 24,  -2, 11 },
			{  9 , 22, 22,  7 , 3  },
	})));
	ASSERT_TRUE(cmp_matr_double(
			some - 10., make_mat({
			{ -15,-15,-10,   1,  5 },
			{ -14,-12,  5, -23,  3 },
			{ -20,-12,  4, -22, -9 },
			{ -11,  2,  2, -13,-17 },
	})));
	ASSERT_TRUE(cmp_matr_double(
			some * 0.,
			Matrix(some.Width(), some.Height(), 0)
	));
	ASSERT_TRUE(cmp_matr_double(
			some * 1.,
			some
	));
	ASSERT_TRUE(cmp_matr_double(
			some / 1.,
			some
	));
	ASSERT_TRUE(cmp_matr_double(
			some / 0.5, make_mat({
			{ -10,-10, 0 , 22 , 30 },
			{ -8 , -4, 30, -26, 26 },
			{ -20, -4, 28, -24, 2  },
			{ -2 , 24, 24, -6 , -14},
	})));
}
Пример #3
0
int make_table()
{
	int p=0;
	
	float *val;
	val = &mat[0];
	if(make_mat())
	{
	/*	for(i=0;i<ROWS;i++)
			for(j=0;j<COLS;j++)
				printf(" %f ",mat[i][j]); */
		while(p<PROG)	
		{
			//val = mat;
			cmp_tim[p][C] = *val++;
			cmp_mem[p][C] = *val++;
			run_tim[p][C] = *val++;
			run_mem[p][C] = *val++;
			p++;
		}
		p=0;
		while(p<PROG)	
		{
			cmp_tim[p][CPP] = *val++;
			cmp_mem[p][CPP] = *val++;
			run_tim[p][CPP] = *val++;
			run_mem[p][CPP] = *val++;
			p++;
		}
		p=0;
		while(p<PROG)	
		{
			cmp_tim[p][JAVA] = *val++;
			cmp_mem[p][JAVA] = *val++;
			run_tim[p][JAVA] = *val++;
			run_mem[p][JAVA] = *val++;
			p++;
		}
		p=0;
		while(p<PROG)	
		{
			cmp_tim[p][PYTH] = 0;
			cmp_mem[p][PYTH] = 0;
			run_tim[p][PYTH] = *val++;
			run_mem[p][PYTH] = *val++;
			p++;
		}
	return 1;
	}
	else 
		return 0;
}
TEST_F(MatrixTest, MatrixUnaryOperatorsTest) {
	ASSERT_EQ(empty, +empty);
	ASSERT_EQ(empty, -empty);
	ASSERT_EQ(some, +some);
	ASSERT_TRUE(cmp_matr_double(
		-some,
		make_mat({
			{  +5, +5,  0, -11,-15 },
			{  +4, +2,-15, +13,-13 },
			{ +10, +2,-14, +12, -1 },
			{  +1,-12,-12, + 3, +7 },
		})
	));
}
#include "MatrixTests.hpp"

static Matrix
	empty(0),
	some(make_mat({
		{ -5 , -5, 0 , 11 , 15 },
		{ -4 , -2, 15, -13, 13 },
		{ -10, -2, 14, -12, 1  },
		{ -1 , 12, 12, -3 , -7 },
	})),
	longmatrix(make_mat({
		{13, -15, -7 , 9  , 13, -1, 1, -13},
		{-9, 2  , 4  , -11, 3 , -1, 5, -13},
		{-5, 9  , -14, -2 , 5 , -2, 7, -3 },
		{1 , 3  , -7 , 8  , 11, -1, 4, 14 },
	}));

TEST_F(MatrixTest, MatrixUnaryOperatorsTest) {
	ASSERT_EQ(empty, +empty);
	ASSERT_EQ(empty, -empty);
	ASSERT_EQ(some, +some);
	ASSERT_TRUE(cmp_matr_double(
		-some,
		make_mat({
			{  +5, +5,  0, -11,-15 },
			{  +4, +2,-15, +13,-13 },
			{ +10, +2,-14, +12, -1 },
			{  +1,-12,-12, + 3, +7 },
		})
	));
}
Пример #6
0
/*Main Function*/
int main(int argc, char *argv[])
{
	FILE *op;
	int i,j,prog,total[LANG]={0,0,0,0,0};
	float ratio[LANG],mod_total[LANG]={0,0,0,0,0},pen_mod_total[LANG]={0,0,0,0,0};
	//char filename[100]="";
	//scanf("%s",filename);
	prog=make_mat(argv[1]);
	op = fopen("/home/Rahul/Desktop/Thesis/Scripts/final_loc.csv","a");
	if(prog)
	{		
		//printf("\tC\t\tCPP\t\tHASKELL\t\tJAVA\t\tPYTHON\n");
		//printf("\t-\t\t---\t\t------\t\t----\t\t------\n");
		for(i=0;i<prog;i++)
		{	
			for(j=0;j<LANG;j++)
			{
				printf("\t%d\t",mat[i][j]);
				total[j] = total[j] + mat[i][j];
			}
			printf("\n");
		}
		
		printf("\n\t----\t\t----\t\t----\t\t----\t\t----\n");
		for(i=0;i<LANG;i++)	
		{
			ratio[i] = total[0];
			printf("\t%d\t",total[i]);
		}		
		for(i=0;i<prog;i++)
			for(j=0;j<LANG;j++)
				if(mat[i][j] == 0)
					ratio[j] = ratio[j] - mat[i][C];
		printf("\n");	
		printf("\t----\t\t----\t\t----\t\t----\t\t----\n");
		for(i=0;i<LANG;i++)	
		{
			ratio[i] = total[i]/ratio[i];
			printf("\t%f",ratio[i]);
		}	
		printf("\n");
		printf("\t-\t\t---\t\t------\t\t----\t\t------\n");
		for(i=0;i<prog;i++)
		{
			for(j=0;j<LANG;j++)
			{
				if(mat[i][j] == 0)
				{
					if(mat[i][C] != 0)
						mod_mat[i][j] = ratio[j]*mat[i][C];
					else
						mod_mat[i][j] = (ratio[j]/ratio[CPP])*mat[i][CPP];
				//	if(j==C) || (j==CPP)
					pen_mod_mat[i][j] = penalty(mod_mat[i][j],j);
				}
				else
					pen_mod_mat[i][j] = mod_mat[i][j] = mat[i][j];							
			}
		}
		printf("\tC\t\tCPP\t\tHASKELL\t\tJAVA\t\tPYTHON\n");
		printf("\t-\t\t---\t\t------\t\t----\t\t------\n");
		for(i=0;i<prog;i++)
		{	
			for(j=0;j<LANG;j++)
			{
				if(mat[i][j])
					printf("\t%f",mod_mat[i][j]);
				
				else
					printf("\t%.5f*",mod_mat[i][j]);
				mod_total[j] = mod_total[j] + mod_mat[i][j];
			}
			printf("\n");
		}
		
		printf("\t----\t\t----\t\t----\t\t----\t\t----\n");
		for(i=0;i<LANG;i++)	
		{
			//ratio[i] = total[0];
			printf("\t%f",mod_total[i]);
		}		
		printf("\n");
		printf("\t-\t\t---\t\t------\t\t----\t\t------\n");
		for(i=0;i<prog;i++)
		{	
			for(j=0;j<LANG;j++)
			{
				if(mat[i][j])
					printf("\t%f",pen_mod_mat[i][j]);
				
				else
					printf("\t%.5f**",pen_mod_mat[i][j]);
				pen_mod_total[j] = pen_mod_total[j] + pen_mod_mat[i][j];
			}
			printf("\n");
		}
		
		printf("\t----\t\t----\t\t----\t\t----\t\t----\n");
//		fprintf(op,"c,cpp,haskell,java,python\n");
		for(i=0;i<LANG;i++)	
		{
			//ratio[i] = total[0];
			printf("\t%f",pen_mod_total[i]);
			if ( i == LANG-1 )
				fprintf(op,"%f,%f",pen_mod_total[i],pen_mod_total[i]);
			else 
				fprintf(op,"%f,",pen_mod_total[i]);
		}		
		fprintf(op,"\n");
		printf("\n");
		printf("---------------------------------------------------------------------------\n");
		fclose(op);
	}
	else 
		printf("\nfailed to open file...\n");
	return 1;
}