likely.js
function calculateError(estimated, input, bias)
{ 	
	var adjustedInput = input.dup();
	
	var adjustedElements = adjustedInput.elements;
		
	// If bias adjustment is provided, adjust for it
	if(bias)
	{
		// subtract the row and column bias from each row
		for(var i = 0; i <= adjustedInput.rows()-1; i++)
		{
			for(var j = 0; j <= adjustedInput.cols()-1; j++)
			{
				if(adjustedElements[i][j] == 0) continue; // skip zeroes
				
				adjustedElements[i][j] -= bias.average;
				
				adjustedElements[i][j] -= bias.rowBiases.e(i+1);
				
				adjustedElements[i][j] -= bias.colBiases.e(j+1);
			}
		}
	}
	
	
	var estimatedElements = estimated.elements;
	
	// Error is (R - R')
	// (but we ignore error on the zero entries since they are unknown)
	for(var i = 0; i <= adjustedInput.rows()-1; i++)
	{
		for(var j = 0; j <= adjustedInput.cols()-1; j++)
		{
			if(adjustedElements[i][j] == 0) continue; // skip zeroes
			
			adjustedElements[i][j] -= estimatedElements[i][j];
		}
	}				

	// Error is (R - R')
	return adjustedInput;
}
function calculateError(estimated, input, bias)
{ 	
	var adjustedInput = input.dup();
	
	var adjustedElements = adjustedInput.elements;
		
	// If bias adjustment is provided, adjust for it
	if(bias)
	{
		// subtract the row and column bias from each row
		for(var i = 0; i <= adjustedInput.rows()-1; i++)
		{
			for(var j = 0; j <= adjustedInput.cols()-1; j++)
			{
				if(adjustedElements[i][j] == 0) continue; // skip zeroes
				
				adjustedElements[i][j] -= bias.average;
				
				adjustedElements[i][j] -= bias.rowBiases.e(i+1);
				
				adjustedElements[i][j] -= bias.colBiases.e(j+1);
			}
		}
	}
	
	
	var estimatedElements = estimated.elements;
	
	// Error is (R - R')
	// (but we ignore error on the zero entries since they are unknown)
	for(var i = 0; i <= adjustedInput.rows()-1; i++)
	{
		for(var j = 0; j <= adjustedInput.cols()-1; j++)
		{
			if(adjustedElements[i][j] == 0) continue; // skip zeroes
			
			adjustedElements[i][j] -= estimatedElements[i][j];
		}
	}				

	// Error is (R - R')
	return adjustedInput;
}
function calculateError ( estimated , input , bias ) { var adjustedInput = input . dup ( ) ; var adjustedElements = adjustedInput . elements ; // If bias adjustment is provided, adjust for it if ( bias ) { // subtract the row and column bias from each row for ( var i = 0 ; i <= adjustedInput . rows ( ) - 1 ; i ++ ) { for ( var j = 0 ; j <= adjustedInput . cols ( ) - 1 ; j ++ ) { if ( adjustedElements [ i ] [ j ] == 0 ) continue ; // skip zeroes adjustedElements [ i ] [ j ] -= bias . average ; adjustedElements [ i ] [ j ] -= bias . rowBiases . e ( i + 1 ) ; adjustedElements [ i ] [ j ] -= bias . colBiases . e ( j + 1 ) ; } } } var estimatedElements = estimated . elements ; // Error is (R - R') // (but we ignore error on the zero entries since they are unknown) for ( var i = 0 ; i <= adjustedInput . rows ( ) - 1 ; i ++ ) { for ( var j = 0 ; j <= adjustedInput . cols ( ) - 1 ; j ++ ) { if ( adjustedElements [ i ] [ j ] == 0 ) continue ; // skip zeroes adjustedElements [ i ] [ j ] -= estimatedElements [ i ] [ j ] ; } } // Error is (R - R') return adjustedInput ; }
Computes the error from model matrices P and Q against the given input.
@param estimated A matrix of the estimated values.
@param input A matrix of the input values
@returns A matrix of size input.rows by input.columns where each entry is the difference between the input and estimated values.
Computes the error from model matrices P and Q against the given input .