# Path: dataset/pose_dataset.py
# def get_pairwise_index(j_id, j_id_end, num_joints):
#     return (num_joints - 1) * j_id + j_id_end - int(j_id < j_id_end)


import math
import time
import sys
import os
import numpy as np
import scipy.io as sio
from collections import namedtuple
from multicut import solve_nl_lmp
from dataset.pose_dataset import get_pairwise_index

    def load(self):
        for cidx1 in range(self.num_keypoints):
            for cidx2 in range(cidx1+1, self.num_keypoints):
                model_name  = "{}/spatial_model_cidx_{}_{}.mat".format(self.cfg.pairwise_model_dir, cidx1 + 1, cidx2 + 1)
                #print "loading:", model_name
                if not os.path.isfile(model_name):
                    continue
    
                spatial_model = sio.loadmat(model_name)

                self.X_max[cidx1][cidx2] = spatial_model['spatial_model']['training_opts'][0][0][0]['X_max'][0][0]
                self.X_min[cidx1][cidx2] = spatial_model['spatial_model']['training_opts'][0][0][0]['X_min'][0][0]
                self.w[cidx1][cidx2] = spatial_model['spatial_model']['log_reg'][0][0][0]['w'][0][0][:]

                #self.pair_class[cidx1][cidx2] = PairClassDistAngle(w=w, X_min=X_min, X_max=X_max)
                
        if not self.cfg.tensorflow_pairwise_order:
            tmpval = sio.loadmat(self.cfg.pairwise_stats_fn)
            self.graph = tmpval['graph']
            self.pairwise_means = tmpval['means']
            self.pairwise_std_devs = tmpval['std_devs']

            for gidx in range(self.graph.shape[0]):
                cidx1 = self.graph[gidx, 0]
                cidx2 = self.graph[gidx, 1]
                self.graph_dict[(cidx1, cidx2)] = gidx

    def get_fwd_bwd_index(self, cidx1, cidx2):
        if self.cfg.tensorflow_pairwise_order:

# Path: dataset/pose_dataset.py
# def get_pairwise_index(j_id, j_id_end, num_joints):
#     return (num_joints - 1) * j_id + j_id_end - int(j_id < j_id_end)


# Path: multiperson/predict.py
import math
import time
import sys
import os
import numpy as np
import scipy.io as sio
from collections import namedtuple
from multicut import solve_nl_lmp
from dataset.pose_dataset import get_pairwise_index


    def load(self):
        for cidx1 in range(self.num_keypoints):
            for cidx2 in range(cidx1+1, self.num_keypoints):
                model_name  = "{}/spatial_model_cidx_{}_{}.mat".format(self.cfg.pairwise_model_dir, cidx1 + 1, cidx2 + 1)
                #print "loading:", model_name
                if not os.path.isfile(model_name):
                    continue
    
                spatial_model = sio.loadmat(model_name)

                self.X_max[cidx1][cidx2] = spatial_model['spatial_model']['training_opts'][0][0][0]['X_max'][0][0]
                self.X_min[cidx1][cidx2] = spatial_model['spatial_model']['training_opts'][0][0][0]['X_min'][0][0]
                self.w[cidx1][cidx2] = spatial_model['spatial_model']['log_reg'][0][0][0]['w'][0][0][:]

                #self.pair_class[cidx1][cidx2] = PairClassDistAngle(w=w, X_min=X_min, X_max=X_max)
                
        if not self.cfg.tensorflow_pairwise_order:
            tmpval = sio.loadmat(self.cfg.pairwise_stats_fn)
            self.graph = tmpval['graph']
            self.pairwise_means = tmpval['means']
            self.pairwise_std_devs = tmpval['std_devs']

            for gidx in range(self.graph.shape[0]):
                cidx1 = self.graph[gidx, 0]
                cidx2 = self.graph[gidx, 1]
                self.graph_dict[(cidx1, cidx2)] = gidx

    def get_fwd_bwd_index(self, cidx1, cidx2):
        if self.cfg.tensorflow_pairwise_order:

            fwd_idx = get_pairwise_index(cidx1, cidx2, self.cfg.num_joints)