text:
from typing import Any

import equinox as eqx
import jax
import jax.interpreters.ad as ad
import jax.interpreters.batching as batching
import jax.interpreters.mlir as mlir
import jax.interpreters.xla as xla
import jax.lax as lax

from ..custom_types import PyTree

# TODO: this will sometimes return False on a perturbed array, see JAX issue #9567.
# Correspondingly it should *not be used* until that is fixed.
# (The only use is in nondifferentiable_input, below, which will simply not raise
# errors quite as frequently as it should do -- not too bad.)
def is_perturbed(x: Any) -> bool:
    if isinstance(x, jax.ad.JVPTracer):
        return True
    elif isinstance(x, jax.core.Tracer):
        return any(is_perturbed(attr) for name, attr in x._contents())
    else:
        return False

def nondifferentiable_input(x: PyTree, name: str) -> None:
    if any(is_perturbed(xi) for xi in jax.tree_leaves(x)):
        raise ValueError(f"Cannot differentiate {name}.")

_nondifferentiable_output_p = jax.core.Primitive("nondifferentiable_output")

def _nondifferentiable_output_batch(x, batch_axes):
    (x,) = x
    (batch_axes,) = batch_axes
    return nondifferentiable_output(x), batch_axes

def _nondifferentiable_output_jvp(primals, tangents):
    (primals,) = primals
    (tangents,) = tangents
    return nondifferentiable_output(primals), nondifferentiable_output(tangents)

def _nondifferentiable_output_transpose(cts_in, _):
    if isinstance(cts_in, ad.Zero):
        return ad.Zero  # the class, not an instance
    else:
        raise RuntimeError(
            "Reverse-mode autodifferentiation is disabled for this operation."
        )

_nondifferentiable_output_p.def_impl(lambda x: x)
_nondifferentiable_output_p.def_abstract_eval(lambda x: x)
batching.primitive_batchers[
    _nondifferentiable_output_p
] = _nondifferentiable_output_batch
if hasattr(xla, "lower_fun"):
    xla.register_translation(
        _nondifferentiable_output_p,
        xla.lower_fun(lambda x: x, multiple_results=False, new_style=True),
    )
mlir.register_lowering(
    _nondifferentiable_output_p,
    mlir.lower_fun(lambda x: x, multiple_results=False),
)
ad.primitive_jvps[_nondifferentiable_output_p] = _nondifferentiable_output_jvp
ad.primitive_transposes[
    _nondifferentiable_output_p
] = _nondifferentiable_output_transpose

def nondifferentiable_output(x: PyTree) -> PyTree:
    return _nondifferentiable_output_p.bind(x)

class fixed_custom_jvp:
    """As jax.custom_jvp but works around JAX issue #9374."""

    def __init__(self, fn, nondiff_argnums=()):
        assert set(nondiff_argnums) == set(range(len(nondiff_argnums)))

        def fn_wrapper(nondiff_args_nontracer, nondiff_args_tracer, diff_args):
            nondiff_args = eqx.combine(nondiff_args_nontracer, nondiff_args_tracer)
            return fn(*nondiff_args, *diff_args)

        self.fn = jax.custom_jvp(fn_wrapper, nondiff_argnums=(0,))
        self.cutoff = max(nondiff_argnums, default=-1) + 1
        self.fn_jvp = None

    def defjvp(self, fn_jvp):
        def fn_jvp_wrapper(nondiff_args_nontracer, combined_args, tang_combined_args):
            nondiff_args_tracer, diff_args = combined_args
            _, tang_diff_args = tang_combined_args
            nondiff_args = eqx.combine(nondiff_args_nontracer, nondiff_args_tracer)
            return fn_jvp(*nondiff_args, diff_args, tang_diff_args)

        self.fn.defjvp(fn_jvp_wrapper)

    def __call__(self, *args):
        is_tracer = lambda x: isinstance(x, jax.core.Tracer)
        nondiff_args = args[: self.cutoff]
        diff_args = args[self.cutoff :]
        nondiff_args_tracer, nondiff_args_nontracer = eqx.partition(
            nondiff_args, is_tracer
        )
        nondiff_args_tracer = jax.tree_map(lax.stop_gradient, nondiff_args_tracer)
        return self.fn(nondiff_args_nontracer, nondiff_args_tracer, diff_args)

max_stars_repo_name: patrick-kidger/diffrax

max_issues_repo_name: patrick-kidger/diffrax

max_forks_repo_name: patrick-kidger/diffrax

reason: import jax


text:
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F

class Connect2Model(nn.Module):

    def __init__(self, board_size, action_size, device):

        super(Connect2Model, self).__init__()

        self.device = device
        self.size = board_size
        self.action_size = action_size

        self.fc1 = nn.Linear(in_features = self.size, out_features=16)
        #fc1에서, 입력 feature은 보드 사이즈로 넣고 출력 feature은 16개
        self.fc2 = nn.Linear(in_features = 16, out_features = 16)
        #fc2에서 방금 그 16개 넣고 out도 16개

        #TWO heads on our network
        self.action_head = nn.Linear(in_features = 16, out_features=self.action_size)
        self.value_head = nn.Linear(in_features=16, out_features=1)

        self.to(device)  #device로 다시 보낸다?

    def forward(self, x):
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))

        action_logits = self.action_head(x)
        value_logits = self.value_head(x)

        return F.softmax(action_logits, dim=1)
        #softmax는 action_logits(1차원의 벡터)을 0~1사이로정규화해서 확률을 추정한다.

    def predict(self, board):
        board = torch.FloatTensor(board.astype(np.float32)).to(self.device)
        #board를 일단 float값으로 바꾸고, 그걸 torch에 넣은 값을 각각 board에 할당
        board = board.view(1, self.size)
        #view - 원소의 수를 유지하면서 텐서의 크기 변경 . 여기서는 shape을 (1, boardsize)
        self.eval() #training과 inference시 다르게 동작하는 layer때문에 모든 동작들을 inference mode로 바꿔줌
        with torch.no_grad(): #pytorch가 autograd engine을 꺼버림. 더이상 gradient를 자동으로 트래킹 안 함
            pi, v = self.forward(board) #함수 fc1, fc2 사용해서 통과시켜줌

        return pi.data.cpu().numpy()[0], v.data.cpu().numpy()[0]

ext: py

reason: import numpy


text:
"""
This code is used to fit KRR. Note that KRR for large
datasets can require a lot of memory. For FMNIST models
we used 64GB and for synthetic datasets (with n = 10^5),
we used 128GB of RAM. This code is written for Python 2.7.13.

Inputs:

experiment_name: The name of the experiment (used for record keeping).

param_1: overloaded argument:
	When kernel name = polynomial: Power of the polynomial kernel
	When dataset == SYNTH: the number of observations
	otherwise, the number of layers for ntk kernel

p2_ind:	The constant term in the polynomial kernel.

kernel_name: The name of the kernel: ntk, gp (ReLU RF), poly (polynomial).

job_id: Job id (used for record keeping).

dataset: The name of the dataset:
	FMNIST (high-frequency noise)/ NFMNIST (low-frequency noise)
	CIFAR10 (low-frequency noise)/ CIFAR2 (high-frequency noise)
	SYNTH (synthetic data).

noise_index: The index of the noise level. An integer typically ranging from zero (no noise) to 14.
"""

from __future__ import print_function
import cPickle as pickle
import math
import numpy as np
import os
import sys
import scipy.linalg as scl
import scipy.sparse as ss
import time
from preprocess import prep_data

experiment_name = sys.argv[1]
param_1 = np.int(sys.argv[2])
p2_ind = np.int(sys.argv[3])
kernel_name = sys.argv[4]
job_id = np.int(sys.argv[5])
dataset = sys.argv[6]
noise_index = np.int(sys.argv[7])

# Read user provided directories:
user_dirs = {}
with open("./directories.txt") as f:
	for line in f:
		(key, val) = line.split()
		user_dirs[key] = val

# The hyper-parameters used for each dataset:
# expand: whether to one-hot-encode the labels
# mean: the mean of the labels to be removed before fitting
# reg_list: the grid of l_2 regularization intensities
# p2_grid: the grid of values used for the constant term in polynomial kernels
if dataset == 'CIFAR10':
	expand = True
	mean = 0.1
	reg_list = 10 ** np.linspace(-6, 1, num=20)
	p2_grid = 2 ** np.linspace(-3, 3, num=10)
elif dataset == 'SYNTH':
	expand = False
	mean = 0.0
	reg_list = 10 ** np.linspace(0, 6, num=10)
	p2_grid = 2 ** np.linspace(-3, 3, num=10)
elif dataset == 'CIFAR2':
	expand = False
	mean = 0.5
	reg_list = 10 ** np.linspace(-2, 4, num=20)
	# Added for RF
	reg_list = np.concatenate([reg_list, 10 ** np.linspace(4.2, 10, num=20)])
	p2_grid = 2 ** np.linspace(-3, 3, num=10)
elif dataset in ['FMNIST', 'NFMNIST']:
	expand = True
	mean = 0.1
	# Changed for the new kernels
	if kernel_name == 'ntk' and param_1 == 3:
		reg_list = 10 ** np.linspace(-4, 3, num=20)
		print('Regularization Param Chosen for Three Layer NTK')
	else:
		# Changed Base Case
		reg_list = 10 ** np.linspace(-1, 5, num=20)
	p2_grid = 2 ** np.linspace(-3, 3, num=10)
else:
	print('Dataset not recognized')
	expand = False
	mean = 0.0
	reg_list = 10 ** np.linspace(0, 6, num=20)
	p2_grid = 2 ** np.linspace(-3, 3, num=10)

param_2 = p2_grid[p2_ind]
# Directory used for saving the KRR results
directory = user_dirs['rkhs_dir'] + '%s_%s_%s_%d_%d_%d_%d'%(experiment_name, dataset, kernel_name, param_1, p2_ind, noise_index, job_id)
if not os.path.exists(directory):
	os.makedirs(directory)

fileName = directory + "/" + 'log_file.txt'
_file = open(fileName, 'w', buffering=1)
print('Arguments:', file=_file)
print('The noise index is %d'%(noise_index), file=_file)
print('The kernel hyper_param is %d, %d'%(param_1, p2_ind), file=_file)
print('Kernel type is: %s'%(kernel_name), file=_file)
print('Numpy version %s'%(np.version.version), file=_file)
print('Scipy version %s'%(scl.__version__), file=_file)
print('=========', file=_file)

def NTK2(X, Z):
	"""This function computes NTK kernel for two-layer ReLU neural networks via
	an analytic formula.

	Input:
	X: d times n_1 matrix, where d is the feature dimension and n_i are # obs.
	Z: d times n_2 matrix, where d is the feature dimension and n_i are # obs.

	output:
	C: The kernel matrix of size n_1 times n_2.
	"""
	pi = math.pi
	assert X.shape[0] == Z.shape[0]
	# X is sized d \times n
	nx = np.linalg.norm(X, axis=0, keepdims=True)
	nx = nx.T
	nz = np.linalg.norm(Z, axis=0, keepdims=True)

	C = np.dot(X.T, Z) #n_1 * n_2
	C = np.multiply(C, (nx ** -1))
	C = np.multiply(C, (nz ** -1))
	# Fixing numerical mistakes
	C = np.minimum(C, 1.0)
	C = np.maximum(C, -1.0)

	C = np.multiply(1.0 - np.arccos(C) / pi, C) + np.sqrt(1 - np.power(C, 2)) / (2 * pi)
	C = np.multiply(nx, np.multiply(C, nz))
	return C

def RFK2(X, Z):
	"""This function computes RF kernel for two-layer ReLU neural networks via
	an analytic formula.

	Input:
	X: d times n_1 matrix, where d is the feature dimension and n_i are # obs.
	Z: d times n_2 matrix, where d is the feature dimension and n_i are # obs.

	output:
	C: The kernel matrix of size n_1 times n_2.
	"""
	pi = math.pi
	assert X.shape[0] == Z.shape[0]
	# X is sized d \times n
	nx = np.linalg.norm(X, axis=0, keepdims=True)
	nx = nx.T
	nz = np.linalg.norm(Z, axis=0, keepdims=True)

	C = np.dot(X.T, Z) #n_1 * n_2
	C = np.multiply(C, (nx ** -1))
	C = np.multiply(C, (nz ** -1))
	# Fixing numerical mistakes
	C = np.minimum(C, 1.0)
	C = np.maximum(C, -1.0)
	C = np.multiply(np.arcsin(C), C) / pi + C / 2.0 + np.sqrt(1 - np.power(C, 2)) / pi
	C = 0.5 * np.multiply(nx, np.multiply(C, nz))
	return C

