def mse_chunked_sum_regularized(g_r, g_i, fg_r, fg_i, fg_comps, nchunks, data_r, data_i, wgts, ant0_inds, ant1_inds, prior_r_sum, prior_i_sum, dtype=np.float32):
    cal_loss = [tf.constant(0.0, dtype) for cnum in range(nchunks)]
    model_i_sum = [tf.constant(0.0, dtype) for cnum in range(nchunks)]
    model_r_sum = [tf.constant(0.0, dtype) for cnum in range(nchunks)]
    for cnum in range(nchunks):
        (model_r, model_i) = data_model(g_r, g_i, fg_r[cnum], fg_i[cnum], fg_comps[cnum], ant0_inds[cnum], ant1_inds[cnum])
        model_r_sum[cnum] += tf.reduce_sum((model_r * wgts[cnum]))
        model_i_sum[cnum] += tf.reduce_sum((model_i * wgts[cnum]))
        cal_loss[cnum] += mse(model_r, model_i, data_r[cnum], data_i[cnum], wgts[cnum])
    return ((tf.reduce_sum(tf.stack(cal_loss)) + tf.square((tf.reduce_sum(tf.stack(model_r_sum)) - prior_r_sum))) + tf.square((tf.reduce_sum(tf.stack(model_i_sum)) - prior_i_sum)))
def mse_chunked_sum_regularized(g_r, g_i, fg_r, fg_i, fg_comps, nchunks, data_r, data_i, wgts, ant0_inds, ant1_inds, prior_r_sum, prior_i_sum, dtype=np.float32):
    cal_loss = [tf.constant(0.0, dtype) for cnum in range(nchunks)]
    model_i_sum = [tf.constant(0.0, dtype) for cnum in range(nchunks)]
    model_r_sum = [tf.constant(0.0, dtype) for cnum in range(nchunks)]
    for cnum in range(nchunks):
        (model_r, model_i) = data_model(g_r, g_i, fg_r[cnum], fg_i[cnum], fg_comps[cnum], ant0_inds[cnum], ant1_inds[cnum])
        model_r_sum[cnum] += tf.reduce_sum((model_r * wgts[cnum]))
        model_i_sum[cnum] += tf.reduce_sum((model_i * wgts[cnum]))
        cal_loss[cnum] += mse(model_r, model_i, data_r[cnum], data_i[cnum], wgts[cnum])
    return ((tf.reduce_sum(tf.stack(cal_loss)) + tf.square((tf.reduce_sum(tf.stack(model_r_sum)) - prior_r_sum))) + tf.square((tf.reduce_sum(tf.stack(model_i_sum)) - prior_i_sum)))