<commit_before>#!/usr/bin/env python

import climate
import joblib
import lmj.cubes
import numpy as np
import os

logging = climate.get_logger('15-compute-jac')


def compute(trial, output, frames):
    trial.load()

    # encode body-relative data.
    body = lmj.cubes.Trial(trial.parent, trial.basename)
    body.df = trial.df.copy()
    stats = body.make_body_relative()
    #body.add_velocities()
    body_delta = body.diff(frames)

    # encode goal-relative data.
    goal = lmj.cubes.Trial(trial.parent, trial.basename)
    goal.df = trial.df.copy()
    goal.make_target_relative()
    #goal.add_velocities()
    goal_delta = goal.diff(frames)

    out = lmj.cubes.Trial(trial.parent, trial.basename)
    out.df = trial.df.copy()
    for bc in body.marker_position_columns:
        bn = 'b{}{}'.format(bc[6:8], bc[-1])
        for gc in goal.marker_position_columns:
            gn = 'g{}{}'.format(gc[6:8], gc[-1])
            out.df['jac-fwd-{}/{}'.format(gn, bn)] = goal_delta[gc] / body_delta[bc]
            out.df['jac-inv-{}/{}'.format(bn, gn)] = body_delta[bc] / goal_delta[gc]

    out.save(trial.root.replace(trial.experiment.root, output))


@climate.annotate(
    root='load data files from this directory tree',
    output='save encoded data to this directory tree',
    pattern='process trials matching this pattern',
    frames=('compute jacobian over this many frames', 'option', None, int),
)
def main(root, output, pattern='*', frames=20):
    work = joblib.delayed(compute)
    trials = lmj.cubes.Experiment(root).trials_matching(pattern)
    #joblib.Parallel(-1)(work(t, output, frames) for t in trials)
    compute(list(trials)[0], output, frames)


if __name__ == '__main__':<commit_msg>Fix bug.<commit_after>#!/usr/bin/env python

import climate
import joblib
import lmj.cubes
import numpy as np
import os

logging = climate.get_logger('15-compute-jac')


def compute(trial, output, frames):
    trial.load()

    # encode body-relative data.
    body = lmj.cubes.Trial(trial.parent, trial.basename)
    body.df = trial.df.copy()
    stats = body.make_body_relative()
    #body.add_velocities()
    body_delta = body.df.diff(frames)

    # encode goal-relative data.
    goal = lmj.cubes.Trial(trial.parent, trial.basename)
    goal.df = trial.df.copy()
    goal.make_target_relative()
    #goal.add_velocities()
    goal_delta = goal.df.diff(frames)

    out = lmj.cubes.Trial(trial.parent, trial.basename)
    out.df = trial.df.copy()
    for bc in body.marker_position_columns:
        bn = 'b{}{}'.format(bc[6:8], bc[-1])
        for gc in goal.marker_position_columns:
            gn = 'g{}{}'.format(gc[6:8], gc[-1])
            out.df['jac-fwd-{}/{}'.format(gn, bn)] = goal_delta[gc] / body_delta[bc]
            out.df['jac-inv-{}/{}'.format(bn, gn)] = body_delta[bc] / goal_delta[gc]

    out.save(trial.root.replace(trial.experiment.root, output))


@climate.annotate(
    root='load data files from this directory tree',
    output='save encoded data to this directory tree',
    pattern='process trials matching this pattern',
    frames=('compute jacobian over this many frames', 'option', None, int),
)
def main(root, output, pattern='*', frames=20):
    work = joblib.delayed(compute)
    trials = lmj.cubes.Experiment(root).trials_matching(pattern)
    #joblib.Parallel(-1)(work(t, output, frames) for t in trials)
    compute(list(trials)[0], output, frames)


if __name__ == '__main__':
{'fraction_non_alphanumeric': 0.1534206695778748, 'fraction_numerical': 0.0069868995633187774, 'mean_word_length': 3.4915032679738562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2113786', 'n_tokens_mistral': 1250, 'n_tokens_neox': 1175, 'n_words': 252}