def theta(self, eta): """The canonical parameter, theta, that corresponds to the natural parameter, eta.""" assert self._check_shape(eta) W = 2. * eta[self.k:].reshape((self.k, self.k)) mu = solve(W, eta[:self.k]) return (mu, W)
def linear_solution_bias_estimate(readings): delta_matrix = delta(readings) num_sensors = len(delta_matrix) target_vector = [ sum([delta_matrix[k, i] for i in range(num_sensors) if i != k]) for k in range(num_sensors) ] + [0] def diagonal(i, j): if i == j: return num_sensors - 1 else: return -1 matrix = [[diagonal(i, j) for i in range(num_sensors)] + [1] for j in range(num_sensors)] + [[1] * num_sensors + [0]] return solve(matrix, target_vector)[:num_sensors]
def adapt_whitepoint(src, dst): """ Compute the adaptation matrix for converting XYZ tristimulus values from a one standard illuminant to another using the Bradford transform. This implementation follows the presentation on http://www.color.org/chadtag.html The results are cached. Parameters ---------- src : str dst : str The names of the standard illuminants to convert from and to, respectively. Valid values are the keys of `whitepoints` like 'D65' or 'CIE A'. Returns ------- adapt : float array (3, 3) Matrix-multiply this matrix against XYZ values with the `src` whitepoint to get XYZ values with the `dst` whitepoint. """ # Check the cache first. key = (src, dst) if key not in adapt_whitepoint.cache: bradford = np.array([[0.8951, 0.2664, -0.1614], [-0.7502, 1.7135, 0.0367], [0.0389, -0.0685, 1.0296]]) src_whitepoint = whitepoints[src][-1] src_rgb = np.dot(bradford, src_whitepoint) dst_whitepoint = whitepoints[dst][-1] dst_rgb = np.dot(bradford, dst_whitepoint) scale = dst_rgb / src_rgb adapt_whitepoint.cache[key] = solve(bradford, scale[:, np.newaxis] * bradford) adapt = adapt_whitepoint.cache[key] return adapt
[0.2434974736455316, 0.8523911562030849, -0.0515994646411065], [-0.3958579552426224, 1.1655483851630273, 0.0837969419671409], [0.0, 0.0, 0.6185822095756526], ] ) xyz_from_lms = inv(lms_from_xyz) # The transformation from XYZ to the ATD opponent colorspace. These are # "official" values directly from Guth 1980. atd_from_xyz = np.array([[0.0, 0.9341, 0.0], [0.7401, -0.6801, -0.1567], [-0.0061, -0.0212, 0.0314]]) xyz_from_atd = inv(atd_from_xyz) # Now we need to compute the intermediate transformations between LMS and ATD. # We derive these directly from the other two instead of specifying potentially # truncated values. atd_from_lms = solve(lms_from_xyz.T, atd_from_xyz.T).T lms_from_atd = solve(atd_from_xyz.T, lms_from_xyz.T).T # XYZ white-point coordinates # from http://www.aim-dtp.net/aim/technology/cie_xyz/cie_xyz.htm whitepoints = { "CIE A": ["Normal incandescent", triwhite(0.4476, 0.4074)], "CIE B": ["Direct sunlight", triwhite(0.3457, 0.3585)], "CIE C": ["Average sunlight", triwhite(0.3101, 0.3162)], "CIE E": ["Normalized reference", triwhite(1.0 / 3, 1.0 / 3)], "D50": ["Bright tungsten", triwhite(0.3457, 0.3585)], "D55": ["Cloudy daylight", triwhite(0.3324, 0.3474)], "D65": ["Daylight", triwhite(0.312713, 0.329016)], "D75": ["?", triwhite(0.299, 0.3149)], "D93": ["low-quality old CRT", triwhite(0.2848, 0.2932)],