polymatrix_t *bayesian_to_polymatrix(bayesian_t *game)
{
    polymatrix_t *poly = polymatrix_alloc(game->m + game->n);

    graph_fill_complete_bipartite(poly->graph, game->m, game->n);
    int i, j;
    double pi, pi_j;
    for (i = 0; i < game->m; i++) {
        pi = 0;
        for (j = 0; j < game->n; j++)
            pi += game->distribution->data[i][j];
        for (j = 0; j < game->n; j++) {
            //printf("Adding %d %d\n", i, j + game->m);
            pi_j = game->distribution->data[i][j] / pi;
            poly->payoffs[i][j + game->m] = matrix_mul_const(game->payoffs[i][j], pi_j);
        }
    }

    for (i = 0; i < game->n; i++) {
        pi = 0;
        for (j = 0; j < game->n; j++)
            pi += game->distribution->data[j][i];
        for (j = 0; j < game->m; j++) {
            pi_j = game->distribution->data[j][i] / pi;
            poly->payoffs[i+game->m][j] = matrix_mul_const(game->payoffs[i + game->m][j], pi_j);
        }
    }

    return poly;
}
Пример #2
0
/* Function: matrix_test
	Perform matrix manipulation.

	Parameters:
	N - Dimensions of the matrix.
	C - memory for result matrix.
	A - input matrix
	B - operator matrix (not changed during operations)

	Returns:
	A CRC value that captures all results calculated in the function.
	In particular, crc of the value calculated on the result matrix 
	after each step by <matrix_sum>.

	Operation:
	
	1 - Add a constant value to all elements of a matrix.
	2 - Multiply a matrix by a constant.
	3 - Multiply a matrix by a vector.
	4 - Multiply a matrix by a matrix.
	5 - Add a constant value to all elements of a matrix.

	After the last step, matrix A is back to original contents.
*/
ee_s16 matrix_test(ee_u32 N, MATRES *C, MATDAT *A, MATDAT *B, MATDAT val) {
	ee_u16 crc=0;
	MATDAT clipval=matrix_big(val);

	matrix_add_const(N,A,val); /* make sure data changes  */
#if CORE_DEBUG
	printmat(A,N,"matrix_add_const");
#endif
	matrix_mul_const(N,C,A,val);
	crc=crc16(matrix_sum(N,C,clipval),crc);
#if CORE_DEBUG
	printmatC(C,N,"matrix_mul_const");
#endif
	matrix_mul_vect(N,C,A,B);
	crc=crc16(matrix_sum(N,C,clipval),crc);
#if CORE_DEBUG
	printmatC(C,N,"matrix_mul_vect");
#endif
	matrix_mul_matrix(N,C,A,B);
	crc=crc16(matrix_sum(N,C,clipval),crc);
#if CORE_DEBUG
	printmatC(C,N,"matrix_mul_matrix");
#endif
	matrix_mul_matrix_bitextract(N,C,A,B);
	crc=crc16(matrix_sum(N,C,clipval),crc);
#if CORE_DEBUG
	printmatC(C,N,"matrix_mul_matrix_bitextract");
#endif
	
	matrix_add_const(N,A,-val); /* return matrix to initial value */
	return crc;
}