#!/usr/bin/env python

import climate
import lmj.cubes
import lmj.cubes.fill
import numpy as np
import theanets

logging = climate.get_logger('fill')

def fill(dfs, rank, window):
    '''Complete missing marker data using a nonlinear autoencoder model.

    This method alters the given `dfs` in-place.

    Parameters
    ----------
    dfs : list of pd.DataFrame
        Frames of source data. The frames will be stacked into a single large
        frame to use during encoding. This stacked frame will then be split and
        returned.
    rank : int
        Encode the data using a nonlinear matrix decomposition of this rank.
    window : int
        Model windows of this many consecutive frames.
    '''
    df = lmj.cubes.fill.stack(dfs, window)
    centers = lmj.cubes.fill.center(df)
    pos, vis, _ = lmj.cubes.fill.window(df, window)

    data = [pos.astype('f'), vis.astype('f')]
    net = theanets.Autoencoder(
        (pos.shape[1], int(rank), pos.shape[1]),
        weighted=True)
    for tm, _ in net.itertrain(data, batch_size=128):
        if tm['loss'] < lmj.cubes.fill.PHASESPACE_TOLERANCE:
            break

    batches = (net.predict(pos[o:o+64].astype('f')) for o in range(0, len(pos), 64))
    lmj.cubes.fill.update(df, np.concatenate(list(batches), axis=0), window)
    lmj.cubes.fill.restore(df, centers)
    lmj.cubes.fill.unstack(df, dfs)


def main(args):
    lmj.cubes.fill.main(fill, args, args.autoencoder_rank, args.window)


if __name__ == '__main__':
    climate.call(main)

@@ -144,16 +144,17 @@
 fill')%0A%0A
+%0A
 def fill
@@ -852,47 +852,22 @@
    d
-ata
  = 
-%5B
 pos.
-astype('f'), vis.astype('f')
+shape%5B1
 %5D%0A  
@@ -899,32 +899,13 @@
 der(
-%0A        (pos.shape%5B1%5D
+(d
 , 
+(
 int(
@@ -915,30 +915,23 @@
 k), 
-pos.shape%5B1%5D),%0A       
+'sigmoid'), d),
  wei
@@ -977,28 +977,134 @@
 ain(
-data, batch_size=128
+%5Bpos.astype('f'), vis.astype('f')%5D,%0A                               batch_size=128,%0A                               momentum=0.5
 ):%0A 

Use sigmoid autoencoder to fill dropouts.