Skip to content

Commit

Permalink
v0.15: Fixed n=1 test bug and bugs with MSLL
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Marquand committed Aug 31, 2020
1 parent 6bd2681 commit 4d9fd55
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
17 changes: 12 additions & 5 deletions pcntoolkit/normative.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,13 @@ def evaluate(Y, Yhat, S2=None, mY=None, sY=None,

feature_num = Y.shape[1]

# Remove metrics that cannot be computed with only a single data point
if Y.shape[0] == 1:
if 'MSLL' in metrics:
metrics.remove('MSLL')
if 'SMSE' in metrics:
metrics.remove('SMSE')

# find and remove bad variables from the response variables
nz = np.where(np.bitwise_and(np.isfinite(Y).any(axis=0),
np.var(Y, axis=0) != 0))[0]
Expand Down Expand Up @@ -163,8 +170,8 @@ def evaluate(Y, Yhat, S2=None, mY=None, sY=None,
if ((S2 is not None) and (mY is not None) and (sY is not None)):
MSLL = np.zeros(feature_num)
MSLL[nz] = compute_MSLL(Y[:,nz], Yhat[:,nz], S2[:,nz],
mY[nz].reshape(-1,1).T,
(sY[nz]**2).reshape(-1,1).T)
mY.reshape(-1,1).T,
(sY**2).reshape(-1,1).T)
results['MSLL'] = MSLL

return results
Expand Down Expand Up @@ -292,18 +299,18 @@ def estimate(covfile, respfile, **kwargs):
run_cv = False
cvfolds = 1
Xte = fileio.load(testcov)
testids = range(X.shape[0], X.shape[0]+Xte.shape[0])
if len(Xte.shape) == 1:
Xte = Xte[:, np.newaxis]
Xte = Xte[:, np.newaxis].T
if testresp is not None:
Yte, testmask = load_response_vars(testresp, maskfile)
if len(Yte.shape) == 1:
Yte = Yte[:, np.newaxis]
Yte = Yte[:, np.newaxis].T
else:
sub_te = Xte.shape[0]
Yte = np.zeros([sub_te, Nmod])

# treat as a single train-test split
testids = range(X.shape[0], X.shape[0]+Xte.shape[0])
splits = CustomCV((range(0, X.shape[0]),), (testids,))

Y = np.concatenate((Y, Yte), axis=0)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(name='pcntoolkit',
version='0.14',
version='0.15',
description='Predictive Clinical Neuroscience toolkit',
url='http://github.com/amarquand/nispat',
author='Andre Marquand',
Expand Down
12 changes: 6 additions & 6 deletions tests/unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
# To fully evaluate the user test cases, this should be run in two ways:

# 1. as a package
from pcntoolkit.normative import estimate
from pcntoolkit.normative_parallel import execute_nm, collect_nm, delete_nm
#from pcntoolkit.normative import estimate
#from pcntoolkit.normative_parallel import execute_nm, collect_nm, delete_nm

## 2. by appending to the path
##sys.path.clear()
#sys.path.append('/home/preclineu/andmar/sfw/pcntoolkit/pcntoolkit')
#from normative import estimate
#from normative_parallel import execute_nm, collect_nm, delete_nm
sys.path.append('/home/preclineu/andmar/sfw/PCNtoolkit/pcntoolkit')
from normative import estimate
from normative_parallel import execute_nm, collect_nm, delete_nm

# ---------------- Config parameters -----------------------------------------

Expand All @@ -25,7 +25,7 @@
python_path='/home/preclineu/andmar/sfw/anaconda3/envs/py36/bin/python'
data_dir = '/home/preclineu/andmar/data/nispat_unit_test_data/'
test_dir = '/home/preclineu/andmar/py.sandbox/unittests/unit_test_results'
alt_alg = 'blr' # alogrithm to test in addition to GPR
alt_alg = 'blr' # algorithm to test in addition to GPR

# cluster paramateters
job_name = 'nm_unit_test'
Expand Down

0 comments on commit 4d9fd55

Please sign in to comment.