def cluster(data,inputs,verbose=False):
N=len(data)<EOL>active = []<EOL>for p in range(<NUM_LIT:0>,N):<EOL><INDENT>active.append([p])<EOL><DEDENT>loglikes = np.zeros(len(active))<EOL>loglikes[:] = None<EOL>pairloglikes = np.zeros([len(active),len(active)])<EOL>pairloglikes[:] = None<EOL>pairoffset = np.zeros([len(active),len(active)])<EOL>it = <NUM_LIT:0><EOL>while True:<EOL><INDENT>if verbose:<EOL><INDENT>it +=<NUM_LIT:1><EOL>print("<STR_LIT>" % it)<EOL><DEDENT>for clusti in range(len(active)):<EOL><INDENT>if verbose:<EOL><INDENT>sys.stdout.write('<STR_LIT:.>')<EOL>sys.stdout.flush()<EOL><DEDENT>if np.isnan(loglikes[clusti]):<EOL><INDENT>loglikes[clusti], unused_offset = get_log_likelihood_offset(inputs,data,[clusti])<EOL><DEDENT>for clustj in range(clusti): <EOL><INDENT>temp = [clusti,clustj]<EOL>if np.isnan(pairloglikes[clusti,clustj]):<EOL><INDENT>pairloglikes[clusti,clustj],pairoffset[clusti,clustj] = get_log_likelihood_offset(inputs,data,temp)<EOL><DEDENT><DEDENT><DEDENT>seploglikes = np.repeat(loglikes[:,None].T,len(loglikes),<NUM_LIT:0>)+np.repeat(loglikes[:,None],len(loglikes),<NUM_LIT:1>)<EOL>loglikeimprovement = pairloglikes - seploglikes <EOL>top = np.unravel_index(np.nanargmax(pairloglikes-seploglikes), pairloglikes.shape)<EOL>if loglikeimprovement[top[<NUM_LIT:0>],top[<NUM_LIT:1>]]><NUM_LIT:0>:<EOL><INDENT>active[top[<NUM_LIT:0>]].extend(active[top[<NUM_LIT:1>]])<EOL>offset=pairoffset[top[<NUM_LIT:0>],top[<NUM_LIT:1>]]<EOL>inputs[top[<NUM_LIT:0>]] = np.vstack([inputs[top[<NUM_LIT:0>]],inputs[top[<NUM_LIT:1>]]-offset])<EOL>data[top[<NUM_LIT:0>]] = np.hstack([data[top[<NUM_LIT:0>]],data[top[<NUM_LIT:1>]]])<EOL>del inputs[top[<NUM_LIT:1>]]<EOL>del data[top[<NUM_LIT:1>]]<EOL>del active[top[<NUM_LIT:1>]]<EOL>pairloglikes[:,top[<NUM_LIT:0>]] = None <EOL>pairloglikes[top[<NUM_LIT:0>],:] = None <EOL>pairloglikes = np.delete(pairloglikes,top[<NUM_LIT:1>],<NUM_LIT:0>)<EOL>pairloglikes = np.delete(pairloglikes,top[<NUM_LIT:1>],<NUM_LIT:1>)<EOL>loglikes[top[<NUM_LIT:0>]] = None<EOL>loglikes = np.delete(loglikes,top[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return active<EOL>
Clusters data

    Using the new offset model, this method uses a greedy algorithm to cluster
    the data. It starts with all the data points in separate clusters and tests
    whether combining them increases the overall log-likelihood (LL). It then
    iteratively joins pairs of clusters which cause the greatest increase in
    the LL, until no join increases the LL.

    arguments:
    inputs -- the 'X's in a list, one item per cluster
    data -- the 'Y's in a list, one item per cluster

    returns a list of the clusters.