def compute_kernel(name, hyper_param):
	"""This function computes the test and the training kernels.
	Inputs:
		name: Kernel name.
		hyper_param: Kernel hyper-parameters.
	Outputs:
		Training Kernel: n times n np.float32 matrix.
		Test Kernel: nt times n np.float32 matrix.
		ytrain: vector of training labels. n times 1 np.float32.
		ytest: vector of test labels. nt times 1 np.float32.
	"""
	X, ytrain, Xtest, ytest = prep_data(dataset, False, noise_index)
	nt = Xtest.shape[0]
	n = X.shape[0]
	d = X.shape[1] + 0.0
	# Read precomputed CNTK kernel and form the kernel matrix
	if dataset == 'CIFAR10' and name == 'ntk':
		K = np.zeros((n, n), dtype=np.float32)
		KT = np.zeros((n, nt), dtype=np.float32)
		main_dir = user_dirs['cntk_dir'] + 'LFGaussian_CIFAR10_Myrtle_%d/'%(noise_index)
		m = 200
		count = 250
		for i in range(count):
			K[(m * i):(m * (i + 1)), :] = np.load(main_dir + 'train_ntk_%d.npy'%(i))
			KT[(m * i):(m * (i + 1)), :] = np.load(main_dir + 'test_ntk_%d.npy'%(i))
		KT = KT.T
		for i in range(n):
			K[:, i] = K[i, :]
	elif dataset == 'SYNTH'	and name == 'ntk':
		n = hyper_param[0]
		K = np.load(user_dirs['synth_dir'] + 'NTK_TRAIN_%d.npy'%(noise_index))
		K = K[:n, :n]
		KT = np.load(user_dirs['synth_dir'] + 'NTK_TEST_%d.npy'%(noise_index))
		KT = KT[:, :n]
		ytrain = ytrain[:n, :]
	elif name == 'polynomial':
		print('Request to use degree %d polynomial kernel with intercept %f'%(hyper_param[0], hyper_param[1]), file=_file)
		p = hyper_param[0]
		intercept = hyper_param[1]
		intercept = intercept.astype(np.float32)
		K =  (np.power(intercept + np.dot(X, X.T) / np.sqrt(d), p))
		KT = (np.power(intercept + np.dot(Xtest, X.T) / np.sqrt(d), p))
	elif name == 'rf':
		directory = user_dirs['rf_dir'] + 'RF_Kernel_noise_%d'%(noise_index)
		name = directory + '/RF_Kernel_Train_N_4200000.npy'
		K = np.load(name)
		name = directory + '/RF_Kernel_Test_N_4200000.npy'
		KT = np.load(name)

		K = K.astype(np.float32)
		KT = KT.astype(np.float32)
	elif name == 'ntk':
		# ntk KRR
		layers = hyper_param[0]
		if layers < 3:
			# For two-layers networks, compute the kernel directly
			K = NTK2(X.T, X.T)
			KT = NTK2(Xtest.T, X.T)
		else:
			# For multilayer networks, read it from the disk
			K = np.load(user_dirs['ntk_dir'] + 'Train_NTK_%d_layers_%d_NFMNIST.npy'%(noise_index, hyper_param[0]))
			KT = np.load(user_dirs['ntk_dir'] + 'Test_NTK_%d_layers_%d_NFMNIST.npy'%(noise_index, hyper_param[0]))
	elif name == 'gp':
		# ReLU RF KRR
		K = RFK2(X.T, X.T)
		KT = RFK2(Xtest.T, X.T)
	else:
		raise Exception('Non-valid Kernel')
	assert K.shape[0] == n and K.shape[1] == n
	assert K.dtype == np.float32
	assert KT.shape[0] == nt and KT.shape[1] == n
	assert KT.dtype == np.float32
	return (K, KT, ytrain, ytest)

def compute_accuracy(true_labels, preds):
	"""This function computes the classification accuracy of the vector
	preds. """
	if true_labels.shape[1] == 1:
		n = len(true_labels)
		true_labels = true_labels.reshape((n, 1))
		preds = preds.reshape((n, 1))
		preds = preds > 0
		inds = true_labels > 0
		return np.mean(preds == inds)
	groundTruth = np.argmax(true_labels, axis=1).astype(np.int32)
	predictions = np.argmax(preds, axis=1).astype(np.int32)
	return np.mean(groundTruth == predictions)

N = len(reg_list)
errors = np.zeros((N, 4)) #Train Loss, Train Accuracy, Test Loss, Test Accuracy
K, KT, ytrain, ytest = compute_kernel(kernel_name, [param_1, param_2])
print('Kernel Computation Done!', file=_file)

n = len(ytrain)
nt = len(ytest)
if expand:
	# Expand the labels
	maxVal = np.int(ytrain.max())
	Y = np.zeros((n, maxVal + 1), dtype=np.float32)
	Y[np.arange(n), ytrain[:, 0].astype(np.int32)] = 1.0

	YT = np.zeros((nt, maxVal + 1), dtype=np.float32)
	YT[np.arange(nt), ytest[:, 0].astype(np.int32)] = 1.0
	Y = Y - mean
	YT = YT - mean
	assert Y.dtype == np.float32
	assert YT.dtype == np.float32
	ytrain = Y
	ytest = YT
	mean = 0.0

for j in range(N):
	reg = reg_list[j].astype(np.float32)
	print('The regularization parameter is %f corresponding to the index %d'%(reg, j), file=_file)
	RK = K + reg * np.eye(n, dtype=np.float32)
	assert K.dtype == np.float32
	assert RK.dtype == np.float32
	print('Solving kernel regression with %d observations and regularization param %f'%(n, reg), file=_file)
	t1 = time.time()
	if expand:
		x = scl.solve(RK, ytrain, assume_a='sym')
	else:
		cg = ss.linalg.cg(RK, ytrain[:, 0] - mean, maxiter=400, atol=1e-4, tol=1e-4)
		x = np.copy(cg[0]).reshape((n, 1))
	t2 = time.time()
	print('iteration took %f seconds'%(t2 - t1), file=_file)
	yhat = np.dot(K, x) + mean
	preds = np.dot(KT, x) + mean
	errors[j, 0] = np.linalg.norm(ytrain - yhat) ** 2 / (len(ytrain) + 0.0)
	errors[j, 2] = np.linalg.norm(ytest - preds) ** 2 / (len(ytest) + 0.0)
	errors[j, 1] = compute_accuracy(ytrain - mean, yhat - mean)
	errors[j, 3] = compute_accuracy(ytest - mean, preds - mean)
	print('Training Error is %f'%(errors[j, 0]), file=_file)
	print('Test Error is %f'%(errors[j, 2]), file=_file)
	print('Training Accuracy is %f'%(errors[j, 1]), file=_file)
	print('Test Accuracy is %f'%(errors[j, 3]), file=_file)

_file.close()
save_dict = {'errors': errors, 'reg_params': [reg_list, p2_grid], 'hyper-params': [param_1, param_2, dataset, kernel_name], 'x': x, 'yhat': yhat, 'ythat': preds}
file_name = directory + '/stats.pkl'
with open(file_name, 'wb') as output:
	pickle.dump(save_dict, output, -1)

reason: import numpy,import scipy


text:
""" PredIE
Copyright 2021 Wang Kang
"""

from __future__ import print_function
from __future__ import division
import torch
import torch.nn as nn
import torch.optim as optim
import numpy as np
import torchvision
from torchvision import datasets, models, transforms
import matplotlib.pyplot as plt
import time
import os
import copy

from torch.autograd import Variable
from torch.utils.data import Dataset
from PIL import Image
import timm.models as tm
import argparse

from sklearn.metrics import mean_squared_error
from sklearn.metrics import mean_absolute_error
from sklearn.metrics import r2_score

# For Conformer
from timm.models import create_model
import models

# output path
out_path = os.path.join('./output', time.strftime("%Y%m%d-%H%M%S", time.localtime()))

# Number of classes in the dataset
num_classes = 1

lr = 0.001

parm = {}  # 初始化保存模块参数的parm字典

# Set argparse
parser = argparse.ArgumentParser(description='PyTorch ImageNet Training')

# Dataset / Model parameters
parser.add_argument('--data_dir', metavar='DIR', default='../ECC',
                    help='path to dataset')
'''
Setting model and training params, some can use parser to get value.
Models to choose from [resnet, regnet, efficientnet, vit, pit, mixer, deit, swin-vit
alexnet, vgg, squeezenet, densenet, inception, Conformer_tiny_patch16]
'''
parser.add_argument('--model', default='conformer', type=str, metavar='MODEL',
                    help='Name of model to train (default: "resnet"')
parser.add_argument('-b', '--batch-size', type=int, default=16, metavar='N',
                    help='input batch size for training (default: 32)')
parser.add_argument('-ep', '--epochs', type=int, default=1, metavar='N',
                    help='number of epochs to train (default: )')
parser.add_argument('-ft', '--use-pretrained', type=bool, default=True, metavar='N',
                    help='Flag to use fine tuneing(default: False)')
parser.add_argument('-fe', '--feature-extract', type=bool, default=True, metavar='N',
                    help='False to finetune the whole model. True to update the reshaped layer params(default: False)')

parser.add_argument('--drop', type=float, default=0.0, metavar='PCT',
                    help='Dropout rate (default: 0.)')
parser.add_argument('--drop-path', type=float, default=0.1, metavar='PCT',
                    help='Drop path rate (default: 0.1)')
parser.add_argument('--drop-block', type=float, default=None, metavar='PCT',
                    help='Drop block rate (default: None)')

# set train and val data prefixs
# prefixs = ['A1','A2','B1','B2','C1','C2','D1','D2','E1','E2']
prefixs = ['A1','A2','B1','B2','C1','C2', 'D2']
# prefixs = ['A1','B1','C2', 'D2', 'E1']

