Skip to content

Commit

Permalink
Merge pull request pyhrf#136 from thperret/ubuntu1404install
Browse files Browse the repository at this point in the history
[Fixes pyhrf#134, Closes pyhrf#135] 0.4.1.post1 release
  • Loading branch information
thperret committed Sep 14, 2015
2 parents 74d3413 + 52abda4 commit 9b64edf
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 3 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,31 @@ Current development

-----------------------------------

Release 0.4.1.post1
+++++++++++++++++++

Fixes:
------

- missing function (#135)
- nipy version required for installation (#134)

Release 0.4.1
+++++++++++++

Fixes:
------

- logging level not set by command line (#113)
- error with VEM algorithm (#115)

Enhancements:
-------------

- clean and update setup.py (#84)
- update travis configuration file (#123)


Release 0.4
+++++++++++

Expand Down
58 changes: 57 additions & 1 deletion python/pyhrf/vbjde/vem_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from numpy.matlib import *
from scipy.linalg import toeplitz
from scipy.optimize import fmin_slsqp

import pyhrf
import pyhrf.vbjde.UtilsC as UtilsC
Expand All @@ -32,7 +33,7 @@
# Tools
##############################################################

eps = 1e-6
eps = np.spacing(1)


def mult_old(v1, v2):
Expand Down Expand Up @@ -269,6 +270,61 @@ def roc_curve(dvals, labels, rocN=None, normalize=True):

return fpc, tpc, area


def norm1_constraint(function, variance):
"""Returns the function constrained with optimization strategy.
Parameters
----------
function : array_like
function to optimize under norm1 constraint
variance : array_like
variance of the `function`, must be the same size
Returns
-------
optimized_function : numpy array
Raises
------
ValueError
If `len(variance) != len(function)`
"""

variance_inv = np.linalg.inv(variance)

current_level = logger.getEffectiveLevel()
if current_level >= logging.WARNING:
disp = 0
elif current_level >= logging.INFO:
disp = 1
else:
disp = 2

def minimized_function(fct):
"""Function to minimize"""
return np.dot(np.dot((fct - function).T, variance_inv), (fct - function))

def norm1_constraint_equation(fct):
"""Norm2(fct) == 1"""
return np.linalg.norm(fct, 2) - 1

def first_element_constraint(fct):
"""fct[0] == 0"""
return fct[0]

def last_element_constraint(fct):
"""fct[-1] == 0"""
return fct[-1]

return fmin_slsqp(minimized_function, function,
eqcons=[norm1_constraint_equation,
first_element_constraint,
last_element_constraint],
bounds=[(None, None)] * (len(function)), disp=disp)


# Expectation functions
##############################################################

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@

setup(
name = "pyhrf",
version = "0.4.1",
version = "0.4.1.post1",
description = ("PyHRF is a set of tools to analyze fMRI data and "
"specifically study hemodynamics."),
long_description = open("README.rst").read(),
Expand All @@ -73,7 +73,7 @@
"matplotlib>=1.1,<1.4",
"nibabel>=1.1",
"sympy>=0.7",
"nipy==0.3.0"],
"nipy>=0.3.0"],
extras_require = {"Ward": ["scikit-learn>=0.10"],
"parallel": ["joblib>=0.5"],
"cluster": ["soma-workflow"],
Expand Down

0 comments on commit 9b64edf

Please sign in to comment.