def train_model(model, dataloaders, criterion, optimizer, num_epochs=25, is_inception=False):
    since = time.time()

    train_acc_history = []
    val_acc_history = []
    result = []

    kernal = np.empty((0, 3))

    best_model_wts = copy.deepcopy(model.state_dict())
    best_epoch = 0
    min_loss = 999999

    for epoch in range(num_epochs):
        print('Epoch {}/{}'.format(epoch, num_epochs - 1))
        print('-' * 10)

        # Each epoch has a training and validation phase
        for phase in ['train', 'val']:
            if phase == 'train':
                model.train()  # Set model to training mode
            else:
                model.eval()   # Set model to evaluate mode

            running_loss = 0.0
            running_corrects = 0

            # Iterate over data.
            for inputs, labels in dataloaders[phase]:
                inputs = inputs.to(device)
                labels = labels.to(device)

                # zero the parameter gradients
                optimizer.zero_grad()

                # forward
                # track history if only in train
                with torch.set_grad_enabled(phase == 'train'):
                    if is_inception and phase == 'train':
                        # From https://discuss.pytorch.org/t/how-to-optimize-inception-model-with-auxiliary-classifiers/7958
                        outputs, aux_outputs = model(inputs)
                        outputs = outputs.view(-1)
                        loss1 = criterion(outputs, labels)
                        loss2 = criterion(aux_outputs, labels)
                        loss = loss1 + 0.4*loss2
                    else:
                        outputs = model(inputs)
                        if isinstance(outputs, list):
                            # Conformer or ...
                            for i, o in enumerate(outputs):
                                outputs[i] = o.view(-1)
                            loss_list = [criterion(o, labels) / len(outputs) for o in outputs]
                            loss = sum(loss_list)
                        else:
                            outputs = outputs.view(-1)
                            loss = criterion(outputs, labels)

                        if phase == 'val' and epoch == num_epochs-1:
                            # result.append(outputs)
                            if isinstance(outputs, list):
                                # Conformer or ...

                                res = outputs[0]
                                for o in range(1, len(outputs)):
                                    res = res + o
                                res = res/len(outputs)

                                temp = res.detach().cpu().numpy()
                                for i in range(temp.shape[0]):
                                    result.append(temp[i])
                            else:
                                temp = outputs.detach().cpu().numpy()
                                for i in range(temp.shape[0]):
                                    result.append(temp[i])

                    if phase == 'train':
                        loss.backward()
                        optimizer.step()

                # save loss value
                running_loss += loss.item() * inputs.size(0)

            epoch_loss = running_loss / len(dataloaders[phase].dataset)
            print('{} Loss: {:.4f}'.format(phase, epoch_loss))
            if phase == 'train':
                train_acc_history.append(epoch_loss)
            if phase == 'val':
                val_acc_history.append(epoch_loss)
                if epoch_loss < min_loss:
                    min_loss = epoch_loss  # update min_loss
                    print('Best val min_loss: {:4f} in Epoch {}/{}'.format(min_loss, epoch, num_epochs - 1))
                    best_model_wts = copy.deepcopy(model.state_dict())
                    best_epoch = epoch
        print()
    time_elapsed = time.time() - since
    print('Training complete in time of {:.0f}m {:.0f}s'.format(time_elapsed // 60, time_elapsed % 60))
    # print('Best val Acc: {:4f}'.format(best_acc))

    # load best model weights
    model.load_state_dict(best_model_wts)
    # save best model weights
    save_path = os.path.join(out_path, args.model + '_' + str(best_epoch) + '_' + 'best_model.pth')
    torch.save(best_model_wts, save_path)
    return model, train_acc_history, val_acc_history, result

def set_parameter_requires_grad(model, feature_extracting):
    if feature_extracting:
        for param in model.parameters():
            param.requires_grad = False

def initialize_model(model_name, num_classes, feature_extract, use_pretrained=False):
    # Initialize these variables which will be set in this if statement. Each of these
    #   variables is model specific.
    model_ft = None
    input_size = 0

    if model_name == "resnet":
        """ Resnet
        """
        model_ft = models.resnet18(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.fc.in_features
        model_ft.fc = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    # if model_name == "resnet":
    #     """ Resnet34
    #     """
    #     model_ft = tm.resnet34(pretrained=use_pretrained)
    #     set_parameter_requires_grad(model_ft, feature_extract)
    #     num_ftrs = model_ft.fc.in_features
    #     model_ft.fc = nn.Linear(num_ftrs, num_classes)
    #     input_size = 224

    elif model_name == "regnet":
        """ regnet
            regnety_040， regnety_080， regnety_160
        """
        model_ft = tm.regnety_040(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.get_classifier().in_features
        model_ft.fc = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    elif model_name == "efficientnet_b2":
        """
            efficientnet_b2 256, efficientnet_b3 288, efficientnet_b4 320
        """
        model_ft = tm.efficientnet_b2(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.get_classifier().in_features
        model_ft.classifier = nn.Linear(num_ftrs, num_classes)
        input_size = 256

    elif model_name == "efficientnet_b3":
        """
            efficientnet_b2 256, efficientnet_b3 288, efficientnet_b4 320
        """
        model_ft = tm.efficientnet_b3(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.get_classifier().in_features
        model_ft.classifier = nn.Linear(num_ftrs, num_classes)
        input_size = 288

    elif model_name == "efficientnet_b4":
        """
            efficientnet_b2 256, efficientnet_b3 288, efficientnet_b4 320
        """
        model_ft = tm.efficientnet_b4(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.get_classifier().in_features
        model_ft.classifier = nn.Linear(num_ftrs, num_classes)
        input_size = 320

    elif model_name == "vit":
        """ vit
        """
        model_ft = tm.vit_tiny_patch16_224(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.head.in_features
        model_ft.head = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    elif model_name == "pit":
        """ pit
        pit_xs_224, pit_s_224
        """
        model_ft = tm.pit_xs_224(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.get_classifier().in_features
        model_ft.head = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    elif model_name == "deit":
        """ deit
            deit_small_patch16_224, deit_base_patch16_224
        """
        model_ft = tm.deit_small_patch16_224(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.head.in_features
        model_ft.head = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    elif model_name == "mixer":
        """ mixer
        """
        model_ft = tm.mixer_b16_224(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.head.in_features
        model_ft.head = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    elif model_name == "swin-vit":
        """ swin-vit
        tm.swin_tiny_patch4_window7_224, tm.swin_small_patch4_window7_224
        """
        model_ft = tm.swin_small_patch4_window7_224(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.head.in_features
        model_ft.head = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    elif model_name == "alexnet":
        """ Alexnet
        """
        model_ft = models.alexnet(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.classifier[6].in_features
        model_ft.classifier[6] = nn.Linear(num_ftrs,num_classes)
        input_size = 224

    elif model_name == "vgg":
        """ VGG11_bn
        """
        model_ft = models.vgg11_bn(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.classifier[6].in_features
        model_ft.classifier[6] = nn.Linear(num_ftrs,num_classes)
        input_size = 224

    elif model_name == "squeezenet":
        """ Squeezenet
        """
        model_ft = models.squeezenet1_0(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        model_ft.classifier[1] = nn.Conv2d(512, num_classes, kernel_size=(1,1), stride=(1,1))
        model_ft.num_classes = num_classes
        input_size = 224

    elif model_name == "densenet":
        """ Densenet
        """
        model_ft = models.densenet121(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        num_ftrs = model_ft.classifier.in_features
        model_ft.classifier = nn.Linear(num_ftrs, num_classes)
        input_size = 224

    elif model_name == "inception":
        """ Inception v3
        Be careful, expects (299,299) sized images and has auxiliary output
        """
        model_ft = models.inception_v3(pretrained=use_pretrained)
        set_parameter_requires_grad(model_ft, feature_extract)
        # Handle the auxilary net
        num_ftrs = model_ft.AuxLogits.fc.in_features
        model_ft.AuxLogits.fc = nn.Linear(num_ftrs, num_classes)
        # Handle the primary net
        num_ftrs = model_ft.fc.in_features
        model_ft.fc = nn.Linear(num_ftrs,num_classes)
        input_size = 299

    elif model_name == "conformer":
        model_ft = create_model(
            "Conformer_tiny_patch16",
            pretrained=False,
            num_classes=1,
            drop_rate=args.drop,
            drop_path_rate=args.drop_path,
            drop_block_rate=args.drop_block,
        )
        set_parameter_requires_grad(model_ft, feature_extract)
        for param in model_ft.conv_cls_head.parameters():
            param.requires_grad = True  # it was require_grad
        for param in model_ft.trans_cls_head.parameters():
            param.requires_grad = True  # it was require_grad
        input_size = 224

    else:
        print("Invalid model name, exiting...")
        exit()

    return model_ft, input_size

# use PIL Image to read image
def default_loader(path):
    try:
        img = Image.open(path)
        return img.convert('RGB')
    except:
        print("Cannot read image: {}".format(path))

# define your Dataset. Assume each line in your .txt file is [name/tab/label], for example:0001.jpg 1
class customData(Dataset):
    def __init__(self, img_path, txt_path, dataset = '', data_transforms=None, loader = default_loader):
        with open(txt_path) as input_file:
            lines = input_file.readlines()
            self.img_name = []
            self.img_label = []
            for line in lines:
                img_name = line.strip().split('\t')[0]
                img_prefix = img_name.split('-')[0]
                # if img_prefix is not None:
                if img_prefix in prefixs:
                    self.img_name.append(os.path.join(img_path,img_name))
                    self.img_label.append(float(line.strip().split('\t')[1]))
        ln = len(self.img_label)
        y = self.img_label
        y = torch.tensor(y)
        y = y.numpy()
        print(np.shape(y))
        meanVal = np.mean(y)
        stdVal = np.std(y)
        y = (y - meanVal) / stdVal
        self.img_label = y
        self.data_transforms = data_transforms
        self.dataset = dataset
        self.loader = loader

    def __len__(self):
        return len(self.img_name)

    def __getitem__(self, item):
        img_name = self.img_name[item]
        label = self.img_label[item]
        img = self.loader(img_name)

        if self.data_transforms is not None:
            try:
                img = self.data_transforms[self.dataset](img)
            except:
                print("Cannot transform image: {}".format(img_name))
        return img, label

def loadCol(infile, k):
    f = open(infile, 'r')
    sourceInLine = f.readlines()
    dataset = []
    for line in sourceInLine:
        temp1 = line.strip('\n')
        temp2 = temp1.split('\t')
        dataset.append(temp2[k])
    if dataset[0].split('.')[-1] != 'png':
        dataset = [float(s) for s in dataset]
    return dataset

def loadColStr(infile, k):
    f = open(infile, 'r')
    sourceInLine = f.readlines()
    dataset = []
    for line in sourceInLine:
        temp1 = line.strip('\n')
        temp2 = temp1.split('\t')
        if temp2[0].split('-')[0] in prefixs:
            dataset.append(float(temp2[k]))
    # for i in range(0, len(dataset)):
    #     for j in range(k):
    #         #dataset[i].append(float(dataset[i][j]))
    #         dataset[i][j] = float(dataset[i][j])
    return dataset

def Normalize(data):
    # res = []
    data = np.array(data)
    meanVal = np.mean(data)
    stdVal = np.std(data)
    res = (data - meanVal) / stdVal
    return res, meanVal, stdVal

def InvNormalize(data, meanVal, stdVal):
    # data = data.cpu().numpy()

    data = np.array(data)
    return (data*stdVal)+meanVal

if __name__ == '__main__':
    print("PyTorch Version: ", torch.__version__)
    print("Torchvision Version: ", torchvision.__version__)
    # get all args params
    args = parser.parse_args()
    infile = args.data_dir
    model_name = args.model
    batch_size = args.batch_size
    num_epochs = args.epochs
    use_pretrained = args.use_pretrained
    feature_extract = args.feature_extract
    # output make dir
    out_path = out_path + '_' + model_name
    if not os.path.exists(out_path):
        os.makedirs(out_path)
    # get data Dir name
    fn = infile.split('/')[-1]

    # Initialize the model for this run
    model_ft, input_size = initialize_model(model_name, num_classes, feature_extract, use_pretrained)

    # Data augmentation and normalization for training
    # Just normalization for validation
    data_transforms = {
        'train': transforms.Compose([
            # transforms.RandomResizedCrop(input_size),
            # transforms.RandomHorizontalFlip(),
            # transforms.Resize(input_size),
            # transforms.CenterCrop(input_size),
            transforms.Resize([input_size, input_size]),
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        ]),
        'val': transforms.Compose([
            transforms.Resize([input_size, input_size]),
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
        ]),
    }

    print("Initializing Datasets and Dataloaders...")

    image_datasets = {x: customData(img_path=infile,
                                    txt_path=os.path.join(infile, (x + '.txt')),
                                    data_transforms=data_transforms,
                                    dataset=x) for x in ['train', 'val']}

    # wrap your data and label into Tensor
    dataloaders_dict = {x: torch.utils.data.DataLoader(image_datasets[x],
                                                 batch_size=batch_size,
                                                 shuffle = True if x == 'train' else False,
                                                 # num_workers=1
                                                       ) for x in ['train', 'val']}

    # Detect if we have a GPU available
    device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
    # Send the model to GPU
    model_ft = model_ft.to(device)

    params_to_update = model_ft.parameters()
    print("Params to learn:")
    if feature_extract:
        params_to_update = []
        for name, param in model_ft.named_parameters():
            if param.requires_grad == True:
                params_to_update.append(param)
                print("\t",name)
    else:
        for name, param in model_ft.named_parameters():
            if param.requires_grad == True:
                print("\t",name)

    # Observe that all parameters are being optimized

    # optimizer_ft = optim.SGD(params_to_update, lr, momentum=0.9)
    optimizer_ft = optim.Adam(params_to_update, lr, weight_decay=0.05)

    # Setup the loss fxn
    criterion = nn.MSELoss()

    # Train and evaluate
    model_ft, train_hist, val_hist, result = train_model(model_ft, dataloaders_dict, criterion, optimizer_ft, num_epochs=num_epochs, is_inception=(model_name=="inception"))

    plt.figure()
    plt.title("Train and val Loss history vs. Number of Training Epochs")
    plt.xlabel("Training Epochs")
    plt.ylabel("Validation Accuracy")
    plt.plot(range(1, num_epochs + 1), train_hist, label="train_hist")
    plt.plot(range(1,num_epochs+1), val_hist, label="val_hist")
    # plt.ylim((0, 2.))
    # plt.xticks(np.arange(1, num_epochs+1, 1.0))
    plt.legend()
    plt.savefig(os.path.join(out_path, 'Hist of ' + fn + "_" + str(model_name) + "_" + str(num_epochs) + "_" + str(lr) + "_" + str(batch_size) + '.png'))
    plt.show()
    hist = np.vstack((train_hist, val_hist))
    np.savetxt(os.path.join(out_path, "Hist of " + fn + "_" + str(model_name) + "_" + str(num_epochs) + "_" + str(lr) + "_" + str(batch_size)), hist.T)

    #######################################################################
    # -----------------------Evaluation--------------------------------
    test_lab = loadColStr(os.path.join(infile, 'val.txt'), 1)
    _, meanVal, stdVal = Normalize(test_lab)
    result = InvNormalize(result, meanVal, stdVal)

    ### test ###
    # test_img_path = loadCol(os.path.join(infile, 'test.txt'), 0)
    # test_lab = loadCol(os.path.join(infile, 'test.txt'), 1)
    # _, meanVal, stdVal = Normalize(test_lab)
    #
    # model_ft.eval()
    # torch.no_grad()
    # result = []
    # transform = transforms.Compose([
    #     transforms.Resize(input_size),
    #     transforms.ToTensor(),
    #     transforms.Normalize(mean=[0.485, 0.456, 0.406],
    #                          std=[0.229, 0.224, 0.225])
    # ])
    # for i in range(len(test_img_path)):
    #     test_img = Image.open(os.path.join(infile, test_img_path[i])).convert('RGB')
    #     test_img = transform(test_img).unsqueeze(0)
    #     test_img = test_img.to(device)
    #     out = model_ft(test_img)
    #     out = out.detach().cpu().numpy()
    #     out_v = out[0][0] * stdVal + meanVal
    #     # print(out_v)
    #     result.append(out_v)
    ############
    plt.figure()
    plt.title(model_name + "_" + str(num_epochs) + "_" + str(lr) + "_" + str(batch_size) + "Validation Result")
    ts = range(len(test_lab))
    plt.plot(ts, test_lab, label="test_lab")
    plt.plot(ts, result, label="pred_lab")
    plt.legend()
    plt.show()
    res = np.vstack((test_lab, result))
    np.savetxt(os.path.join(out_path, 'Results of ' + fn + "_" + model_name + "_" + str(num_epochs) + "_" + str(lr) + "_" + str(batch_size)), res.T, fmt='%s')
    ############
    result = np.array(result)
    test_lab = np.array(test_lab)
    print('[Layered error]')
    error = (result - test_lab)/test_lab
    print('Mean(error): {:.2%}.'.format(np.mean(error)))
    print('Max(error): {:.2%}.'.format(np.max(error)))
    print('Min(error): {:.2%}.'.format(np.min(error)))
    print('Std(error): {:.2f}.'.format(np.std(error)))
    Rs = mean_squared_error(test_lab, result) ** 0.5
    Mae = mean_absolute_error(test_lab, result)
    R2_s = r2_score(test_lab, result)
    print('Root mean_squared_error: {:.2f}J, Mean_absolute_error: {:.2f}, R2_score: {:.2f}.'.format(Rs, Mae, R2_s))
    ############
    print('[Total models error]')
    E1 = np.sum(test_lab)
    E2 = np.sum(result)
    Er = (E1 - E2)/E2
    print('Actual total EC: {:.2f}J, Predicted total EC: {:.2f}J, Er: {:.2%}'.format(E1,E2,Er))
    res_error = [np.mean(error), np.max(error), np.min(error), np.std(error), Rs, Mae, R2_s, E1, E2, Er]
    np.savetxt(os.path.join(out_path, 'Error of ' + fn + "_" + model_name + "_" + str(num_epochs) + "_" + str(lr) + "_" + str(batch_size)),
               np.array(res_error), fmt='%s')

max_stars_repo_name: ichbinkk/Conformer

max_issues_repo_name: ichbinkk/Conformer

max_forks_repo_name: ichbinkk/Conformer


text:
from solver import *
import numpy
import crossover
import mutation
from datetime import datetime
import time
from tabulate import tabulate

'''
Different things to try out:
Increase number of offsprings of each generation (mu) or tournamen Size
Increase population Size
Increase Number of Generations
Increase population Size
(minor: Change the maxFitness and componentCost)
'''
settingB1 = ParameterSetting(maxFitIndiv = 500, popSize = 10, mateProb = 0.9,
mutateProb = 0.02, tournSize = 10, numGens = 100, componentCost = 20, mu=10,
hofSize = 100, number_of_runs = 10, verbose = True,
crossoverFunction = crossover.onePointCrossover,
mutationFunction = mutation.multFlipBit)

settingB2 = ParameterSetting(maxFitIndiv = 1000, popSize = 10, mateProb = 0.9,
mutateProb = 0.02, tournSize = 20, numGens = 10, componentCost = 50, mu=10,
hofSize = 10, number_of_runs = 2, verbose = False,
crossoverFunction = crossover.onePointCrossover,
mutationFunction = mutation.multFlipBit)

settingC1 = ParameterSetting(maxFitIndiv = 10000, popSize = 100, mateProb = 0.9,
mutateProb = 0.02, tournSize = 10, numGens = 150, componentCost = 50, mu=20,
hofSize = 150, number_of_runs = 10, verbose = True,
crossoverFunction = crossover.onePointCrossover,
mutationFunction = mutation.multFlipBit)

settingD1 = ParameterSetting(maxFitIndiv = 30000, popSize = 200, mateProb = 0.9,
mutateProb = 0.02, tournSize = 10, numGens = 200, componentCost = 70, mu=30,
hofSize = 200, number_of_runs = 5, verbose = True,
crossoverFunction = crossover.onePointCrossover,
mutationFunction = mutation.multFlipBit)

settingE1 = ParameterSetting(maxFitIndiv = 50000, popSize = 300, mateProb = 0.9,
mutateProb = 0.02, tournSize = 10, numGens = 300, componentCost = 100, mu=40,
hofSize = 300, number_of_runs = 2, verbose = True,
crossoverFunction = crossover.onePointCrossover,
mutationFunction = mutation.multFlipBit)

settings = [settingB2]
setting_names = ["SettingB2"]

filesB = ["../data/B/b01","../data/B/b02","../data/B/b03","../data/B/b04","../data/B/b05","../data/B/b06","../data/B/b07","../data/B/b08","../data/B/b09",
"../data/B/b10","../data/B/b11","../data/B/b12","../data/B/b13","../data/B/b14","../data/B/b15","../data/B/b16","../data/B/b17","../data/B/b18"]
filesC = ["data/C/c01","data/C/c02","data/C/c03","data/C/c04","data/C/c05","data/C/c06","data/C/c07","data/C/c08","data/C/c09",
"data/C/c10","data/C/c11","data/C/c12","data/C/c13","data/C/c14","data/C/c15","data/C/c16","data/C/c17","data/C/c18", "data/C/c19","data/C/c20"]
filesD = ["data/D/d01","data/D/d02","data/D/d03","data/D/d04","data/D/d05","data/D/d06","data/D/d07","data/D/d08","data/D/d09",
"data/D/d10","data/D/d11","data/D/d12","data/D/d13","data/D/d14","data/D/d15","data/D/d16","data/D/d17","data/D/d18", "data/D/d19","data/D/d20"]
filesE = ["data/E/e01","data/E/e02","data/E/e03","data/E/e04","data/E/e05","data/E/e06","data/E/e07","data/E/e08","data/E/e09",
"data/E/e10","data/E/e11","data/E/e12","data/E/e13","data/E/e14","data/E/e15","data/E/e16","data/E/e17","data/E/e18","data/E/e19","data/E/e20"]

optB = [82,83,138,59,61,122,111,104,220,86,88,174,165,235,318,127,131,218]
optC = [85,144,754,1079,1579,55,102,509,707,1093,32,46,258,323,556,11,18,113,146,267]
optD = [106,220,1565,1935,3250,67,103,1072,1448,2110,29,42,500,667,1116,13,23,223,310,537]
optE = [111,214,4013,5101,8128,73,145,2640,3604,5600,34,67,1280,1732,2784,15,25,564,758,1342]

files = filesB
dataset_name = "filesB"

solutions = optB

#Runs the solver with all setting on all files and saves the best_individuals

def truncate(f, n):
    '''Truncates/pads a float f to n decimal places without rounding'''
    s = '{}'.format(f)
    if 'e' in s or 'E' in s:
        return '{0:.{1}f}'.format(f, n)
    i, p, d = s.partition('.')
    return '.'.join([i, (d+'0'*n)[:n]])

for setting_counter, setting in enumerate(settings):
    print(setting.crossoverFunction.__name__)
    solver = SteinerTreeSolver(setting)
    print("Working with the %sth setting..." % (setting_counter + 1))

    '''
    For us, the best individual is the one with the the lowest weight among
    those with only one component. If we don't have any such individual, we
    take the one with the highest weight among those with two components and so on
    I.e., we virtually set the componentCost to Infinity, since we actually really want
    to have a tree in the end
    '''

    best_individuals = [[[None, 0, 0, 0] for _ in range(setting.number_of_runs)] for __ in range(len(files))]

    '''
    Average of the best individuals among all setting.number_of_runs test runs, including file name, avg of weight, avg of comps, and avg of time
    Stdev includes name of file, stdev of weights and stdev of number of components
    best includes best individual regarding all test runs (first we consider a low number of components, then the weight)
    '''
    avg = [[None, 0, 0, 0]] * len(files)
    stdev = [[None, 0, 0]] * len(files)
    best = [[None, 0, 0]] * len(files)
    worst = [[None, 0, 0]] * len(files)

    for file_counter, file in enumerate(files):

        graph = SteinerInstance(file + ".stp")
        #print("graph:%s ", graph)
        print("Working on problem %s" % (file))

        start_time = time.time()

        for run_counter in range(setting.number_of_runs):
            print("\nsolving it for the %sth time..." % (run_counter + 1))
            pop, hof = solver.solve(graph, output_stats = True, output_plot = False, filename = "plots/" + file[-3:] + "_" + setting_names[setting_counter] + "_run=" + str(run_counter + 1) + ".png")

            print("Presenting the %s best individuals of the problem %s:\ni-th.best\tfitness\t\tweight\t\tcomponents\n" % (setting.hofSize, file))
            '''Here, we also calculate the best individual'''
            index_best = 0
            weight_best, cnt_best = mst(graph, solver.reassemble(hof[0], graph.allowed_vertices))

            for i in range(setting.hofSize):
                weight, cnt = mst(graph, solver.reassemble(hof[i], graph.allowed_vertices))
                if cnt < cnt_best or (cnt == cnt_best and weight < weight_best):
                    index_best, weight_best, cnt_best = i, weight, cnt
                print("%s\t\t%s\t%s\t\t%s" % ((i+1), hof[i].fitness, weight, cnt))

            #print("filecounter=%s, runcounter=%s" %(file_counter, run_counter))
            best_individuals[file_counter][run_counter] = [file, weight_best, cnt_best, hof[index_best]]

        end_time = time.time()
        average_time = (end_time - start_time) / setting.number_of_runs
        print("Average time: ", average_time)

        '''
        Calculating the average and stdev of the best individuals over all test runs
        '''
        best_individuals_weights = [best_individuals[file_counter][run][1] for run in range(setting.number_of_runs)]
        best_individuals_cnts = [best_individuals[file_counter][run][2] for run in range(setting.number_of_runs)]
        avg[file_counter] = [file, numpy.average(best_individuals_weights), numpy.average(best_individuals_cnts), average_time]
        stdev[file_counter] = [file, numpy.std(best_individuals_weights), numpy.std(best_individuals_cnts)]

        best_overall_weight, best_overall_cnt = best_individuals_weights[0], best_individuals_cnts[0]

        for i in range(setting.number_of_runs):
            if best_individuals_cnts[i] < best_overall_cnt or (best_individuals_cnts[i] == best_overall_cnt and best_individuals_weights[i] < best_overall_weight):
                best_overall_weight, best_overall_cnt = best_individuals_weights[i], best_individuals_cnts[i]

        best[file_counter] = [file, best_overall_weight, best_overall_cnt]

        worst_overall_weight, worst_overall_cnt = best_individuals_weights[0], best_individuals_cnts[0]

        for i in range(setting.number_of_runs):
            if best_individuals_cnts[i] > best_overall_cnt or (best_individuals_cnts[i] == best_overall_cnt and best_individuals_weights[i] > best_overall_weight):
                best_overall_weight, best_overall_cnt = best_individuals_weights[i], best_individuals_cnts[i]

        worst[file_counter] = [file, worst_overall_weight, worst_overall_cnt]

    output_file = open('../results/results_%s_%s_%s.txt' % (setting_names[setting_counter], dataset_name, datetime.now().strftime('%Y_%m_%d_%H_%M_%S')), "w")
    output_file.write("ParameterSetting:\n%s\n\nPresenting the results:\n\nBest Individuals:\n" % (str(setting)))
    for i in range(len(files)):
        output_file.write("\nProblem %s\n" % (files[i]))
        for j in range(setting.number_of_runs):
            output_file.write("Run #%s: Weight: %d, Components: %d\n" %((j+1), best_individuals[i][j][1], best_individuals[i][j][2]))
        output_file.write("")

    output_file.write("\nStatistics of the best individuals\n")
    table = [["File","Best (weight)", "Best (components)", "Worst (weight)", "Worst (components)", "Average (weights)","Average (components)","Stdev (weights)","Stdev(components)","Avg. Running Time(s)", "Correct solution"]]
    for (i, file) in enumerate(files):
        table.append([file, truncate(best[i][1], 3), truncate(best[i][2], 3), truncate(worst[i][1], 3), truncate(worst[i][2], 3), truncate(avg[i][1], 3), truncate(avg[i][2], 3), truncate(stdev[i][1], 3), truncate(stdev[i][2], 3), truncate(avg[i][3], 3), solutions[i]])
    output_file.write(tabulate(table))
    output_file.write("\n")

max_stars_repo_name: au-re/steiner-tree

max_issues_repo_name: au-re/steiner-tree

max_forks_repo_name: au-re/steiner-tree


text:
import unittest
from tcrdist import olga
import parasail
import pandas as pd
import numpy as np
from tcrdist import pgen

human_b = pd.DataFrame({'v_b_gene': {0: 'TRBV7-7',  1: 'TRBV7-3',  2: 'TRBV4-2',  3: 'TRBV20-1',  4: 'TRBV5-4',  5: 'TRBV20-1',  6: 'TRBV10-2',  7: 'TRBV5-1',  8: 'TRBV5-1',  9: 'TRBV6-2',  10: 'TRBV9',  11: 'TRBV27',  12: 'TRBV10-1',  13: 'TRBV30',  14: 'TRBV6-5',  15: 'TRBV20-1',  16: 'TRBV10-1',  17: 'TRBV18',  18: 'TRBV6-1',  19: 'TRBV19',  20: 'TRBV13',  21: 'TRBV4-1',  22: 'TRBV11-2',  23: 'TRBV5-6',  24: 'TRBV5-4',  25: 'TRBV7-4',  26: 'TRBV19',  27: 'TRBV5-1',  28: 'TRBV6-1',  29: 'TRBV7-9',  30: 'TRBV7-6',  31: 'TRBV9',  32: 'TRBV6-2',  33: 'TRBV27',  34: 'TRBV6-3',  35: 'TRBV24-1',  36: 'TRBV5-1',  37: 'TRBV24-1',  38: 'TRBV29-1',  39: 'TRBV29-1',  40: 'TRBV20-1',  41: 'TRBV7-9',  42: 'TRBV28',  43: 'TRBV10-1',  44: 'TRBV27',  45: 'TRBV7-9',  46: 'TRBV3-1',  47: 'TRBV9',  48: 'TRBV20-1',  49: 'TRBV5-1',  50: 'TRBV20-1',  51: 'TRBV14',  52: 'TRBV10-3',  53: 'TRBV10-1',  54: 'TRBV24-1',  55: 'TRBV12-3',  56: 'TRBV7-4',  57: 'TRBV28',  58: 'TRBV12-4',  59: 'TRBV6-4',  60: 'TRBV6-8',  61: 'TRBV24-1',  62: 'TRBV10-1',  63: 'TRBV7-9',  64: 'TRBV7-8',  65: 'TRBV7-6',  66: 'TRBV7-4',  67: 'TRBV7-9',  68: 'TRBV20-1',  69: 'TRBV7-4',  70: 'TRBV24-1',  71: 'TRBV6-2',  72: 'TRBV5-1',  73: 'TRBV9',  74: 'TRBV6-1',  75: 'TRBV7-8',  76: 'TRBV29-1',  77: 'TRBV4-1',  78: 'TRBV12-3',  79: 'TRBV5-1',  80: 'TRBV7-3',  81: 'TRBV13',  82: 'TRBV6-3',  83: 'TRBV9',  84: 'TRBV10-1',  85: 'TRBV25-1',  86: 'TRBV13',  87: 'TRBV20-1',  88: 'TRBV11-3',  89: 'TRBV12-5',  90: 'TRBV4-3',  91: 'TRBV5-6',  92: 'TRBV5-6',  93: 'TRBV11-2',  94: 'TRBV29-1',  95: 'TRBV6-9',  96: 'TRBV19',  97: 'TRBV7-4',  98: 'TRBV12-3',  99: 'TRBV5-4'}, 'j_b_gene': {0: 'TRBJ2-7',  1: 'TRBJ2-3',  2: 'TRBJ2-2',  3: 'TRBJ1-3',  4: 'TRBJ2-3',  5: 'TRBJ2-5',  6: 'TRBJ2-7',  7: 'TRBJ2-7',  8: 'TRBJ2-3',  9: 'TRBJ1-4',  10: 'TRBJ1-6',  11: 'TRBJ2-2',  12: 'TRBJ2-2',  13: 'TRBJ2-2',  14: 'TRBJ1-5',  15: 'TRBJ1-1',  16: 'TRBJ1-1',  17: 'TRBJ2-7',  18: 'TRBJ2-7',  19: 'TRBJ1-5',  20: 'TRBJ2-7',  21: 'TRBJ1-2',  22: 'TRBJ2-5',  23: 'TRBJ1-2',  24: 'TRBJ2-7',  25: 'TRBJ2-7',  26: 'TRBJ2-7',  27: 'TRBJ2-1',  28: 'TRBJ2-3',  29: 'TRBJ2-7',  30: 'TRBJ1-5',  31: 'TRBJ1-2',  32: 'TRBJ1-3',  33: 'TRBJ2-3',  34: 'TRBJ1-4',  35: 'TRBJ2-2',  36: 'TRBJ1-2',  37: 'TRBJ2-1',  38: 'TRBJ2-7',  39: 'TRBJ2-7',  40: 'TRBJ2-5',  41: 'TRBJ2-7',  42: 'TRBJ2-5',  43: 'TRBJ2-1',  44: 'TRBJ2-7',  45: 'TRBJ2-5',  46: 'TRBJ2-3',  47: 'TRBJ2-5',  48: 'TRBJ2-1',  49: 'TRBJ1-4',  50: 'TRBJ1-6',  51: 'TRBJ2-7',  52: 'TRBJ1-2',  53: 'TRBJ2-3',  54: 'TRBJ2-5',  55: 'TRBJ2-7',  56: 'TRBJ2-1',  57: 'TRBJ2-7',  58: 'TRBJ2-2',  59: 'TRBJ1-1',  60: 'TRBJ1-2',  61: 'TRBJ2-5',  62: 'TRBJ2-3',  63: 'TRBJ1-3',  64: 'TRBJ2-4',  65: 'TRBJ2-7',  66: 'TRBJ1-5',  67: 'TRBJ1-4',  68: 'TRBJ2-7',  69: 'TRBJ1-4',  70: 'TRBJ2-7',  71: 'TRBJ2-5',  72: 'TRBJ2-1',  73: 'TRBJ2-1',  74: 'TRBJ2-7',  75: 'TRBJ2-7',  76: 'TRBJ2-7',  77: 'TRBJ1-1',  78: 'TRBJ1-4',  79: 'TRBJ1-6',  80: 'TRBJ2-2',  81: 'TRBJ2-1',  82: 'TRBJ2-2',  83: 'TRBJ2-7',  84: 'TRBJ1-2',  85: 'TRBJ2-7',  86: 'TRBJ1-2',  87: 'TRBJ2-1',  88: 'TRBJ2-1',  89: 'TRBJ1-1',  90: 'TRBJ1-1',  91: 'TRBJ1-5',  92: 'TRBJ2-5',  93: 'TRBJ1-6',  94: 'TRBJ2-7',  95: 'TRBJ1-6',  96: 'TRBJ1-2',  97: 'TRBJ2-1',  98: 'TRBJ2-1',  99: 'TRBJ2-7'}, 'cdr3_b_aa': {0: 'CASMAPPSTRVYEQYF',  1: 'CASSPQRRDTQYF',  2: 'CASSRGAANTGELFF',  3: 'CSAPGASGNTIYF',  4: 'CASSQRVATDTQYF',  5: 'CSAPHPETSGSETQYF',  6: 'CASGGRAYYEQYF',  7: 'CASSLYYKTLSYEQYF',  8: 'CASSPWPGQTDTQYF',  9: 'CASWTDLPHEKLFF',  10: 'CASSVGVSLHF',  11: 'CASSVCLVTQHTGELFF',  12: 'CASSGEGQGGNTGELFF',  13: 'CAWIRGGQKVTGELFF',  14: 'CASAPRPQDRGTSWSNQPQHF',  15: 'CSAGAVKEAFF',  16: 'CASARGLNTEAFF',  17: 'CASSPRLADSEQYF',  18: 'CASSEAPWTGEYEQYF',  19: 'CASSPQGERKHF',  20: 'CASSYWGYEQYF',  21: 'CASSQDKRQIYGYTF',  22: 'CASSWTPQTTVLTQYF',  23: 'CASKEGQVTWYGYTF',  24: 'CASSVRRDCYYEQYF',  25: 'CASSPSTGLRNSYEQYF',  26: 'CASRAGASYEQYF',  27: 'CASSLGGIAAYNEQFF',  28: 'CASSEPEYF',  29: 'CASSGSVAESGSSYEQYF',  30: 'CASSLRPGNQPQHF',  31: 'CASSVGTGGGYYGYTF',  32: 'CASSYVRGSVISGNTIYF',  33: 'CASITLGSQGTDTQYF',  34: 'CASSYSRLNEKLFF',  35: 'CATSDLPHLHGVELFF',  36: 'CASSPRTGRDPSPNYGYTF',  37: 'CATRGPRQYNEQFF',  38: 'CKPGLAGAKNYEQYF',  39: 'CSVEGGVYEQYF',  40: 'CSARDSRPGAEETQYF',  41: 'CASKKTGEQYF',  42: 'CATFLSEETQYF',  43: 'CASSEVDEQFF',  44: 'CASSLLPRPPGYEQYF',  45: 'CASSLATGTSPQDYVETQYF',  46: 'CASSQGPVLAARGTDTQYF',  47: 'CASSTGRLETQYF',  48: 'CSAEGRDLYNEQFF',  49: 'CASSLGSRDRGLGHNEKLFF',  50: 'CSAQNRVLIGSSYNSPLHF',  51: 'CASSRASSREAYEQYF',  52: 'CAISKDEGGIYGYTF',  53: 'CAGFGGCGTSVVNTDTQYF',  54: 'CATSAATWGETQYF',  55: 'CASRDRGRGEMPYEQYF',  56: 'CASSSRSGRAHNEQFF',  57: 'CASSFEPGQVLEQYF',  58: 'CASSLIGTLGELFF',  59: 'CASSDPQGAFF',  60: 'CASTSERVVYGYTF',  61: 'CATSPQGGETQYF',  62: 'CASSERDRGLVTDTQYF',  63: 'CASSLIATPSGNTIYF',  64: 'CASSKDRATKNIQYF',  65: 'CASSYWGSSYEQYF',  66: 'CASRGGQGRWNQPQHF',  67: 'CASSLRIGIYELFF',  68: 'CSAAGQVSSYEQYF',  69: 'CASSLITRGGCEKLFF',  70: 'CATSPRQVPTQYF',  71: 'CASRSGQGRETQYF',  72: 'CASSFHPYEQFF',  73: 'CASSKFRNEQFF',  74: 'CASSQLWVGPSSYEQYF',  75: 'CASSTYRSVYEQYF',  76: 'CSVERPRTGTKQYF',  77: 'CASSQDQNFPLRGPGNTEAFF',  78: 'CASSFVQLFF',  79: 'CASSLGRFNSPLHF',  80: 'CASSRQYTGELFF',  81: 'CASSATYNEQFF',  82: 'CASIGARRYTGELFF',  83: 'CASLLRLPGTGEAPQQYF',  84: 'CASSESSRPSDYGYTF',  85: 'CASILAGRAYEQYF',  86: 'CASSKRLQGELRGYTF',  87: 'CSARDRLPGSYNEQFF',  88: 'CASSLYDPAIAEQFF',  89: 'CASGSRQNTEAFF',  90: 'CASSQVDLRDRTEAFF',  91: 'CASSVGARYQPQHF',  92: 'CASSLASPQGKETQYF',  93: 'CASSMRTRARAVNSPLHF',  94: 'CSVANKGGDYEQYF',  95: 'CASSSQGTVCNSPLHF',  96: 'CASSTISPPAGTGRGNYGYTF',  97: 'CASLSRTNEQFF',  98: 'CASRPTSVPGNEQFF',  99: 'CASSSRAAYEQYF'}, 'cdr3_b_aa_pgen_naive': {0: 6.914037864863085e-14,  1: 1.2063033809105577e-08,  2: 7.230480962154434e-08,  3: 2.441254704991944e-08,  4: 5.457779617823437e-09,  5: 1.8105111073751246e-13,  6: 2.2302788533351744e-09,  7: 3.635638135689051e-12,  8: 4.1178891642054886e-10,  9: 1.0396372609162913e-12,  10: 2.2971251444476465e-09,  11: 3.6865609737806515e-14,  12: 1.4255762223071154e-09,  13: 4.3459784193776896e-13,  14: 3.078189409268021e-18,  15: 8.233581355428577e-11,  16: 3.857060427672622e-08,  17: 9.706821174158532e-10,  18: 8.757214158314706e-11,  19: 1.1112551640465755e-11,  20: 2.585145100653314e-07,  21: 2.2327877357855368e-10,  22: 2.010478311901196e-15,  23: 2.8429678895283604e-13,  24: 5.808740878605505e-11,  25: 2.3808007992852488e-11,  26: 1.38334052345602e-07,  27: 6.642448927244691e-10,  28: 1.2205597771236976e-08,  29: 3.7879390833995055e-13,  30: 1.3092281608952943e-07,  31: 2.0386542823859245e-09,  32: 2.1604509938692757e-12,  33: 2.7112690148459317e-12,  34: 1.058584286483682e-08,  35: 2.800222356707047e-15,  36: 1.7932886392772563e-13,  37: 1.2431001470193343e-10,  38: 6.710706240270747e-13,  39: 3.21823557183969e-08,  40: 1.3769398494169063e-11,  41: 1.1156869144824308e-08,  42: 2.8207545717856966e-10,  43: 6.385796860319103e-08,  44: 8.140491043283133e-11,  45: 4.878303472102873e-17,  46: 8.313081659196325e-13,  47: 4.1840368142505525e-08,  48: 1.0399400517805569e-10,  49: 7.99393741473435e-13,  50: 8.080573690917516e-15,  51: 3.0738477758027824e-11,  52: 2.1737276676588726e-13,  53: 4.801501086609653e-19,  54: 2.313565288524842e-11,  55: 6.617674191809395e-13,  56: 8.604386069622438e-11,  57: 2.4603862070337967e-11,  58: 7.643032484461676e-10,  59: 2.0746470730219507e-08,  60: 1.8927778250079475e-11,  61: 7.997046952811914e-09,  62: 2.343315500442348e-10,  63: 1.297618753501468e-10,  64: 9.731967444396922e-10,  65: 5.0156503143109334e-08,  66: 1.7588308829939258e-10,  67: 7.328555678996252e-14,  68: 1.0248607568108533e-09,  69: 1.9655336234540015e-11,  70: 1.3610837460509859e-11,  71: 1.3297974521321031e-08,  72: 1.8353109159998242e-09,  73: 4.884256442763288e-09,  74: 3.919237198300412e-12,  75: 2.9924694535279167e-10,  76: 1.2674495135651994e-13,  77: 4.703195535665928e-16,  78: 1.2689580930823331e-09,  79: 1.5990121704264834e-08,  80: 4.935376573900059e-08,  81: 2.407387842320861e-07,  82: 7.151027574301887e-11,  83: 1.4740281832590636e-18,  84: 1.877582231272972e-11,  85: 9.601384924937414e-09,  86: 1.4375805892905044e-13,  87: 2.9393203210410567e-10,  88: 6.356815915829923e-14,  89: 6.1214917257547434e-09,  90: 1.536760636399668e-11,  91: 5.606605153850914e-09,  92: 4.3059055934637596e-10,  93: 6.442146596910754e-15,  94: 1.7570063235080356e-11,  95: 2.7755532219112647e-11,  96: 9.323350784382565e-16,  97: 2.0563733927894267e-09,  98: 2.5870364121682052e-11,  99: 2.2028072332298127e-07}, 'cdr3_b_aa_pgen_vj': {0: 2.3865502750561543e-16,  1: 7.018929424726567e-10,  2: 8.544662518199813e-10,  3: 2.280828606609376e-08,  4: 6.857431138631455e-11,  5: 1.736578157836307e-13,  6: 2.303235722336972e-11,  7: 4.209493460358739e-13,  8: 2.0117566726160448e-11,  9: 2.4042206282773226e-14,  10: 5.426842932124167e-10,  11: 9.792583155121137e-16,  12: 5.44678798237017e-11,  13: 4.30557550481105e-13,  14: 1.280811127292118e-19,  15: 7.533021838385887e-11,  16: 2.669691153114048e-09,  17: 1.7895196460866634e-10,  18: 5.203983897403474e-11,  19: 2.6027972640667407e-13,  20: 9.060589067714544e-09,  21: 5.644474206563129e-11,  22: 6.60929236362155e-17,  23: 4.1220372605234154e-15,  24: 8.214738656423212e-13,  25: 5.05022947078353e-13,  26: 7.02119106729305e-09,  27: 1.0533021771460002e-10,  28: 2.8023013377676423e-10,  29: 1.9003998943386195e-14,  30: 2.9066851001244205e-09,  31: 8.709407024839163e-10,  32: 2.7442125470226457e-13,  33: 2.72558280239742e-13,  34: 1.2021718585151029e-09,  35: 2.2047398367058983e-15,  36: 8.961710954042191e-15,  37: 8.468200962762522e-11,  38: 8.002459656021119e-14,  39: 3.1730208077380285e-08,  40: 1.37596382386555e-11,  41: 3.890187494205268e-10,  42: 6.368585373496035e-12,  43: 5.427180127623842e-09,  44: 1.0037866949049539e-11,  45: 5.989257946241295e-18,  46: 2.2280206700158056e-13,  47: 2.272321786491923e-09,  48: 9.897217584552818e-11,  49: 1.4764744882686286e-13,  50: 7.689703124531547e-15,  51: 1.4852614312308334e-12,  52: 2.0324100187517432e-13,  53: 2.2969447535675985e-20,  54: 2.1759771574210604e-11,  55: 2.4810878358299248e-14,  56: 1.665124632222371e-12,  57: 2.1962373477886857e-12,  58: 2.203177254289868e-11,  59: 7.112758415455606e-09,  60: 1.8692412762881695e-13,  61: 5.325537944608622e-09,  62: 3.4670584146582016e-11,  63: 9.476944459351147e-12,  64: 1.2391408296574628e-11,  65: 4.1121797222065104e-10,  66: 1.094533411332046e-12,  67: 4.159624131021794e-15,  68: 9.7107703311745e-10,  69: 3.9724700777576946e-13,  70: 1.3618192266404085e-13,  71: 4.484723818780005e-10,  72: 2.3349354957576345e-10,  73: 2.6847105588185296e-10,  74: 2.7554363862346628e-14,  75: 3.7909046756599716e-12,  76: 1.1347382626878078e-13,  77: 1.443137061332558e-16,  78: 4.81940473895189e-11,  79: 2.2366024778700746e-09,  80: 3.269962150775701e-09,  81: 2.1715720862033117e-08,  82: 1.5861668921544012e-12,  83: 6.672168646917713e-20,  84: 8.988117048969934e-12,  85: 2.437139200956509e-10,  86: 1.8602066668521753e-14,  87: 2.932912059438856e-10,  88: 2.069223363622431e-15,  89: 3.9187699591759895e-09,  90: 1.4250556188978398e-12,  91: 9.676074516023271e-11,  92: 3.747226033816331e-11,  93: 8.13599360322581e-17,  94: 1.739205400742978e-11,  95: 2.64538490003725e-13,  96: 9.404784641645238e-17,  97: 1.5940102953678025e-11,  98: 1.1045306727573469e-12,  99: 7.938947607979633e-09}, 'cdr3_b_nuc': {0: 'TGTGCCAGCATGGCCCCCCCGTCGACTAGAGTCTACGAGCAGTACTTC',  1: 'TGTGCCAGCAGCCCACAGCGAAGAGATACGCAGTATTTT',  2: 'TGTGCCAGCAGCCGGGGGGCTGCGAACACCGGGGAGCTGTTTTTT',  3: 'TGCAGTGCGCCAGGGGCCTCTGGAAACACCATATATTTT',  4: 'TGTGCCAGCAGCCAGCGGGTGGCGACAGATACGCAGTATTTT',  5: 'TGCAGTGCTCCCCACCCCGAGACTAGCGGGAGCGAGACCCAGTACTTC',  6: 'TGCGCCAGCGGGGGCCGGGCATACTACGAGCAGTACTTC',  7: 'TGCGCCAGCAGCTTGTATTATAAGACACTATCCTACGAGCAGTACTTC',  8: 'TGCGCCAGCAGCCCTTGGCCGGGACAGACAGATACGCAGTATTTT',  9: 'TGTGCCAGCTGGACAGACCTTCCACATGAAAAACTGTTTTTT',  10: 'TGTGCCAGCAGCGTCGGCGTGTCCCTCCACTTT',  11: 'TGTGCCAGCAGTGTGTGCCTAGTGACCCAGCACACCGGGGAGCTGTTTTTT',  12: 'TGCGCCAGCAGTGGAGAGGGACAGGGCGGGAACACCGGGGAGCTGTTTTTT',  13: 'TGTGCCTGGATCCGGGGGGGCCAAAAGGTTACCGGGGAGCTGTTTTTT',  14: 'TGTGCCAGCGCCCCGAGACCCCAAGACAGGGGGACCTCCTGGAGCAATCAGCCCCAGCATTTT',  15: 'TGCAGTGCTGGGGCAGTTAAGGAAGCTTTCTTT',  16: 'TGCGCCAGCGCTAGGGGGCTGAACACTGAAGCTTTCTTT',  17: 'TGTGCCAGCTCACCACGACTAGCAGACAGCGAGCAGTACTTC',  18: 'TGTGCCAGCAGTGAAGCGCCCTGGACAGGGGAGTACGAGCAGTACTTC',  19: 'TGTGCCAGTAGTCCCCAGGGAGAGAGAAAGCATTTT',  20: 'TGTGCCAGCAGTTACTGGGGCTACGAGCAGTACTTC',  21: 'TGCGCCAGCAGCCAAGATAAGAGACAGATCTATGGCTACACCTTC',  22: 'TGTGCCAGCAGCTGGACCCCCCAAACGACAGTTCTGACCCAGTACTTC',  23: 'TGTGCCAGCAAGGAAGGACAGGTCACTTGGTATGGCTACACCTTC',  24: 'TGTGCCAGCAGCGTGCGGCGGGACTGCTACTACGAGCAGTACTTC',  25: 'TGTGCCAGCAGCCCCTCGACAGGGTTAAGGAACTCCTACGAGCAGTACTTC',  26: 'TGTGCCAGTAGAGCAGGGGCGTCCTACGAGCAGTACTTC',  27: 'TGCGCCAGCAGCTTGGGGGGGATAGCTGCCTACAATGAGCAGTTCTTC',  28: 'TGTGCCAGCAGTGAACCTGAGTATTTT',  29: 'TGTGCCAGCAGCGGTAGTGTGGCAGAAAGCGGCTCCTCCTACGAGCAGTACTTC',  30: 'TGTGCCAGCAGCTTAAGACCAGGAAATCAGCCCCAGCATTTT',  31: 'TGTGCCAGCAGCGTAGGGACAGGGGGGGGCTATTATGGCTACACCTTC',  32: 'TGTGCCAGCAGTTACGTGAGGGGGTCCGTCATATCTGGAAACACCATATATTTT',  33: 'TGTGCCAGCATAACTCTAGGGAGTCAGGGCACAGATACGCAGTATTTT',  34: 'TGTGCCAGCAGTTACTCGCGACTAAATGAAAAACTGTTTTTT',  35: 'TGTGCCACCAGTGATTTGCCTCACCTTCACGGGGTGGAGCTGTTTTTT',  36: 'TGCGCCAGCAGCCCTAGGACAGGGCGGGACCCCTCCCCTAACTATGGCTACACCTTC',  37: 'TGTGCCACCAGGGGCCCGAGACAATACAATGAGCAGTTCTTC',  38: 'TGCAAACCGGGACTAGCGGGAGCGAAGAACTACGAGCAGTACTTC',  39: 'TGCAGCGTTGAAGGAGGGGTCTACGAGCAGTACTTC',  40: 'TGCAGTGCTAGAGACTCTCGTCCGGGGGCCGAAGAGACCCAGTACTTC',  41: 'TGTGCCAGCAAAAAGACGGGCGAGCAGTACTTC',  42: 'TGTGCCACGTTCCTAAGTGAAGAGACCCAGTACTTC',  43: 'TGCGCCAGCAGCGAAGTCGATGAGCAGTTCTTC',  44: 'TGTGCCAGCAGTTTACTACCGAGGCCCCCCGGCTACGAGCAGTACTTC',  45: 'TGTGCCAGCAGCTTAGCCACCGGTACATCCCCTCAGGACTACGTAGAGACCCAGTACTTC',  46: 'TGTGCCAGCAGCCAAGGGCCCGTACTAGCGGCTAGGGGCACAGATACGCAGTATTTT',  47: 'TGTGCCAGCAGCACAGGGCGGCTAGAGACCCAGTACTTC',  48: 'TGCAGTGCCGAGGGGAGGGATCTTTACAATGAGCAGTTCTTC',  49: 'TGCGCCAGCAGCTTGGGGAGCCGGGACAGGGGGCTAGGGCATAATGAAAAACTGTTTTTT',  50: 'TGCAGTGCTCAAAACAGGGTCCTAATCGGAAGCTCCTATAATTCACCCCTCCACTTT',  51: 'TGTGCCAGCAGCCGAGCTTCCTCAAGAGAAGCCTACGAGCAGTACTTC',  52: 'TGTGCCATCAGTAAAGACGAAGGGGGAATTTATGGCTACACCTTC',  53: 'TGCGCCGGTTTCGGAGGTTGCGGGACTAGCGTAGTCAATACAGATACGCAGTATTTT',  54: 'TGTGCCACCAGTGCTGCGACCTGGGGGGAGACCCAGTACTTC',  55: 'TGTGCCAGCAGGGATAGAGGTAGGGGGGAGATGCCCTACGAGCAGTACTTC',  56: 'TGTGCCAGCAGCTCCCGCAGCGGGAGGGCCCACAATGAGCAGTTCTTC',  57: 'TGTGCCAGCAGTTTCGAACCGGGACAGGTTCTCGAGCAGTACTTC',  58: 'TGTGCCAGCAGTTTAATCGGGACCCTCGGGGAGCTGTTTTTT',  59: 'TGTGCCAGCAGTGATCCCCAGGGAGCTTTCTTT',  60: 'TGTGCCAGCACCTCAGAGAGGGTAGTCTATGGCTACACCTTC',  61: 'TGTGCCACCAGTCCCCAGGGGGGGGAGACCCAGTACTTC',  62: 'TGCGCCAGCAGTGAGAGGGACAGGGGCCTAGTCACAGATACGCAGTATTTT',  63: 'TGTGCCAGCAGCTTAATCGCCACCCCCTCTGGAAACACCATATATTTT',  64: 'TGTGCCAGCAGCAAGGACCGGGCAACCAAAAACATTCAGTACTTC',  65: 'TGTGCCAGCAGCTATTGGGGGAGCTCCTACGAGCAGTACTTC',  66: 'TGTGCCAGCAGGGGGGGACAGGGGAGATGGAATCAGCCCCAGCATTTT',  67: 'TGTGCCAGCAGCTTAAGAATTGGGATTTACGAACTGTTTTTT',  68: 'TGCAGTGCGGCAGGACAGGTGAGCTCCTACGAGCAGTACTTC',  69: 'TGTGCCAGCAGCTTAATAACCAGGGGCGGCTGTGAAAAACTGTTTTTT',  70: 'TGTGCCACCAGTCCCCGACAGGTCCCCACGCAGTACTTC',  71: 'TGTGCCAGCAGGTCCGGACAGGGGAGAGAGACCCAGTACTTC',  72: 'TGCGCCAGCAGCTTTCACCCCTATGAGCAGTTCTTC',  73: 'TGTGCCAGCAGCAAGTTTAGGAATGAGCAGTTCTTC',  74: 'TGTGCCAGCTCTCAACTTTGGGTTGGACCGAGCTCCTACGAGCAGTACTTC',  75: 'TGTGCCAGCAGCACATACAGGTCGGTCTACGAGCAGTACTTC',  76: 'TGCAGCGTTGAAAGGCCTCGGACAGGGACGAAGCAGTACTTC',  77: 'TGCGCCAGCAGCCAAGATCAAAATTTCCCTCTAAGAGGACCCGGGAACACTGAAGCTTTCTTT',  78: 'TGTGCCAGCAGTTTCGTACAGCTGTTTTTT',  79: 'TGCGCCAGCAGCTTGGGGAGGTTTAATTCACCCCTCCACTTT',  80: 'TGTGCCAGCAGCCGACAATACACCGGGGAGCTGTTTTTT',  81: 'TGTGCCAGCAGCGCGACTTACAATGAGCAGTTCTTC',  82: 'TGTGCCAGCATCGGGGCCAGGCGTTACACCGGGGAGCTGTTTTTT',  83: 'TGTGCCAGCCTGCTAAGGCTCCCCGGGACAGGGGAGGCCCCGCAGCAGTACTTC',  84: 'TGCGCCAGCAGTGAGTCGAGCCGACCATCGGACTATGGCTACACCTTC',  85: 'TGTGCCAGCATACTAGCGGGGCGCGCCTACGAGCAGTACTTC',  86: 'TGTGCCAGCAGCAAACGGCTTCAGGGGGAGCTCAGGGGCTACACCTTC',  87: 'TGCAGTGCTAGAGATAGACTGCCCGGCTCCTACAATGAGCAGTTCTTC',  88: 'TGTGCCAGCAGCTTATATGACCCGGCCATTGCCGAGCAGTTCTTC',  89: 'TGTGCTAGTGGCTCCCGACAGAACACTGAAGCTTTCTTT',  90: 'TGCGCCAGCAGCCAAGTCGACCTCCGGGACAGGACTGAAGCTTTCTTT',  91: 'TGTGCCAGCAGCGTAGGGGCTCGATATCAGCCCCAGCATTTT',  92: 'TGTGCCAGCAGCTTGGCCTCCCCCCAGGGTAAGGAGACCCAGTACTTC',  93: 'TGTGCCAGCAGCATGAGAACGCGGGCGAGGGCAGTTAATTCACCCCTCCACTTT',  94: 'TGCAGCGTTGCTAATAAGGGGGGAGACTACGAGCAGTACTTC',  95: 'TGTGCCAGCAGTTCGCAGGGGACGGTTTGTAATTCACCCCTCCACTTT',  96: 'TGTGCCAGTAGTACAATTTCTCCTCCAGCCGGGACAGGGCGAGGTAACTATGGCTACACCTTC',  97: 'TGTGCCAGCTTGAGTCGGACCAATGAGCAGTTCTTC',  98: 'TGTGCCAGCAGGCCCACTAGCGTCCCCGGCAATGAGCAGTTCTTC',  99: 'TGTGCCAGCAGCTCGCGGGCGGCCTACGAGCAGTACTTC'}, 'cdr3_b_nuc_pgen_naive': {0: 1.734152261640279e-16,  1: 3.0491878100642465e-11,  2: 1.7814966901051268e-09,  3: 4.061716168558557e-10,  4: 1.7887261912917487e-11,  5: 1.6781558628972619e-15,  6: 1.1327851208671852e-12,  7: 1.0321052750140167e-15,  8: 5.740573709656084e-12,  9: 8.571700249375967e-15,  10: 3.5349750395681235e-12,  11: 1.5366268466322347e-17,  12: 7.316564506943518e-13,  13: 1.8820637641526145e-15,  14: 1.33741239007913e-22,  15: 1.0873182550293804e-12,  16: 1.0060018184333559e-10,  17: 2.458961248195273e-13,  18: 7.389496901374606e-12,  19: 1.123677363576676e-15,  20: 7.281494838140756e-08,  21: 8.204367467276173e-12,  22: 6.965690252113986e-18,  23: 1.5861047752649656e-15,  24: 1.0077473573639502e-13,  25: 8.442946300390104e-14,  26: 6.588106278464312e-11,  27: 1.1710257215649476e-12,  28: 9.051523373136122e-11,  29: 2.1341775873186663e-19,  30: 2.007969881912253e-10,  31: 5.914569096310692e-13,  32: 7.157141622133917e-17,  33: 1.9434236181976194e-15,  34: 6.056459233020752e-11,  35: 1.5834670568995698e-17,  36: 1.129256490971606e-17,  37: 2.518957712023977e-13,  38: 3.2236120437603284e-14,  39: 1.1891442229157848e-09,  40: 1.9722902619993103e-15,  41: 3.0573768156523725e-10,  42: 5.284140000094136e-13,  43: 1.5448013907032131e-10,  44: 7.0024719898054645e-15,  45: 6.138880462179589e-23,  46: 1.260933143160699e-15,  47: 3.1792428354029705e-10,  48: 9.995661436079378e-14,  49: 5.663662550971553e-16,  50: 8.985526424800377e-18,  51: 3.479470811732457e-16,  52: 1.8411911151991907e-16,  53: 6.014861995089492e-25,  54: 1.0460221965227395e-13,  55: 2.2161883056640783e-17,  56: 3.0371205429339787e-13,  57: 3.9059265447378243e-13,  58: 8.431615268098884e-12,  59: 4.775310603434865e-10,  60: 7.178922635665852e-14,  61: 2.303750724454415e-10,  62: 1.6399836408621235e-13,  63: 9.059816879783715e-13,  64: 1.204569861311711e-12,  65: 2.0206695865031807e-09,  66: 4.308746263485896e-12,  67: 7.270048389800469e-17,  68: 4.015330791477852e-12,  69: 1.4607731640812475e-14,  70: 2.27289152689229e-15,  71: 1.533185591851643e-10,  72: 2.437188500830672e-11,  73: 2.354289619584134e-10,  74: 2.556027255901073e-18,  75: 2.027493790150674e-12,  76: 2.9018783720921165e-16,  77: 1.8816620439383223e-21,  78: 5.41089097754921e-11,  79: 1.3922012526777266e-10,  80: 1.8009760557635485e-09,  81: 9.019715264014498e-09,  82: 1.0045783905957992e-13,  83: 4.06128748749541e-23,  84: 7.186141387620951e-15,  85: 1.8069989757881862e-11,  86: 6.039777570833787e-18,  87: 4.2787434602244877e-13,  88: 1.620598071305283e-17,  89: 2.407043487586143e-11,  90: 1.7704705578541354e-13,  91: 2.3620769632981546e-11,  92: 1.7255324593117903e-13,  93: 1.0035547715144568e-19,  94: 1.2495045027935546e-13,  95: 2.292019535606094e-14,  96: 1.2772818463927796e-21,  97: 4.8481852310263515e-12,  98: 8.41485747769262e-14,  99: 1.6392822552171742e-09}, 'cdr3_b_nuc_pgen_vj': {0: 4.1409227921143184e-19,  1: 3.478210575794524e-12,  2: 4.7294530042333246e-11,  3: 4.061453001167187e-10,  4: 4.3878287014439494e-13,  5: 1.6781288809188335e-15,  6: 9.480361762430535e-14,  7: 1.0298497889049737e-15,  8: 2.773314416268998e-12,  9: 2.587813597582129e-16,  10: 9.446806450562872e-13,  11: 1.7301862555380362e-18,  12: 5.766373888815899e-13,  13: 1.867902758609301e-15,  14: 8.652317996399047e-24,  15: 1.0872958221594489e-12,  16: 4.378019580851762e-11,  17: 2.456730068039153e-13,  18: 5.259615738201701e-12,  19: 1.119055454056516e-15,  20: 3.411678575717849e-11,  21: 5.678589327647393e-12,  22: 5.68549567198179e-19,  23: 2.9563666073996867e-17,  24: 2.4335009816717186e-15,  25: 3.3444319442394594e-15,  26: 6.332018308174928e-11,  27: 1.1546167741239983e-12,  28: 3.2307073678663144e-11,  29: 1.825278168804305e-20,  30: 1.0005956287934632e-11,  31: 4.571225099813873e-13,  32: 1.0970970628678228e-17,  33: 2.4913656698368696e-16,  34: 8.30679320691883e-12,  35: 1.562455866664884e-17,  36: 5.6416723250667425e-18,  37: 2.211810917128019e-13,  38: 4.817672354001842e-15,  39: 1.1891356800900881e-09,  40: 1.9722895200645596e-15,  41: 1.3811647335150806e-11,  42: 1.934179214468284e-14,  43: 1.1953499712297234e-11,  44: 2.8608865842953713e-15,  45: 1.3628154441750303e-23,  46: 5.197629280396177e-16,  47: 2.7481810004457766e-11,  48: 9.994708123921187e-14,  49: 5.657532924952974e-16,  50: 8.98544471013633e-18,  51: 3.8081295318087054e-17,  52: 1.8355861385298862e-16,  53: 2.451935176116424e-25,  54: 1.0447905251337959e-13,  55: 1.1737341377524506e-18,  56: 9.752702441431005e-15,  57: 9.849208628997563e-14,  58: 1.1611879995816127e-12,  59: 1.6073413462593622e-10,  60: 9.068702066945604e-16,  61: 2.242638057757804e-10,  62: 1.2966523755897978e-13,  63: 1.3172363965141576e-13,  64: 2.4629041680816547e-14,  65: 6.520257791700524e-11,  66: 3.200771578650519e-14,  67: 1.1081992752552407e-17,  68: 4.015161096886803e-12,  69: 4.98835112534432e-16,  70: 2.0895496379411486e-15,  71: 6.3270508026667134e-12,  72: 2.354973999722037e-11,  73: 2.100152109946426e-11,  74: 7.54502679675825e-20,  75: 4.2152253315825576e-14,  76: 2.822735194831518e-16,  77: 1.4118771108593716e-21,  78: 4.884134602317615e-12,  79: 1.374448267411574e-10,  80: 1.7041012916030437e-10,  81: 1.5594815028174447e-09,  82: 2.866822437802552e-15,  83: 2.5658568965911047e-24,  84: 5.553847931834292e-15,  85: 5.871340724179443e-13,  86: 1.2826332922908185e-18,  87: 4.2787434129342293e-13,  88: 1.6865627129038389e-18,  89: 2.406693182426464e-11,  90: 5.335938132972426e-14,  91: 3.524808517520173e-13,  92: 6.991026620010283e-14,  93: 4.2818941655342064e-21,  94: 1.249490384873736e-13,  95: 8.676999294829004e-16,  96: 1.2767117853239031e-21,  97: 4.920029440707552e-14,  98: 4.465892998345307e-15,  99: 1.1526578649034162e-10}})

human_a = pd.DataFrame({'v_a_gene': {0: 'TRAV4',  1: 'TRAV13-1',  2: 'TRAV19',  3: 'TRAV17',  4: 'TRAV13-1',  5: 'TRAV16',  6: 'TRAV26-1',  7: 'TRAV10',  8: 'TRAV13-1',  9: 'TRAV4'}, 'j_a_gene': {0: 'TRAJ37',  1: 'TRAJ49',  2: 'TRAJ47',  3: 'TRAJ57',  4: 'TRAJ47',  5: 'TRAJ40',  6: 'TRAJ30',  7: 'TRAJ48',  8: 'TRAJ10',  9: 'TRAJ3'}, 'cdr3_a_aa': {0: 'CLVGASSNTGKLIF',  1: 'CAASHTGNQFYF',  2: 'CALSETRGGNKLVF',  3: 'CALIITQGGSEKLVF',  4: 'CAASRWKLVF',  5: 'CALSGTYKYIF',  6: 'CIVRNVPRRDDKIIF',  7: 'CVVSAISNFGNEKLTF',  8: 'CAPRGAGGGNKLTF',  9: 'CLVGDSYSSASKIIF'}, 'cdr3_a_aa_pgen_naive': {0: 2.356257085606877e-06,  1: 5.674401511062899e-06,  2: 2.056949547985796e-09,  3: 5.414401015868125e-07,  4: 4.974986723045059e-09,  5: 9.769011261829654e-06,  6: 1.779310980955549e-11,  7: 1.0285379615056223e-06,  8: 1.0529872573526607e-08,  9: 7.55894850080523e-07}, 'cdr3_a_aa_pgen_vj': {0: 2.356095821265446e-06,  1: 3.2841340812881952e-06,  2: 1.923517237976596e-09,  3: 4.75210786000706e-09,  4: 1.4328067364929772e-09,  5: 7.686461509251469e-07,  6: 1.7792834967565246e-11,  7: 1.0099746880288588e-06,  8: 1.1907572266750828e-09,  9: 7.558932756495962e-07}, 'cdr3_a_nuc': {0: 'TGCCTCGTGGGTGCCTCTAGCAACACAGGCAAACTAATCTTT',  1: 'TGTGCAGCAAGTCACACCGGTAACCAGTTCTATTTT',  2: 'TGTGCTCTGAGTGAGACTAGGGGTGGAAACAAACTGGTCTTT',  3: 'TGTGCCCTAATTATAACTCAGGGCGGATCTGAAAAGCTGGTCTTT',  4: 'TGTGCAGCAAGTCGCTGGAAACTGGTCTTT',  5: 'TGTGCTCTATCAGGAACCTACAAATACATCTTT',  6: 'TGCATCGTCAGAAACGTCCCTCGTAGAGATGACAAGATCATCTTT',  7: 'TGTGTGGTGAGCGCGATATCTAACTTTGGAAATGAGAAATTAACCTTT',  8: 'TGTGCACCACGGGGGGCGGGAGGAGGAAACAAACTCACCTTT',  9: 'TGCCTCGTGGGTGACTCTTACAGCAGTGCTTCCAAGATAATCTTT'}, 'cdr3_a_nuc_pgen_naive': {0: 1.1142712274043998e-06,  1: 2.0523412968867407e-06,  2: 5.435809177786978e-11,  3: 2.050843267361052e-09,  4: 5.346030072407556e-11,  5: 5.42261576251427e-07,  6: 4.4147048976002436e-14,  7: 4.7506814685512685e-07,  8: 3.3207600247451725e-11,  9: 6.01057244903546e-08}, 'cdr3_a_nuc_pgen_vj': {0: 1.1142710428351316e-06,  1: 1.8138150205804282e-06,  2: 5.235023310571021e-11,  3: 1.038061181869578e-10,  4: 5.1459726766662146e-11,  5: 1.2006036071939807e-07,  6: 4.4147030613279436e-14,  7: 4.746203251840253e-07,  8: 1.3216271928249567e-11,  9: 6.010572443540152e-08}})

class test_olga_in_python3(unittest.TestCase):
    """

    Test that results obtained using python 3 modified version are
    the same as results produced in python 2.7 version available on via pip.

    July 2019, tcrdist made minor modifications to the original Olga code base.

    tcrdist2 authors UPDATED THE FOLLOWING CODE TO PYTHON 3
    USING COMMIT e825c333f0f9a4eb02132e0bcf86f0dca9123114 (Jan 18, 2019)

    ORIGINAL OLGA CODE CAN BE FOUND AT:
    https://github.com/zsethna/OLGA

    The test data was produced as follows (human_b)
    Installation:

    .. code-block:: bash

        virtualenv olga-env
        conda activate py27v
        source .source ./olga-env/bin/activate
        conda deactivate
        conda deactivate
        pip install olga
        pip install numpy
        pip install jupyterlab

    Python 2.7.11 |Continuum Analytics, Inc.| (default, Jun 15 2016, 16:09:16)
    [GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin

        Package                            Version
    ---------------------------------- -----------
    numpy                              1.16.4
    olga                               1.0.2

    .. code-block:: bash

        source ./olga-env/bin/activate
        olga-generate_sequences --humanTRB -o human_b_example_seqs.tsv -n 1e2
        olga-compute_pgen -i human_b_example_seqs.tsv --humanTRB -o human_b_example_pgens_wvj.tsv --v_in 2 --j_in 3
        olga-compute_pgen --humanTRB -i human_b_example_seqs.tsv -o human_b_example_pgens_no_vj.tsv

    Manual assignment of headers:
    - cdr3_b_aa_pgen_naive for example_pgens_no_vj.tsv
    - cdr3_b_aa_pgen_vj for example_pgens_wvj.tsv

    .. code-block:: python

        import pandas as pd
        x = pd.read_csv("human_b_example_pgens_wvj.tsv", sep = "\t", header =0)
        z = pd.read_csv("human_b_example_pgens_no_vj.tsv", sep = "\t", header = 0)
        y = pd.read_csv("human_b_example_seqs.tsv", sep = "\t", header = 0)
        data = pd.concat([x,
                      z[[ 'cdr3_b_aa_pgen_naive', 'cdr3_b_nuc_pgen_naive' ]],
                      y[['v_b_gene', 'j_b_gene']]], axis = 1)

        human_b_olga_ref_test_set = data[['v_b_gene',
                                          'j_b_gene',
                                          'cdr3_b_aa',
                                          'cdr3_b_aa_pgen_naive',
                                          'cdr3_b_aa_pgen_vj',
                                          'cdr3_b_nuc',
                                          'cdr3_b_nuc_pgen_naive',
                                          'cdr3_b_nuc_pgen_vj']]
        human_b_olga_ref_test_set.to_dict()

    # For Alpha Chain

    .. code-block:: bash

        source ./olga-env/bin/activate
        olga-generate_sequences --humanTRA -o human_a_example_seqs.tsv -n 10
        olga-compute_pgen -i human_a_example_seqs.tsv --humanTRA -o human_a_example_pgens_wvj.tsv --v_in 2 --j_in 3
        olga-compute_pgen --humanTRA -i human_a_example_seqs.tsv -o human_a_example_pgens_no_vj.tsv

    .. code-block:: python
        x = pd.read_csv("human_a_example_pgens_wvj.tsv", sep = "\t", header =0)
        z = pd.read_csv("human_a_example_pgens_no_vj.tsv", sep = "\t", header = 0)
        y = pd.read_csv("human_a_example_seqs.tsv", sep = "\t", header = 0)

        data = pd.concat([x,
                          z[[ 'cdr3_a_aa_pgen_naive', 'cdr3_a_nuc_pgen_naive' ]],
                          y[['v_a_gene', 'j_a_gene']]], axis = 1)

        human_a_olga_ref_test_set = data[['v_a_gene',
                                          'j_a_gene',
                                          'cdr3_a_aa',
                                          'cdr3_a_aa_pgen_naive',
                                          'cdr3_a_aa_pgen_vj',
                                          'cdr3_a_nuc',
                                          'cdr3_a_nuc_pgen_naive',
                                          'cdr3_a_nuc_pgen_vj']]
        human_a = human_a_olga_ref_test_set.to_dict()
    """

    def test_something(self):
        "this is a template"
        gravitational_waves = True
        self.assertTrue(gravitational_waves)

    def test_olga_update_to_python3_pgens_human_beta_naive(self):
        """
        Providing Only cdr3 Beta No V J Gene Usage Information (naive) for 100 Sequences
        """
        my_olga_model = pgen.OlgaModel(chain_folder = 'human_T_beta', recomb_type = "VDJ")
        r = my_olga_model.compute_aa_cdr3_pgens(human_b.cdr3_b_aa,
                                                None,
                                                None)
        r = np.array(r)
        self.assertTrue(np.allclose(r, human_b.cdr3_b_aa_pgen_naive))

    def test_olga_update_to_python3_pgens_human_beta_with_vj_specified(self):
        """
        Providing Only cdr3 Beta and V J gene usage for 100 Sequence
        """
        my_olga_model = pgen.OlgaModel(chain_folder = 'human_T_beta', recomb_type = "VDJ")
        r = my_olga_model.compute_aa_cdr3_pgens(human_b.cdr3_b_aa,
                                                human_b.v_b_gene,
                                                human_b.j_b_gene)

        r = np.array(r)
        self.assertTrue(np.allclose(r, human_b.cdr3_b_aa_pgen_vj))

    def test_olga_update_to_python3_pgens_human_alpha_naive(self):
        """
        Providing Only cdr3 alpha No Gene Usage for 10 Sequences
        """
        my_olga_model = pgen.OlgaModel(chain_folder = 'human_T_alpha', recomb_type = "VJ")
        r = my_olga_model.compute_aa_cdr3_pgens(human_a.cdr3_a_aa,
                                                None,
                                                None)
        """
        print("FOR HUMAN INSPECTION")
        for x,y in zip(human_a.cdr3_a_aa_pgen_naive, r):
            if not np.isclose(x,y):
                s = "*"
            else:
                s= ""
            print(x,y,s)"""
        r = np.array(r)
        self.assertTrue(np.allclose(r, human_a.cdr3_a_aa_pgen_naive))

    def test_olga_update_to_python3_pgens_human_alpha_with_vj_specified(self):
        """
        Providing cdr3 alpha and V J gene usage for 10 Sequence
        """
        my_olga_model = pgen.OlgaModel(chain_folder = 'human_T_alpha', recomb_type = "VJ")
        r = my_olga_model.compute_aa_cdr3_pgens(human_a.cdr3_a_aa,
                                                human_a.v_a_gene,
                                                human_a.j_a_gene)

        """
        print("FOR HUMAN INSPECTION")
        for x,y in zip(human_a.cdr3_a_aa_pgen_vj, r):
            if not np.isclose(x,y):
                s = "*"
            else:
                s= ""
            print(x,y,s)"""
        r = np.array(r)
        self.assertTrue(np.allclose(r, human_a.cdr3_a_aa_pgen_vj))

if __name__ == '__main__':
    unittest.main()

"""
Additional Information on Environment Used For Python 2.7
pip list
Package                            Version
---------------------------------- -----------
appnope                            0.1.0
attrs                              19.1.0
backports-abc                      0.5
backports.shutil-get-terminal-size 1.0.0
bleach                             3.1.0
configparser                       3.7.4
decorator                          4.4.0
defusedxml                         0.6.0
entrypoints                        0.3
enum34                             1.1.6
functools32                        3.2.3.post2
futures                            3.2.0
ipaddress                          1.0.22
ipykernel                          4.10.0
ipython                            5.8.0
ipython-genutils                   0.2.0
Jinja2                             2.10.1
jsonschema                         3.0.1
jupyter-client                     5.2.4
jupyter-core                       4.5.0
jupyterlab                         0.33.12
jupyterlab-launcher                0.11.2
MarkupSafe                         1.1.1
mistune                            0.8.4
nbconvert                          5.5.0
nbformat                           4.4.0
notebook                           5.7.8
numpy                              1.16.4
olga                               1.0.2
pandocfilters                      1.4.2
pathlib2                           2.3.3
pexpect                            4.7.0
pickleshare                        0.7.5
pip                                19.1.1
prometheus-client                  0.7.0
prompt-toolkit                     1.0.16
ptyprocess                         0.6.0
Pygments                           2.4.2
pyrsistent                         0.15.2
python-dateutil                    2.8.0
pyzmq                              18.0.1
scandir                            1.10.0
Send2Trash                         1.5.0
setuptools                         41.0.1
simplegeneric                      0.8.1
singledispatch                     3.4.0.3
six                                1.12.0
subprocess32                       3.5.4
terminado                          0.8.2
testpath                           0.4.2
tornado                            5.1.1
traitlets                          4.3.2
wcwidth                            0.1.7
webencodings                       0.5.1
wheel                              0.33.4
"""


text:
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import numpy as np

class nlcmap(LinearSegmentedColormap):
    """A nonlinear colormap"""

    name = 'nlcmap'

    def __init__(self, cmap, levels):
        self.cmap = cmap
        self.monochrome = self.cmap.monochrome
        self.levels = np.asarray(levels, dtype='float64')
        self._x = self.levels-self.levels.min()
        self._x/= self._x.max()
        self._y = np.linspace(0, 1, len(self.levels))

    def __call__(self, xi, alpha=1.0, **kw):
        yi = np.interp(xi, self._x, self._y)
        return self.cmap(yi, alpha)

max_stars_repo_name: GunnarBehrens/CBRAIN-CAM

max_issues_repo_name: GunnarBehrens/CBRAIN-CAM

max_forks_repo_name: GunnarBehrens/CBRAIN-CAM